]> Sergey Matveev's repositories - btrtrc.git/blob - global.go
Metadata size handling and DHT logging noise
[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         // libtorrent-rasterbar uses 4MiB at last check. TODO: Add links to values used by other
16         // implementations here. I saw 14143527 in the metainfo for
17         // 3597f16e239aeb8f8524a1a1c4e4725a0a96b470. Large values for legitimate torrents should be
18         // recorded here for consideration.
19         maxMetadataSize uint32 = 16 * 1024 * 1024
20 )
21
22 // These are our extended message IDs. Peers will use these values to
23 // select which extension a message is intended for.
24 const (
25         metadataExtendedId = iota + 1 // 0 is reserved for deleting keys
26         pexExtendedId
27 )
28
29 func defaultPeerExtensionBytes() PeerExtensionBits {
30         return pp.NewPeerExtensionBytes(pp.ExtensionBitDHT, pp.ExtensionBitExtended, pp.ExtensionBitFast)
31 }
32
33 func init() {
34         torrent.Set("peers supporting extension", &peersSupportingExtension)
35         torrent.Set("chunks received", &chunksReceived)
36 }
37
38 // I could move a lot of these counters to their own file, but I suspect they
39 // may be attached to a Client someday.
40 var (
41         torrent                  = expvar.NewMap("torrent")
42         peersSupportingExtension expvar.Map
43         chunksReceived           expvar.Map
44
45         pieceHashedCorrect    = expvar.NewInt("pieceHashedCorrect")
46         pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
47
48         completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
49         // Count of connections to peer with same client ID.
50         connsToSelf        = expvar.NewInt("connsToSelf")
51         receivedKeepalives = expvar.NewInt("receivedKeepalives")
52         // Requests received for pieces we don't have.
53         requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
54         requestedChunkLengths            = expvar.NewMap("requestedChunkLengths")
55
56         messageTypesReceived = expvar.NewMap("messageTypesReceived")
57
58         // Track the effectiveness of Torrent.connPieceInclinationPool.
59         pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
60         pieceInclinationsNew    = expvar.NewInt("pieceInclinationsNew")
61         pieceInclinationsPut    = expvar.NewInt("pieceInclinationsPut")
62
63         concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites")
64 )