Skip to content

Commit

Permalink
Router: deal with early lookups by routing them to the main DB
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Oct 12, 2023
1 parent 5c5ff2e commit 9727f96
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions router/java/src/net/i2p/router/client/LookupDestJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 9727f96

Please sign in to comment.