java.lang.Object
org.klomp.snark.dht.KRPC
org.klomp.snark.dht.TorrentKRPC
- All Implemented Interfaces:
I2PSessionListener, I2PSessionMuxedListener, DHT
A DHT instance for one or more torrents on a shared transient I2P session and destination. Shares the main instance's routing table, tracker, and blacklist, but generates its own NID, query ports, and token maps, so that tokens issued for one destination can never authorize an announce from another, which would make remote nodes store the wrong peer hash for a torrent. Serves tracker queries only for its assigned torrents' infohashes, so probing this destination never reveals torrents hosted elsewhere on the router.
Nested Class Summary
Nested classes/interfaces inherited from class KRPC
KRPC.ReplyWaiterField Summary
Fields inherited from class KRPC
_isRunning, _qPort, _rPort, _session, DHT_FILE_SUFFIX, FAKE_NID, SECURE_NIDModifier and TypeFieldDescriptionprotected booleanTrue betweenKRPC.start()and stop(), so the reply threads know to keep going.protected intSigned datagrams.protected intUnsigned datagrams.protected I2PSessionHook to inject and receive datagrams.static final StringFile suffix for DHT persistent storage.static final NIDAll-zero NID used for pings.static final booleanWhen true, generated NIDs must satisfy a cryptographic puzzle.Constructor Summary
ConstructorsConstructorDescriptionTorrentKRPC(I2PAppContext ctx, KRPC shared, I2PSession session, Collection<InfoHash> ihs) Create a DHT instance on a torrent's transient destination.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidstart()Registers the datagram listeners on this instance's own session and ports, without loading the DHT file or starting the cleaner, explorer, tracker, and routing table, which remain the job of the main instance.voidstop()Unregisters the datagram listeners, leaving the shared routing table, tracker, and blacklist running for the main instance.Methods inherited from class KRPC
addServedTorrent, announce, announce, announce, clear, disconnected, errorOccurred, findClosest, getPeersAndAnnounce, getPort, getRPort, heardAbout, messageAvailable, messageAvailable, ping, removeSelf, removeServedTorrent, renderStatusHTML, reportAbuse, setServeAll, size, unannounceModifier and TypeMethodDescriptionvoidServe tracker queries for the given infohash in addition to any already served.voidannounce(byte[] ih, boolean isSeed) Announce to ourselves.voidannounce(byte[] ih, byte[] peerHash, boolean isSeed) Announce somebody else we know about to ourselves.intannounce(byte[] ih, int max, long maxWait, boolean isSeed) Not recommended - useKRPC.getPeersAndAnnounce(byte[], int, long, int, long, boolean, boolean).voidclear()Clears the tracker and DHT data.voiddisconnected(I2PSession session) Handle a session disconnect.voiderrorOccurred(I2PSession session, String message, Throwable error) Handle a session error.findClosest(byte[] ih, int max) Local lookup only.getPeersAndAnnounce(byte[] ih, int max, long maxWait, int annMax, long annMaxWait, boolean isSeed, boolean noSeeds) Find peers for a torrent, announcing to the closest annMax nodes found.intgetPort()The UDP query port.intgetRPort()The UDP response port.(package private) NodeInfoheardAbout(NodeInfo nInfo) Called for bootstrap or for all nodes in a receiveNodes reply.voidmessageAvailable(I2PSession session, int msgId, long size) For non-muxed.voidmessageAvailable(I2PSession session, int msgId, long size, int proto, int fromPort, int toPort) Instruct the client that the given session has received a message.voidping(Destination dest, int port) Ping.removeSelf(List<NodeInfo> nodes, NodeInfo self) Remove any entries equal to ourselves from a list of candidate nodes.voidStop serving tracker queries for the given infohash.Debug info, HTML formatted.voidreportAbuse(I2PSession session, int severity) Handle a reportAbuse message from the session.voidsetServeAll(boolean serveAll) Whether tracker queries are served for every infohash.intsize()Known nodes, not estimated total network size.voidunannounce(byte[] ih) Remove reference to ourselves in the local tracker.
Constructor Details
TorrentKRPC
Create a DHT instance on a torrent's transient destination.- Parameters:
ctx- the application context owning the session and loggingshared- the main DHT instance, whose routing table, tracker, and blacklist are shared; must be started alreadysession- the transient session of the torrents' destinationihs- the infohashes of the torrents served on this destination
Method Details
start
stop