Skip to content

Commit

Permalink
Router: make netDb() point at the main netDb(), which is equivalent t…
Browse files Browse the repository at this point in the history
…o where it used to point. netDbSegmentor() now replaces netDb internally for most cases.
  • Loading branch information
eyedeekay committed Sep 8, 2023
1 parent c1c8cfc commit 2ade84a
Show file tree
Hide file tree
Showing 44 changed files with 90 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private JSONRPC2Response process(JSONRPC2Request req) {

if (inParams.containsKey("i2p.router.netdb.knownpeers")) {
// Why max(-1, 0) is used I don't know, it is the implementation used in the router console.
outParams.put("i2p.router.netdb.knownpeers", Math.max(_context.netDb().getKnownRouters(null) - 1, 0));
outParams.put("i2p.router.netdb.knownpeers", Math.max(_context.netDbSegmentor().getKnownRouters(null) - 1, 0));
}

if (inParams.containsKey("i2p.router.netdb.activepeers")) {
Expand Down Expand Up @@ -200,7 +200,7 @@ private NETWORK_STATUS getNetworkStatus() {
case CommSystemFacade.STATUS_IPV4_DISABLED_IPV6_FIREWALLED:
if (_context.router().getRouterInfo().getTargetAddress("NTCP2") != null)
return NETWORK_STATUS.WARN_FIREWALLED_WITH_INBOUND_TCP;
if (_context.netDb().floodfillEnabled())
if (_context.netDbSegmentor().floodfillEnabled())
return NETWORK_STATUS.WARN_FIREWALLED_AND_FLOODFILL;
if (_context.router().getRouterInfo().getCapabilities().indexOf('O') >= 0)
return NETWORK_STATUS.WARN_FIREWALLED_AND_FAST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public String getFFChecked(int mode) {

/** @since 0.9.21 */
public boolean isFloodfill() {
return _context.netDb().floodfillEnabled();
return _context.netDbSegmentor().floodfillEnabled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ protected void processForm() {
return;
}
// from BlindCache
List<String> clientBase32s = _context.netDb().lookupClientBySigningPublicKey(spk);
List<String> clientBase32s = _context.netDbSegmentor().lookupClientBySigningPublicKey(spk);
// TODO: This updates all of the blind data for all clients, turning the blind cache into a shared context for the owner of an encrypted leaseSet.
// This is probably not ideal, with some social-engineering a service operator who owns an encrypted destination could associate 2 tunnels.
// How realistic is it? Maybe not very, but I don't like it. Still, this is better than nothing.
for (String clientBase32 : clientBase32s) {
BlindData bdold = _context.netDb().getBlindData(spk, clientBase32);
BlindData bdold = _context.netDbSegmentor().getBlindData(spk, clientBase32);
if (bdold != null && d == null)
d = bdold.getDestination();
if (d != null && _context.clientManager().isLocal(d)) {
Expand Down Expand Up @@ -164,7 +164,7 @@ protected void processForm() {
_log.debug("already cached: " + bdold);
}
try {
_context.netDb().setBlindData(bdout, clientBase32);
_context.netDbSegmentor().setBlindData(bdout, clientBase32);
addFormNotice(_t("Key for {0} added to keyring", bdout.toBase32()));
if (_mode == 6 || _mode == 7) {
addFormNotice(_t("Send key to server operator.") + ' ' + pk.toPublic().toBase64());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private boolean render(StringBuilder buf, boolean local) {
}
// LS2
if (!local) {
List<BlindData> bdata = _context.netDb().getLocalClientsBlindData();
List<BlindData> bdata = _context.netDbSegmentor().getLocalClientsBlindData();
if (bdata.size() > 1)
Collections.sort(bdata, new BDComparator());
for (BlindData bd : bdata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ else if ((_mode == 13 || _mode == 16) && !_postOK)
} else if (_full == 6) {
renderer.renderStatusHTML(_out, _limit, _page, _full, null, true);
} else if (_clientOnly && client == null) {
for (String _client : _context.netDb().getClients()) {
for (String _client : _context.netDbSegmentor().getClients()) {
renderer.renderLeaseSetHTML(_out, _debug, _client, clientOnly);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void renderRouterInfoHTML(Writer out, int pageSize, int page,
boolean notFound = true;
Set<RouterInfo> routers = new HashSet<RouterInfo>();
if (allClients){
routers.addAll(_context.netDb().getRoutersKnownToClients());
routers.addAll(_context.netDbSegmentor().getRoutersKnownToClients());
} else {
if (client == null)
routers.addAll(_context.mainNetDb().getRouters());
Expand Down Expand Up @@ -634,7 +634,7 @@ public void renderLeaseSetHTML(Writer out, boolean debug, String client, boolean
fmt = null;
}
if (clientsOnly)
leases.addAll(_context.netDb().getLeasesKnownToClients());
leases.addAll(_context.netDbSegmentor().getLeasesKnownToClients());
else
leases.addAll(netdb.getLeases());
int medianCount = 0;
Expand Down Expand Up @@ -747,7 +747,7 @@ public void renderLeaseSet(Writer out, String hostname, boolean debug) throws IO
buf.append(hostname);
buf.append("</div>");
} else {
LeaseSet ls = _context.netDb().lookupLeaseSetLocally(hash);
LeaseSet ls = _context.netDbSegmentor().lookupLeaseSetLocally(hash);
if (ls == null) {
// remote lookup
LookupWaiter lw = new LookupWaiter();
Expand Down Expand Up @@ -971,7 +971,7 @@ public void renderStatusHTML(Writer out, int pageSize, int page, int mode, Strin
if (client != null) {
routers.addAll(_context.clientNetDb(client).getRouters());
} else if (clientsOnly) {
routers.addAll(_context.netDb().getRoutersKnownToClients());
routers.addAll(_context.netDbSegmentor().getRoutersKnownToClients());
} else {
routers.addAll(_context.mainNetDb().getRouters());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ public String getDestinations() {
else
buf.append(DataHelper.escapeHTML(ServletUtil.truncate(name, 29))).append("&hellip;");
buf.append("</a></b></td>\n");
LeaseSet ls = _context.netDb().lookupLeaseSetHashIsClient(h);
LeaseSet ls = _context.netDbSegmentor().lookupLeaseSetHashIsClient(h);
if (ls != null && _context.tunnelManager().getOutboundClientTunnelCount(h) > 0) {
if (!ls.isCurrent(0)) {
// yellow light
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ private void renderDestSummary(Writer out, StringBuilder buf, Analysis analysis,
Hash client = iter.next();
if (!_context.clientManager().isLocal(client) ||
!_context.clientManager().shouldPublishLeaseSet(client) ||
_context.netDb().lookupLeaseSetLocally(client) == null) {
_context.netDbSegmentor().lookupLeaseSetLocally(client) == null) {
iter.remove();
}
}
Expand All @@ -503,7 +503,7 @@ private void renderDestSummary(Writer out, StringBuilder buf, Analysis analysis,
return;
}
for (Hash client : destinations) {
LeaseSet ls = _context.netDb().lookupLeaseSetLocally(client);
LeaseSet ls = _context.netDbSegmentor().lookupLeaseSetLocally(client);
if (ls == null)
continue;
Hash rkey = ls.getRoutingKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public int compare(Hash l, Hash r) {

/** @return cap char or ' ' */
private char getCapacity(Hash peer) {
RouterInfo info = (RouterInfo) _context.netDb().lookupLocallyWithoutValidation(peer, null);
RouterInfo info = (RouterInfo) _context.netDbSegmentor().lookupLocallyWithoutValidation(peer, null);
if (info != null) {
String caps = info.getCapabilities();
for (int i = 0; i < RouterInfo.BW_CAPABILITY_CHARS.length(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion router/java/src/net/i2p/router/Banlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public boolean banlistRouter(Hash peer, String reason, String reasonComment, Int

if (transport == null) {
// we hate the peer on *any* transport
_context.netDb().fail(peer);
_context.netDbSegmentor().fail(peer);
_context.tunnelManager().fail(peer);
}
//_context.tunnelManager().peerFailed(peer);
Expand Down
2 changes: 1 addition & 1 deletion router/java/src/net/i2p/router/Blocklist.java
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ private boolean isOnSingleList(BigInteger ip) {
* Will not contain duplicates.
*/
private List<byte[]> getAddresses(Hash peer) {
RouterInfo pinfo = _context.netDb().lookupRouterInfoLocally(peer, null);
RouterInfo pinfo = _context.netDbSegmentor().lookupRouterInfoLocally(peer, null);
if (pinfo == null)
return Collections.emptyList();
return getAddresses(pinfo);
Expand Down
4 changes: 2 additions & 2 deletions router/java/src/net/i2p/router/MultiRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ private static void internalReseed() {

HashSet<RouterInfo> riSet = new HashSet<RouterInfo>();
for(Router r : _routers) {
riSet.addAll(r.getContext().netDb().getRouters());
riSet.addAll(r.getContext().netDbSegmentor().getRouters());
}
for(Router r : _routers) {
for(RouterInfo ri : riSet){
r.getContext().netDb().publish(ri);
r.getContext().netDbSegmentor().publish(ri);
}
}
_out.println(riSet.size() + " RouterInfos were reseeded");
Expand Down
4 changes: 2 additions & 2 deletions router/java/src/net/i2p/router/Router.java
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ public String getCapabilities() {
// rv.append(CAPABILITY_BW256);

// if prop set to true, don't tell people we are ff even if we are
if (_context.netDb().floodfillEnabled() &&
if (_context.netDbSegmentor().floodfillEnabled() &&
!_context.getBooleanProperty("router.hideFloodfillParticipant"))
rv.append(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL);

Expand Down Expand Up @@ -1603,7 +1603,7 @@ public synchronized void shutdown2(int exitCode) {
try { _context.jobQueue().shutdown(); } catch (Throwable t) { _log.error("Error shutting down the job queue", t); }
try { _context.tunnelManager().shutdown(); } catch (Throwable t) { _log.error("Error shutting down the tunnel manager", t); }
try { _context.tunnelDispatcher().shutdown(); } catch (Throwable t) { _log.error("Error shutting down the tunnel dispatcher", t); }
try { _context.netDb().shutdown(); } catch (Throwable t) { _log.error("Error shutting down the networkDb", t); }
try { _context.netDbSegmentor().shutdown(); } catch (Throwable t) { _log.error("Error shutting down the networkDb", t); }
try { _context.commSystem().shutdown(); } catch (Throwable t) { _log.error("Error shutting down the comm system", t); }
try { _context.bandwidthLimiter().shutdown(); } catch (Throwable t) { _log.error("Error shutting down the comm system", t); }
try { _context.peerManager().shutdown(); } catch (Throwable t) { _log.error("Error shutting down the peer manager", t); }
Expand Down
3 changes: 2 additions & 1 deletion router/java/src/net/i2p/router/RouterContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,8 @@ public Hash routerHash() {
/**
* Our db cache
*/
public SegmentedNetworkDatabaseFacade netDb() { return _netDb; }
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); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,18 @@ public synchronized void stopRunning() {
_manager.unregisterEncryptedDestination(this, _encryptedLSHash);
_manager.unregisterConnection(this);
// netdb may be null in unit tests
if (_context.netDb() != null) {
if (_context.netDbSegmentor() != 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.netDb().unpublish(ls);
_context.netDbSegmentor().unpublish(ls);
// unpublish encrypted LS also
ls = sp.currentEncryptedLeaseSet;
if (ls != null)
_context.netDb().unpublish(ls);
_context.netDbSegmentor().unpublish(ls);
if (!sp.isPrimary)
_context.tunnelManager().removeAlias(sp.dest);
}
Expand Down Expand Up @@ -458,11 +458,11 @@ void removeSession(SessionId id) {
_manager.unregisterSession(id, sp.dest);
LeaseSet ls = sp.currentLeaseSet;
if (ls != null)
_context.netDb().unpublish(ls);
_context.netDbSegmentor().unpublish(ls);
// unpublish encrypted LS also
ls = sp.currentEncryptedLeaseSet;
if (ls != null)
_context.netDb().unpublish(ls);
_context.netDbSegmentor().unpublish(ls);
isPrimary = sp.isPrimary;
if (isPrimary)
_context.tunnelManager().removeTunnels(sp.dest);
Expand All @@ -483,11 +483,11 @@ void removeSession(SessionId id) {
_manager.unregisterSession(sp.sessionId, sp.dest);
LeaseSet ls = sp.currentLeaseSet;
if (ls != null)
_context.netDb().unpublish(ls);
_context.netDbSegmentor().unpublish(ls);
// unpublish encrypted LS also
ls = sp.currentEncryptedLeaseSet;
if (ls != null)
_context.netDb().unpublish(ls);
_context.netDbSegmentor().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 @@ -711,13 +711,13 @@ protected void handleCreateLeaseSet(CreateLeaseSetMessage message) {
}
if (_log.shouldDebug())
_log.debug("Publishing: " + ls);
_context.netDb().publish(ls, _runner.getDestHash().toBase32());
_context.netDbSegmentor().publish(ls, _runner.getDestHash().toBase32());
if (type == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
// store the decrypted ls also
EncryptedLeaseSet encls = (EncryptedLeaseSet) ls;
if (_log.shouldDebug())
_log.debug("Storing decrypted: " + encls.getDecryptedLeaseSet());
_context.netDb().store(dest.getHash(), encls.getDecryptedLeaseSet());
_context.netDbSegmentor().store(dest.getHash(), encls.getDecryptedLeaseSet());
}
} catch (IllegalArgumentException iae) {
if (_log.shouldLog(Log.ERROR))
Expand Down Expand Up @@ -861,9 +861,9 @@ private void handleBlindingInfo(BlindingInfoMessage message) {
_log.warn("Unsupported BlindingInfo type: " + message);
return;
}
BlindData obd = _context.netDb().getBlindData(spk);
BlindData obd = _context.netDbSegmentor().getBlindData(spk);
if (obd == null) {
_context.netDb().setBlindData(bd, _runner.getDestHash().toBase32());
_context.netDbSegmentor().setBlindData(bd, _runner.getDestHash().toBase32());
if (_log.shouldWarn())
_log.warn("New: " + bd);
} else {
Expand All @@ -884,7 +884,7 @@ private void handleBlindingInfo(BlindingInfoMessage message) {
return;
}
}
_context.netDb().setBlindData(bd, _runner.getDestHash().toBase32());
_context.netDbSegmentor().setBlindData(bd, _runner.getDestHash().toBase32());
if (_log.shouldWarn())
_log.warn("Updated: " + bd);
} else {
Expand All @@ -893,7 +893,7 @@ private void handleBlindingInfo(BlindingInfoMessage message) {
if (nexp > oexp) {
obd.setExpiration(nexp);
// to force save at shutdown
_context.netDb().setBlindData(obd, _runner.getDestHash().toBase32());
_context.netDbSegmentor().setBlindData(obd, _runner.getDestHash().toBase32());
if (_log.shouldWarn())
_log.warn("Updated expiration: " + obd);
} else {
Expand Down
10 changes: 5 additions & 5 deletions router/java/src/net/i2p/router/client/LookupDestJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public LookupDestJob(RouterContext context, ClientConnectionRunner runner,
try {
bd = Blinding.decode(context, b);
SigningPublicKey spk = bd.getUnblindedPubKey();
BlindData bd2 = getContext().netDb().getBlindData(spk);
BlindData bd2 = getContext().netDbSegmentor().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 @@ -110,7 +110,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);
getContext().netDb().setBlindData(bd, toBase32());
getContext().netDbSegmentor().setBlindData(bd, toBase32());
}
h = bd.getBlindedHash();
if (_log.shouldDebug())
Expand Down Expand Up @@ -185,7 +185,7 @@ else if (fail1)
if (timeout > 1500)
timeout -= 500;
// TODO tell router this is an encrypted lookup, skip 38 or earlier ffs?
getContext().netDb().lookupDestination(_hash, done, timeout, _fromLocalDest, toBase32());
getContext().netDbSegmentor().lookupDestination(_hash, done, timeout, _fromLocalDest, toBase32());
} else {
// blinding decode fail
returnFail(HostReplyMessage.RESULT_DECRYPTION_FAILURE);
Expand All @@ -204,10 +204,10 @@ public DoneJob(RouterContext enclosingContext) {
}
public String getName() { return "LeaseSet Lookup Reply to Client"; }
public void runJob() {
Destination dest = getContext().netDb().lookupDestinationLocally(_hash, toBase32());
Destination dest = getContext().netDbSegmentor().lookupDestinationLocally(_hash, toBase32());
if (dest == null && _blindData != null) {
// TODO store and lookup original hash instead
LeaseSet ls = getContext().netDb().lookupLeaseSetLocally(_hash, toBase32());
LeaseSet ls = getContext().netDbSegmentor().lookupLeaseSetLocally(_hash, toBase32());
if (ls != null && ls.getType() == DatabaseEntry.KEY_TYPE_ENCRYPTED_LS2) {
// already decrypted
EncryptedLeaseSet encls = (EncryptedLeaseSet) ls;
Expand Down
Loading

0 comments on commit 2ade84a

Please sign in to comment.