]> Sergey Matveev's repositories - btrtrc.git/blob - global.go
feat(config): Allows the torrent client to customise the client identity and connecti...
[btrtrc.git] / global.go
1 package torrent
2
3 import (
4         "crypto"
5         "expvar"
6 )
7
8 const (
9         pieceHash        = crypto.SHA1
10         maxRequests      = 250    // Maximum pending requests we allow peers to send us.
11         defaultChunkSize = 0x4000 // 16KiB
12
13         // Justification for set bits follows.
14         //
15         // Extension protocol ([5]|=0x10):
16         // http://www.bittorrent.org/beps/bep_0010.html
17         //
18         // Fast Extension ([7]|=0x04):
19         // http://bittorrent.org/beps/bep_0006.html.
20         // Disabled until AllowedFast is implemented. TODO
21         //
22         // DHT ([7]|=1):
23         // http://www.bittorrent.org/beps/bep_0005.html
24         defaultExtensionBytes = "\x00\x00\x00\x00\x00\x10\x00\x01"
25
26         // These are our extended message IDs. Peers will use these values to
27         // select which extension a message is intended for.
28         metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
29         pexExtendedId
30 )
31
32 // I could move a lot of these counters to their own file, but I suspect they
33 // may be attached to a Client someday.
34 var (
35         unwantedChunksReceived   = expvar.NewInt("chunksReceivedUnwanted")
36         unexpectedChunksReceived = expvar.NewInt("chunksReceivedUnexpected")
37         chunksReceived           = expvar.NewInt("chunksReceived")
38
39         peersAddedBySource = expvar.NewMap("peersAddedBySource")
40
41         uploadChunksPosted = expvar.NewInt("uploadChunksPosted")
42         unexpectedCancels  = expvar.NewInt("unexpectedCancels")
43
44         pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
45         pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
46
47         unsuccessfulDials = expvar.NewInt("dialSuccessful")
48         successfulDials   = expvar.NewInt("dialUnsuccessful")
49
50         acceptUTP    = expvar.NewInt("acceptUTP")
51         acceptTCP    = expvar.NewInt("acceptTCP")
52         acceptReject = expvar.NewInt("acceptReject")
53
54         peerExtensions                    = expvar.NewMap("peerExtensions")
55         completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
56         // Count of connections to peer with same client ID.
57         connsToSelf = expvar.NewInt("connsToSelf")
58         // Number of completed connections to a client we're already connected with.
59         duplicateClientConns       = expvar.NewInt("duplicateClientConns")
60         receivedKeepalives         = expvar.NewInt("receivedKeepalives")
61         supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages")
62         postedKeepalives           = expvar.NewInt("postedKeepalives")
63         // Requests received for pieces we don't have.
64         requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
65
66         messageTypesReceived = expvar.NewMap("messageTypesReceived")
67         messageTypesSent     = expvar.NewMap("messageTypesSent")
68         messageTypesPosted   = expvar.NewMap("messageTypesPosted")
69
70         // Track the effectiveness of Torrent.connPieceInclinationPool.
71         pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
72         pieceInclinationsNew    = expvar.NewInt("pieceInclinationsNew")
73         pieceInclinationsPut    = expvar.NewInt("pieceInclinationsPut")
74
75         fillBufferSentCancels  = expvar.NewInt("fillBufferSentCancels")
76         fillBufferSentRequests = expvar.NewInt("fillBufferSentRequests")
77         numFillBuffers         = expvar.NewInt("numFillBuffers")
78 )