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
|
|
|
|
maxRequests = 250 // Maximum pending requests we allow peers to send us.
|
|
|
|
defaultChunkSize = 0x4000 // 16KiB
|
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
|
|
|
}
|
|
|
|
|
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 (
|
2018-02-04 21:18:38 +08:00
|
|
|
torrent = expvar.NewMap("torrent")
|
|
|
|
|
2016-04-14 15:19:07 +08: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-07-10 10:20:36 +08:00
|
|
|
connsToSelf = expvar.NewInt("connsToSelf")
|
|
|
|
receivedKeepalives = expvar.NewInt("receivedKeepalives")
|
|
|
|
postedKeepalives = expvar.NewInt("postedKeepalives")
|
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")
|
|
|
|
)
|