]> Sergey Matveev's repositories - btrtrc.git/blob - global.go
Merge branch 'master' of https://github.com/lovedboy/torrent
[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
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         receivedMessageTypes       = expvar.NewMap("receivedMessageTypes")
84         receivedKeepalives         = expvar.NewInt("receivedKeepalives")
85         supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages")
86         postedMessageTypes         = expvar.NewMap("postedMessageTypes")
87         postedKeepalives           = expvar.NewInt("postedKeepalives")
88         // Requests received for pieces we don't have.
89         requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
90
91         // Track the effectiveness of Torrent.connPieceInclinationPool.
92         pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
93         pieceInclinationsNew    = expvar.NewInt("pieceInclinationsNew")
94         pieceInclinationsPut    = expvar.NewInt("pieceInclinationsPut")
95 )