network: rework discoverer/server interaction
* treat connected/handshaked peers separately in the discoverer, save "original" address for connected ones, it can be a name instead of IP and it's important to keep it to avoid reconnections * store name->IP mapping for seeds if and when they're connected to avoid reconnections * block seed if it's detected to be our own node (which is often the case for small private networks) * add an event for handshaked peers in the server, connected but non-handshaked ones are not really helpful for MinPeers or GetAddr logic Fixes #2796.
This commit is contained in:
parent
6ba4afc977
commit
23f118a1a9
10 changed files with 180 additions and 100 deletions
|
@ -141,14 +141,17 @@ func TestServerRegisterPeer(t *testing.T) {
|
|||
for i := range ps {
|
||||
ps[i] = newLocalPeer(t, s)
|
||||
ps[i].netaddr.Port = i + 1
|
||||
ps[i].version = &payload.Version{Nonce: uint32(i), UserAgent: []byte("fake")}
|
||||
}
|
||||
|
||||
startWithCleanup(t, s)
|
||||
|
||||
s.register <- ps[0]
|
||||
require.Eventually(t, func() bool { return 1 == s.PeerCount() }, time.Second, time.Millisecond*10)
|
||||
s.handshake <- ps[0]
|
||||
|
||||
s.register <- ps[1]
|
||||
s.handshake <- ps[1]
|
||||
require.Eventually(t, func() bool { return 2 == s.PeerCount() }, time.Second, time.Millisecond*10)
|
||||
|
||||
require.Equal(t, 0, len(s.discovery.UnconnectedPeers()))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue