All Implemented Interfaces:
DataStructure

public class InfoHashextends SHA1Hash
Represents a BitTorrent info hash used for DHT operations.

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.

  • 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

      public String 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:
      toString in class SimpleDataStructure
      Returns:
      a formatted string containing the info hash in hexadecimal format