2016-04-14 07:19:07 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto"
|
|
|
|
"expvar"
|
2018-07-07 01:36:58 +00:00
|
|
|
|
|
|
|
pp "github.com/anacrolix/torrent/peer_protocol"
|
2016-04-14 07:19:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
pieceHash = crypto.SHA1
|
|
|
|
maxRequests = 250 // Maximum pending requests we allow peers to send us.
|
|
|
|
defaultChunkSize = 0x4000 // 16KiB
|
2018-07-10 02:20:36 +00:00
|
|
|
)
|
2016-04-14 07:19:07 +00:00
|
|
|
|
2018-07-10 02:20:36 +00: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 07:19:07 +00:00
|
|
|
metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
|
|
|
|
pexExtendedId
|
|
|
|
)
|
|
|
|
|
2018-07-07 01:31:29 +00:00
|
|
|
func defaultPeerExtensionBytes() PeerExtensionBits {
|
|
|
|
return pp.NewPeerExtensionBytes(pp.ExtensionBitDHT, pp.ExtensionBitExtended, pp.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 (
|
2018-02-04 13:18:38 +00:00
|
|
|
torrent = expvar.NewMap("torrent")
|
|
|
|
|
2016-04-14 07:19:07 +00: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 02:20:36 +00:00
|
|
|
connsToSelf = expvar.NewInt("connsToSelf")
|
|
|
|
receivedKeepalives = expvar.NewInt("receivedKeepalives")
|
|
|
|
postedKeepalives = expvar.NewInt("postedKeepalives")
|
2016-04-14 07:19:07 +00:00
|
|
|
// 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")
|
|
|
|
|
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")
|
2019-06-13 02:18:08 +00:00
|
|
|
|
|
|
|
concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites")
|
2016-04-14 07:19:07 +00:00
|
|
|
)
|