All Implemented Interfaces:
DataStructure

class Peerextends Hash
Represents a single peer participating in a specific torrent within the DHT tracker.

This class extends Hash to store the peer's identification (typically their destination hash) along with metadata about their participation in the torrent. The DHT tracker maintains collections of these peers to respond to peer discovery requests from other clients.

Each peer tracks when it was last seen and whether it's a seed (has the complete torrent). This information is used to prioritize peers in responses and to maintain an accurate view of the torrent's swarm health.

  • Field Details

    • lastSeen

      private volatile long lastSeen
      Timestamp when this peer was last active in the torrent.
    • isSeed

      private volatile boolean isSeed
      Flag indicating whether this peer has the complete torrent.
  • Constructor Details

    • Peer

      public Peer(byte[] data)
      Creates a new peer with the specified identification data.
      Parameters:
      data - the peer's identification data (typically destination hash)
  • Method Details

    • lastSeen

      public long lastSeen()
      Returns the timestamp when this peer was last seen active in the torrent.
      Returns:
      the timestamp in milliseconds since epoch, or 0 if never seen
    • setLastSeen

      public void setLastSeen(long now)
      Updates the timestamp when this peer was last seen.
      Parameters:
      now - the current timestamp in milliseconds since epoch
    • isSeed

      public boolean isSeed()
      Returns whether this peer is a seed (has the complete torrent).

      Seeds are prioritized differently in peer responses as they can provide the complete torrent to leechers. This information is also used to calculate swarm health statistics.

      Returns:
      true if this peer has the complete torrent, false otherwise
    • setSeed

      public void setSeed(boolean isSeed)
      Whether this peer is a seed.
      Parameters:
      isSeed - true if this peer has the complete torrent, false otherwise