Don't connect to peers that are already connected

This commit is contained in:
obscuren 2014-01-31 01:12:48 +01:00
parent 7f100e9610
commit 36f221dbe7
1 changed files with 16 additions and 0 deletions

View File

@ -90,6 +90,22 @@ func (s *Ethereum) ProcessPeerList(addrs []string) {
}
func (s *Ethereum) ConnectToPeer(addr string) error {
var alreadyConnected bool
eachPeer(s.peers, func(p *Peer, v *list.Element) {
phost, _, _ := net.SplitHostPort(p.conn.RemoteAddr().String())
ahost, _, _ := net.SplitHostPort(addr)
if phost == ahost {
alreadyConnected = true
return
}
})
if alreadyConnected {
return nil
}
peer := NewOutboundPeer(addr, s)
s.peers.PushBack(peer)