Router: eliminate mainNetDb() call from RouterContext, then replace all calls with calls to netDb()

This commit is contained in:
eyedeekay
2023-09-21 19:55:07 -04:00
parent a343f781d0
commit ded7b6dda9
73 changed files with 166 additions and 167 deletions

View File

@@ -106,7 +106,7 @@ public class ConfigAdvancedHandler extends FormHandler {
private void saveFF() {
boolean saved = _context.router().saveConfig(ConfigAdvancedHelper.PROP_FLOODFILL_PARTICIPANT, _ff);
if (_ff.equals("false") || _ff.equals("true")) {
FloodfillNetworkDatabaseFacade fndf = (FloodfillNetworkDatabaseFacade) _context.mainNetDb();
FloodfillNetworkDatabaseFacade fndf = (FloodfillNetworkDatabaseFacade) _context.netDb();
boolean isFF = _ff.equals("true");
// this will rebuild the RI, log in the event log, etc.
fndf.setFloodfillEnabled(isFF);

View File

@@ -66,6 +66,6 @@ public class ConfigAdvancedHelper extends HelperBase {
/** @since 0.9.21 */
public boolean isFloodfill() {
return _context.mainNetDb().floodfillEnabled();
return _context.netDb().floodfillEnabled();
}
}

View File

@@ -45,7 +45,7 @@ public class ConfigFamilyHandler extends FormHandler {
if (ks.exists()) {
addFormError("Keystore for family " + family + " already exists! Delete or rename it first: " + ks);
} else {
for (RouterInfo ri : _context.mainNetDb().getRouters()) {
for (RouterInfo ri : _context.netDb().getRouters()) {
if (family.equals(ri.getOption("family"))) {
addFormError("The family name \"" + family + "\" is already in use by another router. Please select a different family name.");
return;

View File

@@ -194,7 +194,7 @@ public class ConfigKeyringHandler extends FormHandler {
BlindData bd = Blinding.decode(_context, p);
if (bd != null) {
SigningPublicKey spk = bd.getUnblindedPubKey();
removed = _context.mainNetDb().removeBlindData(spk);
removed = _context.netDb().removeBlindData(spk);
}
} catch (IllegalArgumentException iae) {}
} else {

View File

@@ -82,7 +82,7 @@ public class ConfigKeyringHelper extends HelperBase {
buf.append("<input value=\"").append(b32).append("\" type=\"checkbox\" name=\"revokeClient\" class=\"tickbox\"/></td><td>");
buf.append(b32);
buf.append("</td><td>");
Destination dest = _context.mainNetDb().lookupDestinationLocally(h);
Destination dest = _context.netDb().lookupDestinationLocally(h);
if (dest != null && local) {
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(h);
if (in != null && in.getDestinationNickname() != null)

View File

@@ -24,7 +24,7 @@ public class ConfigReseedHandler extends FormHandler {
@Override
protected void processForm() {
ReseedChecker checker = _context.mainNetDb().reseedChecker();
ReseedChecker checker = _context.netDb().reseedChecker();
if (_action.equals(_t("Save changes and reseed now"))) {
saveChanges();
if (!checker.requestReseed()) {

View File

@@ -130,14 +130,14 @@ class NetDbRenderer {
String tr, int cost, int icount, String client, boolean allClients) throws IOException {
StringBuilder buf = new StringBuilder(4*1024);
List<Hash> sybils = sybil != null ? new ArrayList<Hash>(128) : null;
FloodfillNetworkDatabaseFacade netdb = _context.mainNetDb();
FloodfillNetworkDatabaseFacade netdb = _context.netDb();
if (allClients) {
netdb = _context.mainNetDb();
netdb = _context.netDb();
}else{
if (client != null)
netdb = _context.clientNetDb(client);
else
netdb = _context.mainNetDb();
netdb = _context.netDb();
}
if (".".equals(routerPrefix)) {
@@ -234,7 +234,7 @@ class NetDbRenderer {
routers.addAll(_context.netDbSegmentor().getRoutersKnownToClients());
} else {
if (client == null)
routers.addAll(_context.mainNetDb().getRouters());
routers.addAll(_context.netDb().getRouters());
else
routers.addAll(_context.clientNetDb(client).getRouters());
@@ -617,12 +617,12 @@ class NetDbRenderer {
DecimalFormat fmt;
FloodfillNetworkDatabaseFacade netdb = null;
if (clientsOnly){
netdb = _context.mainNetDb();
netdb = _context.netDb();
}else{
if (client != null)
netdb = _context.clientNetDb(client);
else
netdb = _context.mainNetDb();
netdb = _context.netDb();
}
if (debug) {
ourRKey = _context.routerHash();
@@ -747,17 +747,17 @@ class NetDbRenderer {
buf.append(hostname);
buf.append("</div>");
} else {
LeaseSet ls = _context.mainNetDb().lookupLeaseSetLocally(hash);
LeaseSet ls = _context.netDb().lookupLeaseSetLocally(hash);
if (ls == null) {
// remote lookup
LookupWaiter lw = new LookupWaiter();
// use-case for the exploratory netDb here?
_context.mainNetDb().lookupLeaseSetRemotely(hash, lw, lw, 8*1000, null);
_context.netDb().lookupLeaseSetRemotely(hash, lw, lw, 8*1000, null);
// just wait right here in the middle of the rendering, sure
synchronized(lw) {
try { lw.wait(9*1000); } catch (InterruptedException ie) {}
}
ls = _context.mainNetDb().lookupLeaseSetLocally(hash);
ls = _context.netDb().lookupLeaseSetLocally(hash);
}
if (ls != null) {
BigInteger dist = HashDistance.getDistance(_context.routerHash(), ls.getRoutingKey());
@@ -952,7 +952,7 @@ class NetDbRenderer {
* mode 3: Same as 0 but sort countries by count
*/
public void renderStatusHTML(Writer out, int pageSize, int page, int mode, String client, boolean clientsOnly) throws IOException {
if (!_context.mainNetDb().isInitialized()) {
if (!_context.netDb().isInitialized()) {
out.write("<div id=\"notinitialized\">");
out.write(_t("Not initialized"));
out.write("</div>");
@@ -973,7 +973,7 @@ class NetDbRenderer {
} else if (clientsOnly) {
routers.addAll(_context.netDbSegmentor().getRoutersKnownToClients());
} else {
routers.addAll(_context.mainNetDb().getRouters());
routers.addAll(_context.netDb().getRouters());
}
int toSkip = pageSize * page;
boolean nextpg = routers.size() > toSkip + pageSize;

View File

@@ -55,7 +55,7 @@ class ProfileOrganizerRenderer {
if (prof == null)
continue;
if (mode == 2) {
RouterInfo info = (RouterInfo) _context.mainNetDb().lookupLocallyWithoutValidation(peer);
RouterInfo info = (RouterInfo) _context.netDb().lookupLocallyWithoutValidation(peer);
if (info != null && info.getCapabilities().indexOf('f') >= 0)
order.add(prof);
continue;
@@ -145,7 +145,7 @@ class ProfileOrganizerRenderer {
buf.append(", ");
buf.append(_t("Integrated"));
}
RouterInfo info = (RouterInfo) _context.mainNetDb().lookupLocallyWithoutValidation(peer);
RouterInfo info = (RouterInfo) _context.netDb().lookupLocallyWithoutValidation(peer);
if (info != null) {
// prevent HTML injection in the caps and version
buf.append("<td align=\"right\">").append(DataHelper.stripHTML(info.getCapabilities()));
@@ -244,7 +244,7 @@ class ProfileOrganizerRenderer {
buf.append("<tr><td align=\"center\" nowrap>");
buf.append(_context.commSystem().renderPeerHTML(peer));
buf.append("</td>");
RouterInfo info = (RouterInfo) _context.mainNetDb().lookupLocallyWithoutValidation(peer);
RouterInfo info = (RouterInfo) _context.netDb().lookupLocallyWithoutValidation(peer);
if (info != null)
buf.append("<td align=\"center\">").append(DataHelper.stripHTML(info.getCapabilities())).append("</td>");
else

View File

@@ -24,6 +24,6 @@ public class ReseedHandler extends HelperBase {
}
private void requestReseed() {
_context.mainNetDb().reseedChecker().requestReseed();
_context.netDb().reseedChecker().requestReseed();
}
}

View File

@@ -162,13 +162,13 @@ public class SummaryHelper extends HelperBase {
/** allowReseed */
public boolean allowReseed() {
return _context.mainNetDb().isInitialized() &&
(_context.mainNetDb().getKnownRouters() < ReseedChecker.MINIMUM) ||
return _context.netDb().isInitialized() &&
(_context.netDb().getKnownRouters() < ReseedChecker.MINIMUM) ||
_context.getBooleanProperty("i2p.alwaysAllowReseed");
}
/** subtract one for ourselves, so if we know no other peers it displays zero */
public int getAllPeers() { return Math.max(_context.mainNetDb().getKnownRouters() - 1, 0); }
public int getAllPeers() { return Math.max(_context.netDb().getKnownRouters() - 1, 0); }
public enum NetworkState {
HIDDEN,
@@ -286,7 +286,7 @@ public class SummaryHelper extends HelperBase {
// fall through...
case IPV4_FIREWALLED_IPV6_OK:
case IPV4_FIREWALLED_IPV6_UNKNOWN:
if ((_context.mainNetDb()).floodfillEnabled())
if ((_context.netDb()).floodfillEnabled())
return new NetworkStateMessage(NetworkState.WARN, fixup(_t("WARN-Firewalled and Floodfill")));
//if (_context.router().getRouterInfo().getCapabilities().indexOf('O') >= 0)
// return new NetworkStateMessage(NetworkState.WARN, _t("WARN-Firewalled and Fast"));
@@ -411,11 +411,11 @@ public class SummaryHelper extends HelperBase {
*/
public boolean showFirewallWarning() {
return _context != null &&
_context.mainNetDb().isInitialized() &&
_context.netDb().isInitialized() &&
_context.router().getUptime() > 2*60*1000 &&
(!_context.commSystem().isDummy()) &&
_context.commSystem().countActivePeers() <= 0 &&
_context.mainNetDb().getKnownRouters() > 5;
_context.netDb().getKnownRouters() > 5;
}
/**
@@ -985,7 +985,7 @@ public class SummaryHelper extends HelperBase {
.append("</b></div>");
}
ReseedChecker checker = _context.mainNetDb().reseedChecker();
ReseedChecker checker = _context.netDb().reseedChecker();
String status = checker.getStatus();
if (status.length() > 0) {
// Show status message even if not running, timer in ReseedChecker should remove after 20 minutes

View File

@@ -493,7 +493,7 @@ public class SybilRenderer {
Hash client = iter.next();
if (!_context.clientManager().isLocal(client) ||
!_context.clientManager().shouldPublishLeaseSet(client) ||
_context.mainNetDb().lookupLeaseSetLocally(client) == null) {
_context.netDb().lookupLeaseSetLocally(client) == null) {
iter.remove();
}
}
@@ -503,7 +503,7 @@ public class SybilRenderer {
return;
}
for (Hash client : destinations) {
LeaseSet ls = _context.mainNetDb().lookupLeaseSetLocally(client);
LeaseSet ls = _context.netDb().lookupLeaseSetLocally(client);
if (ls == null)
continue;
Hash rkey = ls.getRoutingKey();
@@ -553,7 +553,7 @@ public class SybilRenderer {
buf.append("<li><b>").append(s, 0, c+1).append("</b>").append(s, c+1, s.length()).append("</li>");
}
buf.append("</ul>");
RouterInfo ri = (RouterInfo) _context.mainNetDb().lookupLocallyWithoutValidation(h);
RouterInfo ri = (RouterInfo) _context.netDb().lookupLocallyWithoutValidation(h);
if (ri != null) {
renderRouterInfo(buf, ri, null, false, false);
} else {

View File

@@ -559,7 +559,7 @@ class TunnelRenderer {
/** @return cap char or ' ' */
private char getCapacity(Hash peer) {
RouterInfo info = (RouterInfo) _context.mainNetDb().lookupLocallyWithoutValidation(peer);
RouterInfo info = (RouterInfo) _context.netDb().lookupLocallyWithoutValidation(peer);
if (info != null) {
String caps = info.getCapabilities();
for (int i = 0; i < RouterInfo.BW_CAPABILITY_CHARS.length(); i++) {