From 4f94e0f200d046cafb803dbd9cad854d236b9bac Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sat, 25 Apr 2015 18:01:02 -0700 Subject: [PATCH] only allow one connection per ip --- p2p/peer.go | 2 +- p2p/pex_reactor.go | 6 +++--- p2p/switch.go | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/p2p/peer.go b/p2p/peer.go index 549200e24..071efd65f 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -68,7 +68,7 @@ func newPeer(conn net.Conn, peerNodeInfo *types.NodeInfo, outbound bool, reactor mconn: mconn, running: 0, NodeInfo: peerNodeInfo, - Key: mconn.RemoteAddress.String(), + Key: mconn.RemoteAddress.IP.String(), Data: NewCMap(), } return p diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index 0f9766d62..f5d26d573 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -170,9 +170,9 @@ func (pexR *PEXReactor) ensurePeers() { if try == nil { break } - alreadySelected := toDial.Has(try.String()) + alreadySelected := toDial.Has(try.IP.String()) alreadyDialing := pexR.sw.IsDialing(try) - alreadyConnected := pexR.sw.Peers().Has(try.String()) + alreadyConnected := pexR.sw.Peers().Has(try.IP.String()) if alreadySelected || alreadyDialing || alreadyConnected { /* log.Debug("Cannot dial address", "addr", try, @@ -190,7 +190,7 @@ func (pexR *PEXReactor) ensurePeers() { if picked == nil { continue } - toDial.Set(picked.String(), picked) + toDial.Set(picked.IP.String(), picked) } // Dial picked addresses diff --git a/p2p/switch.go b/p2p/switch.go index b56b86aaf..e86b46511 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -188,9 +188,9 @@ func (sw *Switch) startInitPeer(peer *Peer) { func (sw *Switch) DialPeerWithAddress(addr *NetAddress) (*Peer, error) { log.Debug("Dialing address", "address", addr) - sw.dialing.Set(addr.String(), addr) + sw.dialing.Set(addr.IP.String(), addr) conn, err := addr.DialTimeout(peerDialTimeoutSeconds * time.Second) - sw.dialing.Delete(addr.String()) + sw.dialing.Delete(addr.IP.String()) if err != nil { log.Debug("Failed dialing address", "address", addr, "error", err) return nil, err @@ -205,7 +205,7 @@ func (sw *Switch) DialPeerWithAddress(addr *NetAddress) (*Peer, error) { } func (sw *Switch) IsDialing(addr *NetAddress) bool { - return sw.dialing.Has(addr.String()) + return sw.dialing.Has(addr.IP.String()) } // Broadcast runs a go routine for each attempted send, which will block