]> Sergey Matveev's repositories - btrtrc.git/blob - global.go
Merge branch 'request-strategy-rewrite'
[btrtrc.git] / global.go
1 package torrent
2
3 import (
4         "crypto"
5         "expvar"
6
7         pp "github.com/anacrolix/torrent/peer_protocol"
8 )
9
10 const (
11         pieceHash        = crypto.SHA1
12         defaultChunkSize = 0x4000 // 16KiB
13 )
14
15 // These are our extended message IDs. Peers will use these values to
16 // select which extension a message is intended for.
17 const (
18         metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
19         pexExtendedId
20 )
21
22 func defaultPeerExtensionBytes() PeerExtensionBits {
23         return pp.NewPeerExtensionBytes(pp.ExtensionBitDHT, pp.ExtensionBitExtended, pp.ExtensionBitFast)
24 }
25
26 func init() {
27         torrent.Set("peers supporting extension", &peersSupportingExtension)
28         torrent.Set("chunks received", &chunksReceived)
29 }
30
31 // I could move a lot of these counters to their own file, but I suspect they
32 // may be attached to a Client someday.
33 var (
34         torrent                  = expvar.NewMap("torrent")
35         peersSupportingExtension expvar.Map
36         chunksReceived           expvar.Map
37
38         pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
39         pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
40
41         completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
42         // Count of connections to peer with same client ID.
43         connsToSelf        = expvar.NewInt("connsToSelf")
44         receivedKeepalives = expvar.NewInt("receivedKeepalives")
45         // Requests received for pieces we don't have.
46         requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
47         requestedChunkLengths            = expvar.NewMap("requestedChunkLengths")
48
49         messageTypesReceived = expvar.NewMap("messageTypesReceived")
50
51         // Track the effectiveness of Torrent.connPieceInclinationPool.
52         pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
53         pieceInclinationsNew    = expvar.NewInt("pieceInclinationsNew")
54         pieceInclinationsPut    = expvar.NewInt("pieceInclinationsPut")
55
56         concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites")
57 )