2015-07-07 00:54:22 +00:00
|
|
|
// Copyright 2014 The go-ethereum Authors
|
2015-07-22 16:48:40 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 00:54:22 +00:00
|
|
|
//
|
2015-07-23 16:35:11 +00:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-07 00:54:22 +00:00
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
2015-07-22 16:48:40 +00:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-07 00:54:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 16:48:40 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 00:54:22 +00:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 16:48:40 +00:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 00:54:22 +00:00
|
|
|
|
2015-07-07 03:08:16 +00:00
|
|
|
// Package p2p implements the Ethereum p2p network protocols.
|
2014-10-23 15:57:54 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
"bytes"
|
2022-02-22 18:18:43 +00:00
|
|
|
"context"
|
2015-02-05 02:07:58 +00:00
|
|
|
"crypto/ecdsa"
|
2018-10-12 09:47:24 +00:00
|
|
|
"encoding/hex"
|
2014-11-21 20:48:49 +00:00
|
|
|
"errors"
|
2019-06-11 10:45:33 +00:00
|
|
|
"fmt"
|
2014-10-23 15:57:54 +00:00
|
|
|
"net"
|
2018-10-12 09:47:24 +00:00
|
|
|
"sort"
|
2014-10-23 15:57:54 +00:00
|
|
|
"sync"
|
2018-06-08 01:50:08 +00:00
|
|
|
"sync/atomic"
|
2014-10-23 15:57:54 +00:00
|
|
|
"time"
|
|
|
|
|
2022-07-08 09:14:16 +00:00
|
|
|
"golang.org/x/sync/semaphore"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
2021-06-13 16:41:39 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common/debug"
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common/mclock"
|
|
|
|
"github.com/ledgerwatch/erigon/crypto"
|
|
|
|
"github.com/ledgerwatch/erigon/event"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p/discover"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p/enode"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p/enr"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p/nat"
|
|
|
|
"github.com/ledgerwatch/erigon/p2p/netutil"
|
2021-07-29 10:23:23 +00:00
|
|
|
"github.com/ledgerwatch/log/v3"
|
2014-10-23 15:57:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2018-02-22 17:20:28 +00:00
|
|
|
defaultDialTimeout = 15 * time.Second
|
2015-03-04 15:27:37 +00:00
|
|
|
|
2019-10-29 15:08:57 +00:00
|
|
|
// This is the fairness knob for the discovery mixer. When looking for peers, we'll
|
|
|
|
// wait this long for a single source of candidates before moving on and trying other
|
|
|
|
// sources.
|
|
|
|
discmixTimeout = 5 * time.Second
|
|
|
|
|
2018-02-12 12:36:09 +00:00
|
|
|
// Connectivity defaults.
|
2022-04-28 02:21:52 +00:00
|
|
|
defaultDialRatio = 3
|
2015-04-30 12:06:05 +00:00
|
|
|
|
2019-06-11 10:45:33 +00:00
|
|
|
// This time limits inbound connection attempts per source IP.
|
|
|
|
inboundThrottleTime = 30 * time.Second
|
|
|
|
|
2015-05-22 13:38:17 +00:00
|
|
|
// Maximum time allowed for reading a complete message.
|
|
|
|
// This is effectively the amount of time a connection can be idle.
|
|
|
|
frameReadTimeout = 30 * time.Second
|
|
|
|
|
|
|
|
// Maximum amount of time allowed for writing a complete message.
|
2015-06-09 10:10:40 +00:00
|
|
|
frameWriteTimeout = 20 * time.Second
|
2014-10-23 15:57:54 +00:00
|
|
|
)
|
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
var errServerStopped = errors.New("server stopped")
|
|
|
|
|
2016-05-18 09:31:00 +00:00
|
|
|
// Config holds Server options.
|
|
|
|
type Config struct {
|
2015-02-05 02:07:58 +00:00
|
|
|
// This field must be set to a valid secp256k1 private key.
|
2017-04-12 14:27:23 +00:00
|
|
|
PrivateKey *ecdsa.PrivateKey `toml:"-"`
|
2014-11-21 20:48:49 +00:00
|
|
|
|
|
|
|
// MaxPeers is the maximum number of peers that can be
|
|
|
|
// connected. It must be greater than zero.
|
|
|
|
MaxPeers int
|
|
|
|
|
2015-05-04 14:35:49 +00:00
|
|
|
// MaxPendingPeers is the maximum number of peers that can be pending in the
|
|
|
|
// handshake phase, counted separately for inbound and outbound connections.
|
2022-04-28 02:21:52 +00:00
|
|
|
// It must be greater than zero.
|
2017-04-12 14:27:23 +00:00
|
|
|
MaxPendingPeers int `toml:",omitempty"`
|
2015-05-04 14:35:49 +00:00
|
|
|
|
2018-02-12 12:36:09 +00:00
|
|
|
// DialRatio controls the ratio of inbound to dialed connections.
|
|
|
|
// Example: a DialRatio of 2 allows 1/2 of connections to be dialed.
|
|
|
|
// Setting DialRatio to zero defaults it to 3.
|
|
|
|
DialRatio int `toml:",omitempty"`
|
|
|
|
|
2017-04-12 14:27:23 +00:00
|
|
|
// NoDiscovery can be used to disable the peer discovery mechanism.
|
|
|
|
// Disabling is useful for protocol debugging (manual topology).
|
|
|
|
NoDiscovery bool
|
2015-05-26 16:07:24 +00:00
|
|
|
|
2018-08-27 08:49:29 +00:00
|
|
|
// DiscoveryV5 specifies whether the new topic-discovery based V5 discovery
|
2016-11-09 14:35:04 +00:00
|
|
|
// protocol should be started or not.
|
2017-04-12 14:27:23 +00:00
|
|
|
DiscoveryV5 bool `toml:",omitempty"`
|
2016-10-19 11:04:55 +00:00
|
|
|
|
2015-02-05 02:07:58 +00:00
|
|
|
// Name sets the node name of this server.
|
2015-03-16 10:27:38 +00:00
|
|
|
// Use common.MakeName to create a name that follows existing conventions.
|
2017-04-12 14:27:23 +00:00
|
|
|
Name string `toml:"-"`
|
2015-02-05 02:07:58 +00:00
|
|
|
|
2016-11-09 14:35:04 +00:00
|
|
|
// BootstrapNodes are used to establish connectivity
|
2015-02-05 02:07:58 +00:00
|
|
|
// with the rest of the network.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
BootstrapNodes []*enode.Node
|
2015-02-05 02:07:58 +00:00
|
|
|
|
2016-11-09 14:35:04 +00:00
|
|
|
// BootstrapNodesV5 are used to establish connectivity
|
|
|
|
// with the rest of the network using the V5 discovery
|
|
|
|
// protocol.
|
2021-01-26 20:41:35 +00:00
|
|
|
BootstrapNodesV5 []*enode.Node `toml:",omitempty"`
|
2016-11-09 14:35:04 +00:00
|
|
|
|
2015-04-30 16:32:48 +00:00
|
|
|
// Static nodes are used as pre-configured connections which are always
|
|
|
|
// maintained and re-connected on disconnects.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
StaticNodes []*enode.Node
|
2015-04-29 15:04:08 +00:00
|
|
|
|
2015-05-04 10:59:51 +00:00
|
|
|
// Trusted nodes are used as pre-configured connections which are always
|
|
|
|
// allowed to connect, even above the peer limit.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
TrustedNodes []*enode.Node
|
2015-05-04 10:59:51 +00:00
|
|
|
|
2016-11-22 19:51:59 +00:00
|
|
|
// Connectivity can be restricted to certain IP networks.
|
|
|
|
// If this option is set to a non-nil value, only hosts which match one of the
|
|
|
|
// IP networks contained in the list are considered.
|
2017-04-12 14:27:23 +00:00
|
|
|
NetRestrict *netutil.Netlist `toml:",omitempty"`
|
2016-11-22 19:51:59 +00:00
|
|
|
|
2015-04-24 15:04:41 +00:00
|
|
|
// NodeDatabase is the path to the database containing the previously seen
|
|
|
|
// live nodes in the network.
|
2017-04-12 14:27:23 +00:00
|
|
|
NodeDatabase string `toml:",omitempty"`
|
2015-04-23 15:47:24 +00:00
|
|
|
|
2014-11-21 20:48:49 +00:00
|
|
|
// Protocols should contain the protocols supported
|
|
|
|
// by the server. Matching protocols are launched for
|
|
|
|
// each peer.
|
2017-04-12 14:27:23 +00:00
|
|
|
Protocols []Protocol `toml:"-"`
|
2014-11-21 20:48:49 +00:00
|
|
|
|
|
|
|
// If ListenAddr is set to a non-nil address, the server
|
|
|
|
// will listen for incoming connections.
|
|
|
|
//
|
|
|
|
// If the port is zero, the operating system will pick a port. The
|
|
|
|
// ListenAddr field will be updated with the actual address when
|
|
|
|
// the server is started.
|
2022-07-08 09:14:16 +00:00
|
|
|
ListenAddr string
|
|
|
|
|
|
|
|
// eth/66, eth/67, etc
|
|
|
|
ProtocolVersion uint
|
|
|
|
|
|
|
|
SentryAddr []string
|
2014-11-21 20:48:49 +00:00
|
|
|
|
|
|
|
// If set to a non-nil value, the given NAT port mapper
|
|
|
|
// is used to make the listening port available to the
|
|
|
|
// Internet.
|
2017-04-12 14:27:23 +00:00
|
|
|
NAT nat.Interface `toml:",omitempty"`
|
2014-11-21 20:48:49 +00:00
|
|
|
|
|
|
|
// If Dialer is set to a non-nil value, the given Dialer
|
|
|
|
// is used to dial outbound peer connections.
|
2017-09-25 08:08:07 +00:00
|
|
|
Dialer NodeDialer `toml:"-"`
|
2014-11-21 20:48:49 +00:00
|
|
|
|
|
|
|
// If NoDial is true, the server will not dial any peers.
|
2017-04-12 14:27:23 +00:00
|
|
|
NoDial bool `toml:",omitempty"`
|
2017-09-25 08:08:07 +00:00
|
|
|
|
|
|
|
// If EnableMsgEvents is set then the server will emit PeerEvents
|
|
|
|
// whenever a message is sent to or received from a peer
|
|
|
|
EnableMsgEvents bool
|
2017-12-01 11:49:04 +00:00
|
|
|
|
2022-02-22 18:17:15 +00:00
|
|
|
// Log is a custom logger to use with the p2p.Server.
|
|
|
|
Log log.Logger `toml:",omitempty"`
|
2020-02-13 10:10:03 +00:00
|
|
|
|
2020-02-21 15:25:11 +00:00
|
|
|
// it is actually used but a linter got confused
|
|
|
|
clock mclock.Clock //nolint:structcheck
|
2016-05-18 09:31:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Server manages all peer connections.
|
|
|
|
type Server struct {
|
|
|
|
// Config fields may not be modified while the server is running.
|
|
|
|
Config
|
2014-11-21 20:48:49 +00:00
|
|
|
|
2015-02-05 02:07:58 +00:00
|
|
|
// Hooks for testing. These are useful because we can inhibit
|
2014-11-21 20:48:49 +00:00
|
|
|
// the whole protocol stack.
|
2020-09-22 08:17:39 +00:00
|
|
|
newTransport func(net.Conn, *ecdsa.PublicKey) transport
|
2015-05-15 22:38:28 +00:00
|
|
|
newPeerHook func(*Peer)
|
2019-06-11 10:45:33 +00:00
|
|
|
listenFunc func(network, addr string) (net.Listener, error)
|
2015-05-15 22:38:28 +00:00
|
|
|
|
|
|
|
lock sync.Mutex // protects running
|
|
|
|
running bool
|
2014-10-23 15:57:54 +00:00
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
listener net.Listener
|
2015-02-19 00:52:03 +00:00
|
|
|
ourHandshake *protoHandshake
|
2019-06-11 10:45:33 +00:00
|
|
|
loopWG sync.WaitGroup // loop, listenLoop
|
|
|
|
peerFeed event.Feed
|
|
|
|
log log.Logger
|
|
|
|
|
2019-10-29 15:08:57 +00:00
|
|
|
nodedb *enode.DB
|
|
|
|
localnode *enode.LocalNode
|
|
|
|
ntab *discover.UDPv4
|
2021-01-26 20:41:35 +00:00
|
|
|
DiscV5 *discover.UDPv5
|
2019-10-29 15:08:57 +00:00
|
|
|
discmix *enode.FairMix
|
2020-02-13 10:10:03 +00:00
|
|
|
dialsched *dialScheduler
|
2019-10-29 15:08:57 +00:00
|
|
|
|
2019-06-11 10:45:33 +00:00
|
|
|
// Channels into the run loop.
|
2022-04-28 02:21:52 +00:00
|
|
|
quitCtx context.Context
|
|
|
|
quitFunc context.CancelFunc
|
|
|
|
quit <-chan struct{}
|
2019-06-11 10:45:33 +00:00
|
|
|
addtrusted chan *enode.Node
|
|
|
|
removetrusted chan *enode.Node
|
|
|
|
peerOp chan peerOpFunc
|
|
|
|
peerOpDone chan struct{}
|
|
|
|
delpeer chan peerDrop
|
|
|
|
checkpointPostHandshake chan *conn
|
|
|
|
checkpointAddPeer chan *conn
|
|
|
|
|
|
|
|
// State of run loop and listenLoop.
|
|
|
|
inboundHistory expHeap
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
type peerOpFunc func(map[enode.ID]*Peer)
|
2015-05-15 22:38:28 +00:00
|
|
|
|
2017-02-24 08:58:04 +00:00
|
|
|
type peerDrop struct {
|
|
|
|
*Peer
|
|
|
|
err error
|
|
|
|
requested bool // true if signaled by the peer
|
|
|
|
}
|
|
|
|
|
2018-06-08 01:50:08 +00:00
|
|
|
type connFlag int32
|
2015-02-05 02:07:58 +00:00
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
const (
|
|
|
|
dynDialedConn connFlag = 1 << iota
|
|
|
|
staticDialedConn
|
|
|
|
inboundConn
|
|
|
|
trustedConn
|
|
|
|
)
|
|
|
|
|
|
|
|
// conn wraps a network connection with information gathered
|
|
|
|
// during the two handshakes.
|
|
|
|
type conn struct {
|
|
|
|
fd net.Conn
|
|
|
|
transport
|
2022-04-10 07:01:25 +00:00
|
|
|
node *enode.Node
|
|
|
|
flags connFlag
|
|
|
|
cont chan error // The run loop uses cont to signal errors to SetupConn.
|
|
|
|
caps []Cap // valid after the protocol handshake
|
|
|
|
name string // valid after the protocol handshake
|
|
|
|
pubkey [64]byte
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
2015-02-05 02:07:58 +00:00
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
type transport interface {
|
|
|
|
// The two handshakes.
|
2020-09-22 08:17:39 +00:00
|
|
|
doEncHandshake(prv *ecdsa.PrivateKey) (*ecdsa.PublicKey, error)
|
2015-05-15 22:38:28 +00:00
|
|
|
doProtoHandshake(our *protoHandshake) (*protoHandshake, error)
|
|
|
|
// The MsgReadWriter can only be used after the encryption
|
|
|
|
// handshake has completed. The code uses conn.id to track this
|
|
|
|
// by setting it to a non-nil value after the encryption handshake.
|
|
|
|
MsgReadWriter
|
2021-11-21 19:36:26 +00:00
|
|
|
// transports must provide Close because we use MsgPipe in some
|
|
|
|
// tests. Closing the actual network connection doesn't do
|
2018-11-08 11:25:14 +00:00
|
|
|
// anything in those tests because MsgPipe doesn't use it.
|
2015-05-15 22:38:28 +00:00
|
|
|
close(err error)
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
func (c *conn) String() string {
|
2017-02-24 08:58:04 +00:00
|
|
|
s := c.flags.String()
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
if (c.node.ID() != enode.ID{}) {
|
|
|
|
s += " " + c.node.ID().String()
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
s += " " + c.fd.RemoteAddr().String()
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f connFlag) String() string {
|
|
|
|
s := ""
|
|
|
|
if f&trustedConn != 0 {
|
2017-02-24 08:58:04 +00:00
|
|
|
s += "-trusted"
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
if f&dynDialedConn != 0 {
|
2017-02-24 08:58:04 +00:00
|
|
|
s += "-dyndial"
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
if f&staticDialedConn != 0 {
|
2017-02-24 08:58:04 +00:00
|
|
|
s += "-staticdial"
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
if f&inboundConn != 0 {
|
2017-02-24 08:58:04 +00:00
|
|
|
s += "-inbound"
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
if s != "" {
|
|
|
|
s = s[1:]
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *conn) is(f connFlag) bool {
|
2018-06-08 01:50:08 +00:00
|
|
|
flags := connFlag(atomic.LoadInt32((*int32)(&c.flags)))
|
|
|
|
return flags&f != 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *conn) set(f connFlag, val bool) {
|
2018-08-06 12:46:30 +00:00
|
|
|
for {
|
|
|
|
oldFlags := connFlag(atomic.LoadInt32((*int32)(&c.flags)))
|
|
|
|
flags := oldFlags
|
|
|
|
if val {
|
|
|
|
flags |= f
|
|
|
|
} else {
|
|
|
|
flags &= ^f
|
|
|
|
}
|
|
|
|
if atomic.CompareAndSwapInt32((*int32)(&c.flags), int32(oldFlags), int32(flags)) {
|
|
|
|
return
|
|
|
|
}
|
2018-06-08 01:50:08 +00:00
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
2014-10-23 15:57:54 +00:00
|
|
|
|
2019-07-08 15:53:47 +00:00
|
|
|
// LocalNode returns the local node record.
|
|
|
|
func (srv *Server) LocalNode() *enode.LocalNode {
|
|
|
|
return srv.localnode
|
|
|
|
}
|
|
|
|
|
2014-11-21 20:48:49 +00:00
|
|
|
// Peers returns all connected peers.
|
2015-05-15 22:38:28 +00:00
|
|
|
func (srv *Server) Peers() []*Peer {
|
|
|
|
var ps []*Peer
|
2020-02-13 10:10:03 +00:00
|
|
|
srv.doPeerOp(func(peers map[enode.ID]*Peer) {
|
2015-05-15 22:38:28 +00:00
|
|
|
for _, p := range peers {
|
|
|
|
ps = append(ps, p)
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
2020-02-13 10:10:03 +00:00
|
|
|
})
|
2015-05-15 22:38:28 +00:00
|
|
|
return ps
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2020-10-06 19:25:01 +00:00
|
|
|
func (srv *Server) SetP2PListenFunc(listenFunc func(network, addr string) (net.Listener, error)) {
|
|
|
|
srv.listenFunc = listenFunc
|
|
|
|
}
|
|
|
|
|
2014-11-21 20:48:49 +00:00
|
|
|
// PeerCount returns the number of connected peers.
|
|
|
|
func (srv *Server) PeerCount() int {
|
2015-05-15 22:38:28 +00:00
|
|
|
var count int
|
2020-02-13 10:10:03 +00:00
|
|
|
srv.doPeerOp(func(ps map[enode.ID]*Peer) {
|
|
|
|
count = len(ps)
|
|
|
|
})
|
2015-05-15 22:38:28 +00:00
|
|
|
return count
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 10:10:03 +00:00
|
|
|
// AddPeer adds the given node to the static node set. When there is room in the peer set,
|
|
|
|
// the server will connect to the node. If the connection fails for any reason, the server
|
|
|
|
// will attempt to reconnect the peer.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
func (srv *Server) AddPeer(node *enode.Node) {
|
2020-02-13 10:10:03 +00:00
|
|
|
srv.dialsched.addStatic(node)
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 10:10:03 +00:00
|
|
|
// RemovePeer removes a node from the static node set. It also disconnects from the given
|
|
|
|
// node if it is currently connected as a peer.
|
|
|
|
//
|
|
|
|
// This method blocks until all protocols have exited and the peer is removed. Do not use
|
|
|
|
// RemovePeer in protocol implementations, call Disconnect on the Peer instead.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
func (srv *Server) RemovePeer(node *enode.Node) {
|
2020-02-13 10:10:03 +00:00
|
|
|
var (
|
|
|
|
ch chan *PeerEvent
|
|
|
|
sub event.Subscription
|
|
|
|
)
|
|
|
|
// Disconnect the peer on the main loop.
|
|
|
|
srv.doPeerOp(func(peers map[enode.ID]*Peer) {
|
|
|
|
srv.dialsched.removeStatic(node)
|
|
|
|
if peer := peers[node.ID()]; peer != nil {
|
|
|
|
ch = make(chan *PeerEvent, 1)
|
|
|
|
sub = srv.peerFeed.Subscribe(ch)
|
|
|
|
peer.Disconnect(DiscRequested)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// Wait for the peer connection to end.
|
|
|
|
if ch != nil {
|
|
|
|
defer sub.Unsubscribe()
|
|
|
|
for ev := range ch {
|
|
|
|
if ev.Peer == node.ID() && ev.Type == PeerEventTypeDrop {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2016-06-24 20:27:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-25 20:39:29 +00:00
|
|
|
// AddTrustedPeer adds the given node to a reserved whitelist which allows the
|
|
|
|
// node to always connect, even if the slot are full.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
func (srv *Server) AddTrustedPeer(node *enode.Node) {
|
2018-02-25 20:39:29 +00:00
|
|
|
select {
|
|
|
|
case srv.addtrusted <- node:
|
|
|
|
case <-srv.quit:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveTrustedPeer removes the given node from the trusted peer set.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
func (srv *Server) RemoveTrustedPeer(node *enode.Node) {
|
2018-02-25 20:39:29 +00:00
|
|
|
select {
|
|
|
|
case srv.removetrusted <- node:
|
|
|
|
case <-srv.quit:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-21 19:36:26 +00:00
|
|
|
// SubscribeEvents subscribes the given channel to peer events.
|
2017-09-25 08:08:07 +00:00
|
|
|
func (srv *Server) SubscribeEvents(ch chan *PeerEvent) event.Subscription {
|
|
|
|
return srv.peerFeed.Subscribe(ch)
|
|
|
|
}
|
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
// Self returns the local node's endpoint information.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
func (srv *Server) Self() *enode.Node {
|
2015-04-30 09:41:27 +00:00
|
|
|
srv.lock.Lock()
|
2018-10-12 09:47:24 +00:00
|
|
|
ln := srv.localnode
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
srv.lock.Unlock()
|
2015-05-26 16:16:05 +00:00
|
|
|
|
2018-10-12 09:47:24 +00:00
|
|
|
if ln == nil {
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
return enode.NewV4(&srv.PrivateKey.PublicKey, net.ParseIP("0.0.0.0"), 0, 0)
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
2018-10-12 09:47:24 +00:00
|
|
|
return ln.Node()
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
// Stop terminates the server and all active peer connections.
|
|
|
|
// It blocks until all active connections have been closed.
|
|
|
|
func (srv *Server) Stop() {
|
|
|
|
srv.lock.Lock()
|
|
|
|
if !srv.running {
|
2022-02-04 06:04:37 +00:00
|
|
|
if srv.nodedb != nil {
|
|
|
|
srv.nodedb.Close()
|
|
|
|
}
|
2018-07-30 09:44:17 +00:00
|
|
|
srv.lock.Unlock()
|
2015-05-15 22:38:28 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
srv.running = false
|
2022-04-28 02:21:52 +00:00
|
|
|
srv.quitFunc()
|
2015-05-15 22:38:28 +00:00
|
|
|
if srv.listener != nil {
|
|
|
|
// this unblocks listener Accept
|
2022-04-28 02:21:52 +00:00
|
|
|
_ = srv.listener.Close()
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
2022-02-04 06:04:37 +00:00
|
|
|
if srv.nodedb != nil {
|
|
|
|
srv.nodedb.Close()
|
|
|
|
}
|
2018-07-30 09:44:17 +00:00
|
|
|
srv.lock.Unlock()
|
2015-05-15 22:38:28 +00:00
|
|
|
srv.loopWG.Wait()
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2018-01-22 12:38:34 +00:00
|
|
|
// sharedUDPConn implements a shared connection. Write sends messages to the underlying connection while read returns
|
|
|
|
// messages that were found unprocessable and sent to the unhandled channel by the primary listener.
|
|
|
|
type sharedUDPConn struct {
|
|
|
|
*net.UDPConn
|
|
|
|
unhandled chan discover.ReadPacket
|
|
|
|
}
|
|
|
|
|
2021-01-26 20:41:35 +00:00
|
|
|
// ReadFromUDP implements discover.UDPConn
|
2018-01-22 12:38:34 +00:00
|
|
|
func (s *sharedUDPConn) ReadFromUDP(b []byte) (n int, addr *net.UDPAddr, err error) {
|
|
|
|
packet, ok := <-s.unhandled
|
|
|
|
if !ok {
|
2019-11-19 16:16:08 +00:00
|
|
|
return 0, nil, errors.New("connection was closed")
|
2018-01-22 12:38:34 +00:00
|
|
|
}
|
|
|
|
l := len(packet.Data)
|
|
|
|
if l > len(b) {
|
|
|
|
l = len(b)
|
|
|
|
}
|
|
|
|
copy(b[:l], packet.Data[:l])
|
|
|
|
return l, packet.Addr, nil
|
|
|
|
}
|
|
|
|
|
2021-01-26 20:41:35 +00:00
|
|
|
// Close implements discover.UDPConn
|
2018-01-22 12:38:34 +00:00
|
|
|
func (s *sharedUDPConn) Close() error {
|
|
|
|
return nil
|
|
|
|
}
|
2021-05-30 02:53:30 +00:00
|
|
|
func (srv *Server) Running() bool {
|
|
|
|
srv.lock.Lock()
|
|
|
|
defer srv.lock.Unlock()
|
|
|
|
return srv.running
|
|
|
|
}
|
2018-01-22 12:38:34 +00:00
|
|
|
|
2014-11-21 20:48:49 +00:00
|
|
|
// Start starts running the server.
|
2015-05-15 22:38:28 +00:00
|
|
|
// Servers can not be re-used after stopping.
|
2022-02-22 18:18:43 +00:00
|
|
|
func (srv *Server) Start(ctx context.Context) error {
|
2014-11-21 20:48:49 +00:00
|
|
|
srv.lock.Lock()
|
|
|
|
defer srv.lock.Unlock()
|
|
|
|
if srv.running {
|
|
|
|
return errors.New("server already running")
|
|
|
|
}
|
2021-11-21 19:36:26 +00:00
|
|
|
|
2022-02-22 18:17:15 +00:00
|
|
|
srv.log = srv.Config.Log
|
2017-12-01 11:49:04 +00:00
|
|
|
if srv.log == nil {
|
2019-06-11 10:45:33 +00:00
|
|
|
srv.log = log.Root()
|
2017-12-01 11:49:04 +00:00
|
|
|
}
|
2020-02-13 10:10:03 +00:00
|
|
|
if srv.clock == nil {
|
|
|
|
srv.clock = mclock.System{}
|
|
|
|
}
|
2018-10-12 09:47:24 +00:00
|
|
|
if srv.NoDial && srv.ListenAddr == "" {
|
|
|
|
srv.log.Warn("P2P server will be useless, neither dialing nor listening")
|
|
|
|
}
|
2014-11-21 20:48:49 +00:00
|
|
|
|
2015-02-19 16:08:18 +00:00
|
|
|
// static fields
|
2015-02-05 02:07:58 +00:00
|
|
|
if srv.PrivateKey == nil {
|
2018-11-30 21:38:37 +00:00
|
|
|
return errors.New("Server.PrivateKey must be set to a non-nil key")
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
2022-04-28 02:21:52 +00:00
|
|
|
if srv.MaxPendingPeers <= 0 {
|
|
|
|
return errors.New("MaxPendingPeers must be greater than zero")
|
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
if srv.newTransport == nil {
|
|
|
|
srv.newTransport = newRLPX
|
2015-04-29 15:04:08 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
if srv.listenFunc == nil {
|
|
|
|
srv.listenFunc = net.Listen
|
|
|
|
}
|
2022-04-28 02:21:52 +00:00
|
|
|
srv.quitCtx, srv.quitFunc = context.WithCancel(ctx)
|
|
|
|
srv.quit = srv.quitCtx.Done()
|
2017-02-24 08:58:04 +00:00
|
|
|
srv.delpeer = make(chan peerDrop)
|
2019-06-11 10:45:33 +00:00
|
|
|
srv.checkpointPostHandshake = make(chan *conn)
|
|
|
|
srv.checkpointAddPeer = make(chan *conn)
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
srv.addtrusted = make(chan *enode.Node)
|
|
|
|
srv.removetrusted = make(chan *enode.Node)
|
2015-05-15 22:38:28 +00:00
|
|
|
srv.peerOp = make(chan peerOpFunc)
|
|
|
|
srv.peerOpDone = make(chan struct{})
|
2015-02-05 02:07:58 +00:00
|
|
|
|
2018-10-12 09:47:24 +00:00
|
|
|
if err := srv.setupLocalNode(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if srv.ListenAddr != "" {
|
2022-04-28 02:21:52 +00:00
|
|
|
if err := srv.setupListening(srv.quitCtx); err != nil {
|
2018-01-22 12:38:34 +00:00
|
|
|
return err
|
|
|
|
}
|
2018-10-12 09:47:24 +00:00
|
|
|
}
|
2022-04-28 02:21:52 +00:00
|
|
|
if err := srv.setupDiscovery(srv.quitCtx); err != nil {
|
2018-10-12 09:47:24 +00:00
|
|
|
return err
|
|
|
|
}
|
2020-02-13 10:10:03 +00:00
|
|
|
srv.setupDialScheduler()
|
2018-10-12 09:47:24 +00:00
|
|
|
|
2021-11-21 19:36:26 +00:00
|
|
|
srv.running = true
|
2018-10-12 09:47:24 +00:00
|
|
|
srv.loopWG.Add(1)
|
2020-02-13 10:10:03 +00:00
|
|
|
go srv.run()
|
2018-10-12 09:47:24 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (srv *Server) setupLocalNode() error {
|
|
|
|
// Create the devp2p handshake.
|
2022-03-31 04:06:20 +00:00
|
|
|
pubkey := crypto.MarshalPubkey(&srv.PrivateKey.PublicKey)
|
|
|
|
srv.ourHandshake = &protoHandshake{Version: baseProtocolVersion, Name: srv.Name, Pubkey: pubkey}
|
2018-10-12 09:47:24 +00:00
|
|
|
for _, p := range srv.Protocols {
|
|
|
|
srv.ourHandshake.Caps = append(srv.ourHandshake.Caps, p.cap())
|
|
|
|
}
|
|
|
|
sort.Sort(capsByNameAndVersion(srv.ourHandshake.Caps))
|
2021-05-30 02:53:30 +00:00
|
|
|
// Create the local node
|
2018-10-12 09:47:24 +00:00
|
|
|
db, err := enode.OpenDB(srv.Config.NodeDatabase)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
srv.nodedb = db
|
|
|
|
srv.localnode = enode.NewLocalNode(db, srv.PrivateKey)
|
|
|
|
srv.localnode.SetFallbackIP(net.IP{127, 0, 0, 1})
|
|
|
|
// TODO: check conflicts
|
|
|
|
for _, p := range srv.Protocols {
|
|
|
|
for _, e := range p.Attributes {
|
|
|
|
srv.localnode.Set(e)
|
2018-01-22 12:38:34 +00:00
|
|
|
}
|
2018-10-12 09:47:24 +00:00
|
|
|
}
|
|
|
|
switch srv.NAT.(type) {
|
|
|
|
case nil:
|
|
|
|
// No NAT interface, do nothing.
|
|
|
|
case nat.ExtIP:
|
|
|
|
// ExtIP doesn't block, set the IP right away.
|
|
|
|
ip, _ := srv.NAT.ExternalIP()
|
|
|
|
srv.localnode.SetStaticIP(ip)
|
|
|
|
default:
|
|
|
|
// Ask the router about the IP. This takes a while and blocks startup,
|
|
|
|
// do it in the background.
|
|
|
|
srv.loopWG.Add(1)
|
|
|
|
go func() {
|
2021-06-22 10:09:45 +00:00
|
|
|
defer debug.LogPanic()
|
2018-10-12 09:47:24 +00:00
|
|
|
defer srv.loopWG.Done()
|
|
|
|
if ip, err := srv.NAT.ExternalIP(); err == nil {
|
|
|
|
srv.localnode.SetStaticIP(ip)
|
2018-01-22 12:38:34 +00:00
|
|
|
}
|
2018-10-12 09:47:24 +00:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-22 18:18:43 +00:00
|
|
|
func (srv *Server) setupDiscovery(ctx context.Context) error {
|
2019-10-29 15:08:57 +00:00
|
|
|
srv.discmix = enode.NewFairMix(discmixTimeout)
|
|
|
|
|
|
|
|
// Add protocol-specific discovery sources.
|
|
|
|
added := make(map[string]bool)
|
|
|
|
for _, proto := range srv.Protocols {
|
|
|
|
if proto.DialCandidates != nil && !added[proto.Name] {
|
|
|
|
srv.discmix.AddSource(proto.DialCandidates)
|
|
|
|
added[proto.Name] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't listen on UDP endpoint if DHT is disabled.
|
2018-10-12 09:47:24 +00:00
|
|
|
if srv.NoDiscovery && !srv.DiscoveryV5 {
|
|
|
|
return nil
|
2018-01-22 12:38:34 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 09:47:24 +00:00
|
|
|
addr, err := net.ResolveUDPAddr("udp", srv.ListenAddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
conn, err := net.ListenUDP("udp", addr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
realaddr := conn.LocalAddr().(*net.UDPAddr)
|
2021-10-05 01:14:04 +00:00
|
|
|
srv.log.Trace("UDP listener up", "addr", realaddr)
|
2018-10-12 09:47:24 +00:00
|
|
|
if srv.NAT != nil {
|
2022-02-24 15:09:56 +00:00
|
|
|
if !realaddr.IP.IsLoopback() && srv.NAT.SupportsMapping() {
|
geth 1.9.13 (#469)
* core: initial version of state snapshots
* core/state: lazy sorting, snapshot invalidation
* core/state/snapshot: extract and split cap method, cover corners
* snapshot: iteration and buffering optimizations
* core/state/snapshot: unlink snapshots from blocks, quad->linear cleanup
* 123
* core/rawdb, core/state/snapshot: runtime snapshot generation
* core/state/snapshot: fix difflayer origin-initalization after flatten
* add "to merge"
* core/state/snapshot: implement snapshot layer iteration
* core/state/snapshot: node behavioural difference on bloom content
* core: journal the snapshot inside leveldb, not a flat file
* core/state/snapshot: bloom, metrics and prefetcher fixes
* core/state/snapshot: move iterator out into its own files
* core/state/snapshot: implement iterator priority for fast direct data lookup
* core/state/snapshot: full featured account iteration
* core/state/snapshot: faster account iteration, CLI integration
* core: fix broken tests due to API changes + linter
* core/state: fix an account resurrection issue
* core/tests: test for destroy+recreate contract with storage
* squashme
* core/state/snapshot, tests: sync snap gen + snaps in consensus tests
* core/state: extend snapshotter to handle account resurrections
* core/state: fix account root hash update point
* core/state: fix resurrection state clearing and access
* core/state/snapshot: handle deleted accounts in fast iterator
* core: more blockchain tests
* core/state/snapshot: fix various iteration issues due to destruct set
* core: fix two snapshot iterator flaws, decollide snap storage prefix
* core/state/snapshot/iterator: fix two disk iterator flaws
* core/rawdb: change SnapshotStoragePrefix to avoid prefix collision with preimagePrefix
* params: begin v1.9.13 release cycle
* cmd/checkpoint-admin: add some documentation (#20697)
* go.mod: update duktape to fix sprintf warnings (#20777)
This revision of go-duktype fixes the following warning
```
duk_logging.c: In function ‘duk__logger_prototype_log_shared’:
duk_logging.c:184:64: warning: ‘Z’ directive writing 1 byte into a region of size between 0 and 9 [-Wformat-overflow=]
184 | sprintf((char *) date_buf, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
| ^
In file included from /usr/include/stdio.h:867,
from duk_logging.c:5:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 25 and 85 bytes into a destination of size 32
36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
* core/rawdb: fix freezer table test error check
Fixes: Condition is always 'false' because 'err' is always 'nil'
* core/rawdb: improve table database (#20703)
This PR fixes issues in TableDatabase.
TableDatabase is a wrapper of underlying ethdb.Database with an additional prefix.
The prefix is applied to all entries it maintains. However when we try to retrieve entries
from it we don't handle the key properly. In theory the prefix should be truncated and
only user key is returned. But we don't do it in some cases, e.g. the iterator and batch
replayer created from it. So this PR is the fix to these issues.
* eth: when triggering a sync, check the head header TD, not block
* internal/web3ext: fix clique console apis to work on missing arguments
* rpc: dont log an error if user configures --rpcapi=rpc... (#20776)
This just prevents a false negative ERROR warning when, for some unknown
reason, a user attempts to turn on the module rpc even though it's already going
to be on.
* node, cmd/clef: report actual port used for http rpc (#20789)
* internal/ethapi: don't set sender-balance to maxuint, fixes #16999 (#20783)
Prior to this change, eth_call changed the balance of the sender account in the
EVM environment to 2^256 wei to cover the gas cost of the call execution.
We've had this behavior for a long time even though it's super confusing.
This commit sets the default call gasprice to zero instead of updating the balance,
which is better because it makes eth_call semantics less surprising. Removing
the built-in balance assignment also makes balance overrides work as expected.
* metrics: disable CPU stats (gosigar) on iOS
* cmd/devp2p: tweak DNS TTLs (#20801)
* cmd/devp2p: tweak DNS TTLs
* cmd/devp2p: bump treeNodeTTL to four weeks
* cmd/devp2p: lower route53 change limit again (#20819)
* cmd/devp2p: be very correct about route53 change splitting (#20820)
Turns out the way RDATA limits work is documented after all,
I just didn't search right. The trick to make it work is to
count UPSERTs twice.
This also adds an additional check to ensure TTL changes are
applied on existing records.
* graphql, node, rpc: fix typos in comments (#20824)
* eth: improve shutdown synchronization (#20695)
* eth: improve shutdown synchronization
Most goroutines started by eth.Ethereum didn't have any shutdown sync at
all, which lead to weird error messages when quitting the client.
This change improves the clean shutdown path by stopping all internal
components in dependency order and waiting for them to actually be
stopped before shutdown is considered done. In particular, we now stop
everything related to peers before stopping 'resident' parts such as
core.BlockChain.
* eth: rewrite sync controller
* eth: remove sync start debug message
* eth: notify chainSyncer about new peers after handshake
* eth: move downloader.Cancel call into chainSyncer
* eth: make post-sync block broadcast synchronous
* eth: add comments
* core: change blockchain stop message
* eth: change closeBloomHandler channel type
* eth/filters: fix typo on unindexedLogs function's comment (#20827)
* core: bump txpool tx max size to 128KB
* snapshotter/tests: verify snapdb post-state against trie (#20812)
* core/state/snapshot: basic trie-to-hash implementation
* tests: validate snapshot after test
* core/state/snapshot: fix review concerns
* cmd, consensus: add option to disable mmap for DAG caches/datasets (#20484)
* cmd, consensus: add option to disable mmap for DAG caches/datasets
* consensus: add benchmarks for mmap with/with lock
* cmd/clef: add newaccount command (#20782)
* cmd/clef: add newaccount command
* cmd/clef: document clef_New, update API versioning
* Update cmd/clef/intapi_changelog.md
Co-Authored-By: ligi <ligi@ligi.de>
* Update signer/core/uiapi.go
Co-Authored-By: ligi <ligi@ligi.de>
Co-authored-by: ligi <ligi@ligi.de>
* eth: add debug_accountRange API (#19645)
This new API allows reading accounts and their content by address range.
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
* travis: allow cocoapods deploy to fail (#20833)
* metrics: improve TestTimerFunc (#20818)
The test failed due to what appears to be fluctuations in time.Sleep, which is
not the actual method under test. This change modifies it so we compare the
metered Max to the actual time instead of the desired time.
* README: update private network genesis spec with istanbul (#20841)
* add istanbul and muirGlacier to genesis states in README
* remove muirGlacier, relocate istanbul
* cmd/evm: Rework execution stats (#20792)
- Dump stats also for --bench flag.
- From memory stats only show number and size of allocations. This is what `test -bench` shows. I doubt others like number of GC runs are any useful, but can be added if requested.
- Now the mem stats are for single execution in case of --bench.
* cmd/devp2p, cmd/wnode, whisper: add missing calls to Timer.Stop (#20843)
* p2p/server: add UDP port mapping goroutine to wait group (#20846)
* accounts/abi faster unpacking of int256 (#20850)
* p2p/discv5: add missing Timer.Stop calls (#20853)
* miner/worker: add missing timer.Stop call (#20857)
* cmd/geth: fix bad genesis test (#20860)
* eth/filters: add missing Ticker.Stop call (#20862)
* eth/fetcher: add missing timer.Stop calls (#20861)
* event: add missing timer.Stop call in TestFeed (#20868)
* metrics: add missing calls to Ticker.Stop in tests (#20866)
* ethstats: add missing Ticker.Stop call (#20867)
* p2p/discv5, p2p/testing: add missing Timer.Stop calls in tests (#20869)
* core: add missing Timer.Stop call in TestLogReorgs (#20870)
* rpc: add missing timer.Stop calls in websocket tests (#20863)
* crypto/ecies: improve concatKDF (#20836)
This removes a bunch of weird code around the counter overflow check in
concatKDF and makes it actually work for different hash output sizes.
The overflow check worked as follows: concatKDF applies the hash function N
times, where N is roundup(kdLen, hashsize) / hashsize. N should not
overflow 32 bits because that would lead to a repetition in the KDF output.
A couple issues with the overflow check:
- It used the hash.BlockSize, which is wrong because the
block size is about the input of the hash function. Luckily, all standard
hash functions have a block size that's greater than the output size, so
concatKDF didn't crash, it just generated too much key material.
- The check used big.Int to compare against 2^32-1.
- The calculation could still overflow before reaching the check.
The new code in concatKDF doesn't check for overflow. Instead, there is a
new check on ECIESParams which ensures that params.KeyLen is < 512. This
removes any possibility of overflow.
There are a couple of miscellaneous improvements bundled in with this
change:
- The key buffer is pre-allocated instead of appending the hash output
to an initially empty slice.
- The code that uses concatKDF to derive keys is now shared between Encrypt
and Decrypt.
- There was a redundant invocation of IsOnCurve in Decrypt. This is now removed
because elliptic.Unmarshal already checks whether the input is a valid curve
point since Go 1.5.
Co-authored-by: Felix Lange <fjl@twurst.com>
* rpc: metrics for JSON-RPC method calls (#20847)
This adds a couple of metrics for tracking the timing
and frequency of method calls:
- rpc/requests gauge counts all requests
- rpc/success gauge counts requests which return err == nil
- rpc/failure gauge counts requests which return err != nil
- rpc/duration/all timer tracks timing of all requests
- rpc/duration/<method>/<success/failure> tracks per-method timing
* mobile: use bind.NewKeyedTransactor instead of duplicating (#20888)
It's better to reuse the existing code to create a keyed transactor
than to rewrite the logic again.
* internal/ethapi: add CallArgs.ToMessage method (#20854)
ToMessage is used to convert between ethapi.CallArgs and types.Message.
It reduces the length of the DoCall method by about half by abstracting out
the conversion between the CallArgs and the Message. This should improve the
code's maintainability and reusability.
* eth, les: fix flaky tests (#20897)
* les: fix flaky test
* eth: fix flaky test
* cmd/geth: enable metrics for geth import command (#20738)
* cmd/geth: enable metrics for geth import command
* cmd/geth: enable metrics-flags for import command
* core/vm: use a callcontext struct (#20761)
* core/vm: use a callcontext struct
* core/vm: fix tests
* core/vm/runtime: benchmark
* core/vm: make intpool push inlineable, unexpose callcontext
* docs/audits: add discv5 protocol audits from LA and C53 (#20898)
* .github: change gitter reference to discord link in issue template (#20896)
* couple of fixes to docs in clef (#20900)
* p2p/discover: add initial discovery v5 implementation (#20750)This adds an implementation of the current discovery v5 spec.There is full integration with cmd/devp2p and enode.Iterator in thisversion. In theory we could enable the new protocol as a replacement ofdiscovery v4 at any time. In practice, there will likely be a few morechanges to the spec and implementation before this can happen.
* build: upgrade to golangci-lint 1.24.0 (#20901)
* accounts/scwallet: remove unnecessary uses of fmt.Sprintf
* cmd/puppeth: remove unnecessary uses of fmt.Sprintf
* p2p/discv5: remove unnecessary use of fmt.Sprintf
* whisper/mailserver: remove unnecessary uses of fmt.Sprintf
* core: goimports -w tx_pool_test.go
* eth/downloader: goimports -w downloader_test.go
* build: upgrade to golangci-lint 1.24.0
* accounts/abi/bind: Refactored topics (#20851)
* accounts/abi/bind: refactored topics
* accounts/abi/bind: use store function to remove code duplication
* accounts/abi/bind: removed unused type defs
* accounts/abi/bind: error on tuples in topics
* Cosmetic changes to restart travis build
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
* node: allow websocket and HTTP on the same port (#20810)
This change makes it possible to run geth with JSON-RPC over HTTP and
WebSocket on the same TCP port. The default port for WebSocket
is still 8546.
geth --rpc --rpcport 8545 --ws --wsport 8545
This also removes a lot of deprecated API surface from package rpc.
The rpc package is now purely about serving JSON-RPC and no longer
provides a way to start an HTTP server.
* crypto: improve error messages in LoadECDSA (#20718)
This improves error messages when the file is too short or too long.
Also rewrite the test for SaveECDSA because LoadECDSA has its own
test now.
Co-authored-by: Felix Lange <fjl@twurst.com>
* changed date of rpcstack.go since new file (#20904)
* accounts/abi/bind: fixed erroneous filtering of negative ints (#20865)
* accounts/abi/bind: fixed erroneous packing of negative ints
* accounts/abi/bind: added test cases for negative ints in topics
* accounts/abi/bind: fixed genIntType for go 1.12
* accounts/abi: minor nitpick
* cmd: deprecate --testnet, use named networks instead (#20852)
* cmd/utils: make goerli the default testnet
* cmd/geth: explicitly rename testnet to ropsten
* core: explicitly rename testnet to ropsten
* params: explicitly rename testnet to ropsten
* cmd: explicitly rename testnet to ropsten
* miner: explicitly rename testnet to ropsten
* mobile: allow for returning the goerli spec
* tests: explicitly rename testnet to ropsten
* docs: update readme to reflect changes to the default testnet
* mobile: allow for configuring goerli and rinkeby nodes
* cmd/geth: revert --testnet back to ropsten and mark as legacy
* cmd/util: mark --testnet flag as deprecated
* docs: update readme to properly reflect the 3 testnets
* cmd/utils: add an explicit deprecation warning on startup
* cmd/utils: swap goerli and ropsten in usage
* cmd/geth: swap goerli and ropsten in usage
* cmd/geth: if running a known preset, log it for convenience
* docs: improve readme on usage of ropsten's testnet datadir
* cmd/utils: check if legacy `testnet` datadir exists for ropsten
* cmd/geth: check for legacy testnet path in console command
* cmd/geth: use switch statement for complex conditions in main
* cmd/geth: move known preset log statement to the very top
* cmd/utils: create new ropsten configurations in the ropsten datadir
* cmd/utils: makedatadir should check for existing testnet dir
* cmd/geth: add legacy testnet flag to the copy db command
* cmd/geth: add legacy testnet flag to the inspect command
* les, les/lespay/client: add service value statistics and API (#20837)
This PR adds service value measurement statistics to the light client. It
also adds a private API that makes these statistics accessible. A follow-up
PR will add the new server pool which uses these statistics to select
servers with good performance.
This document describes the function of the new components:
https://gist.github.com/zsfelfoldi/3c7ace895234b7b345ab4f71dab102d4
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
* README: update min go version to 1.13 (#20911)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2 (#20913)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2
* travis, appveyor: force GO111MODULE=on for every build
* core/rawdb: fix data race between Retrieve and Close (#20919)
* core/rawdb: fixed data race between retrieve and close
closes https://github.com/ethereum/go-ethereum/issues/20420
* core/rawdb: use non-atomic load while holding mutex
* all: simplify and fix database iteration with prefix/start (#20808)
* core/state/snapshot: start fixing disk iterator seek
* ethdb, rawdb, leveldb, memorydb: implement iterators with prefix and start
* les, core/state/snapshot: iterator fixes
* all: remove two iterator methods
* all: rename Iteratee.NewIteratorWith -> NewIterator
* ethdb: fix review concerns
* params: update CHTs for the 1.9.13 release
* params: release Geth v1.9.13
* added some missing files
* post-rebase fixups
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: gary rong <garyrong0905@gmail.com>
Co-authored-by: Alex Willmer <alex@moreati.org.uk>
Co-authored-by: meowsbits <45600330+meowsbits@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: rene <41963722+renaynay@users.noreply.github.com>
Co-authored-by: Ha ĐANG <dvietha@gmail.com>
Co-authored-by: Hanjiang Yu <42531996+de1acr0ix@users.noreply.github.com>
Co-authored-by: ligi <ligi@ligi.de>
Co-authored-by: Wenbiao Zheng <delweng@gmail.com>
Co-authored-by: Adam Schmideg <adamschmideg@users.noreply.github.com>
Co-authored-by: Jeff Wentworth <jeff@curvegrid.com>
Co-authored-by: Paweł Bylica <chfast@gmail.com>
Co-authored-by: ucwong <ucwong@126.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Luke Champine <luke.champine@gmail.com>
Co-authored-by: Boqin Qin <Bobbqqin@gmail.com>
Co-authored-by: William Morriss <wjmelements@gmail.com>
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
Co-authored-by: Raw Pong Ghmoa <58883403+q9f@users.noreply.github.com>
Co-authored-by: Felföldi Zsolt <zsfelfoldi@gmail.com>
2020-04-19 17:31:47 +00:00
|
|
|
srv.loopWG.Add(1)
|
|
|
|
go func() {
|
2021-06-22 10:09:45 +00:00
|
|
|
defer debug.LogPanic()
|
2022-04-28 02:21:52 +00:00
|
|
|
defer srv.loopWG.Done()
|
geth 1.9.13 (#469)
* core: initial version of state snapshots
* core/state: lazy sorting, snapshot invalidation
* core/state/snapshot: extract and split cap method, cover corners
* snapshot: iteration and buffering optimizations
* core/state/snapshot: unlink snapshots from blocks, quad->linear cleanup
* 123
* core/rawdb, core/state/snapshot: runtime snapshot generation
* core/state/snapshot: fix difflayer origin-initalization after flatten
* add "to merge"
* core/state/snapshot: implement snapshot layer iteration
* core/state/snapshot: node behavioural difference on bloom content
* core: journal the snapshot inside leveldb, not a flat file
* core/state/snapshot: bloom, metrics and prefetcher fixes
* core/state/snapshot: move iterator out into its own files
* core/state/snapshot: implement iterator priority for fast direct data lookup
* core/state/snapshot: full featured account iteration
* core/state/snapshot: faster account iteration, CLI integration
* core: fix broken tests due to API changes + linter
* core/state: fix an account resurrection issue
* core/tests: test for destroy+recreate contract with storage
* squashme
* core/state/snapshot, tests: sync snap gen + snaps in consensus tests
* core/state: extend snapshotter to handle account resurrections
* core/state: fix account root hash update point
* core/state: fix resurrection state clearing and access
* core/state/snapshot: handle deleted accounts in fast iterator
* core: more blockchain tests
* core/state/snapshot: fix various iteration issues due to destruct set
* core: fix two snapshot iterator flaws, decollide snap storage prefix
* core/state/snapshot/iterator: fix two disk iterator flaws
* core/rawdb: change SnapshotStoragePrefix to avoid prefix collision with preimagePrefix
* params: begin v1.9.13 release cycle
* cmd/checkpoint-admin: add some documentation (#20697)
* go.mod: update duktape to fix sprintf warnings (#20777)
This revision of go-duktype fixes the following warning
```
duk_logging.c: In function ‘duk__logger_prototype_log_shared’:
duk_logging.c:184:64: warning: ‘Z’ directive writing 1 byte into a region of size between 0 and 9 [-Wformat-overflow=]
184 | sprintf((char *) date_buf, "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ",
| ^
In file included from /usr/include/stdio.h:867,
from duk_logging.c:5:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 25 and 85 bytes into a destination of size 32
36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
* core/rawdb: fix freezer table test error check
Fixes: Condition is always 'false' because 'err' is always 'nil'
* core/rawdb: improve table database (#20703)
This PR fixes issues in TableDatabase.
TableDatabase is a wrapper of underlying ethdb.Database with an additional prefix.
The prefix is applied to all entries it maintains. However when we try to retrieve entries
from it we don't handle the key properly. In theory the prefix should be truncated and
only user key is returned. But we don't do it in some cases, e.g. the iterator and batch
replayer created from it. So this PR is the fix to these issues.
* eth: when triggering a sync, check the head header TD, not block
* internal/web3ext: fix clique console apis to work on missing arguments
* rpc: dont log an error if user configures --rpcapi=rpc... (#20776)
This just prevents a false negative ERROR warning when, for some unknown
reason, a user attempts to turn on the module rpc even though it's already going
to be on.
* node, cmd/clef: report actual port used for http rpc (#20789)
* internal/ethapi: don't set sender-balance to maxuint, fixes #16999 (#20783)
Prior to this change, eth_call changed the balance of the sender account in the
EVM environment to 2^256 wei to cover the gas cost of the call execution.
We've had this behavior for a long time even though it's super confusing.
This commit sets the default call gasprice to zero instead of updating the balance,
which is better because it makes eth_call semantics less surprising. Removing
the built-in balance assignment also makes balance overrides work as expected.
* metrics: disable CPU stats (gosigar) on iOS
* cmd/devp2p: tweak DNS TTLs (#20801)
* cmd/devp2p: tweak DNS TTLs
* cmd/devp2p: bump treeNodeTTL to four weeks
* cmd/devp2p: lower route53 change limit again (#20819)
* cmd/devp2p: be very correct about route53 change splitting (#20820)
Turns out the way RDATA limits work is documented after all,
I just didn't search right. The trick to make it work is to
count UPSERTs twice.
This also adds an additional check to ensure TTL changes are
applied on existing records.
* graphql, node, rpc: fix typos in comments (#20824)
* eth: improve shutdown synchronization (#20695)
* eth: improve shutdown synchronization
Most goroutines started by eth.Ethereum didn't have any shutdown sync at
all, which lead to weird error messages when quitting the client.
This change improves the clean shutdown path by stopping all internal
components in dependency order and waiting for them to actually be
stopped before shutdown is considered done. In particular, we now stop
everything related to peers before stopping 'resident' parts such as
core.BlockChain.
* eth: rewrite sync controller
* eth: remove sync start debug message
* eth: notify chainSyncer about new peers after handshake
* eth: move downloader.Cancel call into chainSyncer
* eth: make post-sync block broadcast synchronous
* eth: add comments
* core: change blockchain stop message
* eth: change closeBloomHandler channel type
* eth/filters: fix typo on unindexedLogs function's comment (#20827)
* core: bump txpool tx max size to 128KB
* snapshotter/tests: verify snapdb post-state against trie (#20812)
* core/state/snapshot: basic trie-to-hash implementation
* tests: validate snapshot after test
* core/state/snapshot: fix review concerns
* cmd, consensus: add option to disable mmap for DAG caches/datasets (#20484)
* cmd, consensus: add option to disable mmap for DAG caches/datasets
* consensus: add benchmarks for mmap with/with lock
* cmd/clef: add newaccount command (#20782)
* cmd/clef: add newaccount command
* cmd/clef: document clef_New, update API versioning
* Update cmd/clef/intapi_changelog.md
Co-Authored-By: ligi <ligi@ligi.de>
* Update signer/core/uiapi.go
Co-Authored-By: ligi <ligi@ligi.de>
Co-authored-by: ligi <ligi@ligi.de>
* eth: add debug_accountRange API (#19645)
This new API allows reading accounts and their content by address range.
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Felix Lange <fjl@twurst.com>
* travis: allow cocoapods deploy to fail (#20833)
* metrics: improve TestTimerFunc (#20818)
The test failed due to what appears to be fluctuations in time.Sleep, which is
not the actual method under test. This change modifies it so we compare the
metered Max to the actual time instead of the desired time.
* README: update private network genesis spec with istanbul (#20841)
* add istanbul and muirGlacier to genesis states in README
* remove muirGlacier, relocate istanbul
* cmd/evm: Rework execution stats (#20792)
- Dump stats also for --bench flag.
- From memory stats only show number and size of allocations. This is what `test -bench` shows. I doubt others like number of GC runs are any useful, but can be added if requested.
- Now the mem stats are for single execution in case of --bench.
* cmd/devp2p, cmd/wnode, whisper: add missing calls to Timer.Stop (#20843)
* p2p/server: add UDP port mapping goroutine to wait group (#20846)
* accounts/abi faster unpacking of int256 (#20850)
* p2p/discv5: add missing Timer.Stop calls (#20853)
* miner/worker: add missing timer.Stop call (#20857)
* cmd/geth: fix bad genesis test (#20860)
* eth/filters: add missing Ticker.Stop call (#20862)
* eth/fetcher: add missing timer.Stop calls (#20861)
* event: add missing timer.Stop call in TestFeed (#20868)
* metrics: add missing calls to Ticker.Stop in tests (#20866)
* ethstats: add missing Ticker.Stop call (#20867)
* p2p/discv5, p2p/testing: add missing Timer.Stop calls in tests (#20869)
* core: add missing Timer.Stop call in TestLogReorgs (#20870)
* rpc: add missing timer.Stop calls in websocket tests (#20863)
* crypto/ecies: improve concatKDF (#20836)
This removes a bunch of weird code around the counter overflow check in
concatKDF and makes it actually work for different hash output sizes.
The overflow check worked as follows: concatKDF applies the hash function N
times, where N is roundup(kdLen, hashsize) / hashsize. N should not
overflow 32 bits because that would lead to a repetition in the KDF output.
A couple issues with the overflow check:
- It used the hash.BlockSize, which is wrong because the
block size is about the input of the hash function. Luckily, all standard
hash functions have a block size that's greater than the output size, so
concatKDF didn't crash, it just generated too much key material.
- The check used big.Int to compare against 2^32-1.
- The calculation could still overflow before reaching the check.
The new code in concatKDF doesn't check for overflow. Instead, there is a
new check on ECIESParams which ensures that params.KeyLen is < 512. This
removes any possibility of overflow.
There are a couple of miscellaneous improvements bundled in with this
change:
- The key buffer is pre-allocated instead of appending the hash output
to an initially empty slice.
- The code that uses concatKDF to derive keys is now shared between Encrypt
and Decrypt.
- There was a redundant invocation of IsOnCurve in Decrypt. This is now removed
because elliptic.Unmarshal already checks whether the input is a valid curve
point since Go 1.5.
Co-authored-by: Felix Lange <fjl@twurst.com>
* rpc: metrics for JSON-RPC method calls (#20847)
This adds a couple of metrics for tracking the timing
and frequency of method calls:
- rpc/requests gauge counts all requests
- rpc/success gauge counts requests which return err == nil
- rpc/failure gauge counts requests which return err != nil
- rpc/duration/all timer tracks timing of all requests
- rpc/duration/<method>/<success/failure> tracks per-method timing
* mobile: use bind.NewKeyedTransactor instead of duplicating (#20888)
It's better to reuse the existing code to create a keyed transactor
than to rewrite the logic again.
* internal/ethapi: add CallArgs.ToMessage method (#20854)
ToMessage is used to convert between ethapi.CallArgs and types.Message.
It reduces the length of the DoCall method by about half by abstracting out
the conversion between the CallArgs and the Message. This should improve the
code's maintainability and reusability.
* eth, les: fix flaky tests (#20897)
* les: fix flaky test
* eth: fix flaky test
* cmd/geth: enable metrics for geth import command (#20738)
* cmd/geth: enable metrics for geth import command
* cmd/geth: enable metrics-flags for import command
* core/vm: use a callcontext struct (#20761)
* core/vm: use a callcontext struct
* core/vm: fix tests
* core/vm/runtime: benchmark
* core/vm: make intpool push inlineable, unexpose callcontext
* docs/audits: add discv5 protocol audits from LA and C53 (#20898)
* .github: change gitter reference to discord link in issue template (#20896)
* couple of fixes to docs in clef (#20900)
* p2p/discover: add initial discovery v5 implementation (#20750)This adds an implementation of the current discovery v5 spec.There is full integration with cmd/devp2p and enode.Iterator in thisversion. In theory we could enable the new protocol as a replacement ofdiscovery v4 at any time. In practice, there will likely be a few morechanges to the spec and implementation before this can happen.
* build: upgrade to golangci-lint 1.24.0 (#20901)
* accounts/scwallet: remove unnecessary uses of fmt.Sprintf
* cmd/puppeth: remove unnecessary uses of fmt.Sprintf
* p2p/discv5: remove unnecessary use of fmt.Sprintf
* whisper/mailserver: remove unnecessary uses of fmt.Sprintf
* core: goimports -w tx_pool_test.go
* eth/downloader: goimports -w downloader_test.go
* build: upgrade to golangci-lint 1.24.0
* accounts/abi/bind: Refactored topics (#20851)
* accounts/abi/bind: refactored topics
* accounts/abi/bind: use store function to remove code duplication
* accounts/abi/bind: removed unused type defs
* accounts/abi/bind: error on tuples in topics
* Cosmetic changes to restart travis build
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
* node: allow websocket and HTTP on the same port (#20810)
This change makes it possible to run geth with JSON-RPC over HTTP and
WebSocket on the same TCP port. The default port for WebSocket
is still 8546.
geth --rpc --rpcport 8545 --ws --wsport 8545
This also removes a lot of deprecated API surface from package rpc.
The rpc package is now purely about serving JSON-RPC and no longer
provides a way to start an HTTP server.
* crypto: improve error messages in LoadECDSA (#20718)
This improves error messages when the file is too short or too long.
Also rewrite the test for SaveECDSA because LoadECDSA has its own
test now.
Co-authored-by: Felix Lange <fjl@twurst.com>
* changed date of rpcstack.go since new file (#20904)
* accounts/abi/bind: fixed erroneous filtering of negative ints (#20865)
* accounts/abi/bind: fixed erroneous packing of negative ints
* accounts/abi/bind: added test cases for negative ints in topics
* accounts/abi/bind: fixed genIntType for go 1.12
* accounts/abi: minor nitpick
* cmd: deprecate --testnet, use named networks instead (#20852)
* cmd/utils: make goerli the default testnet
* cmd/geth: explicitly rename testnet to ropsten
* core: explicitly rename testnet to ropsten
* params: explicitly rename testnet to ropsten
* cmd: explicitly rename testnet to ropsten
* miner: explicitly rename testnet to ropsten
* mobile: allow for returning the goerli spec
* tests: explicitly rename testnet to ropsten
* docs: update readme to reflect changes to the default testnet
* mobile: allow for configuring goerli and rinkeby nodes
* cmd/geth: revert --testnet back to ropsten and mark as legacy
* cmd/util: mark --testnet flag as deprecated
* docs: update readme to properly reflect the 3 testnets
* cmd/utils: add an explicit deprecation warning on startup
* cmd/utils: swap goerli and ropsten in usage
* cmd/geth: swap goerli and ropsten in usage
* cmd/geth: if running a known preset, log it for convenience
* docs: improve readme on usage of ropsten's testnet datadir
* cmd/utils: check if legacy `testnet` datadir exists for ropsten
* cmd/geth: check for legacy testnet path in console command
* cmd/geth: use switch statement for complex conditions in main
* cmd/geth: move known preset log statement to the very top
* cmd/utils: create new ropsten configurations in the ropsten datadir
* cmd/utils: makedatadir should check for existing testnet dir
* cmd/geth: add legacy testnet flag to the copy db command
* cmd/geth: add legacy testnet flag to the inspect command
* les, les/lespay/client: add service value statistics and API (#20837)
This PR adds service value measurement statistics to the light client. It
also adds a private API that makes these statistics accessible. A follow-up
PR will add the new server pool which uses these statistics to select
servers with good performance.
This document describes the function of the new components:
https://gist.github.com/zsfelfoldi/3c7ace895234b7b345ab4f71dab102d4
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
Co-authored-by: rjl493456442 <garyrong0905@gmail.com>
* README: update min go version to 1.13 (#20911)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2 (#20913)
* travis, appveyor, build, Dockerfile: bump Go to 1.14.2
* travis, appveyor: force GO111MODULE=on for every build
* core/rawdb: fix data race between Retrieve and Close (#20919)
* core/rawdb: fixed data race between retrieve and close
closes https://github.com/ethereum/go-ethereum/issues/20420
* core/rawdb: use non-atomic load while holding mutex
* all: simplify and fix database iteration with prefix/start (#20808)
* core/state/snapshot: start fixing disk iterator seek
* ethdb, rawdb, leveldb, memorydb: implement iterators with prefix and start
* les, core/state/snapshot: iterator fixes
* all: remove two iterator methods
* all: rename Iteratee.NewIteratorWith -> NewIterator
* ethdb: fix review concerns
* params: update CHTs for the 1.9.13 release
* params: release Geth v1.9.13
* added some missing files
* post-rebase fixups
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: gary rong <garyrong0905@gmail.com>
Co-authored-by: Alex Willmer <alex@moreati.org.uk>
Co-authored-by: meowsbits <45600330+meowsbits@users.noreply.github.com>
Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: rene <41963722+renaynay@users.noreply.github.com>
Co-authored-by: Ha ĐANG <dvietha@gmail.com>
Co-authored-by: Hanjiang Yu <42531996+de1acr0ix@users.noreply.github.com>
Co-authored-by: ligi <ligi@ligi.de>
Co-authored-by: Wenbiao Zheng <delweng@gmail.com>
Co-authored-by: Adam Schmideg <adamschmideg@users.noreply.github.com>
Co-authored-by: Jeff Wentworth <jeff@curvegrid.com>
Co-authored-by: Paweł Bylica <chfast@gmail.com>
Co-authored-by: ucwong <ucwong@126.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Luke Champine <luke.champine@gmail.com>
Co-authored-by: Boqin Qin <Bobbqqin@gmail.com>
Co-authored-by: William Morriss <wjmelements@gmail.com>
Co-authored-by: Guillaume Ballet <gballet@gmail.com>
Co-authored-by: Raw Pong Ghmoa <58883403+q9f@users.noreply.github.com>
Co-authored-by: Felföldi Zsolt <zsfelfoldi@gmail.com>
2020-04-19 17:31:47 +00:00
|
|
|
nat.Map(srv.NAT, srv.quit, "udp", realaddr.Port, realaddr.Port, "ethereum discovery")
|
|
|
|
}()
|
2018-10-12 09:47:24 +00:00
|
|
|
}
|
2018-01-22 12:38:34 +00:00
|
|
|
}
|
2018-10-12 09:47:24 +00:00
|
|
|
srv.localnode.SetFallbackUDP(realaddr.Port)
|
2018-01-22 12:38:34 +00:00
|
|
|
|
2018-10-12 09:47:24 +00:00
|
|
|
// Discovery V4
|
|
|
|
var unhandled chan discover.ReadPacket
|
|
|
|
var sconn *sharedUDPConn
|
2017-04-12 14:27:23 +00:00
|
|
|
if !srv.NoDiscovery {
|
2018-10-12 09:47:24 +00:00
|
|
|
if srv.DiscoveryV5 {
|
|
|
|
unhandled = make(chan discover.ReadPacket, 100)
|
|
|
|
sconn = &sharedUDPConn{conn, unhandled}
|
|
|
|
}
|
2018-02-12 12:36:09 +00:00
|
|
|
cfg := discover.Config{
|
2018-10-12 09:47:24 +00:00
|
|
|
PrivateKey: srv.PrivateKey,
|
|
|
|
NetRestrict: srv.NetRestrict,
|
|
|
|
Bootnodes: srv.BootstrapNodes,
|
|
|
|
Unhandled: unhandled,
|
2019-06-11 10:45:33 +00:00
|
|
|
Log: srv.log,
|
2015-05-26 16:07:24 +00:00
|
|
|
}
|
2022-02-22 18:18:43 +00:00
|
|
|
ntab, err := discover.ListenV4(ctx, conn, srv.localnode, cfg)
|
2018-02-12 12:36:09 +00:00
|
|
|
if err != nil {
|
2015-12-07 11:06:49 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-05-26 16:07:24 +00:00
|
|
|
srv.ntab = ntab
|
2019-10-29 15:08:57 +00:00
|
|
|
srv.discmix.AddSource(ntab.RandomNodes())
|
2015-02-05 02:07:58 +00:00
|
|
|
}
|
2019-10-29 15:08:57 +00:00
|
|
|
|
2018-10-12 09:47:24 +00:00
|
|
|
// Discovery V5
|
2016-10-19 11:04:55 +00:00
|
|
|
if srv.DiscoveryV5 {
|
2021-01-26 20:41:35 +00:00
|
|
|
cfg := discover.Config{
|
|
|
|
PrivateKey: srv.PrivateKey,
|
|
|
|
NetRestrict: srv.NetRestrict,
|
|
|
|
Bootnodes: srv.BootstrapNodesV5,
|
|
|
|
Log: srv.log,
|
|
|
|
}
|
2018-10-12 09:47:24 +00:00
|
|
|
var err error
|
2018-01-22 12:38:34 +00:00
|
|
|
if sconn != nil {
|
2022-02-22 18:18:43 +00:00
|
|
|
srv.DiscV5, err = discover.ListenV5(ctx, sconn, srv.localnode, cfg)
|
2018-01-22 12:38:34 +00:00
|
|
|
} else {
|
2022-02-22 18:18:43 +00:00
|
|
|
srv.DiscV5, err = discover.ListenV5(ctx, conn, srv.localnode, cfg)
|
2018-01-22 12:38:34 +00:00
|
|
|
}
|
2016-10-19 11:04:55 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2014-11-21 20:48:49 +00:00
|
|
|
return nil
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 10:10:03 +00:00
|
|
|
func (srv *Server) setupDialScheduler() {
|
|
|
|
config := dialConfig{
|
|
|
|
self: srv.localnode.ID(),
|
|
|
|
maxDialPeers: srv.maxDialedConns(),
|
|
|
|
maxActiveDials: srv.MaxPendingPeers,
|
2022-02-22 18:17:15 +00:00
|
|
|
log: srv.Log,
|
2020-02-13 10:10:03 +00:00
|
|
|
netRestrict: srv.NetRestrict,
|
|
|
|
dialer: srv.Dialer,
|
|
|
|
clock: srv.clock,
|
|
|
|
}
|
|
|
|
if srv.ntab != nil {
|
|
|
|
config.resolver = srv.ntab
|
|
|
|
}
|
|
|
|
if config.dialer == nil {
|
|
|
|
config.dialer = tcpDialer{&net.Dialer{Timeout: defaultDialTimeout}}
|
|
|
|
}
|
2021-07-03 03:35:11 +00:00
|
|
|
var subProtocolVersion uint
|
|
|
|
if len(srv.Protocols) > 0 {
|
|
|
|
subProtocolVersion = srv.Protocols[0].Version
|
|
|
|
}
|
|
|
|
srv.dialsched = newDialScheduler(config, srv.discmix, srv.SetupConn, subProtocolVersion)
|
2020-02-13 10:10:03 +00:00
|
|
|
for _, n := range srv.StaticNodes {
|
|
|
|
srv.dialsched.addStatic(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (srv *Server) maxInboundConns() int {
|
|
|
|
return srv.MaxPeers - srv.maxDialedConns()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (srv *Server) maxDialedConns() (limit int) {
|
|
|
|
if srv.NoDial || srv.MaxPeers == 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if srv.DialRatio == 0 {
|
|
|
|
limit = srv.MaxPeers / defaultDialRatio
|
|
|
|
} else {
|
|
|
|
limit = srv.MaxPeers / srv.DialRatio
|
|
|
|
}
|
|
|
|
if limit == 0 {
|
|
|
|
limit = 1
|
|
|
|
}
|
|
|
|
return limit
|
|
|
|
}
|
|
|
|
|
2022-04-28 02:21:52 +00:00
|
|
|
func (srv *Server) setupListening(ctx context.Context) error {
|
2019-06-11 10:45:33 +00:00
|
|
|
// Launch the listener.
|
|
|
|
listener, err := srv.listenFunc("tcp", srv.ListenAddr)
|
2014-11-21 20:48:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-08-19 19:46:01 +00:00
|
|
|
srv.listener = listener
|
2019-06-11 10:45:33 +00:00
|
|
|
srv.ListenAddr = listener.Addr().String()
|
|
|
|
|
|
|
|
// Update the local node record and map the TCP listening port if NAT is configured.
|
|
|
|
if tcp, ok := listener.Addr().(*net.TCPAddr); ok {
|
|
|
|
srv.localnode.Set(enr.TCP(tcp.Port))
|
2022-02-24 15:09:56 +00:00
|
|
|
if !tcp.IP.IsLoopback() && (srv.NAT != nil) && srv.NAT.SupportsMapping() {
|
2019-06-11 10:45:33 +00:00
|
|
|
srv.loopWG.Add(1)
|
|
|
|
go func() {
|
2021-06-22 10:09:45 +00:00
|
|
|
defer debug.LogPanic()
|
2022-04-28 02:21:52 +00:00
|
|
|
defer srv.loopWG.Done()
|
2019-06-11 10:45:33 +00:00
|
|
|
nat.Map(srv.NAT, srv.quit, "tcp", tcp.Port, tcp.Port, "ethereum p2p")
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
2018-10-12 09:47:24 +00:00
|
|
|
|
2015-02-05 02:07:58 +00:00
|
|
|
srv.loopWG.Add(1)
|
2022-04-28 02:21:52 +00:00
|
|
|
go func() {
|
|
|
|
defer debug.LogPanic()
|
|
|
|
defer srv.loopWG.Done()
|
|
|
|
srv.listenLoop(ctx)
|
|
|
|
}()
|
2014-11-21 20:48:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-13 10:10:03 +00:00
|
|
|
// doPeerOp runs fn on the main loop.
|
|
|
|
func (srv *Server) doPeerOp(fn peerOpFunc) {
|
|
|
|
select {
|
|
|
|
case srv.peerOp <- fn:
|
|
|
|
<-srv.peerOpDone
|
|
|
|
case <-srv.quit:
|
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-13 10:10:03 +00:00
|
|
|
// run is the main loop of the server.
|
|
|
|
func (srv *Server) run() {
|
2021-06-22 10:09:45 +00:00
|
|
|
defer debug.LogPanic()
|
2021-07-01 21:30:55 +00:00
|
|
|
if len(srv.Config.Protocols) > 0 {
|
2021-07-15 09:11:39 +00:00
|
|
|
srv.log.Info("Started P2P networking", "version", srv.Config.Protocols[0].Version, "self", srv.localnode.Node().URLv4(), "name", srv.Name)
|
2021-07-01 21:30:55 +00:00
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
defer srv.loopWG.Done()
|
2018-10-12 09:47:24 +00:00
|
|
|
defer srv.nodedb.Close()
|
2019-10-29 15:08:57 +00:00
|
|
|
defer srv.discmix.Close()
|
2020-02-13 10:10:03 +00:00
|
|
|
defer srv.dialsched.stop()
|
2018-10-12 09:47:24 +00:00
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
var (
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
peers = make(map[enode.ID]*Peer)
|
2018-02-12 12:36:09 +00:00
|
|
|
inboundCount = 0
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
trusted = make(map[enode.ID]bool, len(srv.TrustedNodes))
|
2015-05-15 22:38:28 +00:00
|
|
|
)
|
|
|
|
// Put trusted nodes into a map to speed up checks.
|
2018-02-25 20:39:29 +00:00
|
|
|
// Trusted peers are loaded on startup or added via AddTrustedPeer RPC.
|
2015-05-15 22:38:28 +00:00
|
|
|
for _, n := range srv.TrustedNodes {
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
trusted[n.ID()] = true
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
running:
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-srv.quit:
|
|
|
|
// The server was stopped. Run the cleanup logic.
|
|
|
|
break running
|
2018-02-25 20:39:29 +00:00
|
|
|
case n := <-srv.addtrusted:
|
2020-02-13 10:10:03 +00:00
|
|
|
// This channel is used by AddTrustedPeer to add a node
|
2018-02-25 20:39:29 +00:00
|
|
|
// to the trusted node set.
|
|
|
|
srv.log.Trace("Adding trusted node", "node", n)
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
trusted[n.ID()] = true
|
|
|
|
if p, ok := peers[n.ID()]; ok {
|
2018-06-08 01:50:08 +00:00
|
|
|
p.rw.set(trustedConn, true)
|
2018-02-25 20:39:29 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
|
2018-02-25 20:39:29 +00:00
|
|
|
case n := <-srv.removetrusted:
|
2020-02-13 10:10:03 +00:00
|
|
|
// This channel is used by RemoveTrustedPeer to remove a node
|
2018-02-25 20:39:29 +00:00
|
|
|
// from the trusted node set.
|
|
|
|
srv.log.Trace("Removing trusted node", "node", n)
|
2019-06-10 11:21:02 +00:00
|
|
|
delete(trusted, n.ID())
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
if p, ok := peers[n.ID()]; ok {
|
2018-06-08 01:50:08 +00:00
|
|
|
p.rw.set(trustedConn, false)
|
2018-02-25 20:39:29 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
case op := <-srv.peerOp:
|
2021-07-11 07:01:16 +00:00
|
|
|
// This channel is used by GoodPeers and PeerCount.
|
2015-05-15 22:38:28 +00:00
|
|
|
op(peers)
|
|
|
|
srv.peerOpDone <- struct{}{}
|
2019-06-11 10:45:33 +00:00
|
|
|
|
|
|
|
case c := <-srv.checkpointPostHandshake:
|
2015-05-15 22:38:28 +00:00
|
|
|
// A connection has passed the encryption handshake so
|
|
|
|
// the remote identity is known (but hasn't been verified yet).
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
if trusted[c.node.ID()] {
|
2015-05-15 22:38:28 +00:00
|
|
|
// Ensure that the trusted flag is set before checking against MaxPeers.
|
|
|
|
c.flags |= trustedConn
|
|
|
|
}
|
2022-04-28 22:21:22 +00:00
|
|
|
c.cont <- nil
|
2019-06-11 10:45:33 +00:00
|
|
|
|
|
|
|
case c := <-srv.checkpointAddPeer:
|
2015-05-15 22:38:28 +00:00
|
|
|
// At this point the connection is past the protocol handshake.
|
|
|
|
// Its capabilities are known and the remote identity is verified.
|
2022-04-28 22:21:22 +00:00
|
|
|
err := srv.postHandshakeChecks(peers, inboundCount, c)
|
2017-02-24 08:58:04 +00:00
|
|
|
if err == nil {
|
2015-05-15 22:38:28 +00:00
|
|
|
// The handshakes are done and it passed all checks.
|
2022-04-10 07:01:25 +00:00
|
|
|
p := srv.launchPeer(c, c.pubkey)
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
peers[c.node.ID()] = p
|
2021-10-05 01:14:04 +00:00
|
|
|
srv.log.Trace("Adding p2p peer", "peercount", len(peers), "id", p.ID(), "conn", c.flags, "addr", p.RemoteAddr(), "name", p.Name())
|
2020-02-13 10:10:03 +00:00
|
|
|
srv.dialsched.peerAdded(c)
|
|
|
|
if p.Inbound() {
|
|
|
|
inboundCount++
|
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
c.cont <- err
|
|
|
|
|
2017-02-24 08:58:04 +00:00
|
|
|
case pd := <-srv.delpeer:
|
2015-05-15 22:38:28 +00:00
|
|
|
// A peer disconnected.
|
2017-02-24 08:58:04 +00:00
|
|
|
d := common.PrettyDuration(mclock.Now() - pd.created)
|
|
|
|
delete(peers, pd.ID())
|
2021-10-05 01:14:04 +00:00
|
|
|
srv.log.Trace("Removing p2p peer", "peercount", len(peers), "id", pd.ID(), "duration", d, "req", pd.requested, "err", pd.err)
|
2020-02-13 10:10:03 +00:00
|
|
|
srv.dialsched.peerRemoved(pd.rw)
|
2018-02-12 12:36:09 +00:00
|
|
|
if pd.Inbound() {
|
|
|
|
inboundCount--
|
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-01 11:49:04 +00:00
|
|
|
srv.log.Trace("P2P networking is spinning down")
|
2017-02-24 08:58:04 +00:00
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
// Terminate discovery. If there is a running lookup it will terminate soon.
|
2015-05-26 16:07:24 +00:00
|
|
|
if srv.ntab != nil {
|
|
|
|
srv.ntab.Close()
|
|
|
|
}
|
2016-10-19 11:04:55 +00:00
|
|
|
if srv.DiscV5 != nil {
|
|
|
|
srv.DiscV5.Close()
|
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
// Disconnect all peers.
|
|
|
|
for _, p := range peers {
|
|
|
|
p.Disconnect(DiscQuitting)
|
|
|
|
}
|
|
|
|
// Wait for peers to shut down. Pending connections and tasks are
|
|
|
|
// not handled here and will terminate soon-ish because srv.quit
|
|
|
|
// is closed.
|
|
|
|
for len(peers) > 0 {
|
|
|
|
p := <-srv.delpeer
|
2020-02-13 10:10:03 +00:00
|
|
|
p.log.Trace("<-delpeer (spindown)")
|
2015-05-15 22:38:28 +00:00
|
|
|
delete(peers, p.ID())
|
2014-11-21 20:48:49 +00:00
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
}
|
2014-11-21 20:48:49 +00:00
|
|
|
|
2019-06-11 10:45:33 +00:00
|
|
|
func (srv *Server) postHandshakeChecks(peers map[enode.ID]*Peer, inboundCount int, c *conn) error {
|
2015-05-15 22:38:28 +00:00
|
|
|
switch {
|
2020-02-13 10:10:03 +00:00
|
|
|
case !c.is(trustedConn) && len(peers) >= srv.MaxPeers:
|
2015-05-15 22:38:28 +00:00
|
|
|
return DiscTooManyPeers
|
2018-02-12 12:36:09 +00:00
|
|
|
case !c.is(trustedConn) && c.is(inboundConn) && inboundCount >= srv.maxInboundConns():
|
|
|
|
return DiscTooManyPeers
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
case peers[c.node.ID()] != nil:
|
2015-05-15 22:38:28 +00:00
|
|
|
return DiscAlreadyConnected
|
2018-10-12 09:47:24 +00:00
|
|
|
case c.node.ID() == srv.localnode.ID():
|
2015-05-15 22:38:28 +00:00
|
|
|
return DiscSelf
|
2022-04-28 22:21:22 +00:00
|
|
|
case (len(srv.Protocols) > 0) && (countMatchingProtocols(srv.Protocols, c.caps) == 0):
|
|
|
|
return DiscUselessPeer
|
2015-05-15 22:38:28 +00:00
|
|
|
default:
|
|
|
|
return nil
|
2015-04-22 08:59:15 +00:00
|
|
|
}
|
2015-04-10 11:25:35 +00:00
|
|
|
}
|
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
// listenLoop runs in its own goroutine and accepts
|
|
|
|
// inbound connections.
|
2022-04-28 02:21:52 +00:00
|
|
|
func (srv *Server) listenLoop(ctx context.Context) {
|
2021-10-05 01:14:04 +00:00
|
|
|
srv.log.Trace("TCP listener up", "addr", srv.listener.Addr())
|
2015-04-10 15:24:41 +00:00
|
|
|
|
2022-04-28 02:21:52 +00:00
|
|
|
// The slots limit accepts of new connections.
|
|
|
|
slots := semaphore.NewWeighted(int64(srv.MaxPendingPeers))
|
2015-04-10 15:24:41 +00:00
|
|
|
|
2020-01-16 12:10:15 +00:00
|
|
|
// Wait for slots to be returned on exit. This ensures all connection goroutines
|
|
|
|
// are down before listenLoop returns.
|
|
|
|
defer func() {
|
2022-04-28 02:21:52 +00:00
|
|
|
_ = slots.Acquire(ctx, int64(srv.MaxPendingPeers))
|
2020-01-16 12:10:15 +00:00
|
|
|
}()
|
|
|
|
|
2014-10-23 15:57:54 +00:00
|
|
|
for {
|
2019-06-11 10:45:33 +00:00
|
|
|
// Wait for a free slot before accepting.
|
2022-04-28 02:21:52 +00:00
|
|
|
if slotErr := slots.Acquire(ctx, 1); slotErr != nil {
|
|
|
|
if !errors.Is(slotErr, context.Canceled) {
|
|
|
|
srv.log.Error("Failed to get a peer connection slot", "err", slotErr)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2015-08-19 12:35:01 +00:00
|
|
|
|
|
|
|
var (
|
2020-11-20 14:14:25 +00:00
|
|
|
fd net.Conn
|
|
|
|
err error
|
|
|
|
lastLog time.Time
|
2015-08-19 12:35:01 +00:00
|
|
|
)
|
|
|
|
for {
|
|
|
|
fd, err = srv.listener.Accept()
|
2018-10-12 09:47:24 +00:00
|
|
|
if netutil.IsTemporaryError(err) {
|
2020-11-20 14:14:25 +00:00
|
|
|
if time.Since(lastLog) > 1*time.Second {
|
2021-10-05 01:14:04 +00:00
|
|
|
srv.log.Trace("Temporary read error", "err", err)
|
2020-11-20 14:14:25 +00:00
|
|
|
lastLog = time.Now()
|
|
|
|
}
|
|
|
|
time.Sleep(time.Millisecond * 200)
|
2015-08-19 12:35:01 +00:00
|
|
|
continue
|
|
|
|
} else if err != nil {
|
2022-04-28 02:21:52 +00:00
|
|
|
// Log the error unless the server is shutting down.
|
|
|
|
select {
|
|
|
|
case <-srv.quit:
|
|
|
|
default:
|
|
|
|
srv.log.Error("Server listener failed to accept a connection", "err", err)
|
|
|
|
}
|
|
|
|
slots.Release(1)
|
2015-08-19 12:35:01 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
break
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
2016-11-22 19:51:59 +00:00
|
|
|
|
2019-06-11 10:45:33 +00:00
|
|
|
remoteIP := netutil.AddrIP(fd.RemoteAddr())
|
|
|
|
if err := srv.checkInboundConn(fd, remoteIP); err != nil {
|
2022-04-28 02:21:52 +00:00
|
|
|
srv.log.Trace("Rejected inbound connection", "addr", fd.RemoteAddr(), "err", err)
|
|
|
|
_ = fd.Close()
|
|
|
|
slots.Release(1)
|
2019-06-11 10:45:33 +00:00
|
|
|
continue
|
2016-11-22 19:51:59 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
if remoteIP != nil {
|
dashboard: send current block to the dashboard client (#19762)
This adds all dashboard changes from the last couple months.
We're about to remove the dashboard, but decided that we should
get all the recent work in first in case anyone wants to pick up this
project later on.
* cmd, dashboard, eth, p2p: send peer info to the dashboard
* dashboard: update npm packages, improve UI, rebase
* dashboard, p2p: remove println, change doc
* cmd, dashboard, eth, p2p: cleanup after review
* dashboard: send current block to the dashboard client
2019-11-13 11:13:13 +00:00
|
|
|
var addr *net.TCPAddr
|
|
|
|
if tcp, ok := fd.RemoteAddr().(*net.TCPAddr); ok {
|
|
|
|
addr = tcp
|
|
|
|
}
|
|
|
|
fd = newMeteredConn(fd, true, addr)
|
|
|
|
srv.log.Trace("Accepted connection", "addr", fd.RemoteAddr())
|
2018-10-15 22:40:51 +00:00
|
|
|
}
|
2015-04-10 15:24:41 +00:00
|
|
|
go func() {
|
2021-06-22 10:09:45 +00:00
|
|
|
defer debug.LogPanic()
|
2022-04-28 02:21:52 +00:00
|
|
|
defer slots.Release(1)
|
|
|
|
// The error is logged in Server.setupConn().
|
|
|
|
_ = srv.SetupConn(fd, inboundConn, nil)
|
2015-04-10 15:24:41 +00:00
|
|
|
}()
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 10:45:33 +00:00
|
|
|
func (srv *Server) checkInboundConn(fd net.Conn, remoteIP net.IP) error {
|
2020-02-13 10:10:03 +00:00
|
|
|
if remoteIP == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// Reject connections that do not match NetRestrict.
|
|
|
|
if srv.NetRestrict != nil && !srv.NetRestrict.Contains(remoteIP) {
|
|
|
|
return fmt.Errorf("not whitelisted in NetRestrict")
|
2019-06-11 10:45:33 +00:00
|
|
|
}
|
2020-02-13 10:10:03 +00:00
|
|
|
// Reject Internet peers that try too often.
|
|
|
|
now := srv.clock.Now()
|
|
|
|
srv.inboundHistory.expire(now, nil)
|
|
|
|
if !netutil.IsLAN(remoteIP) && srv.inboundHistory.contains(remoteIP.String()) {
|
|
|
|
return fmt.Errorf("too many attempts")
|
|
|
|
}
|
|
|
|
srv.inboundHistory.add(remoteIP.String(), now.Add(inboundThrottleTime))
|
2019-06-11 10:45:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-09-25 08:08:07 +00:00
|
|
|
// SetupConn runs the handshakes and attempts to add the connection
|
2015-05-15 22:38:28 +00:00
|
|
|
// as a peer. It returns when the connection has been added as a peer
|
|
|
|
// or the handshakes have failed.
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
func (srv *Server) SetupConn(fd net.Conn, flags connFlag, dialDest *enode.Node) error {
|
2020-09-22 08:17:39 +00:00
|
|
|
c := &conn{fd: fd, flags: flags, cont: make(chan error)}
|
|
|
|
if dialDest == nil {
|
|
|
|
c.transport = srv.newTransport(fd, nil)
|
|
|
|
} else {
|
|
|
|
c.transport = srv.newTransport(fd, dialDest.Pubkey())
|
|
|
|
}
|
|
|
|
|
2017-12-01 11:49:04 +00:00
|
|
|
err := srv.setupConn(c, flags, dialDest)
|
|
|
|
if err != nil {
|
|
|
|
c.close(err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
func (srv *Server) setupConn(c *conn, flags connFlag, dialDest *enode.Node) error {
|
2015-05-15 22:38:28 +00:00
|
|
|
// Prevent leftover pending conns from entering the handshake.
|
|
|
|
srv.lock.Lock()
|
|
|
|
running := srv.running
|
|
|
|
srv.lock.Unlock()
|
|
|
|
if !running {
|
2017-12-01 11:49:04 +00:00
|
|
|
return errServerStopped
|
2015-04-30 12:06:05 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
// If dialing, figure out the remote public key.
|
|
|
|
var dialPubkey *ecdsa.PublicKey
|
|
|
|
if dialDest != nil {
|
|
|
|
dialPubkey = new(ecdsa.PublicKey)
|
|
|
|
if err := dialDest.Load((*enode.Secp256k1)(dialPubkey)); err != nil {
|
2020-02-13 10:10:03 +00:00
|
|
|
err = errors.New("dial destination doesn't have a secp256k1 public key")
|
|
|
|
srv.log.Trace("Setting up connection failed", "addr", c.fd.RemoteAddr(), "conn", c.flags, "err", err)
|
|
|
|
return err
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
|
|
|
|
// Run the RLPx handshake.
|
2020-09-22 08:17:39 +00:00
|
|
|
remotePubkey, err := c.doEncHandshake(srv.PrivateKey)
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
if err != nil {
|
2017-12-01 11:49:04 +00:00
|
|
|
srv.log.Trace("Failed RLPx handshake", "addr", c.fd.RemoteAddr(), "conn", c.flags, "err", err)
|
|
|
|
return err
|
2015-04-03 01:56:17 +00:00
|
|
|
}
|
2022-04-10 07:01:25 +00:00
|
|
|
copy(c.pubkey[:], crypto.MarshalPubkey(remotePubkey)[1:])
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
if dialDest != nil {
|
|
|
|
c.node = dialDest
|
|
|
|
} else {
|
|
|
|
c.node = nodeFromConn(remotePubkey, c.fd)
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
clog := srv.log.New("id", c.node.ID(), "addr", c.fd.RemoteAddr(), "conn", c.flags)
|
2019-06-11 10:45:33 +00:00
|
|
|
err = srv.checkpoint(c, srv.checkpointPostHandshake)
|
2017-12-01 11:49:04 +00:00
|
|
|
if err != nil {
|
2019-06-11 10:45:33 +00:00
|
|
|
clog.Trace("Rejected peer", "err", err)
|
2017-12-01 11:49:04 +00:00
|
|
|
return err
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
|
|
|
|
// Run the capability negotiation handshake.
|
2015-05-15 22:38:28 +00:00
|
|
|
phs, err := c.doProtoHandshake(srv.ourHandshake)
|
2015-02-05 02:07:58 +00:00
|
|
|
if err != nil {
|
2020-02-13 10:10:03 +00:00
|
|
|
clog.Trace("Failed p2p handshake", "err", err)
|
2017-12-01 11:49:04 +00:00
|
|
|
return err
|
2015-02-05 02:07:58 +00:00
|
|
|
}
|
2021-11-22 05:39:31 +00:00
|
|
|
if id := c.node.ID(); !bytes.Equal(crypto.Keccak256(phs.Pubkey), id[:]) {
|
|
|
|
clog.Trace("Wrong devp2p handshake identity", "phsid", hex.EncodeToString(phs.Pubkey))
|
2017-12-01 11:49:04 +00:00
|
|
|
return DiscUnexpectedIdentity
|
2015-03-04 15:27:37 +00:00
|
|
|
}
|
2015-05-15 22:38:28 +00:00
|
|
|
c.caps, c.name = phs.Caps, phs.Name
|
2019-06-11 10:45:33 +00:00
|
|
|
err = srv.checkpoint(c, srv.checkpointAddPeer)
|
2017-12-01 11:49:04 +00:00
|
|
|
if err != nil {
|
2017-02-24 08:58:04 +00:00
|
|
|
clog.Trace("Rejected peer", "err", err)
|
2017-12-01 11:49:04 +00:00
|
|
|
return err
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
|
2017-12-01 11:49:04 +00:00
|
|
|
return nil
|
2015-04-03 01:56:17 +00:00
|
|
|
}
|
2015-02-19 16:09:33 +00:00
|
|
|
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
func nodeFromConn(pubkey *ecdsa.PublicKey, conn net.Conn) *enode.Node {
|
|
|
|
var ip net.IP
|
|
|
|
var port int
|
|
|
|
if tcp, ok := conn.RemoteAddr().(*net.TCPAddr); ok {
|
|
|
|
ip = tcp.IP
|
|
|
|
port = tcp.Port
|
|
|
|
}
|
|
|
|
return enode.NewV4(pubkey, ip, port, port)
|
|
|
|
}
|
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
// checkpoint sends the conn to run, which performs the
|
|
|
|
// post-handshake checks for the stage (posthandshake, addpeer).
|
|
|
|
func (srv *Server) checkpoint(c *conn, stage chan<- *conn) error {
|
|
|
|
select {
|
|
|
|
case stage <- c:
|
|
|
|
case <-srv.quit:
|
|
|
|
return errServerStopped
|
2015-05-08 13:54:35 +00:00
|
|
|
}
|
2019-06-11 10:45:33 +00:00
|
|
|
return <-c.cont
|
2015-05-08 13:54:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-10 07:01:25 +00:00
|
|
|
func (srv *Server) launchPeer(c *conn, pubkey [64]byte) *Peer {
|
|
|
|
p := newPeer(srv.log, c, srv.Protocols, pubkey)
|
2020-02-13 10:10:03 +00:00
|
|
|
if srv.EnableMsgEvents {
|
|
|
|
// If message events are enabled, pass the peerFeed
|
|
|
|
// to the peer.
|
|
|
|
p.events = &srv.peerFeed
|
|
|
|
}
|
|
|
|
go srv.runPeer(p)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2015-05-15 22:38:28 +00:00
|
|
|
// runPeer runs in its own goroutine for each peer.
|
2015-04-03 01:56:17 +00:00
|
|
|
func (srv *Server) runPeer(p *Peer) {
|
2021-06-22 10:09:45 +00:00
|
|
|
defer debug.LogPanic()
|
2015-02-06 23:13:22 +00:00
|
|
|
if srv.newPeerHook != nil {
|
|
|
|
srv.newPeerHook(p)
|
|
|
|
}
|
2017-09-25 08:08:07 +00:00
|
|
|
srv.peerFeed.Send(&PeerEvent{
|
2019-07-05 18:27:13 +00:00
|
|
|
Type: PeerEventTypeAdd,
|
|
|
|
Peer: p.ID(),
|
|
|
|
RemoteAddress: p.RemoteAddr().String(),
|
|
|
|
LocalAddress: p.LocalAddr().String(),
|
2017-09-25 08:08:07 +00:00
|
|
|
})
|
|
|
|
|
2020-02-13 10:10:03 +00:00
|
|
|
// Run the per-peer main loop.
|
2017-02-24 08:58:04 +00:00
|
|
|
remoteRequested, err := p.run()
|
2017-09-25 08:08:07 +00:00
|
|
|
|
2020-02-13 10:10:03 +00:00
|
|
|
// Announce disconnect on the main loop to update the peer set.
|
|
|
|
// The main loop waits for existing peers to be sent on srv.delpeer
|
|
|
|
// before returning, so this send should not select on srv.quit.
|
|
|
|
srv.delpeer <- peerDrop{p, err, remoteRequested}
|
|
|
|
|
|
|
|
// Broadcast peer drop to external subscribers. This needs to be
|
|
|
|
// after the send to delpeer so subscribers have a consistent view of
|
2021-07-11 07:01:16 +00:00
|
|
|
// the peer set (i.e. Server.GoodPeers() doesn't include the peer when the
|
2020-02-13 10:10:03 +00:00
|
|
|
// event is received.
|
2017-09-25 08:08:07 +00:00
|
|
|
srv.peerFeed.Send(&PeerEvent{
|
2019-07-05 18:27:13 +00:00
|
|
|
Type: PeerEventTypeDrop,
|
|
|
|
Peer: p.ID(),
|
|
|
|
Error: err.Error(),
|
|
|
|
RemoteAddress: p.RemoteAddr().String(),
|
|
|
|
LocalAddress: p.LocalAddr().String(),
|
2017-09-25 08:08:07 +00:00
|
|
|
})
|
2014-10-23 15:57:54 +00:00
|
|
|
}
|
2015-10-27 13:10:30 +00:00
|
|
|
|
|
|
|
// NodeInfo represents a short summary of the information known about the host.
|
|
|
|
type NodeInfo struct {
|
2021-11-22 05:39:31 +00:00
|
|
|
ID string `json:"id"` // Unique node identifier
|
2015-10-27 13:10:30 +00:00
|
|
|
Name string `json:"name"` // Name of the node, including client type, version, OS, custom data
|
|
|
|
Enode string `json:"enode"` // Enode URL for adding this peer from remote peers
|
2018-10-12 09:47:24 +00:00
|
|
|
ENR string `json:"enr"` // Ethereum Node Record
|
2015-10-27 13:10:30 +00:00
|
|
|
IP string `json:"ip"` // IP address of the node
|
|
|
|
Ports struct {
|
|
|
|
Discovery int `json:"discovery"` // UDP listening port for discovery protocol
|
|
|
|
Listener int `json:"listener"` // TCP listening port for RLPx
|
|
|
|
} `json:"ports"`
|
|
|
|
ListenAddr string `json:"listenAddr"`
|
|
|
|
Protocols map[string]interface{} `json:"protocols"`
|
|
|
|
}
|
|
|
|
|
2016-09-05 16:07:57 +00:00
|
|
|
// NodeInfo gathers and returns a collection of metadata known about the host.
|
2015-10-27 13:10:30 +00:00
|
|
|
func (srv *Server) NodeInfo() *NodeInfo {
|
|
|
|
// Gather and assemble the generic node infos
|
2018-10-12 09:47:24 +00:00
|
|
|
node := srv.Self()
|
2015-10-27 13:10:30 +00:00
|
|
|
info := &NodeInfo{
|
|
|
|
Name: srv.Name,
|
2019-06-07 13:31:00 +00:00
|
|
|
Enode: node.URLv4(),
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
ID: node.ID().String(),
|
|
|
|
IP: node.IP().String(),
|
2015-10-27 13:10:30 +00:00
|
|
|
ListenAddr: srv.ListenAddr,
|
|
|
|
Protocols: make(map[string]interface{}),
|
|
|
|
}
|
all: new p2p node representation (#17643)
Package p2p/enode provides a generalized representation of p2p nodes
which can contain arbitrary information in key/value pairs. It is also
the new home for the node database. The "v4" identity scheme is also
moved here from p2p/enr to remove the dependency on Ethereum crypto from
that package.
Record signature handling is changed significantly. The identity scheme
registry is removed and acceptable schemes must be passed to any method
that needs identity. This means records must now be validated explicitly
after decoding.
The enode API is designed to make signature handling easy and safe: most
APIs around the codebase work with enode.Node, which is a wrapper around
a valid record. Going from enr.Record to enode.Node requires a valid
signature.
* p2p/discover: port to p2p/enode
This ports the discovery code to the new node representation in
p2p/enode. The wire protocol is unchanged, this can be considered a
refactoring change. The Kademlia table can now deal with nodes using an
arbitrary identity scheme. This requires a few incompatible API changes:
- Table.Lookup is not available anymore. It used to take a public key
as argument because v4 protocol requires one. Its replacement is
LookupRandom.
- Table.Resolve takes *enode.Node instead of NodeID. This is also for
v4 protocol compatibility because nodes cannot be looked up by ID
alone.
- Types Node and NodeID are gone. Further commits in the series will be
fixes all over the the codebase to deal with those removals.
* p2p: port to p2p/enode and discovery changes
This adapts package p2p to the changes in p2p/discover. All uses of
discover.Node and discover.NodeID are replaced by their equivalents from
p2p/enode.
New API is added to retrieve the enode.Node instance of a peer. The
behavior of Server.Self with discovery disabled is improved. It now
tries much harder to report a working IP address, falling back to
127.0.0.1 if no suitable address can be determined through other means.
These changes were needed for tests of other packages later in the
series.
* p2p/simulations, p2p/testing: port to p2p/enode
No surprises here, mostly replacements of discover.Node, discover.NodeID
with their new equivalents. The 'interesting' API changes are:
- testing.ProtocolSession tracks complete nodes, not just their IDs.
- adapters.NodeConfig has a new method to create a complete node.
These changes were needed to make swarm tests work.
Note that the NodeID change makes the code incompatible with old
simulation snapshots.
* whisper/whisperv5, whisper/whisperv6: port to p2p/enode
This port was easy because whisper uses []byte for node IDs and
URL strings in the API.
* eth: port to p2p/enode
Again, easy to port because eth uses strings for node IDs and doesn't
care about node information in any way.
* les: port to p2p/enode
Apart from replacing discover.NodeID with enode.ID, most changes are in
the server pool code. It now deals with complete nodes instead
of (Pubkey, IP, Port) triples. The database format is unchanged for now,
but we should probably change it to use the node database later.
* node: port to p2p/enode
This change simply replaces discover.Node and discover.NodeID with their
new equivalents.
* swarm/network: port to p2p/enode
Swarm has its own node address representation, BzzAddr, containing both
an overlay address (the hash of a secp256k1 public key) and an underlay
address (enode:// URL).
There are no changes to the BzzAddr format in this commit, but certain
operations such as creating a BzzAddr from a node ID are now impossible
because node IDs aren't public keys anymore.
Most swarm-related changes in the series remove uses of
NewAddrFromNodeID, replacing it with NewAddr which takes a complete node
as argument. ToOverlayAddr is removed because we can just use the node
ID directly.
2018-09-24 22:59:00 +00:00
|
|
|
info.Ports.Discovery = node.UDP()
|
|
|
|
info.Ports.Listener = node.TCP()
|
2019-06-07 13:31:00 +00:00
|
|
|
info.ENR = node.String()
|
2015-10-27 13:10:30 +00:00
|
|
|
|
|
|
|
// Gather all the running protocol infos (only once per protocol type)
|
|
|
|
for _, proto := range srv.Protocols {
|
|
|
|
if _, ok := info.Protocols[proto.Name]; !ok {
|
|
|
|
nodeInfo := interface{}("unknown")
|
|
|
|
if query := proto.NodeInfo; query != nil {
|
|
|
|
nodeInfo = proto.NodeInfo()
|
|
|
|
}
|
|
|
|
info.Protocols[proto.Name] = nodeInfo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return info
|
|
|
|
}
|
|
|
|
|
|
|
|
// PeersInfo returns an array of metadata objects describing connected peers.
|
|
|
|
func (srv *Server) PeersInfo() []*PeerInfo {
|
|
|
|
// Gather all the generic and sub-protocol specific infos
|
|
|
|
infos := make([]*PeerInfo, 0, srv.PeerCount())
|
|
|
|
for _, peer := range srv.Peers() {
|
|
|
|
if peer != nil {
|
|
|
|
infos = append(infos, peer.Info())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Sort the result array alphabetically by node identifier
|
|
|
|
for i := 0; i < len(infos); i++ {
|
|
|
|
for j := i + 1; j < len(infos); j++ {
|
|
|
|
if infos[i].ID > infos[j].ID {
|
|
|
|
infos[i], infos[j] = infos[j], infos[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return infos
|
|
|
|
}
|