Browse Source

only allow one connection per ip

pull/67/head
Ethan Buchman 10 years ago
committed by Jae Kwon
parent
commit
4f94e0f200
3 changed files with 7 additions and 7 deletions
  1. +1
    -1
      p2p/peer.go
  2. +3
    -3
      p2p/pex_reactor.go
  3. +3
    -3
      p2p/switch.go

+ 1
- 1
p2p/peer.go View File

@ -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


+ 3
- 3
p2p/pex_reactor.go View File

@ -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


+ 3
- 3
p2p/switch.go View File

@ -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


Loading…
Cancel
Save