client.go | 15 +++++++++++---- diff --git a/client.go b/client.go index 920875478f83f9ca5d4677e8f5e4af0d0cc758f3..ae20854a0f92f66045dc4dbe2a66e546fe15c5ef 100644 --- a/client.go +++ b/client.go @@ -310,12 +310,19 @@ func (me *Client) initiateConn(peer Peer, torrent *torrent) { if peer.Id == me.peerID { return } + addr := &net.TCPAddr{ + IP: peer.IP, + 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() { - addr := &net.TCPAddr{ - IP: peer.IP, - Port: peer.Port, - } // 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 // this address so that peers associate our local address with our