network: register peer only if it's not a duplicate

This commit is contained in:
Roman Khimov 2022-10-14 10:16:50 +03:00
parent 851cbc7dab
commit 65f0fadddb

View file

@ -670,7 +670,6 @@ func (s *Server) handleVersionCmd(p Peer, version *payload.Version) error {
return errInvalidNetwork return errInvalidNetwork
} }
peerAddr := p.PeerAddr().String() peerAddr := p.PeerAddr().String()
s.discovery.RegisterConnectedAddr(peerAddr)
s.lock.RLock() s.lock.RLock()
for peer := range s.peers { for peer := range s.peers {
if p == peer { if p == peer {
@ -684,6 +683,7 @@ func (s *Server) handleVersionCmd(p Peer, version *payload.Version) error {
} }
} }
s.lock.RUnlock() s.lock.RUnlock()
s.discovery.RegisterConnectedAddr(peerAddr)
return p.SendVersionAck(NewMessage(CMDVerack, payload.NewNullPayload())) return p.SendVersionAck(NewMessage(CMDVerack, payload.NewNullPayload()))
} }