From abee01602bf4529aeddb8ed73a892f305516b149 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Sat, 23 Sep 2023 14:02:40 -0400 Subject: [PATCH] Router: check in WIP stuff --- .../src/net/i2p/router/ClientManagerFacade.java | 7 +++++++ .../net/i2p/router/client/ClientManager.java | 17 +++++++++++++++++ .../router/client/ClientManagerFacadeImpl.java | 4 ++++ .../client/ClientMessageEventListener.java | 1 + .../router/dummy/DummyClientManagerFacade.java | 4 +++- .../OutboundClientMessageOneShotJob.java | 14 +++++++------- .../tunnel/InboundMessageDistributor.java | 6 +++--- .../router/tunnel/pool/AliasedTunnelPool.java | 3 ++- 8 files changed, 44 insertions(+), 12 deletions(-) diff --git a/router/java/src/net/i2p/router/ClientManagerFacade.java b/router/java/src/net/i2p/router/ClientManagerFacade.java index 82f62bb237..2c4ad5597c 100644 --- a/router/java/src/net/i2p/router/ClientManagerFacade.java +++ b/router/java/src/net/i2p/router/ClientManagerFacade.java @@ -121,4 +121,11 @@ public void registerMetaDest(Destination dest) throws I2PSessionException {} * @since 0.9.41 */ public void unregisterMetaDest(Destination dest) {} + + /** + * get the primary dbid of a client by the dest + * + * @since 0.9.60 + */ + public abstract Hash getPrimaryDbid(Hash dest); } diff --git a/router/java/src/net/i2p/router/client/ClientManager.java b/router/java/src/net/i2p/router/client/ClientManager.java index a8bc8f46ee..ede66b2fc4 100644 --- a/router/java/src/net/i2p/router/client/ClientManager.java +++ b/router/java/src/net/i2p/router/client/ClientManager.java @@ -668,6 +668,23 @@ private ClientConnectionRunner getRunner(Hash destHash) { return null; return _runnersByHash.get(destHash); } + + /** + * + * get the client's primary dbid + * + * @param fromDest + * + * @since 0.9.60 + */ + public Hash getPrimaryDbid(Hash fromDest) { + // first, get the runner + ClientConnectionRunner runner = getRunner(fromDest); + if (runner != null) { + return runner.getDestHash(); + } + return null; + } /** * @param id the router's ID for this message diff --git a/router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java b/router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java index 629d3e5e07..b97798f7ea 100644 --- a/router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java +++ b/router/java/src/net/i2p/router/client/ClientManagerFacadeImpl.java @@ -220,6 +220,10 @@ public SessionConfig getClientSessionConfig(Destination dest) { return null; } } + + public Hash getPrimaryDbid(Hash dest) { + return _manager.getPrimaryDbid(dest); + } /** * Return the client's current manager or null if not connected diff --git a/router/java/src/net/i2p/router/client/ClientMessageEventListener.java b/router/java/src/net/i2p/router/client/ClientMessageEventListener.java index 9d9fb4c821..56fe345428 100644 --- a/router/java/src/net/i2p/router/client/ClientMessageEventListener.java +++ b/router/java/src/net/i2p/router/client/ClientMessageEventListener.java @@ -83,6 +83,7 @@ public ClientMessageEventListener(RouterContext context, ClientConnectionRunner _context = context; _log = _context.logManager().getLog(ClientMessageEventListener.class); _runner = runner; + _context.netDbSegmentor().createClientNetDB(_runner.getDestHash()); _enforceAuth = enforceAuth; if ((!_enforceAuth) || !_context.getBooleanProperty(PROP_AUTH)) _authorized = true; diff --git a/router/java/src/net/i2p/router/dummy/DummyClientManagerFacade.java b/router/java/src/net/i2p/router/dummy/DummyClientManagerFacade.java index ba40badd00..f9ab837321 100644 --- a/router/java/src/net/i2p/router/dummy/DummyClientManagerFacade.java +++ b/router/java/src/net/i2p/router/dummy/DummyClientManagerFacade.java @@ -49,6 +49,8 @@ public void messageDeliveryStatusUpdate(Destination fromDest, MessageId id, long public SessionKeyManager getClientSessionKeyManager(Hash _dest) { return null; } public void requestLeaseSet(Hash dest, LeaseSet set) {} - + public Hash getPrimaryDbid(Hash dest){ + return null; + } } diff --git a/router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java b/router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java index ae4064013c..1e6b5f4b4c 100644 --- a/router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java +++ b/router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java @@ -209,7 +209,7 @@ public OutboundClientMessageOneShotJob(RouterContext ctx, OutboundCache cache, C _hashPair = new OutboundCache.HashPair(_from.calculateHash(), toHash); _toString = toHash.toBase32(); // we look up here rather than runJob() so we may adjust the timeout - _leaseSet = ctx.clientNetDb(_from.calculateHash()).lookupLeaseSetLocally(toHash); + _leaseSet = ctx.clientNetDb(getContext().clientManager().getPrimaryDbid(_from.calculateHash())).lookupLeaseSetLocally(toHash); // use expiration requested by client if available, otherwise session config, // otherwise router config, otherwise default @@ -307,7 +307,7 @@ public void runJob() { if (_log.shouldInfo()) _log.info(getJobId() + ": RAP LS, firing search: " + _leaseSet.getHash().toBase32()); LookupLeaseSetFailedJob failed = new LookupLeaseSetFailedJob(getContext()); - getContext().clientNetDb(_from.calculateHash()).lookupLeaseSetRemotely(_leaseSet.getHash(), success, failed, + getContext().clientNetDb(getContext().clientManager().getPrimaryDbid(_from.calculateHash())).lookupLeaseSetRemotely(_leaseSet.getHash(), success, failed, LS_LOOKUP_TIMEOUT, _from.calculateHash()); } else { dieFatal(MessageStatusMessage.STATUS_SEND_FAILURE_NO_LEASESET); @@ -330,7 +330,7 @@ public void runJob() { long exp = now - _leaseSet.getLatestLeaseDate(); _log.info(getJobId() + ": leaseSet expired " + DataHelper.formatDuration(exp) + " ago, firing search: " + _leaseSet.getHash().toBase32()); } - getContext().clientNetDb(_from.calculateHash()).lookupLeaseSetRemotely(_leaseSet.getHash(), _from.calculateHash()); + getContext().clientNetDb(getContext().clientManager().getPrimaryDbid(_from.calculateHash())).lookupLeaseSetRemotely(_leaseSet.getHash(), _from.calculateHash()); } } success.runJob(); @@ -340,7 +340,7 @@ public void runJob() { _log.debug(getJobId() + ": Send outbound client message - sending off leaseSet lookup job for " + _toString + " from client " + _from.calculateHash().toBase32()); LookupLeaseSetFailedJob failed = new LookupLeaseSetFailedJob(getContext()); Hash key = _to.calculateHash(); - getContext().clientNetDb(_from.calculateHash()).lookupLeaseSet(key, success, failed, LS_LOOKUP_TIMEOUT, _from.calculateHash()); + getContext().clientNetDb(getContext().clientManager().getPrimaryDbid(_from.calculateHash())).lookupLeaseSet(key, success, failed, LS_LOOKUP_TIMEOUT, _from.calculateHash()); } } @@ -349,7 +349,7 @@ public void runJob() { * @return lease set or null if we should not send the lease set */ private LeaseSet getReplyLeaseSet(boolean force) { - LeaseSet newLS = getContext().clientNetDb(_from.calculateHash()).lookupLeaseSetLocally(_from.calculateHash()); + LeaseSet newLS = getContext().clientNetDb(getContext().clientManager().getPrimaryDbid(_from.calculateHash())).lookupLeaseSetLocally(_from.calculateHash()); if (newLS == null) return null; // punt @@ -423,7 +423,7 @@ public void runJob() { private int getNextLease() { // set in runJob if found locally if (_leaseSet == null || !_leaseSet.getReceivedAsReply()) { - _leaseSet = getContext().clientNetDb(_from.calculateHash()).lookupLeaseSetLocally(_to.calculateHash()); + _leaseSet = getContext().clientNetDb(getContext().clientManager().getPrimaryDbid(_from.calculateHash())).lookupLeaseSetLocally(_to.calculateHash()); if (_leaseSet == null) { // shouldn't happen if (_log.shouldLog(Log.WARN)) @@ -587,7 +587,7 @@ public void runJob() { int cause; - if (getContext().clientNetDb(_from.calculateHash()).isNegativeCachedForever(_to.calculateHash())) { + if (getContext().clientNetDb(getContext().clientManager().getPrimaryDbid(_from.calculateHash())).isNegativeCachedForever(_to.calculateHash())) { if (_log.shouldLog(Log.WARN)) _log.warn("Unable to send to " + _toString + " because the sig type is unsupported"); cause = MessageStatusMessage.STATUS_SEND_FAILURE_UNSUPPORTED_ENCRYPTION; diff --git a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java index 1586bd004d..c60acfef47 100644 --- a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java +++ b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java @@ -140,7 +140,7 @@ public void distribute(I2NPMessage msg, Hash target, TunnelId tunnel) { return; RouterInfo oldri = null; if (_client != null) - oldri = _context.clientNetDb(_client).lookupRouterInfoLocally(key); + oldri = _context.clientNetDb(_context.clientManager().getPrimaryDbid(_client)).lookupRouterInfoLocally(key); else oldri = _context.mainNetDb().lookupRouterInfoLocally(key); // only update if RI is newer and non-ff @@ -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.clientNetDb(_client)); + FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.clientNetDb(_context.clientManager().getPrimaryDbid(_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.clientNetDb(_client)); + FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.clientNetDb(_context.clientManager().getPrimaryDbid(_client))); Job j = _FDSMH.createJob(data, null, null); j.runJob(); if (sz > 0) { diff --git a/router/java/src/net/i2p/router/tunnel/pool/AliasedTunnelPool.java b/router/java/src/net/i2p/router/tunnel/pool/AliasedTunnelPool.java index 8e092d8d3e..b503777781 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/AliasedTunnelPool.java +++ b/router/java/src/net/i2p/router/tunnel/pool/AliasedTunnelPool.java @@ -2,6 +2,7 @@ import java.util.List; +import net.i2p.data.Destination; import net.i2p.data.Hash; import net.i2p.data.Lease; import net.i2p.data.LeaseSet; @@ -115,7 +116,7 @@ boolean buildFallback() { @Override protected LeaseSet locked_buildNewLeaseSet() { - LeaseSet ls = _context.clientNetDb(_aliasOf.getSettings().getDestination()).lookupLeaseSetLocally(_aliasOf.getSettings().getDestination()); + LeaseSet ls = _context.clientNetDb(_context.clientManager().getPrimaryDbid(_aliasOf.getSettings().getDestination())).lookupLeaseSetLocally(_aliasOf.getSettings().getDestination()); if (ls == null) return null; // copy everything so it isn't corrupted