From 76fd9abd7373f889f5589136dd623e6d5db0d8e8 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Wed, 6 Sep 2023 20:42:54 -0400 Subject: [PATCH] Router: don't persist client db's on disk. Add a job which can clean up the subdbs periodically --- .../net/i2p/client/impl/I2PSessionImpl.java | 22 ----------------- .../src/net/i2p/router/CleanupNetDbJob.java | 24 +++++++++++++++++++ .../FloodfillNetworkDatabaseFacade.java | 1 + .../FloodfillNetworkDatabaseSegmentor.java | 19 +++++++++++++++ .../KademliaNetworkDatabaseFacade.java | 6 ++++- 5 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 router/java/src/net/i2p/router/CleanupNetDbJob.java diff --git a/core/java/src/net/i2p/client/impl/I2PSessionImpl.java b/core/java/src/net/i2p/client/impl/I2PSessionImpl.java index 598b95bde8..07bde4a1a2 100644 --- a/core/java/src/net/i2p/client/impl/I2PSessionImpl.java +++ b/core/java/src/net/i2p/client/impl/I2PSessionImpl.java @@ -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. */ diff --git a/router/java/src/net/i2p/router/CleanupNetDbJob.java b/router/java/src/net/i2p/router/CleanupNetDbJob.java new file mode 100644 index 0000000000..85be933332 --- /dev/null +++ b/router/java/src/net/i2p/router/CleanupNetDbJob.java @@ -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()); + } + +} diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java index a4c9bb3498..7b5e03ee84 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java @@ -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 diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java index 73eba0e0a1..cde8e2044f 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java @@ -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 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, diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java index 9e75d5a25c..35d6f26536 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java @@ -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; @@ -313,7 +315,9 @@ public synchronized void startup() { BUCKET_SIZE, KAD_B, new RejectTrimmer()); _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); }