Skip to content

Commit c6a97a1

Browse files
author
eyedeekay
committed
Router: remove dead dbs from segmented table when they are shut down
1 parent c1c8cfc commit c6a97a1

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

router/java/src/net/i2p/router/client/ClientConnectionRunner.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,19 @@ public synchronized void stopRunning() {
211211
_manager.unregisterEncryptedDestination(this, _encryptedLSHash);
212212
_manager.unregisterConnection(this);
213213
// netdb may be null in unit tests
214-
if (_context.netDb() != null) {
214+
String dbid = this.getDestHash().toBase32();
215+
if (_context.netDb().getSubNetDB(dbid) != null) {
215216
// Note that if the client sent us a destroy message,
216217
// removeSession() was called just before this, and
217218
// _sessions will be empty.
218219
for (SessionParams sp : _sessions.values()) {
219220
LeaseSet ls = sp.currentLeaseSet;
220221
if (ls != null)
221-
_context.netDb().unpublish(ls);
222+
_context.netDb().getSubNetDB(dbid).unpublish(ls);
222223
// unpublish encrypted LS also
223224
ls = sp.currentEncryptedLeaseSet;
224225
if (ls != null)
225-
_context.netDb().unpublish(ls);
226+
_context.netDb().getSubNetDB(dbid).unpublish(ls);
226227
if (!sp.isPrimary)
227228
_context.tunnelManager().removeAlias(sp.dest);
228229
}
@@ -448,6 +449,7 @@ void removeSession(SessionId id) {
448449
if (id == null)
449450
return;
450451
boolean isPrimary = false;
452+
String dbid = this.getDestHash().toBase32();
451453
for (Iterator<SessionParams> iter = _sessions.values().iterator(); iter.hasNext(); ) {
452454
SessionParams sp = iter.next();
453455
if (id.equals(sp.sessionId)) {
@@ -458,11 +460,11 @@ void removeSession(SessionId id) {
458460
_manager.unregisterSession(id, sp.dest);
459461
LeaseSet ls = sp.currentLeaseSet;
460462
if (ls != null)
461-
_context.netDb().unpublish(ls);
463+
_context.netDb().getSubNetDB(dbid).unpublish(ls);
462464
// unpublish encrypted LS also
463465
ls = sp.currentEncryptedLeaseSet;
464466
if (ls != null)
465-
_context.netDb().unpublish(ls);
467+
_context.netDb().getSubNetDB(dbid).unpublish(ls);
466468
isPrimary = sp.isPrimary;
467469
if (isPrimary)
468470
_context.tunnelManager().removeTunnels(sp.dest);
@@ -483,11 +485,11 @@ void removeSession(SessionId id) {
483485
_manager.unregisterSession(sp.sessionId, sp.dest);
484486
LeaseSet ls = sp.currentLeaseSet;
485487
if (ls != null)
486-
_context.netDb().unpublish(ls);
488+
_context.netDb().getSubNetDB(dbid).unpublish(ls);
487489
// unpublish encrypted LS also
488490
ls = sp.currentEncryptedLeaseSet;
489491
if (ls != null)
490-
_context.netDb().unpublish(ls);
492+
_context.netDb().getSubNetDB(dbid).unpublish(ls);
491493
_context.tunnelManager().removeAlias(sp.dest);
492494
synchronized(this) {
493495
if (sp.rerequestTimer != null)

router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public FloodfillNetworkDatabaseFacade getSubNetDB(String dbid){
4444

4545
public void restart() {}
4646
public void shutdown() {}
47+
public void remove(String dbid){}
4748
public void startup() {
4849
RouterInfo info = _context.router().getRouterInfo();
4950
_routers.put(info.getIdentity().getHash(), info);

router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java

+14
Original file line numberDiff line numberDiff line change
@@ -956,4 +956,18 @@ private String matchDbid(Hash clientKey) {
956956
}
957957
return null;
958958
}
959+
960+
public void remove(String dbid) {
961+
if (dbid != null) {
962+
if (dbid.endsWith(".i2p") && !dbid.startsWith("clients_"))
963+
dbid = "clients_" + dbid;
964+
else if (dbid.equals(""))
965+
dbid = MAIN_DBID;
966+
GetSubNetDB(dbid).shutdown();
967+
_subDBs.remove(dbid);
968+
} else {
969+
if (_log.shouldLog(Log.DEBUG))
970+
_log.debug("remove called with null dbid, refusing to remove main DB");
971+
}
972+
}
959973
}

router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java

+2
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,6 @@ public BlindData getBlindData(SigningPublicKey spk, String dbid) {
332332
}
333333

334334
public abstract String getDbidByHash(Hash clientKey);
335+
336+
public abstract void remove(String dbid);
335337
}

0 commit comments

Comments
 (0)