diff --git a/router/java/src/net/i2p/data/router/RouterInfo.java b/router/java/src/net/i2p/data/router/RouterInfo.java index ba556a7271..be0581d2c8 100644 --- a/router/java/src/net/i2p/data/router/RouterInfo.java +++ b/router/java/src/net/i2p/data/router/RouterInfo.java @@ -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; @@ -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; + } } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java index 98c853478b..4fd18aefc4 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java @@ -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 _activeFloodQueries; private boolean _floodfillEnabled; private final Set _verifiesInProgress; @@ -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; @@ -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 getKnownRouterData() { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java index 5e3ac202dd..4738481023 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/FloodfillPeerSelector.java @@ -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, diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseLookupMessageJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseLookupMessageJob.java index 1fbca44a72..8be75c5c8f 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseLookupMessageJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/HandleFloodfillDatabaseLookupMessageJob.java @@ -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()); } /** diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/IterativeLookupJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/IterativeLookupJob.java index 6b243b7695..7750bd0310 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/IterativeLookupJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/IterativeLookupJob.java @@ -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) { diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java index 8ddd61123e..a24e8cd0fb 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/IterativeSearchJob.java @@ -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; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java index a2a5f9922a..e8055a3ae6 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java @@ -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; @@ -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 @@ -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); @@ -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) diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java index f7598f8654..84658a4a79 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java @@ -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; diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/SingleLookupJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/SingleLookupJob.java index b7fd6161e4..1645505088 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/SingleLookupJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/SingleLookupJob.java @@ -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)); } } diff --git a/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java b/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java index 5865cb47d7..592d9bf49b 100644 --- a/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java +++ b/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java @@ -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) diff --git a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java index ca4c317620..487ad100f3 100644 --- a/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java +++ b/router/java/src/net/i2p/router/tunnel/InboundMessageDistributor.java @@ -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() + '"');