Avoid connecting to the same peer twice by address
This commit is contained in:
parent
aeee372506
commit
2765ad04ca
11
client.go
11
client.go
|
@ -310,12 +310,19 @@ func (me *Client) initiateConn(peer Peer, torrent *torrent) {
|
||||||
if peer.Id == me.peerID {
|
if peer.Id == me.peerID {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
me.halfOpen++
|
|
||||||
go func() {
|
|
||||||
addr := &net.TCPAddr{
|
addr := &net.TCPAddr{
|
||||||
IP: peer.IP,
|
IP: peer.IP,
|
||||||
Port: peer.Port,
|
Port: peer.Port,
|
||||||
}
|
}
|
||||||
|
// Don't connect to the same address twice for the same torrent.
|
||||||
|
for _, c := range torrent.Conns {
|
||||||
|
if c.Socket.RemoteAddr().String() == addr.String() {
|
||||||
|
duplicateConnsAvoided.Add(1)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
me.halfOpen++
|
||||||
|
go func() {
|
||||||
// Binding to the listener address and dialing via net.Dialer gives
|
// Binding to the listener address and dialing via net.Dialer gives
|
||||||
// "address in use" error. It seems it's not possible to dial out from
|
// "address in use" error. It seems it's not possible to dial out from
|
||||||
// this address so that peers associate our local address with our
|
// this address so that peers associate our local address with our
|
||||||
|
|
Loading…
Reference in New Issue