java.lang.Object
org.klomp.snark.TrackerInfo

class TrackerInfoextends Object
The data structure for the tracker response. Handles both traditional and compact formats.

Compact format 1 - a list of hashes - early format for testing. Compact format 2 - One big string of concatenated hashes - official format.

  • Field Details

    • failure_reason

      private final String failure_reason
      Why the last announce failed, null on success.
    • interval

      private final int interval
      Seconds the tracker asks between announces.
    • peers

      private final Set<Peer> peers
      The peers from the response, unmodifiable and never null: a failure response has no peers, and is reported by getFailureReason() instead.
    • complete

      private int complete
      Peers reported as complete.
    • incomplete

      private int incomplete
      Peers reported as incomplete.
    • downloaders

      private int downloaders
      Peers reported as downloading.
    • HASH_LENGTH

      private static final int HASH_LENGTH
      Length of the info hash, in bytes.
      See Also:
  • Constructor Details

    • TrackerInfo

      public TrackerInfo(InputStream in, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) throws IOException, Throwable
      Reads a tracker response from a stream and parses it.
      Parameters:
      in - the stream to read
      my_id - our peer id to send
      infohash - the torrent's info hash
      metainfo - the torrent being announced to
      util - the snark instance running the announce
      Throws:
      IOException - if the response stream cannot be read
      Throwable - if the bencoded map is malformed, including InvalidBEncodingException
    • TrackerInfo

      private TrackerInfo(BDecoder be, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) throws IOException, Throwable
      Parses a tracker response from a decoder.
      Parameters:
      be - the decoder to read from
      my_id - our peer id to send
      infohash - the torrent's info hash
      metainfo - the torrent being announced to
      util - the snark instance running the announce
      Throws:
      IOException - if the response stream cannot be read
      Throwable - if the bencoded map is malformed, including InvalidBEncodingException
    • TrackerInfo

      private TrackerInfo(Map<String,BEValue> m, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) throws IOException
      Reads a tracker response into a record.
      Parameters:
      m - the decoded map from the tracker
      my_id - our node id
      infohash - the info hash of the torrent
      metainfo - the metadata of the torrent
      util - the snark utilities
      Throws:
      IOException - if the tracker reported a failure
    • TrackerInfo

      public TrackerInfo(Set<Hash> hashes, int interval, int complete, int incomplete, int downloaders, String error, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util)
      To convert returned UDPTracker data to the standard structure.
      Parameters:
      hashes - may be null
      interval - seconds to wait before re-announcing, from the tracker's response
      complete - the seeding count, 0 if the tracker did not report one
      incomplete - the downloading count, 0 if the tracker did not report one
      downloaders - the active downloader count, 0 if unknown (BEP 21)
      error - may be null
      my_id - our 20-byte peer ID, used to tell our own entry from the others
      infohash - the torrent infohash, needed to build peers in magnet mode
      metainfo - may be null
      util - supplies the router context the peer IDs are resolved in
  • Method Details

    • getPeers

      private static Set<Peer> getPeers(List<BEValue> l, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) throws IOException
      List of Dictionaries or List of Strings.
      Parameters:
      l - the peer list from a non-compact announce, each entry a dictionary or a raw string
      my_id - our peer id from the tracker, used by each Peer for its handshake
      infohash - the 20-byte torrent info hash carried by each Peer
      metainfo - the torrent metadata carried by each Peer
      util - supplies the crypto used to decrypt peer ids
      Returns:
      the parsed peers, entries that fail to parse being skipped
      Throws:
      IOException - declared on the method; every parse failure is caught and skipped
    • getPeers

      private static Set<Peer> getPeers(byte[] l, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) throws IOException
      One big string of concatenated 32-byte hashes.
      Parameters:
      l - concatenated 32-byte peer hashes, a trailing partial hash being ignored
      my_id - our peer id from the tracker, used by each Peer for its handshake
      infohash - the 20-byte torrent info hash carried by each Peer
      metainfo - the torrent metadata carried by each Peer
      util - supplies the crypto used to decrypt peer ids
      Returns:
      a peer for each whole 32-byte hash in the array, skipping any that fail to parse as a peer ID; a trailing partial hash is ignored
      Throws:
      IOException - declared on the method; every parse failure is caught and skipped
    • getPeers

      private static Set<Peer> getPeers(Set<Hash> hashes, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util)
      From Hash to Peer.
      Parameters:
      hashes - the peer hashes from the router's cache, null yielding an empty set
      my_id - our peer id from the tracker, used by each Peer for its handshake
      infohash - the 20-byte torrent info hash carried by each Peer
      metainfo - the torrent metadata carried by each Peer
      util - supplies the crypto used to decrypt peer ids
      Returns:
      a peer for each hash, empty if hashes is null
    • getPeers

      public Set<Peer> getPeers()
      Peers returned by the tracker. Empty when the response was a failure, or carried no peer list.
      Returns:
      an unmodifiable set of peers, never null
    • getPeerCount

      public int getPeerCount()
      Peer count including seeds and leeches from the tracker response.
      Returns:
      the number of known peers, or 0 if none
    • getPeerCount

      static int getPeerCount(Set<Hash> peers, int complete, int incomplete)
      Compute peer count from tracker response data. Shared by TrackerInfo and UDPTrackerClient.TrackerResponse.
      Parameters:
      peers - the peer set from the tracker, may be null
      complete - the seed count
      incomplete - the leech count
      Returns:
      the peer count
    • getSeedCount

      public int getSeedCount()
      The seed count.
      Returns:
      number of complete peers (seeds) from the last reply
    • getLeechCount

      public int getLeechCount()
      The leech count.
      Returns:
      number of incomplete peers (leeches) from the last reply
    • getPartialSeedCount

      public int getPartialSeedCount()
      The partial seed count, derived from the BEP 21 downloaders scrape field.

      Partial seeds have some files but download nothing more; trackers report them separately from active downloaders. Zero when the tracker omits the field.

      Returns:
      the partial seed count
    • getFailureReason

      public String getFailureReason()
      Not HTML escaped.
      Returns:
      the tracker's failure reason, or null if the announce succeeded
    • getInterval

      public int getInterval()
      Interval in seconds.
      Returns:
      the re-announce interval in seconds, -1 after a failure response
    • toString

      public String toString()
      String form of the tracker info.
      Overrides:
      toString in class Object