From 3da6c22ae64b81e92c9e03b416e133bcd2121d43 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Fri, 15 Sep 2023 11:54:26 -0400 Subject: [PATCH] Router: just use _facade instead of looking up the netDb with the dbid --- .../java/src/net/i2p/router/RouterContext.java | 1 - .../router/client/ClientConnectionRunner.java | 16 +++++++--------- .../client/ClientMessageEventListener.java | 2 +- .../kademlia/FloodfillVerifyStoreJob.java | 2 +- .../kademlia/SearchUpdateReplyFoundJob.java | 4 ++-- .../router/tunnel/InboundMessageDistributor.java | 4 ++-- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/router/java/src/net/i2p/router/RouterContext.java b/router/java/src/net/i2p/router/RouterContext.java index 2856f4b7f7..89152e52b7 100644 --- a/router/java/src/net/i2p/router/RouterContext.java +++ b/router/java/src/net/i2p/router/RouterContext.java @@ -375,7 +375,6 @@ public Hash routerHash() { public SegmentedNetworkDatabaseFacade netDbSegmentor() { return _netDb; } public FloodfillNetworkDatabaseFacade netDb() { return _netDb.mainNetDB(); } public FloodfillNetworkDatabaseFacade mainNetDb() { return _netDb.mainNetDB(); } - //public FloodfillNetworkDatabaseFacade exploratoryNetDb() { return _netDb.exploratoryNetDB(); } public FloodfillNetworkDatabaseFacade clientNetDb(String id) { return _netDb.clientNetDB(id); } public FloodfillNetworkDatabaseFacade clientNetDb(Hash id) { return _netDb.clientNetDB(id); } /** diff --git a/router/java/src/net/i2p/router/client/ClientConnectionRunner.java b/router/java/src/net/i2p/router/client/ClientConnectionRunner.java index 6f87e9a73f..b6b2694289 100644 --- a/router/java/src/net/i2p/router/client/ClientConnectionRunner.java +++ b/router/java/src/net/i2p/router/client/ClientConnectionRunner.java @@ -211,19 +211,18 @@ public synchronized void stopRunning() { _manager.unregisterEncryptedDestination(this, _encryptedLSHash); _manager.unregisterConnection(this); // netdb may be null in unit tests - Hash dbid = getDestHash(); - if (_context.netDbSegmentor() != null) { + if (_context.clientNetDb(getDestHash()) != null) { // Note that if the client sent us a destroy message, // removeSession() was called just before this, and // _sessions will be empty. for (SessionParams sp : _sessions.values()) { LeaseSet ls = sp.currentLeaseSet; if (ls != null) - _context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls); + _context.clientNetDb(getDestHash()).unpublish(ls); // unpublish encrypted LS also ls = sp.currentEncryptedLeaseSet; if (ls != null) - _context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls); + _context.clientNetDb(getDestHash()).unpublish(ls); if (!sp.isPrimary) _context.tunnelManager().removeAlias(sp.dest); } @@ -449,7 +448,6 @@ void removeSession(SessionId id) { if (id == null) return; boolean isPrimary = false; - Hash dbid = getDestHash(); for (Iterator iter = _sessions.values().iterator(); iter.hasNext(); ) { SessionParams sp = iter.next(); if (id.equals(sp.sessionId)) { @@ -460,11 +458,11 @@ void removeSession(SessionId id) { _manager.unregisterSession(id, sp.dest); LeaseSet ls = sp.currentLeaseSet; if (ls != null) - _context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls); + _context.clientNetDb(getDestHash()).unpublish(ls); // unpublish encrypted LS also ls = sp.currentEncryptedLeaseSet; if (ls != null) - _context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls); + _context.clientNetDb(getDestHash()).unpublish(ls); isPrimary = sp.isPrimary; if (isPrimary) _context.tunnelManager().removeTunnels(sp.dest); @@ -485,11 +483,11 @@ void removeSession(SessionId id) { _manager.unregisterSession(sp.sessionId, sp.dest); LeaseSet ls = sp.currentLeaseSet; if (ls != null) - _context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls); + _context.clientNetDb(getDestHash()).unpublish(ls); // unpublish encrypted LS also ls = sp.currentEncryptedLeaseSet; if (ls != null) - _context.netDbSegmentor().getSubNetDB(dbid).unpublish(ls); + _context.clientNetDb(getDestHash()).unpublish(ls); _context.tunnelManager().removeAlias(sp.dest); synchronized(this) { if (sp.rerequestTimer != null) diff --git a/router/java/src/net/i2p/router/client/ClientMessageEventListener.java b/router/java/src/net/i2p/router/client/ClientMessageEventListener.java index 03ef645299..e3d7e7e2f2 100644 --- a/router/java/src/net/i2p/router/client/ClientMessageEventListener.java +++ b/router/java/src/net/i2p/router/client/ClientMessageEventListener.java @@ -717,7 +717,7 @@ protected void handleCreateLeaseSet(CreateLeaseSetMessage message) { EncryptedLeaseSet encls = (EncryptedLeaseSet) ls; if (_log.shouldDebug()) _log.debug("Storing decrypted: " + encls.getDecryptedLeaseSet()); - _context.netDbSegmentor().getSubNetDB(dest.getHash()).store(dest.getHash(), encls.getDecryptedLeaseSet()); + _context.clientNetDb(_runner.getDestHash()).store(dest.getHash(), encls.getDecryptedLeaseSet()); } } catch (IllegalArgumentException iae) { if (_log.shouldLog(Log.ERROR)) diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java index b3815d3063..c88992941a 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java @@ -460,7 +460,7 @@ public void runJob() { private void resend() { // It's safe to check the default netDb first, but if the lookup is for // a client, nearly all RI is expected to be found in the FF netDb. - DatabaseEntry ds = getContext().netDbSegmentor().getSubNetDB(_facade._dbid).lookupLocally(_key); + DatabaseEntry ds = _facade.lookupLocally(_key); if ((ds == null) && _facade.isClientDb() && _isRouterInfo) // It's safe to check the floodfill netDb for RI ds = getContext().mainNetDb().lookupLocally(_key); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java index 9806a57d0a..faf12102c1 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java @@ -88,11 +88,11 @@ public void runJob() { switch (entry.getType()) { case DatabaseEntry.KEY_TYPE_ROUTERINFO: RouterInfo ri = (RouterInfo) entry; - getContext().netDbSegmentor().getSubNetDB(_facade._dbid).store(ri.getHash(), ri); + _facade.store(ri.getHash(), ri); break; case DatabaseEntry.KEY_TYPE_LEASESET: LeaseSet ls = (LeaseSet) entry; - getContext().netDbSegmentor().getSubNetDB(_facade._dbid).store(ls.getHash(), ls); + _facade.store(ls.getHash(), ls); break; default: break; diff --git a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java index 19ce1170c6..1586bd004d 100644 --- a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java +++ b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java @@ -271,7 +271,7 @@ public void distribute(I2NPMessage msg, Hash target, TunnelId tunnel) { if (dsm.getEntry().isLeaseSet()) { if (_log.shouldLog(Log.INFO)) _log.info("[client: " + _clientNickname + "] Saving LS DSM from client tunnel."); - FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.netDbSegmentor().getSubNetDB(_client)); + FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.clientNetDb(_client)); Job j = _FDSMH.createJob(msg, null, null); j.runJob(); if (sz > 0) { @@ -403,7 +403,7 @@ public void handleClove(DeliveryInstructions instructions, I2NPMessage data) { // ToDo: This should actually have a try and catch. if (_log.shouldLog(Log.INFO)) _log.info("Store the LS in the correct dbid subDb: " + _client.toBase32()); - FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.netDbSegmentor().getSubNetDB(_client)); + FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.clientNetDb(_client)); Job j = _FDSMH.createJob(data, null, null); j.runJob(); if (sz > 0) {