From fadbd68d9998a6a7c5f912490bcaa2cbc330c4ea Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Thu, 8 Feb 2018 23:55:28 +1100 Subject: [PATCH] Count peers not added because of bad addresses and rearrange method --- torrent.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/torrent.go b/torrent.go index 69ad0ca0..f058a72f 100644 --- a/torrent.go +++ b/torrent.go @@ -245,16 +245,16 @@ func (t *Torrent) unclosedConnsAsSlice() (ret []*connection) { func (t *Torrent) addPeer(p Peer) { cl := t.cl - t.openNewConns() - if len(t.peers) >= cl.config.TorrentPeersHighWater { + peersAddedBySource.Add(string(p.Source), 1) + if cl.badPeerIPPort(p.IP, p.Port) { + torrent.Add("peers not added because of bad addr", 1) return } - key := peersKey{string(p.IP), p.Port} - if _, ok := t.peers[key]; ok { + t.openNewConns() + if len(t.peers) >= cl.config.TorrentPeersHighWater { return } - t.peers[key] = p - peersAddedBySource.Add(string(p.Source), 1) + t.peers[peersKey{string(p.IP), p.Port}] = p t.openNewConns() } @@ -1395,9 +1395,6 @@ func (t *Torrent) dhtAnnouncer() { func (t *Torrent) addPeers(peers []Peer) { for _, p := range peers { - if t.cl.badPeerIPPort(p.IP, p.Port) { - continue - } t.addPeer(p) } } -- 2.50.0