global.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package torrent
  2. import (
  3. "crypto"
  4. "expvar"
  5. pp "github.com/anacrolix/torrent/peer_protocol"
  6. )
  7. const (
  8. pieceHash = crypto.SHA1
  9. defaultChunkSize = 0x4000 // 16KiB
  10. // Arbitrary maximum of "metadata_size" (see https://www.bittorrent.org/beps/bep_0009.html)
  11. // libtorrent-rasterbar uses 4MiB at last check. TODO: Add links to values used by other
  12. // implementations here. I saw 14143527 in the metainfo for
  13. // 3597f16e239aeb8f8524a1a1c4e4725a0a96b470. Large values for legitimate torrents should be
  14. // recorded here for consideration.
  15. maxMetadataSize uint32 = 16 * 1024 * 1024
  16. )
  17. func defaultPeerExtensionBytes() PeerExtensionBits {
  18. return pp.NewPeerExtensionBytes(pp.ExtensionBitDht, pp.ExtensionBitLtep, pp.ExtensionBitFast)
  19. }
  20. func init() {
  21. torrent.Set("peers supporting extension", &peersSupportingExtension)
  22. torrent.Set("chunks received", &ChunksReceived)
  23. }
  24. // I could move a lot of these counters to their own file, but I suspect they
  25. // may be attached to a Client someday.
  26. var (
  27. torrent = expvar.NewMap("torrent")
  28. peersSupportingExtension expvar.Map
  29. // This could move at any time. It contains counts of chunks received and the conditions they
  30. // were received.
  31. ChunksReceived expvar.Map
  32. pieceHashedCorrect = expvar.NewInt("pieceHashedCorrect")
  33. pieceHashedNotCorrect = expvar.NewInt("pieceHashedNotCorrect")
  34. completedHandshakeConnectionFlags = expvar.NewMap("completedHandshakeConnectionFlags")
  35. // Count of connections to peer with same client ID.
  36. connsToSelf = expvar.NewInt("connsToSelf")
  37. receivedKeepalives = expvar.NewInt("receivedKeepalives")
  38. // Requests received for pieces we don't have.
  39. requestsReceivedForMissingPieces = expvar.NewInt("requestsReceivedForMissingPieces")
  40. requestedChunkLengths = expvar.NewMap("requestedChunkLengths")
  41. messageTypesReceived = expvar.NewMap("messageTypesReceived")
  42. // Track the effectiveness of Torrent.connPieceInclinationPool.
  43. pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")
  44. pieceInclinationsNew = expvar.NewInt("pieceInclinationsNew")
  45. pieceInclinationsPut = expvar.NewInt("pieceInclinationsPut")
  46. concurrentChunkWrites = expvar.NewInt("torrentConcurrentChunkWrites")
  47. )