]> Sergey Matveev's repositories - btrtrc.git/blob - global.go
go fmt ./...
[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         // Arbitrary maximum of "metadata_size" (see https://www.bittorrent.org/beps/bep_0009.html)
15         // This value is 2x what libtorrent-rasterbar uses, which should be plenty
16         maxMetadataSize uint32 = 8 * 1024 * 1024
17 )
18
19 // These are our extended message IDs. Peers will use these values to
20 // select which extension a message is intended for.
21 const (
22         metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
23         pexExtendedId
24 )
25
26 func defaultPeerExtensionBytes() PeerExtensionBits {
27         return pp.NewPeerExtensionBytes(pp.ExtensionBitDHT, pp.ExtensionBitExtended, pp.ExtensionBitFast)
28 }
29
30 func init() {
31         torrent.Set("peers supporting extension", &peersSupportingExtension)
32         torrent.Set("chunks received", &chunksReceived)
33 }
34
35 // I could move a lot of these counters to their own file, but I suspect they
36 // may be attached to a Client someday.
37 var (
38         torrent                  = expvar.NewMap("torrent")
39         peersSupportingExtension expvar.Map
40         chunksReceived           expvar.Map
41
42         pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
43         pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
44
45         completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
46         // Count of connections to peer with same client ID.
47         connsToSelf        = expvar.NewInt("connsToSelf")
48         receivedKeepalives = expvar.NewInt("receivedKeepalives")
49         // Requests received for pieces we don't have.
50         requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
51         requestedChunkLengths            = expvar.NewMap("requestedChunkLengths")
52
53         messageTypesReceived = expvar.NewMap("messageTypesReceived")
54
55         // Track the effectiveness of Torrent.connPieceInclinationPool.
56         pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
57         pieceInclinationsNew    = expvar.NewInt("pieceInclinationsNew")
58         pieceInclinationsPut    = expvar.NewInt("pieceInclinationsPut")
59
60         concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites")
61 )