java.lang.Object
org.klomp.snark.TrackerInfo
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 Summary
FieldsModifier and TypeFieldDescriptionprivate intPeers reported as complete.private intPeers reported as downloading.private final StringWhy the last announce failed, null on success.private static final intLength of the info hash, in bytes.private intPeers reported as incomplete.private final intSeconds the tracker asks between announces.The peers from the response, unmodifiable and never null: a failure response has no peers, and is reported bygetFailureReason()instead.Constructor Summary
ModifierConstructorDescriptionTrackerInfo(InputStream in, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) Reads a tracker response from a stream and parses it.privateTrackerInfo(Map<String, BEValue> m, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) Reads a tracker response into a record.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.privateTrackerInfo(BDecoder be, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) Parses a tracker response from a decoder.Method Summary
Modifier and TypeMethodDescriptionNot HTML escaped.intInterval in seconds.intThe leech count.intThe partial seed count, derived from the BEP 21 downloaders scrape field.intPeer count including seeds and leeches from the tracker response.(package private) static intgetPeerCount(Set<Hash> peers, int complete, int incomplete) Compute peer count from tracker response data.getPeers()Peers returned by the tracker.getPeers(byte[] l, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) One big string of concatenated 32-byte hashes.getPeers(List<BEValue> l, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) List of Dictionaries or List of Strings.getPeers(Set<Hash> hashes, byte[] my_id, byte[] infohash, MetaInfo metainfo, I2PSnarkUtil util) From Hash to Peer.intThe seed count.toString()String form of the tracker info.
Field Details
failure_reason
Why the last announce failed, null on success.interval
private final int intervalSeconds the tracker asks between announces.peers
The peers from the response, unmodifiable and never null: a failure response has no peers, and is reported bygetFailureReason()instead.complete
private int completePeers reported as complete.incomplete
private int incompletePeers reported as incomplete.downloaders
private int downloadersPeers reported as downloading.HASH_LENGTH
private static final int HASH_LENGTHLength 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 readmy_id- our peer id to sendinfohash- the torrent's info hashmetainfo- the torrent being announced toutil- the snark instance running the announce- Throws:
IOException- if the response stream cannot be readThrowable- 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 frommy_id- our peer id to sendinfohash- the torrent's info hashmetainfo- the torrent being announced toutil- the snark instance running the announce- Throws:
IOException- if the response stream cannot be readThrowable- 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 IOExceptionReads a tracker response into a record.- Parameters:
m- the decoded map from the trackermy_id- our node idinfohash- the info hash of the torrentmetainfo- the metadata of the torrentutil- 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 nullinterval- seconds to wait before re-announcing, from the tracker's responsecomplete- the seeding count, 0 if the tracker did not report oneincomplete- the downloading count, 0 if the tracker did not report onedownloaders- the active downloader count, 0 if unknown (BEP 21)error- may be nullmy_id- our 20-byte peer ID, used to tell our own entry from the othersinfohash- the torrent infohash, needed to build peers in magnet modemetainfo- may be nullutil- 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 stringmy_id- our peer id from the tracker, used by each Peer for its handshakeinfohash- the 20-byte torrent info hash carried by each Peermetainfo- the torrent metadata carried by each Peerutil- 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 ignoredmy_id- our peer id from the tracker, used by each Peer for its handshakeinfohash- the 20-byte torrent info hash carried by each Peermetainfo- the torrent metadata carried by each Peerutil- 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 setmy_id- our peer id from the tracker, used by each Peer for its handshakeinfohash- the 20-byte torrent info hash carried by each Peermetainfo- the torrent metadata carried by each Peerutil- supplies the crypto used to decrypt peer ids- Returns:
- a peer for each hash, empty if
hashesis null
getPeers
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
Compute peer count from tracker response data. Shared by TrackerInfo and UDPTrackerClient.TrackerResponse.- Parameters:
peers- the peer set from the tracker, may be nullcomplete- the seed countincomplete- 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
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