forked from cerc-io/plugeth
p2p: ensure we don't dial ourself
addPeer doesn't allow self connects, but we can avoid opening connections in the first place.
This commit is contained in:
parent
7101f44998
commit
5cc1256fd6
@ -289,10 +289,13 @@ func (srv *Server) dialLoop() {
|
|||||||
go srv.findPeers()
|
go srv.findPeers()
|
||||||
|
|
||||||
case dest := <-srv.peerConnect:
|
case dest := <-srv.peerConnect:
|
||||||
|
// avoid dialing nodes that are already connected.
|
||||||
|
// there is another check for this in addPeer,
|
||||||
|
// which runs after the handshake.
|
||||||
srv.lock.Lock()
|
srv.lock.Lock()
|
||||||
_, isconnected := srv.peers[dest.ID]
|
_, isconnected := srv.peers[dest.ID]
|
||||||
srv.lock.Unlock()
|
srv.lock.Unlock()
|
||||||
if isconnected || dialing[dest.ID] {
|
if isconnected || dialing[dest.ID] || dest.ID == srv.ntab.Self() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user