Skip to content

Commit

Permalink
Router: check in WIP stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Sep 23, 2023
1 parent b4cf5dc commit abee016
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 12 deletions.
7 changes: 7 additions & 0 deletions router/java/src/net/i2p/router/ClientManagerFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
17 changes: 17 additions & 0 deletions router/java/src/net/i2p/router/client/ClientManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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());
}
}

Expand All @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit abee016

Please sign in to comment.