forked from TrueCloudLab/neoneo-go
network: detect duplicate connections before handshake completes
We can have more than one connection attempt in progress and not yet completed the handshake, so if there is a Version already received we should look it.
This commit is contained in:
parent
48ca0e1126
commit
b79abd1e27
1 changed files with 5 additions and 1 deletions
|
@ -350,8 +350,12 @@ func (s *Server) handleVersionCmd(p Peer, version *payload.Version) error {
|
||||||
peerAddr := p.PeerAddr().String()
|
peerAddr := p.PeerAddr().String()
|
||||||
s.lock.RLock()
|
s.lock.RLock()
|
||||||
for peer := range s.peers {
|
for peer := range s.peers {
|
||||||
|
if p == peer {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ver := peer.Version()
|
||||||
// Already connected, drop this connection.
|
// Already connected, drop this connection.
|
||||||
if peer.Handshaked() && peer.PeerAddr().String() == peerAddr && peer.Version().Nonce == version.Nonce {
|
if ver != nil && ver.Nonce == version.Nonce && peer.PeerAddr().String() == peerAddr {
|
||||||
s.lock.RUnlock()
|
s.lock.RUnlock()
|
||||||
return errAlreadyConnected
|
return errAlreadyConnected
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue