Skip to content

Commit

Permalink
Router: don't persist client db's on disk. Add a job which can clean …
Browse files Browse the repository at this point in the history
…up the subdbs periodically
  • Loading branch information
eyedeekay committed Sep 7, 2023
1 parent 4e63234 commit 76fd9ab
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
22 changes: 0 additions & 22 deletions core/java/src/net/i2p/client/impl/I2PSessionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1335,31 +1335,9 @@ public void destroySession(boolean sendDisconnect) {
_availabilityNotifier.stopNotifying();
closeSocket();
_subsessionMap.clear();
clearOldNetDB();
if (_sessionListener != null) _sessionListener.disconnected(this);
}

private void clearOldNetDB() {
Destination myDest = getMyDestination();
if (myDest != null) {
String base32 = myDest.toBase32();
if (base32 != null) {
String dbid = "clients_"+base32;
// get the netDb directory
File netDbDir = new File(_context.getConfigDir(), "netDb");
File subNetDbDir = new File(netDbDir, dbid);
if (subNetDbDir.exists()) {
subNetDbDir.delete();
}
File baseNetDbDir = new File(_context.getConfigDir(), "netDb");
File baseSubNetDbDir = new File(baseNetDbDir, dbid);
if (baseSubNetDbDir.exists()) {
baseSubNetDbDir.delete();
}
}
}
}

/**
* Close the socket carefully.
*/
Expand Down
24 changes: 24 additions & 0 deletions router/java/src/net/i2p/router/CleanupNetDbJob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.i2p.router;

import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseSegmentor;

public class CleanupNetDbJob extends JobImpl {
private final RouterContext ctx;

public CleanupNetDbJob(RouterContext context) {
super(context);
ctx = context;
}

@Override
public String getName() {
return "CleanupNetDbJob";
}

@Override
public void runJob() {
FloodfillNetworkDatabaseSegmentor fnds = (FloodfillNetworkDatabaseSegmentor) ctx.netDb();
fnds.removeDeadSubDbs(ctx.clientManager().listClients());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.i2p.util.Log;
import net.i2p.util.RandomSource;
import net.i2p.util.SystemVersion;
//import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseSegmentor;

/**
* The network database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,25 @@ public synchronized void shutdown() {
}
}

public synchronized void remove(String dbid){
if (dbid != null)
if (dbid.endsWith(".i2p"))
dbid = "clients_" + dbid;
else if (dbid.equals(""))
dbid = MAIN_DBID;
GetSubNetDB(dbid).shutdown();
_subDBs.remove(dbid);
}

public synchronized void removeDeadSubDbs(Set<Destination> clientDests) {
for (String dbid : _subDBs.keySet()) {
for (Destination db : clientDests) {
if (!db.toBase32().equals(dbid))
remove(dbid);
}
}
}

/**
* This maybe could be shorter than
* RepublishLeaseSetJob.REPUBLISH_LEASESET_TIMEOUT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import net.i2p.router.crypto.FamilyKeyCrypto;
import net.i2p.router.networkdb.PublishLocalRouterInfoJob;
import net.i2p.router.networkdb.reseed.ReseedChecker;
import net.i2p.router.networkdb.kademlia.PersistentDataStore;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseSegmentor;
import net.i2p.router.peermanager.PeerProfile;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log;
Expand Down Expand Up @@ -313,7 +315,9 @@ public synchronized void startup() {
BUCKET_SIZE, KAD_B, new RejectTrimmer<Hash>());
_dbDir = getDbDir();
try {
_ds = new PersistentDataStore(_context, _dbDir, this);
if (_dbid == null || _dbid.equals(FloodfillNetworkDatabaseSegmentor.MAIN_DBID) || _dbid.isEmpty()) {
_ds = new PersistentDataStore(_context, "", this);
}
} catch (IOException ioe) {
throw new RuntimeException("Unable to initialize netdb storage", ioe);
}
Expand Down

0 comments on commit 76fd9ab

Please sign in to comment.