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.
This commit is contained in:
Roman Khimov 2020-01-28 20:52:24 +03:00
parent 49bd7aada5
commit b2c4587dad

View file

@ -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())