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
|
@ -30,14 +30,14 @@ func NewTCPTransport(s *Server, bindAddr string, log *zap.Logger) *TCPTransport
|
|||
}
|
||||
|
||||
// Dial implements the Transporter interface.
|
||||
func (t *TCPTransport) Dial(addr string, timeout time.Duration) error {
|
||||
func (t *TCPTransport) Dial(addr string, timeout time.Duration) (AddressablePeer, error) {
|
||||
conn, err := net.DialTimeout("tcp", addr, timeout)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
p := NewTCPPeer(conn, t.server)
|
||||
p := NewTCPPeer(conn, addr, t.server)
|
||||
go p.handleConn()
|
||||
return nil
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Accept implements the Transporter interface.
|
||||
|
@ -69,7 +69,7 @@ func (t *TCPTransport) Accept() {
|
|||
t.log.Warn("TCP accept error", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
p := NewTCPPeer(conn, t.server)
|
||||
p := NewTCPPeer(conn, "", t.server)
|
||||
go p.handleConn()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue