]> Sergey Matveev's repositories - btrtrc.git/blob - global.go
Merge all our global consts and vars into global.go
[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         socketsPerTorrent     = 80
40         torrentPeersHighWater = 200
41         torrentPeersLowWater  = 50
42
43         // Limit how long handshake can take. This is to reduce the lingering
44         // impact of a few bad apples. 4s loses 1% of successful handshakes that
45         // are obtained with 60s timeout, and 5% of unsuccessful handshakes.
46         handshakesTimeout = 20 * time.Second
47
48         // These are our extended message IDs. Peers will use these values to
49         // select which extension a message is intended for.
50         metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
51         pexExtendedId
52 )
53
54 // I could move a lot of these counters to their own file, but I suspect they
55 // may be attached to a Client someday.
56 var (
57         unwantedChunksReceived   = expvar.NewInt("chunksReceivedUnwanted")
58         unexpectedChunksReceived = expvar.NewInt("chunksReceivedUnexpected")
59         chunksReceived           = expvar.NewInt("chunksReceived")
60
61         peersAddedBySource = expvar.NewMap("peersAddedBySource")
62
63         uploadChunksPosted    = expvar.NewInt("uploadChunksPosted")
64         unexpectedCancels     = expvar.NewInt("unexpectedCancels")
65         postedCancels         = expvar.NewInt("postedCancels")
66         duplicateConnsAvoided = expvar.NewInt("duplicateConnsAvoided")
67
68         pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
69         pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
70
71         unsuccessfulDials = expvar.NewInt("dialSuccessful")
72         successfulDials   = expvar.NewInt("dialUnsuccessful")
73
74         acceptUTP    = expvar.NewInt("acceptUTP")
75         acceptTCP    = expvar.NewInt("acceptTCP")
76         acceptReject = expvar.NewInt("acceptReject")
77
78         peerExtensions                    = expvar.NewMap("peerExtensions")
79         completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
80         // Count of connections to peer with same client ID.
81         connsToSelf = expvar.NewInt("connsToSelf")
82         // Number of completed connections to a client we're already connected with.
83         duplicateClientConns       = expvar.NewInt("duplicateClientConns")
84         receivedMessageTypes       = expvar.NewMap("receivedMessageTypes")
85         receivedKeepalives         = expvar.NewInt("receivedKeepalives")
86         supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages")
87         postedMessageTypes         = expvar.NewMap("postedMessageTypes")
88         postedKeepalives           = expvar.NewInt("postedKeepalives")
89         // Requests received for pieces we don't have.
90         requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
91
92         // Track the effectiveness of Torrent.connPieceInclinationPool.
93         pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
94         pieceInclinationsNew    = expvar.NewInt("pieceInclinationsNew")
95         pieceInclinationsPut    = expvar.NewInt("pieceInclinationsPut")
96 )