From 25d8e13293a50967634d200ca03aef492b635d77 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 4 Jun 2025 10:24:56 +1000 Subject: [PATCH] Move expvars into expvar.go --- expvar.go | 35 +++++++++++++++++++++++++++++++++++ global.go | 31 ------------------------------- 2 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 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") -) -- 2.51.0