Skip to content

Commit

Permalink
Router: add config option which allows us to ignore if a peer is floo…
Browse files Browse the repository at this point in the history
…dfill or not while preserving the real caps
  • Loading branch information
eyedeekay committed Dec 20, 2023
1 parent e49c18a commit d7a7812
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 17 deletions.
6 changes: 6 additions & 0 deletions router/java/src/net/i2p/data/router/RouterInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.i2p.data.Signature;
import net.i2p.data.SimpleDataStructure;
import net.i2p.router.Router;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.util.Clock;
import net.i2p.util.Log;
import net.i2p.util.OrderedProperties;
Expand Down Expand Up @@ -723,4 +724,9 @@ public static void main(String[] args) {
if (fail)
System.exit(1);
}

public boolean isFloodfill() {
String caps = this.getCapabilities();
return caps.indexOf(FloodfillNetworkDatabaseFacade.CAPABILITY_FLOODFILL) >= 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacade {
public static final char CAPABILITY_FLOODFILL = 'f';
private static final String MINIMUM_SUBDB_PEERS = "router.subDbMinimumPeers";
private static final String ALWAYS_CONSIDER_PEER_FLOODFILL = "router.ignoreFloodfillCapability";
private final Map<Hash, FloodSearchJob> _activeFloodQueries;
private boolean _floodfillEnabled;
private final Set<Hash> _verifiesInProgress;
Expand Down Expand Up @@ -98,6 +98,10 @@ public FloodfillNetworkDatabaseFacade(RouterContext context, Hash dbid) {
_ffMonitor = new FloodfillMonitorJob(_context, this);
}

private boolean ignoreFloodfillCapability() {
return _context.getBooleanProperty(ALWAYS_CONSIDER_PEER_FLOODFILL);
}

@Override
public synchronized void startup() {
boolean isFF;
Expand Down Expand Up @@ -435,11 +439,20 @@ public boolean floodfillEnabled() {

/**
* @param peer may be null, returns false if null
* always returns true if ignoreFloodfillCapability()
*/
public boolean isFloodfill(RouterInfo peer) {
if (ignoreFloodfillCapability()) return true;
return peer.isFloodfill();
}

/**
* @param peer may be null, returns false if null
* always returns false if ignoreFloodfillCapability()
*/
public static boolean isFloodfill(RouterInfo peer) {
if (peer == null) return false;
String caps = peer.getCapabilities();
return caps.indexOf(CAPABILITY_FLOODFILL) >= 0;
public boolean isNotFloodfill(RouterInfo peer) {
if (ignoreFloodfillCapability()) return false;
return !peer.isFloodfill();
}

public List<RouterInfo> getKnownRouterData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public void add(Hash entry) {
//if (info == null)
// return;

if (info != null && FloodfillNetworkDatabaseFacade.isFloodfill(info)) {
if (info != null && ((FloodfillNetworkDatabaseFacade) _context.netDb()).isFloodfill(info)) {
_floodfillMatches.add(entry);
} else {
// This didn't really work because we stopped filling up when _wanted == _matches,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public HandleFloodfillDatabaseLookupMessageJob(RouterContext ctx, DatabaseLookup
@Override
protected boolean answerAllQueries() {
if (!getContext().netDb().floodfillEnabled()) return false;
return FloodfillNetworkDatabaseFacade.isFloodfill(getContext().router().getRouterInfo());
return ((FloodfillNetworkDatabaseFacade)getContext().netDb()).isFloodfill(getContext().router().getRouterInfo());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void runJob() {
}
newPeers++;
} else if (ri.getPublished() < getContext().clock().now() - 60*60*1000 ||
!FloodfillNetworkDatabaseFacade.isFloodfill(ri)) {
((FloodfillNetworkDatabaseFacade) getContext().netDb()).isNotFloodfill(ri)) {
// get an updated RI from the (now ff?) peer
// Only if original search used expl. tunnels
if (_search.getFromHash() == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ void newPeerToTry(Hash peer) {
return;
}
RouterInfo ri = getContext().netDb().lookupRouterInfoLocally(peer);
if (ri != null && !FloodfillNetworkDatabaseFacade.isFloodfill(ri)) {
if (ri != null && ((FloodfillNetworkDatabaseFacade) getContext().netDb()).isNotFloodfill(ri)) {
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": non-ff peer from DSRM " + peer);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ protected void continueSearch() {
_state.replyTimeout(peer);
} else {
RouterInfo ri = (RouterInfo)ds;
if (!FloodfillNetworkDatabaseFacade.isFloodfill(ri)) {
if (((FloodfillNetworkDatabaseFacade) _facade).isNotFloodfill(ri)) {
_floodfillPeersExhausted = true;
if (onlyFloodfill)
continue;
Expand Down Expand Up @@ -481,7 +481,7 @@ protected void sendLeaseSearch(RouterInfo router) {
SearchUpdateReplyFoundJob reply = new SearchUpdateReplyFoundJob(getContext(), router, _state, _facade,
this, outTunnel, inTunnel);

if (FloodfillNetworkDatabaseFacade.isFloodfill(router))
if (((FloodfillNetworkDatabaseFacade) _facade).isFloodfill(router))
_floodfillSearchesOutstanding++;
getContext().messageRegistry().registerPending(sel, reply, new FailedJob(getContext(), router));
// TODO pass a priority to the dispatcher
Expand Down Expand Up @@ -517,7 +517,7 @@ protected void sendRouterSearch(RouterInfo router) {
SendMessageDirectJob j = new SendMessageDirectJob(getContext(), msg, to,
reply, new FailedJob(getContext(), router), sel, timeout,
OutNetMessage.PRIORITY_EXPLORATORY, _msgIDBloomXor);
if (FloodfillNetworkDatabaseFacade.isFloodfill(router))
if (((FloodfillNetworkDatabaseFacade) _facade).isFloodfill(router))
_floodfillSearchesOutstanding++;
j.runJob();
//getContext().jobQueue().addJob(j);
Expand Down Expand Up @@ -608,7 +608,7 @@ public FailedJob(RouterContext enclosingContext, RouterInfo peer, boolean penali
_penalizePeer = penalizePeer;
_peer = peer.getIdentity().getHash();
_sentOn = enclosingContext.clock().now();
_isFloodfill = FloodfillNetworkDatabaseFacade.isFloodfill(peer);
_isFloodfill = ((FloodfillNetworkDatabaseFacade) _facade).isFloodfill(peer);
}
public void runJob() {
if (_isFloodfill)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public SearchUpdateReplyFoundJob(RouterContext context, RouterInfo peer,
super(context);
_log = context.logManager().getLog(SearchUpdateReplyFoundJob.class);
_peer = peer.getIdentity().getHash();
_isFloodfillPeer = FloodfillNetworkDatabaseFacade.isFloodfill(peer);
_isFloodfillPeer = ((FloodfillNetworkDatabaseFacade) facade).isFloodfill(peer);
_state = state;
_facade = facade;
_job = job;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void runJob() {
if (ri == null)
getContext().jobQueue().addJob(new SingleSearchJob(getContext(), peer, from));
else if (ri.getPublished() < getContext().clock().now() - 60*60*1000 ||
!FloodfillNetworkDatabaseFacade.isFloodfill(ri))
((FloodfillNetworkDatabaseFacade) getContext().netDb()).isNotFloodfill(ri))
getContext().jobQueue().addJob(new SingleSearchJob(getContext(), peer, peer));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static double calc(PeerProfile profile) {
if (ndb != null) {
RouterInfo ri = (RouterInfo) ndb.lookupLocallyWithoutValidation(profile.getPeer());
if (ri != null) {
if (!FloodfillNetworkDatabaseFacade.isFloodfill(ri))
if (((FloodfillNetworkDatabaseFacade) ndb).isNotFloodfill(ri))
capacity += BONUS_NON_FLOODFILL;
String caps = ri.getCapabilities();
if (caps.indexOf(Router.CAPABILITY_REACHABLE) < 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void distribute(I2NPMessage msg, Hash target, TunnelId tunnel) {
RouterInfo oldri = _context.netDb().lookupRouterInfoLocally(key);
// only update if RI is newer and non-ff
if (oldri != null && oldri.getPublished() < ri.getPublished() &&
!FloodfillNetworkDatabaseFacade.isFloodfill(ri)) {
((FloodfillNetworkDatabaseFacade)_context.netDb()).isNotFloodfill(ri)) {
if (_log.shouldLog(Log.WARN))
_log.warn("Updating caps for RI " + key + " from \"" +
oldri.getCapabilities() + "\" to \"" + ri.getCapabilities() + '"');
Expand Down

0 comments on commit d7a7812

Please sign in to comment.