forked from I2P_Developers/i2p.i2p
2nd instance bootstraps DHT from 1st instance
This commit is contained in:
@ -114,6 +114,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
/** signed dgrams */
|
/** signed dgrams */
|
||||||
private final int _qPort;
|
private final int _qPort;
|
||||||
private final File _dhtFile;
|
private final File _dhtFile;
|
||||||
|
private final File _backupDhtFile;
|
||||||
private volatile boolean _isRunning;
|
private volatile boolean _isRunning;
|
||||||
private volatile boolean _hasBootstrapped;
|
private volatile boolean _hasBootstrapped;
|
||||||
/** stats */
|
/** stats */
|
||||||
@ -160,7 +161,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
/**
|
/**
|
||||||
* @param baseName generally "i2psnark"
|
* @param baseName generally "i2psnark"
|
||||||
*/
|
*/
|
||||||
public KRPC (I2PAppContext ctx, String baseName, I2PSession session) {
|
public KRPC(I2PAppContext ctx, String baseName, I2PSession session) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
_session = session;
|
_session = session;
|
||||||
_log = ctx.logManager().getLog(KRPC.class);
|
_log = ctx.logManager().getLog(KRPC.class);
|
||||||
@ -186,6 +187,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
}
|
}
|
||||||
_myNodeInfo = new NodeInfo(_myNID, session.getMyDestination(), _qPort);
|
_myNodeInfo = new NodeInfo(_myNID, session.getMyDestination(), _qPort);
|
||||||
_dhtFile = new File(ctx.getConfigDir(), baseName + DHT_FILE_SUFFIX);
|
_dhtFile = new File(ctx.getConfigDir(), baseName + DHT_FILE_SUFFIX);
|
||||||
|
_backupDhtFile = baseName.equals("i2psnark") ? null : new File(ctx.getConfigDir(), "i2psnark" + DHT_FILE_SUFFIX);
|
||||||
_knownNodes = new DHTNodes(ctx, _myNID);
|
_knownNodes = new DHTNodes(ctx, _myNID);
|
||||||
|
|
||||||
start();
|
start();
|
||||||
@ -550,7 +552,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
_session.addMuxedSessionListener(this, I2PSession.PROTO_DATAGRAM, _qPort);
|
_session.addMuxedSessionListener(this, I2PSession.PROTO_DATAGRAM, _qPort);
|
||||||
_knownNodes.start();
|
_knownNodes.start();
|
||||||
_tracker.start();
|
_tracker.start();
|
||||||
PersistDHT.loadDHT(this, _dhtFile);
|
PersistDHT.loadDHT(this, _dhtFile, _backupDhtFile);
|
||||||
// start the explore thread
|
// start the explore thread
|
||||||
_isRunning = true;
|
_isRunning = true;
|
||||||
// no need to keep ref, it will eventually stop
|
// no need to keep ref, it will eventually stop
|
||||||
|
@ -23,6 +23,17 @@ abstract class PersistDHT {
|
|||||||
|
|
||||||
private static final long MAX_AGE = 60*60*1000;
|
private static final long MAX_AGE = 60*60*1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param backupFile may be null
|
||||||
|
* @since 0.9.6
|
||||||
|
*/
|
||||||
|
public static synchronized void loadDHT(KRPC krpc, File file, File backupFile) {
|
||||||
|
if (file.exists())
|
||||||
|
loadDHT(krpc, file);
|
||||||
|
else if (backupFile != null)
|
||||||
|
loadDHT(krpc, backupFile);
|
||||||
|
}
|
||||||
|
|
||||||
public static synchronized void loadDHT(KRPC krpc, File file) {
|
public static synchronized void loadDHT(KRPC krpc, File file) {
|
||||||
Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
|
Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
@ -57,7 +68,6 @@ abstract class PersistDHT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO - multiple instances overwrite each other
|
|
||||||
* @param saveAll if true, don't check last seen time
|
* @param saveAll if true, don't check last seen time
|
||||||
*/
|
*/
|
||||||
public static synchronized void saveDHT(DHTNodes nodes, boolean saveAll, File file) {
|
public static synchronized void saveDHT(DHTNodes nodes, boolean saveAll, File file) {
|
||||||
|
Reference in New Issue
Block a user