Skip to content

Commit

Permalink
Router: just use _facade instead of looking up the netDb with the dbid
Browse files Browse the repository at this point in the history
  • Loading branch information
eyedeekay committed Sep 15, 2023
1 parent 6e636c5 commit 3da6c22
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
1 change: 0 additions & 1 deletion router/java/src/net/i2p/router/RouterContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -449,7 +448,6 @@ void removeSession(SessionId id) {
if (id == null)
return;
boolean isPrimary = false;
Hash dbid = getDestHash();
for (Iterator<SessionParams> iter = _sessions.values().iterator(); iter.hasNext(); ) {
SessionParams sp = iter.next();
if (id.equals(sp.sessionId)) {
Expand All @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
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.netDbSegmentor().getSubNetDB(_client));
FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.clientNetDb(_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.netDbSegmentor().getSubNetDB(_client));
FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, _context.clientNetDb(_client));
Job j = _FDSMH.createJob(data, null, null);
j.runJob();
if (sz > 0) {
Expand Down

0 comments on commit 3da6c22

Please sign in to comment.