diff options
author | obscuren <geffobscura@gmail.com> | 2014-01-31 08:12:48 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-01-31 08:12:48 +0800 |
commit | 36f221dbe7e66568fc3f1680208b73e4ea20c4ef (patch) | |
tree | 2b05a23d05abff8329f66431c8ead60830c245da /ethereum.go | |
parent | 7f100e96101a057cba7b2d5c58c12d2f7accf381 (diff) | |
download | go-tangerine-36f221dbe7e66568fc3f1680208b73e4ea20c4ef.tar.gz go-tangerine-36f221dbe7e66568fc3f1680208b73e4ea20c4ef.tar.zst go-tangerine-36f221dbe7e66568fc3f1680208b73e4ea20c4ef.zip |
Don't connect to peers that are already connected
Diffstat (limited to 'ethereum.go')
-rw-r--r-- | ethereum.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/ethereum.go b/ethereum.go index 98316cf04..dd6256f4b 100644 --- a/ethereum.go +++ b/ethereum.go @@ -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) |