java.lang.Object
org.klomp.snark.PeerCoordinatorSet
All Implemented Interfaces:
Iterable<PeerCoordinator>

class PeerCoordinatorSetextends Object implements Iterable<PeerCoordinator>
Thread-safe collection for managing PeerCoordinator instances across multiple torrents.

This class provides a centralized registry for PeerCoordinator objects, enabling the multi-torrent functionality in I2PSnark. It is primarily used by:

  • PeerAcceptor - to route incoming connections to the correct coordinator
  • Snark instances - to register and unregister themselves
  • DHT and tracker systems - to find the appropriate coordinator for a torrent

The set maps torrent info hashes to their corresponding PeerCoordinator instances, allowing efficient lookup by torrent identifier. All operations are thread-safe through ConcurrentHashMap.

Each PeerCoordinator is automatically added when a torrent starts and removed when the torrent stops, ensuring the set always reflects currently active torrents.

  • Field Details

    • _coordinators

      private final Map<SHA1Hash, PeerCoordinator> _coordinators
      Keyed by the info hash of the torrent each coordinator works on.
  • Constructor Details

    • PeerCoordinatorSet

      public PeerCoordinatorSet()
      Creates a new empty PeerCoordinatorSet.
  • Method Details

    • iterator

      public Iterator<PeerCoordinator> iterator()
      Returns an iterator over all registered coordinators.
      Specified by:
      iterator in interface Iterable<PeerCoordinator>
      Returns:
      iterator of PeerCoordinator instances
    • add

      public void add(PeerCoordinator coordinator)
      Register a coordinator for its torrent's info hash.
      Parameters:
      coordinator - the peer coordinator, filed under its torrent's info hash
    • remove

      public void remove(PeerCoordinator coordinator)
      Unregister a coordinator.
      Parameters:
      coordinator - the peer coordinator to unregister, matched on its torrent's info hash
    • hasOtherRunning

      public boolean hasOtherRunning(PeerCoordinator exclude)
      Whether any other live, non-halted coordinator is registered. Consulted before dropping the shared I2CP session in single-destination mode, where every torrent runs on one session and one torrent tearing it down strands the rest.
      Parameters:
      exclude - the coordinator being torn down, so it does not count as another user
      Returns:
      true if some other torrent still needs the shared session
    • get

      public PeerCoordinator get(byte[] infoHash)
      Look up the coordinator handling a torrent.
      Parameters:
      infoHash - the 20-byte info hash to look up
      Returns:
      the coordinator running that torrent, or null if there is none