]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Track peers supporting extension in a nested expvar.Map
authorMatt Joiner <anacrolix@gmail.com>
Tue, 11 May 2021 02:09:26 +0000 (12:09 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 14 May 2021 05:41:14 +0000 (15:41 +1000)
global.go
peerconn.go

index 6542ac393daaf324d9b2427db851b559d707aea1..ff237c8ee1edda4f9d464d08d9db1bb49c7fa670 100644 (file)
--- a/global.go
+++ b/global.go
@@ -24,10 +24,15 @@ func defaultPeerExtensionBytes() PeerExtensionBits {
        return pp.NewPeerExtensionBytes(pp.ExtensionBitDHT, pp.ExtensionBitExtended, pp.ExtensionBitFast)
 }
 
+func init() {
+       torrent.Set("peers supporting extension", &peersSupportingExtension)
+}
+
 // I could move a lot of these counters to their own file, but I suspect they
 // may be attached to a Client someday.
 var (
-       torrent = expvar.NewMap("torrent")
+       torrent                  = expvar.NewMap("torrent")
+       peersSupportingExtension expvar.Map
 
        pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
        pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
index 535ba737fca0765413868c03bed9d03b5b8cbff0..41e8662d295f31dcd93e81720ccbf5cbb31b157b 100644 (file)
@@ -1308,7 +1308,7 @@ func (c *PeerConn) onReadExtendedMsg(id pp.ExtensionNumber, payload []byte) (err
                c.PeerPrefersEncryption = d.Encryption
                for name, id := range d.M {
                        if _, ok := c.PeerExtensionIDs[name]; !ok {
-                               torrent.Add(fmt.Sprintf("peers supporting extension %q", name), 1)
+                               peersSupportingExtension.Add(string(name), 1)
                        }
                        c.PeerExtensionIDs[name] = id
                }