]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Count peers not added because of bad addresses and rearrange method
authorMatt Joiner <anacrolix@gmail.com>
Thu, 8 Feb 2018 12:55:28 +0000 (23:55 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 8 Feb 2018 12:55:28 +0000 (23:55 +1100)
torrent.go

index 69ad0ca0b02c78be72f1fdff4ecdc03e5542c36e..f058a72f5d52510bc6e53e8ce6831ff2955f10bd 100644 (file)
@@ -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)
        }
 }