7 pp "github.com/anacrolix/torrent/peer_protocol"
11 pieceHash = crypto.SHA1
12 defaultChunkSize = 0x4000 // 16KiB
14 // Arbitrary maximum of "metadata_size" (see https://www.bittorrent.org/beps/bep_0009.html)
15 // libtorrent-rasterbar uses 4MiB at last check. TODO: Add links to values used by other
16 // implementations here. I saw 14143527 in the metainfo for
17 // 3597f16e239aeb8f8524a1a1c4e4725a0a96b470. Large values for legitimate torrents should be
18 // recorded here for consideration.
19 maxMetadataSize uint32 = 16 * 1024 * 1024
22 // These are our extended message IDs. Peers will use these values to
23 // select which extension a message is intended for.
25 metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
30 func defaultPeerExtensionBytes() PeerExtensionBits {
31 return pp.NewPeerExtensionBytes(pp.ExtensionBitDHT, pp.ExtensionBitExtended, pp.ExtensionBitFast)
35 torrent.Set("peers supporting extension", &peersSupportingExtension)
36 torrent.Set("chunks received", &chunksReceived)
39 // I could move a lot of these counters to their own file, but I suspect they
40 // may be attached to a Client someday.
42 torrent = expvar.NewMap("torrent")
43 peersSupportingExtension expvar.Map
44 chunksReceived expvar.Map
46 pieceHashedCorrect = expvar.NewInt("pieceHashedCorrect")
47 pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
49 completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
50 // Count of connections to peer with same client ID.
51 connsToSelf = expvar.NewInt("connsToSelf")
52 receivedKeepalives = expvar.NewInt("receivedKeepalives")
53 // Requests received for pieces we don't have.
54 requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
55 requestedChunkLengths = expvar.NewMap("requestedChunkLengths")
57 messageTypesReceived = expvar.NewMap("messageTypesReceived")
59 // Track the effectiveness of Torrent.connPieceInclinationPool.
60 pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
61 pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew")
62 pieceInclinationsPut = expvar.NewInt("pieceInclinationsPut")
64 concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites")