From 36f221dbe7e66568fc3f1680208b73e4ea20c4ef Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 31 Jan 2014 01:12:48 +0100 Subject: Don't connect to peers that are already connected --- ethereum.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'ethereum.go') 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) -- cgit