forked from I2P_Developers/i2p.i2p
* i2psnark: Fix DHT nodes not being saved at shutdown
Log infohashes in hex Don't write out nodes if we don't have any
This commit is contained in:
@@ -37,6 +37,8 @@ import net.i2p.util.SecureFileOutputStream;
|
|||||||
import net.i2p.util.SimpleScheduler;
|
import net.i2p.util.SimpleScheduler;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer;
|
||||||
|
|
||||||
|
import org.klomp.snark.dht.DHT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage multiple snarks
|
* Manage multiple snarks
|
||||||
*/
|
*/
|
||||||
@@ -1752,6 +1754,9 @@ public class SnarkManager implements Snark.CompleteListener {
|
|||||||
}
|
}
|
||||||
if (_util.connected()) {
|
if (_util.connected()) {
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
|
DHT dht = _util.getDHT();
|
||||||
|
if (dht != null)
|
||||||
|
dht.stop();
|
||||||
// Schedule this even for final shutdown, as there's a chance
|
// Schedule this even for final shutdown, as there's a chance
|
||||||
// that it's just this webapp that is stopping.
|
// that it's just this webapp that is stopping.
|
||||||
_context.simpleScheduler().addEvent(new Disconnector(), 60*1000);
|
_context.simpleScheduler().addEvent(new Disconnector(), 60*1000);
|
||||||
|
@@ -4,6 +4,7 @@ package org.klomp.snark.dht;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import net.i2p.crypto.SHA1Hash;
|
import net.i2p.crypto.SHA1Hash;
|
||||||
|
import org.klomp.snark.I2PSnarkUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 20-byte SHA1 info hash
|
* A 20-byte SHA1 info hash
|
||||||
@@ -16,4 +17,13 @@ class InfoHash extends SHA1Hash {
|
|||||||
public InfoHash(byte[] data) {
|
public InfoHash(byte[] data) {
|
||||||
super(data);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (_data == null) {
|
||||||
|
return super.toString();
|
||||||
|
} else {
|
||||||
|
return "[InfoHash: " + I2PSnarkUtil.toHex(_data) + ']';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -176,8 +176,6 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
_dhtFile = new File(ctx.getConfigDir(), DHT_FILE);
|
_dhtFile = new File(ctx.getConfigDir(), DHT_FILE);
|
||||||
_knownNodes = new DHTNodes(ctx, _myNID);
|
_knownNodes = new DHTNodes(ctx, _myNID);
|
||||||
|
|
||||||
session.addMuxedSessionListener(this, I2PSession.PROTO_DATAGRAM_RAW, _rPort);
|
|
||||||
session.addMuxedSessionListener(this, I2PSession.PROTO_DATAGRAM, _qPort);
|
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,7 +515,11 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
* Loads the DHT from file.
|
* Loads the DHT from file.
|
||||||
* Can't be restarted after stopping?
|
* Can't be restarted after stopping?
|
||||||
*/
|
*/
|
||||||
public void start() {
|
public synchronized void start() {
|
||||||
|
if (_isRunning)
|
||||||
|
return;
|
||||||
|
session.addMuxedSessionListener(this, I2PSession.PROTO_DATAGRAM_RAW, _rPort);
|
||||||
|
session.addMuxedSessionListener(this, I2PSession.PROTO_DATAGRAM, _qPort);
|
||||||
_knownNodes.start();
|
_knownNodes.start();
|
||||||
_tracker.start();
|
_tracker.start();
|
||||||
PersistDHT.loadDHT(this, _dhtFile);
|
PersistDHT.loadDHT(this, _dhtFile);
|
||||||
@@ -536,7 +538,9 @@ public class KRPC implements I2PSessionMuxedListener, DHT {
|
|||||||
/**
|
/**
|
||||||
* Stop everything.
|
* Stop everything.
|
||||||
*/
|
*/
|
||||||
public void stop() {
|
public synchronized void stop() {
|
||||||
|
if (!_isRunning)
|
||||||
|
return;
|
||||||
_isRunning = false;
|
_isRunning = false;
|
||||||
// FIXME stop the explore thread
|
// FIXME stop the explore thread
|
||||||
// unregister port listeners
|
// unregister port listeners
|
||||||
|
@@ -56,6 +56,8 @@ abstract class PersistDHT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void saveDHT(DHTNodes nodes, File file) {
|
public static synchronized void saveDHT(DHTNodes nodes, File file) {
|
||||||
|
if (nodes.isEmpty())
|
||||||
|
return;
|
||||||
Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
|
Log log = I2PAppContext.getGlobalContext().logManager().getLog(PersistDHT.class);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
long maxAge = I2PAppContext.getGlobalContext().clock().now() - MAX_AGE;
|
long maxAge = I2PAppContext.getGlobalContext().clock().now() - MAX_AGE;
|
||||||
|
Reference in New Issue
Block a user