forked from I2P_Developers/i2p.i2p
add dht stub
This commit is contained in:
@ -34,6 +34,7 @@ import net.i2p.util.SimpleScheduler;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
import net.i2p.util.Translate;
|
||||
|
||||
import org.klomp.snark.dht.DHT;
|
||||
import org.klomp.snark.dht.KRPC;
|
||||
|
||||
/**
|
||||
@ -61,7 +62,7 @@ public class I2PSnarkUtil {
|
||||
private File _tmpDir;
|
||||
private int _startupDelay;
|
||||
private boolean _shouldUseOT;
|
||||
private KRPC _krpc;
|
||||
private DHT _dht;
|
||||
|
||||
public static final int DEFAULT_STARTUP_DELAY = 3;
|
||||
public static final String PROP_USE_OPENTRACKERS = "i2psnark.useOpentrackers";
|
||||
@ -195,8 +196,8 @@ public class I2PSnarkUtil {
|
||||
_manager = I2PSocketManagerFactory.createManager(_i2cpHost, _i2cpPort, opts);
|
||||
}
|
||||
// FIXME this only instantiates krpc once, left stuck with old manager
|
||||
if (ENABLE_DHT && _manager != null && _krpc == null)
|
||||
_krpc = new KRPC(_context, _manager.getSession());
|
||||
if (ENABLE_DHT && _manager != null && _dht == null)
|
||||
_dht = new KRPC(_context, _manager.getSession());
|
||||
return (_manager != null);
|
||||
}
|
||||
|
||||
@ -204,7 +205,7 @@ public class I2PSnarkUtil {
|
||||
* @return null if disabled or not started
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public KRPC getDHT() { return _krpc; }
|
||||
public DHT getDHT() { return _dht; }
|
||||
|
||||
public boolean connected() { return _manager != null; }
|
||||
|
||||
|
@ -36,7 +36,7 @@ import net.i2p.util.I2PAppThread;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleTimer2;
|
||||
|
||||
import org.klomp.snark.dht.KRPC;
|
||||
import org.klomp.snark.dht.DHT;
|
||||
|
||||
/**
|
||||
* Coordinates what peer does what.
|
||||
@ -1194,9 +1194,9 @@ public class PeerCoordinator implements PeerListener
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public void gotPort(Peer peer, int port) {
|
||||
KRPC krpc = _util.getDHT();
|
||||
if (krpc != null)
|
||||
krpc.ping(peer.getDestination(), port);
|
||||
DHT dht = _util.getDHT();
|
||||
if (dht != null)
|
||||
dht.ping(peer.getDestination(), port);
|
||||
}
|
||||
|
||||
/** Return number of allowed uploaders for this torrent.
|
||||
|
@ -38,7 +38,7 @@ import net.i2p.data.Hash;
|
||||
import net.i2p.util.I2PAppThread;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import org.klomp.snark.dht.KRPC;
|
||||
import org.klomp.snark.dht.DHT;
|
||||
|
||||
/**
|
||||
* Informs metainfo tracker of events and gets new peers for peer
|
||||
|
83
apps/i2psnark/java/src/org/klomp/snark/dht/DHT.java
Normal file
83
apps/i2psnark/java/src/org/klomp/snark/dht/DHT.java
Normal file
@ -0,0 +1,83 @@
|
||||
package org.klomp.snark.dht;
|
||||
|
||||
/*
|
||||
* Copyright 2010 zzz (zzz@mail.i2p)
|
||||
* GPLv2
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.i2p.data.Destination;
|
||||
import net.i2p.data.Hash;
|
||||
|
||||
|
||||
/**
|
||||
* Stub for KRPC
|
||||
*/
|
||||
public interface DHT {
|
||||
|
||||
|
||||
/**
|
||||
* @return The UDP port that should be included in a PORT message.
|
||||
*/
|
||||
public int getPort();
|
||||
|
||||
/**
|
||||
* Ping. We don't have a NID yet so the node is presumed
|
||||
* to be absent from our DHT.
|
||||
* Non-blocking, does not wait for pong.
|
||||
* If and when the pong is received the node will be inserted in our DHT.
|
||||
*/
|
||||
public void ping(Destination dest, int port);
|
||||
|
||||
/**
|
||||
* Get peers for a torrent.
|
||||
* Blocking!
|
||||
* Caller should run in a thread.
|
||||
*
|
||||
* @param ih the Info Hash (torrent)
|
||||
* @param max maximum number of peers to return
|
||||
* @param maxWait the maximum time to wait (ms) must be > 0
|
||||
* @return list or empty list (never null)
|
||||
*/
|
||||
public List<Hash> getPeers(byte[] ih, int max, long maxWait);
|
||||
|
||||
/**
|
||||
* Announce to ourselves.
|
||||
* Non-blocking.
|
||||
*
|
||||
* @param ih the Info Hash (torrent)
|
||||
*/
|
||||
public void announce(byte[] ih);
|
||||
|
||||
/**
|
||||
* Announce somebody else we know about.
|
||||
* Non-blocking.
|
||||
*
|
||||
* @param ih the Info Hash (torrent)
|
||||
* @param peer the peer's Hash
|
||||
*/
|
||||
public void announce(byte[] ih, byte[] peerHash);
|
||||
|
||||
/**
|
||||
* Remove reference to ourselves in the local tracker.
|
||||
* Use when shutting down the torrent locally.
|
||||
* Non-blocking.
|
||||
*
|
||||
* @param ih the Info Hash (torrent)
|
||||
*/
|
||||
public void unannounce(byte[] ih);
|
||||
|
||||
/**
|
||||
* Announce to the closest DHT peers.
|
||||
* Blocking unless maxWait <= 0
|
||||
* Caller should run in a thread.
|
||||
* This also automatically announces ourself to our local tracker.
|
||||
* For best results do a getPeers() first so we have tokens.
|
||||
*
|
||||
* @param ih the Info Hash (torrent)
|
||||
* @param maxWait the maximum total time to wait (ms) or 0 to do all in parallel and return immediately.
|
||||
* @return the number of successful announces, not counting ourselves.
|
||||
*/
|
||||
public int announce(byte[] ih, int max, long maxWait);
|
||||
}
|
Reference in New Issue
Block a user