java.lang.Object
org.klomp.snark.PeerCoordinatorSet
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<SHA1Hash, PeerCoordinator> Keyed by the info hash of the torrent each coordinator works on.Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionvoidadd(PeerCoordinator coordinator) Register a coordinator for its torrent's info hash.get(byte[] infoHash) Look up the coordinator handling a torrent.booleanhasOtherRunning(PeerCoordinator exclude) Whether any other live, non-halted coordinator is registered.iterator()Returns an iterator over all registered coordinators.voidremove(PeerCoordinator coordinator) Unregister a coordinator.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
Field Details
_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
Returns an iterator over all registered coordinators.- Specified by:
iteratorin interfaceIterable<PeerCoordinator>- Returns:
- iterator of PeerCoordinator instances
add
Register a coordinator for its torrent's info hash.- Parameters:
coordinator- the peer coordinator, filed under its torrent's info hash
remove
Unregister a coordinator.- Parameters:
coordinator- the peer coordinator to unregister, matched on its torrent's info hash
hasOtherRunning
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
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