提交 36f221db 编写于 作者: O obscuren

Don't connect to peers that are already connected

上级 7f100e96
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册