- All Implemented Interfaces:
DataStructure
An info hash is a 20-byte SHA1 hash that uniquely identifies a torrent. In the DHT context, info hashes are used as keys to locate peers and track torrent participation across the distributed network.
Info hashes serve as the primary identifier for DHT operations:
- get_peer requests use info hashes to find peers for specific torrents
- announce_peer requests associate peers with specific info hashes
- DHT routing uses info hashes to determine which nodes should store peer information
This class extends SHA1Hash to provide torrent-specific functionality and formatting for debugging and logging purposes.
Field Summary
Fields inherited from class SHA1Hash
HASH_LENGTHFields inherited from class SimpleDataStructure
_dataConstructor Summary
ConstructorsMethod Summary
All MethodsMethods inherited from class SHA1Hash
hashCode, length, readBytes, setDataModifier and TypeMethodDescriptioninthashCode()A Hash is a hash, so just use the first 4 bytes for speed.intlength()Length of a SHA-1 hash.voidreadBytes(InputStream in) Read the hash data from a stream.voidsetData(byte[] data) IllegalArgumentException if data is not 20 bytes (null is ok).Methods inherited from class SimpleDataStructure
calculateHash, equals, fromBase64, fromByteArray, getData, read, toBase64, toByteArray, writeBytesModifier and TypeMethodDescriptionSHA256 hash of the byte array, or null if data is null.booleanCompares the raw data only: two different SimpleDataStructure subclasses of the same length holding the same bytes are equal, e.g.voidfromBase64(String data) Data from the base64 string.voidfromByteArray(byte[] data) Does the same thing asSimpleDataStructure.setData(byte[])but null not allowed.byte[]getData()Data reference (not a copy).protected intread(InputStream in, byte[] target) Repeated reads until the buffer is full or IOException is thrown.toBase64()Renders the structure into modified base 64 notation.byte[]Same thing as getData().voidwriteBytes(OutputStream out) Writes the data to the output stream.
Constructor Details
InfoHash
public InfoHash(byte[] data) Creates a new info hash from the specified 20-byte data.- Parameters:
data- the 20-byte SHA1 hash data representing the torrent info hash
Method Details
toString
Returns a string representation of the info hash for debugging and logging.Formats the info hash as hexadecimal within brackets for easy identification in log files and debug output. This provides a more readable representation than the default SHA1Hash
toString()method.- Overrides:
toStringin classSimpleDataStructure- Returns:
- a formatted string containing the info hash in hexadecimal format