From b2c4587dad732e2150d1591e7f2ccd2b216f5682 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 28 Jan 2020 20:52:24 +0300 Subject: [PATCH] network: fix PeerAddr() for not-yet-handshaked case If we have already got Version message, we don't need the rest of handshake to complete before being able to properly answer the PeerAddr() requests. Fixes some duplicate connections between machines. --- pkg/network/tcp_peer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/network/tcp_peer.go b/pkg/network/tcp_peer.go index 84fb00c4c..5fff05736 100644 --- a/pkg/network/tcp_peer.go +++ b/pkg/network/tcp_peer.go @@ -333,7 +333,7 @@ func (p *TCPPeer) RemoteAddr() net.Addr { func (p *TCPPeer) PeerAddr() net.Addr { remote := p.conn.RemoteAddr() // The network can be non-tcp in unit tests. - if !p.Handshaked() || remote.Network() != "tcp" { + if p.version == nil || remote.Network() != "tcp" { return p.RemoteAddr() } host, _, err := net.SplitHostPort(remote.String())