2016-04-14 07:19:07 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto"
|
|
|
|
"expvar"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
pieceHash = crypto.SHA1
|
|
|
|
maxRequests = 250 // Maximum pending requests we allow peers to send us.
|
|
|
|
defaultChunkSize = 0x4000 // 16KiB
|
|
|
|
|
|
|
|
// These are our extended message IDs. Peers will use these values to
|
|
|
|
// select which extension a message is intended for.
|
|
|
|
metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
|
|
|
|
pexExtendedId
|
|
|
|
)
|
|
|
|
|
2018-02-03 02:36:17 +00:00
|
|
|
func defaultPeerExtensionBytes() peerExtensionBytes {
|
2018-02-04 13:18:38 +00:00
|
|
|
return newPeerExtensionBytes(ExtensionBitDHT, ExtensionBitExtended, ExtensionBitFast)
|
2018-02-03 02:36:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-14 07:19:07 +00: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 (
|
|
|
|
unwantedChunksReceived = expvar.NewInt("chunksReceivedUnwanted")
|
|
|
|
unexpectedChunksReceived = expvar.NewInt("chunksReceivedUnexpected")
|
|
|
|
chunksReceived = expvar.NewInt("chunksReceived")
|
|
|
|
|
2018-02-04 13:18:38 +00:00
|
|
|
torrent = expvar.NewMap("torrent")
|
|
|
|
|
2016-04-14 07:19:07 +00:00
|
|
|
peersAddedBySource = expvar.NewMap("peersAddedBySource")
|
|
|
|
|
|
|
|
pieceHashedCorrect = expvar.NewInt("pieceHashedCorrect")
|
|
|
|
pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
|
|
|
|
|
|
|
|
peerExtensions = expvar.NewMap("peerExtensions")
|
|
|
|
completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
|
|
|
|
// Count of connections to peer with same client ID.
|
2018-06-12 10:23:26 +00:00
|
|
|
connsToSelf = expvar.NewInt("connsToSelf")
|
2016-04-14 07:19:07 +00:00
|
|
|
receivedKeepalives = expvar.NewInt("receivedKeepalives")
|
|
|
|
supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages")
|
|
|
|
postedKeepalives = expvar.NewInt("postedKeepalives")
|
|
|
|
// Requests received for pieces we don't have.
|
|
|
|
requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
|
2018-02-02 05:06:24 +00:00
|
|
|
requestedChunkLengths = expvar.NewMap("requestedChunkLengths")
|
2016-04-14 07:19:07 +00:00
|
|
|
|
2017-09-01 00:53:59 +00:00
|
|
|
messageTypesReceived = expvar.NewMap("messageTypesReceived")
|
|
|
|
messageTypesSent = expvar.NewMap("messageTypesSent")
|
|
|
|
messageTypesPosted = expvar.NewMap("messageTypesPosted")
|
|
|
|
|
2016-04-14 07:19:07 +00:00
|
|
|
// Track the effectiveness of Torrent.connPieceInclinationPool.
|
|
|
|
pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
|
|
|
|
pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew")
|
|
|
|
pieceInclinationsPut = expvar.NewInt("pieceInclinationsPut")
|
2017-09-01 00:36:43 +00:00
|
|
|
|
|
|
|
fillBufferSentCancels = expvar.NewInt("fillBufferSentCancels")
|
|
|
|
fillBufferSentRequests = expvar.NewInt("fillBufferSentRequests")
|
|
|
|
numFillBuffers = expvar.NewInt("numFillBuffers")
|
2016-04-14 07:19:07 +00:00
|
|
|
)
|