network: allow discoverer to reuse addresses

...and don't try to connect to the nodes we're already connected to.

Before this change we had a problem of discoverer throwing away good valid
addresses just because they are already known which lead to pool draining over
time (as address reuse was basically forbidden and getaddr may not get enough
new nodes).
This commit is contained in:
Roman Khimov 2019-09-13 19:51:58 +03:00
parent 46dc141c6c
commit 773ccc2b92
3 changed files with 62 additions and 16 deletions

View file

@ -160,7 +160,9 @@ func (s *Server) run() {
"reason": drop.reason,
"peerCount": s.PeerCount(),
}).Warn("peer disconnected")
s.discovery.BackFill(drop.peer.NetAddr().String())
addr := drop.peer.NetAddr().String()
s.discovery.UnregisterConnectedAddr(addr)
s.discovery.BackFill(addr)
}
// else the peer is already gone, which can happen
// because we have two goroutines sending signals here
@ -191,6 +193,7 @@ func (s *Server) startProtocol(p Peer) {
"id": p.Version().Nonce,
}).Info("started protocol")
s.discovery.RegisterGoodAddr(p.NetAddr().String())
err := s.requestHeaders(p)
if err != nil {
p.Disconnect(err)