From: Matt Joiner Date: Wed, 4 Jun 2025 00:24:56 +0000 (+1000) Subject: Move expvars into expvar.go X-Git-Tag: v1.59.0~81 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=25d8e13293a50967634d200ca03aef492b635d77;p=btrtrc.git Move expvars into expvar.go --- diff --git a/expvar.go b/expvar.go new file mode 100644 index 00000000..2a1f3863 --- /dev/null +++ b/expvar.go @@ -0,0 +1,35 @@ +package torrent + +import ( + "expvar" +) + +func init() { + torrent.Set("peers supporting extension", &peersSupportingExtension) + torrent.Set("chunks received", &ChunksReceived) +} + +// 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") + peersSupportingExtension expvar.Map + // This could move at any time. It contains counts of chunks received and the conditions they + // were received. + ChunksReceived expvar.Map + + pieceHashedCorrect = expvar.NewInt("pieceHashedCorrect") + pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect") + + completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags") + // Count of connections to peer with same client ID. + connsToSelf = expvar.NewInt("connsToSelf") + receivedKeepalives = expvar.NewInt("receivedKeepalives") + // Requests received for pieces we don't have. + requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces") + requestedChunkLengths = expvar.NewMap("requestedChunkLengths") + + messageTypesReceived = expvar.NewMap("messageTypesReceived") + + concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites") +) diff --git a/global.go b/global.go index b0c1ce4a..436c84f6 100644 --- a/global.go +++ b/global.go @@ -2,7 +2,6 @@ package torrent import ( "crypto" - "expvar" pp "github.com/anacrolix/torrent/peer_protocol" ) @@ -22,33 +21,3 @@ const ( func defaultPeerExtensionBytes() PeerExtensionBits { return pp.NewPeerExtensionBytes(pp.ExtensionBitDht, pp.ExtensionBitLtep, pp.ExtensionBitFast) } - -func init() { - torrent.Set("peers supporting extension", &peersSupportingExtension) - torrent.Set("chunks received", &ChunksReceived) -} - -// 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") - peersSupportingExtension expvar.Map - // This could move at any time. It contains counts of chunks received and the conditions they - // were received. - ChunksReceived expvar.Map - - pieceHashedCorrect = expvar.NewInt("pieceHashedCorrect") - pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect") - - completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags") - // Count of connections to peer with same client ID. - connsToSelf = expvar.NewInt("connsToSelf") - receivedKeepalives = expvar.NewInt("receivedKeepalives") - // Requests received for pieces we don't have. - requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces") - requestedChunkLengths = expvar.NewMap("requestedChunkLengths") - - messageTypesReceived = expvar.NewMap("messageTypesReceived") - - concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites") -)