]> Sergey Matveev's repositories - btrtrc.git/blob - global.go
Merge branch 'master' into pull-writer
[btrtrc.git] / global.go
1 package torrent
2
3 import (
4         "crypto"
5         "expvar"
6         "time"
7 )
8
9 const (
10         pieceHash        = crypto.SHA1
11         maxRequests      = 250    // Maximum pending requests we allow peers to send us.
12         defaultChunkSize = 0x4000 // 16KiB
13
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
16         // `bep20`.
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`.
21         bep20 = "-GT0001-"
22
23         nominalDialTimeout = time.Second * 30
24         minDialTimeout     = 5 * time.Second
25
26         // Justification for set bits follows.
27         //
28         // Extension protocol ([5]|=0x10):
29         // http://www.bittorrent.org/beps/bep_0010.html
30         //
31         // Fast Extension ([7]|=0x04):
32         // http://bittorrent.org/beps/bep_0006.html.
33         // Disabled until AllowedFast is implemented.
34         //
35         // DHT ([7]|=1):
36         // http://www.bittorrent.org/beps/bep_0005.html
37         defaultExtensionBytes = "\x00\x00\x00\x00\x00\x10\x00\x01"
38
39         defaultEstablishedConnsPerTorrent = 80
40         defaultHalfOpenConnsPerTorrent    = 80
41         torrentPeersHighWater             = 200
42         torrentPeersLowWater              = 50
43
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
48
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
52         pexExtendedId
53 )
54
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.
57 var (
58         unwantedChunksReceived   = expvar.NewInt("chunksReceivedUnwanted")
59         unexpectedChunksReceived = expvar.NewInt("chunksReceivedUnexpected")
60         chunksReceived           = expvar.NewInt("chunksReceived")
61
62         peersAddedBySource = expvar.NewMap("peersAddedBySource")
63
64         uploadChunksPosted = expvar.NewInt("uploadChunksPosted")
65         unexpectedCancels  = expvar.NewInt("unexpectedCancels")
66
67         pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
68         pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
69
70         unsuccessfulDials = expvar.NewInt("dialSuccessful")
71         successfulDials   = expvar.NewInt("dialUnsuccessful")
72
73         acceptUTP    = expvar.NewInt("acceptUTP")
74         acceptTCP    = expvar.NewInt("acceptTCP")
75         acceptReject = expvar.NewInt("acceptReject")
76
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")
88
89         messageTypesReceived = expvar.NewMap("messageTypesReceived")
90         messageTypesSent     = expvar.NewMap("messageTypesSent")
91         messageTypesPosted   = expvar.NewMap("messageTypesPosted")
92
93         // Track the effectiveness of Torrent.connPieceInclinationPool.
94         pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
95         pieceInclinationsNew    = expvar.NewInt("pieceInclinationsNew")
96         pieceInclinationsPut    = expvar.NewInt("pieceInclinationsPut")
97
98         fillBufferSentCancels  = expvar.NewInt("fillBufferSentCancels")
99         fillBufferSentRequests = expvar.NewInt("fillBufferSentRequests")
100         numFillBuffers         = expvar.NewInt("numFillBuffers")
101 )