diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2018-10-12 17:47:24 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-12 17:47:24 +0800 |
commit | 6f607de5d590ff2fbe8798b04e5924be3b7ca0b4 (patch) | |
tree | 2905b3462c0d4f162914a948dac6d1836ace4b77 /p2p/dial.go | |
parent | dcae0d348bb7f5d9052e50a83383a33538ce376a (diff) | |
download | dexon-6f607de5d590ff2fbe8798b04e5924be3b7ca0b4.tar dexon-6f607de5d590ff2fbe8798b04e5924be3b7ca0b4.tar.gz dexon-6f607de5d590ff2fbe8798b04e5924be3b7ca0b4.tar.bz2 dexon-6f607de5d590ff2fbe8798b04e5924be3b7ca0b4.tar.lz dexon-6f607de5d590ff2fbe8798b04e5924be3b7ca0b4.tar.xz dexon-6f607de5d590ff2fbe8798b04e5924be3b7ca0b4.tar.zst dexon-6f607de5d590ff2fbe8798b04e5924be3b7ca0b4.zip |
p2p, p2p/discover: add signed ENR generation (#17753)
This PR adds enode.LocalNode and integrates it into the p2p
subsystem. This new object is the keeper of the local node
record. For now, a new version of the record is produced every
time the client restarts. We'll make it smarter to avoid that in
the future.
There are a couple of other changes in this commit: discovery now
waits for all of its goroutines at shutdown and the p2p server
now closes the node database after discovery has shut down. This
fixes a leveldb crash in tests. p2p server startup is faster
because it doesn't need to wait for the external IP query
anymore.
Diffstat (limited to 'p2p/dial.go')
-rw-r--r-- | p2p/dial.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/p2p/dial.go b/p2p/dial.go index 359cdbcbb..d228514fc 100644 --- a/p2p/dial.go +++ b/p2p/dial.go @@ -71,6 +71,7 @@ type dialstate struct { maxDynDials int ntab discoverTable netrestrict *netutil.Netlist + self enode.ID lookupRunning bool dialing map[enode.ID]connFlag @@ -84,7 +85,6 @@ type dialstate struct { } type discoverTable interface { - Self() *enode.Node Close() Resolve(*enode.Node) *enode.Node LookupRandom() []*enode.Node @@ -126,10 +126,11 @@ type waitExpireTask struct { time.Duration } -func newDialState(static []*enode.Node, bootnodes []*enode.Node, ntab discoverTable, maxdyn int, netrestrict *netutil.Netlist) *dialstate { +func newDialState(self enode.ID, static []*enode.Node, bootnodes []*enode.Node, ntab discoverTable, maxdyn int, netrestrict *netutil.Netlist) *dialstate { s := &dialstate{ maxDynDials: maxdyn, ntab: ntab, + self: self, netrestrict: netrestrict, static: make(map[enode.ID]*dialTask), dialing: make(map[enode.ID]connFlag), @@ -266,7 +267,7 @@ func (s *dialstate) checkDial(n *enode.Node, peers map[enode.ID]*Peer) error { return errAlreadyDialing case peers[n.ID()] != nil: return errAlreadyConnected - case s.ntab != nil && n.ID() == s.ntab.Self().ID(): + case n.ID() == s.self: return errSelf case s.netrestrict != nil && !s.netrestrict.Contains(n.IP()): return errNotWhitelisted |