diff --git a/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java index 4d71392968..9382bb07b2 100644 --- a/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/dummy/DummyNetworkDatabaseFacade.java @@ -55,6 +55,14 @@ public FloodfillNetworkDatabaseFacade getSubNetDB(Hash dbid){ return null; } + public void removeSubNetDB(String dbid) { + return; + } + + public void removeSubNetDB(Hash dbid) { + return; + } + public void restart() {} public void shutdown() {} public void startup() { 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 678c24d871..832e102d8b 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseSegmentor.java @@ -95,7 +95,6 @@ protected FloodfillNetworkDatabaseFacade createSubNetDB(String id) { if (id.equals(myHash.toBase32())) return mainNetDB(); - id = clientDbidString(id); FloodfillNetworkDatabaseFacade subdb = get(id); @@ -116,14 +115,6 @@ protected FloodfillNetworkDatabaseFacade createSubNetDB(String id) { return subdb; } - private String clientDbidString(String id) { - if (id.endsWith(".i2p")) { - if (!id.startsWith("clients_")) - id = "clients_" + id; - } - return id; - } - @Override public FloodfillNetworkDatabaseFacade getSubNetDB(Hash dbid) { if (dbid == null) @@ -148,6 +139,35 @@ public FloodfillNetworkDatabaseFacade getSubNetDB(String id) { return get(id); } + @Override + public void removeSubNetDB(Hash id) { + if (id == null) + return; + Hash myHash = _context.routerHash(); + if (id.equals(myHash.toBase32())) + return; + + String dbid = id.toBase32(); + dbid = clientDbidString(dbid); + remove(dbid); + } + + @Override + public void removeSubNetDB(String id) { + if (id == null || id.isEmpty() || id.equals(MAIN_DBID)) + return; + if (id.equals(MULTIHOME_DBID)) + return; + if (id.equals(EXPLORATORY_DBID)) + return; + Hash myHash = _context.routerHash(); + if (id.equals(myHash.toBase32())) + return; + + String dbid = clientDbidString(id); + remove(dbid); + } + /** * If we are floodfill, turn it off and tell everybody. * @@ -380,6 +400,12 @@ private void put(String id, FloodfillNetworkDatabaseFacade subdb) { } } + private void remove(String id) { + synchronized(_subDBs) { + _subDBs.remove(id); + } + } + private List keySet() { synchronized(_subDBs) { return new ArrayList(_subDBs.keySet()); @@ -391,4 +417,12 @@ private List values() { return new ArrayList(_subDBs.values()); } } + + private String clientDbidString(String id) { + if (id.endsWith(".i2p")) { + if (!id.startsWith("clients_")) + id = "clients_" + id; + } + return id; + } } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java index 73b7f6ca65..86db7ce466 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SegmentedNetworkDatabaseFacade.java @@ -64,6 +64,8 @@ public SegmentedNetworkDatabaseFacade(RouterContext context) { public abstract FloodfillNetworkDatabaseFacade createSubNetDB(Hash dbid); public abstract FloodfillNetworkDatabaseFacade getSubNetDB(String dbid); public abstract FloodfillNetworkDatabaseFacade getSubNetDB(Hash dbid); + public abstract void removeSubNetDB(String dbid); + public abstract void removeSubNetDB(Hash dbid); public abstract FloodfillNetworkDatabaseFacade mainNetDB(); public abstract FloodfillNetworkDatabaseFacade multiHomeNetDB(); public abstract FloodfillNetworkDatabaseFacade clientNetDB(String dbid);