diff --git a/apps/i2psnark/java/src/org/klomp/snark/dht/KRPC.java b/apps/i2psnark/java/src/org/klomp/snark/dht/KRPC.java index c0be11182e35c9287560d3ab62168446215fe17f..6b17c463aad22d6748b084b8dee2a5a7842fd628 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/dht/KRPC.java +++ b/apps/i2psnark/java/src/org/klomp/snark/dht/KRPC.java @@ -114,6 +114,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT { /** signed dgrams */ private final int _qPort; private final File _dhtFile; + private final File _backupDhtFile; private volatile boolean _isRunning; private volatile boolean _hasBootstrapped; /** stats */ @@ -160,7 +161,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT { /** * @param baseName generally "i2psnark" */ - public KRPC (I2PAppContext ctx, String baseName, I2PSession session) { + public KRPC(I2PAppContext ctx, String baseName, I2PSession session) { _context = ctx; _session = session; _log = ctx.logManager().getLog(KRPC.class); @@ -186,6 +187,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT { } _myNodeInfo = new NodeInfo(_myNID, session.getMyDestination(), _qPort); _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); start(); @@ -550,7 +552,7 @@ public class KRPC implements I2PSessionMuxedListener, DHT { _session.addMuxedSessionListener(this, I2PSession.PROTO_DATAGRAM, _qPort); _knownNodes.start(); _tracker.start(); - PersistDHT.loadDHT(this, _dhtFile); + PersistDHT.loadDHT(this, _dhtFile, _backupDhtFile); // start the explore thread _isRunning = true; // no need to keep ref, it will eventually stop diff --git a/apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java b/apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java index 491312989946eb8d2aecf80c1deb1e6abcec270a..c690bc340a26e946c9e25f8d35829f5c0fe9b1a9 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java +++ b/apps/i2psnark/java/src/org/klomp/snark/dht/PersistDHT.java @@ -23,6 +23,17 @@ abstract class PersistDHT { 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) { Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class); 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 */ public static synchronized void saveDHT(DHTNodes nodes, boolean saveAll, File file) {