I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 6c32a053 authored by zzz's avatar zzz
Browse files

2nd instance bootstraps DHT from 1st instance

parent 9e5d8096
No related branches found
No related tags found
No related merge requests found
...@@ -114,6 +114,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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 { ...@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment