2016-04-14 15:19:07 +08:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto"
|
|
|
|
"expvar"
|
2018-07-07 09:36:58 +08:00
|
|
|
|
|
|
|
pp "github.com/anacrolix/torrent/peer_protocol"
|
2016-04-14 15:19:07 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
pieceHash = crypto.SHA1
|
|
|
|
defaultChunkSize = 0x4000 // 16KiB
|
2021-10-05 14:48:52 +08:00
|
|
|
|
2021-09-14 20:36:19 +08:00
|
|
|
// Arbitrary maximum of "metadata_size" (see https://www.bittorrent.org/beps/bep_0009.html)
|
|
|
|
// This value is 2x what libtorrent-rasterbar uses, which should be plenty
|
2021-10-05 14:48:52 +08:00
|
|
|
maxMetadataSize uint32 = 8 * 1024 * 1024
|
2018-07-10 10:20:36 +08:00
|
|
|
)
|
2016-04-14 15:19:07 +08:00
|
|
|
|
2018-07-10 10:20:36 +08:00
|
|
|
// These are our extended message IDs. Peers will use these values to
|
|
|
|
// select which extension a message is intended for.
|
|
|
|
const (
|
2016-04-14 15:19:07 +08:00
|
|
|
metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
|
|
|
|
pexExtendedId
|
|
|
|
)
|
|
|
|
|
2018-07-07 09:31:29 +08:00
|
|
|
func defaultPeerExtensionBytes() PeerExtensionBits {
|
|
|
|
return pp.NewPeerExtensionBytes(pp.ExtensionBitDHT, pp.ExtensionBitExtended, pp.ExtensionBitFast)
|
2018-02-03 10:36:17 +08:00
|
|
|
}
|
|
|
|
|
2021-05-11 10:09:26 +08:00
|
|
|
func init() {
|
|
|
|
torrent.Set("peers supporting extension", &peersSupportingExtension)
|
2021-05-11 15:13:03 +08:00
|
|
|
torrent.Set("chunks received", &chunksReceived)
|
2021-05-11 10:09:26 +08:00
|
|
|
}
|
|
|
|
|
2016-04-14 15:19:07 +08:00
|
|
|
// I could move a lot of these counters to their own file, but I suspect they
|
|
|
|
// may be attached to a Client someday.
|
|
|
|
var (
|
2021-05-11 10:09:26 +08:00
|
|
|
torrent = expvar.NewMap("torrent")
|
|
|
|
peersSupportingExtension expvar.Map
|
2021-05-11 15:13:03 +08:00
|
|
|
chunksReceived expvar.Map
|
2018-02-04 21:18:38 +08:00
|
|
|
|
2016-04-14 15:19:07 +08:00
|
|
|
pieceHashedCorrect = expvar.NewInt("pieceHashedCorrect")
|
|
|
|
pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
|
|
|
|
|
|
|
|
completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
|
|
|
|
// Count of connections to peer with same client ID.
|
2018-07-10 10:20:36 +08:00
|
|
|
connsToSelf = expvar.NewInt("connsToSelf")
|
|
|
|
receivedKeepalives = expvar.NewInt("receivedKeepalives")
|
2016-04-14 15:19:07 +08:00
|
|
|
// Requests received for pieces we don't have.
|
|
|
|
requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
|
2018-02-02 13:06:24 +08:00
|
|
|
requestedChunkLengths = expvar.NewMap("requestedChunkLengths")
|
2016-04-14 15:19:07 +08:00
|
|
|
|
2017-09-01 08:53:59 +08:00
|
|
|
messageTypesReceived = expvar.NewMap("messageTypesReceived")
|
|
|
|
|
2016-04-14 15:19:07 +08:00
|
|
|
// Track the effectiveness of Torrent.connPieceInclinationPool.
|
|
|
|
pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
|
|
|
|
pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew")
|
|
|
|
pieceInclinationsPut = expvar.NewInt("pieceInclinationsPut")
|
2019-06-13 10:18:08 +08:00
|
|
|
|
|
|
|
concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites")
|
2016-04-14 15:19:07 +08:00
|
|
|
)
|