From 9727f96c021bef8ce7cc7992ae160c31dc9ce885 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Thu, 12 Oct 2023 11:29:49 -0400 Subject: [PATCH] Router: deal with early lookups by routing them to the main DB --- .../net/i2p/router/client/LookupDestJob.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/router/java/src/net/i2p/router/client/LookupDestJob.java b/router/java/src/net/i2p/router/client/LookupDestJob.java index 8fec06c100..9824aa5268 100644 --- a/router/java/src/net/i2p/router/client/LookupDestJob.java +++ b/router/java/src/net/i2p/router/client/LookupDestJob.java @@ -92,7 +92,7 @@ public LookupDestJob(RouterContext context, ClientConnectionRunner runner, try { bd = Blinding.decode(context, b); SigningPublicKey spk = bd.getUnblindedPubKey(); - BlindData bd2 = _runner.getFloodfillNetworkDatabaseFacade().getBlindData(spk); + BlindData bd2 = getRequiredFloodfillNetworkDatabaseFacade().getBlindData(spk); if (bd2 != null) { // BlindData from database may have privkey or secret // check if we need it but don't have it @@ -111,7 +111,7 @@ public LookupDestJob(RouterContext context, ClientConnectionRunner runner, long exp = now + ((bd.getAuthRequired() || bd.getSecretRequired()) ? 365*24*60*60*1000L : 90*24*68*60*1000L); bd.setExpiration(exp); - _runner.getFloodfillNetworkDatabaseFacade().setBlindData(bd); + getRequiredFloodfillNetworkDatabaseFacade().setBlindData(bd); } h = bd.getBlindedHash(); if (_log.shouldDebug()) @@ -186,19 +186,14 @@ else if (fail1) if (timeout > 1500) timeout -= 500; // TODO tell router this is an encrypted lookup, skip 38 or earlier ffs? - FloodfillNetworkDatabaseFacade fndf = _runner.getFloodfillNetworkDatabaseFacade(); - if (fndf != null) - fndf.lookupDestination(_hash, done, timeout, _fromLocalDest); - else - if (_log.shouldLog(Log.DEBUG)) - _log.debug("fndf is null in lookup for " + _hash); + getRequiredFloodfillNetworkDatabaseFacade().lookupDestination(_hash, done, timeout, _fromLocalDest); } else { // blinding decode fail returnFail(HostReplyMessage.RESULT_DECRYPTION_FAILURE); } } - private String toBase32(){ + private String toBase32() { if (_fromLocalDest != null) return _fromLocalDest.toBase32(); return null; @@ -210,10 +205,10 @@ public DoneJob(RouterContext enclosingContext) { } public String getName() { return "LeaseSet Lookup Reply to Client"; } public void runJob() { - Destination dest = _runner.getFloodfillNetworkDatabaseFacade().lookupDestinationLocally(_hash); + Destination dest = getRequiredFloodfillNetworkDatabaseFacade().lookupDestinationLocally(_hash); if (dest == null && _blindData != null) { // TODO store and lookup original hash instead - LeaseSet ls = _runner.getFloodfillNetworkDatabaseFacade().lookupLeaseSetLocally(_hash); + LeaseSet ls = getRequiredFloodfillNetworkDatabaseFacade().lookupLeaseSetLocally(_hash); if (ls != null && ls.getType() == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) { // already decrypted EncryptedLeaseSet encls = (EncryptedLeaseSet) ls; @@ -271,4 +266,20 @@ else if (_hash != null) _runner.doSend(msg); } catch (I2CPMessageException ime) {} } + + /** + * If we don't have an FNDF in our runner, get the main netDb instead. This happens + * if there is not a session established yet. + * + * @return + */ + private FloodfillNetworkDatabaseFacade getRequiredFloodfillNetworkDatabaseFacade() { + FloodfillNetworkDatabaseFacade fndf = _runner.getFloodfillNetworkDatabaseFacade(); + if (fndf == null){ + fndf = getContext().netDb(); + if (_log.shouldLog(Log.DEBUG)) + _log.debug("fndf is null in lookup for " + _runner.getDestHash() + " using the main DB instead"); + } + return fndf; + } }