10 pieceHash = crypto.SHA1
11 maxRequests = 250 // Maximum pending requests we allow peers to send us.
12 defaultChunkSize = 0x4000 // 16KiB
14 // Updated occasionally to when there's been some changes to client
15 // behaviour in case other clients are assuming anything of us. See also
17 extendedHandshakeClientVersion = "go.torrent dev 20150624"
18 // Peer ID client identifier prefix. We'll update this occasionally to
19 // reflect changes to client behaviour that other clients may depend on.
20 // Also see `extendedHandshakeClientVersion`.
23 nominalDialTimeout = time.Second * 30
24 minDialTimeout = 5 * time.Second
26 // Justification for set bits follows.
28 // Extension protocol ([5]|=0x10):
29 // http://www.bittorrent.org/beps/bep_0010.html
31 // Fast Extension ([7]|=0x04):
32 // http://bittorrent.org/beps/bep_0006.html.
33 // Disabled until AllowedFast is implemented. TODO
36 // http://www.bittorrent.org/beps/bep_0005.html
37 defaultExtensionBytes = "\x00\x00\x00\x00\x00\x10\x00\x01"
39 defaultEstablishedConnsPerTorrent = 80
40 defaultHalfOpenConnsPerTorrent = 80
41 torrentPeersHighWater = 200
42 torrentPeersLowWater = 50
44 // Limit how long handshake can take. This is to reduce the lingering
45 // impact of a few bad apples. 4s loses 1% of successful handshakes that
46 // are obtained with 60s timeout, and 5% of unsuccessful handshakes.
47 handshakesTimeout = 20 * time.Second
49 // These are our extended message IDs. Peers will use these values to
50 // select which extension a message is intended for.
51 metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
55 // I could move a lot of these counters to their own file, but I suspect they
56 // may be attached to a Client someday.
58 unwantedChunksReceived = expvar.NewInt("chunksReceivedUnwanted")
59 unexpectedChunksReceived = expvar.NewInt("chunksReceivedUnexpected")
60 chunksReceived = expvar.NewInt("chunksReceived")
62 peersAddedBySource = expvar.NewMap("peersAddedBySource")
64 uploadChunksPosted = expvar.NewInt("uploadChunksPosted")
65 unexpectedCancels = expvar.NewInt("unexpectedCancels")
67 pieceHashedCorrect = expvar.NewInt("pieceHashedCorrect")
68 pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
70 unsuccessfulDials = expvar.NewInt("dialSuccessful")
71 successfulDials = expvar.NewInt("dialUnsuccessful")
73 acceptUTP = expvar.NewInt("acceptUTP")
74 acceptTCP = expvar.NewInt("acceptTCP")
75 acceptReject = expvar.NewInt("acceptReject")
77 peerExtensions = expvar.NewMap("peerExtensions")
78 completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
79 // Count of connections to peer with same client ID.
80 connsToSelf = expvar.NewInt("connsToSelf")
81 // Number of completed connections to a client we're already connected with.
82 duplicateClientConns = expvar.NewInt("duplicateClientConns")
83 receivedKeepalives = expvar.NewInt("receivedKeepalives")
84 supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages")
85 postedKeepalives = expvar.NewInt("postedKeepalives")
86 // Requests received for pieces we don't have.
87 requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
89 messageTypesReceived = expvar.NewMap("messageTypesReceived")
90 messageTypesSent = expvar.NewMap("messageTypesSent")
91 messageTypesPosted = expvar.NewMap("messageTypesPosted")
93 // Track the effectiveness of Torrent.connPieceInclinationPool.
94 pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
95 pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew")
96 pieceInclinationsPut = expvar.NewInt("pieceInclinationsPut")
98 fillBufferSentCancels = expvar.NewInt("fillBufferSentCancels")
99 fillBufferSentRequests = expvar.NewInt("fillBufferSentRequests")
100 numFillBuffers = expvar.NewInt("numFillBuffers")