From f64894ea1242b49e92aeac91f16234bb05db36e7 Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 10 Sep 2022 14:11:00 -0400 Subject: [PATCH] Router: ProfileOrganizer and TunnelPeerSelector cleanup of unused code, in prep for some redesign --- .../router/peermanager/ProfileOrganizer.java | 38 +--- .../tunnel/pool/TunnelPeerSelector.java | 181 ------------------ 2 files changed, 1 insertion(+), 218 deletions(-) diff --git a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java index 3090bd39a..568dc8e9d 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java +++ b/router/java/src/net/i2p/router/peermanager/ProfileOrganizer.java @@ -552,42 +552,6 @@ public class ProfileOrganizer { return; } - /** - * Return a set of Hashes for peers that are well integrated into the network. - * - * @deprecated unused - */ - @Deprecated - public void selectWellIntegratedPeers(int howMany, Set exclude, Set matches) { - selectWellIntegratedPeers(howMany, exclude, matches, 0, null); - } - - /** - * Return a set of Hashes for peers that are well integrated into the network. - * - * @param mask 0-4 Number of bytes to match to determine if peers in the same IP range should - * not be in the same tunnel. 0 = disable check; 1 = /8; 2 = /16; 3 = /24; 4 = exact IP match - * @since 0.9.53 added ipSet param - * @deprecated unused - */ - @Deprecated - public void selectWellIntegratedPeers(int howMany, Set exclude, Set matches, int mask, MaskedIPSet ipSet) { - getReadLock(); - try { - locked_selectPeers(_wellIntegratedPeers, howMany, exclude, matches, mask, ipSet); - } finally { releaseReadLock(); } - if (matches.size() < howMany) { - if (_log.shouldLog(Log.INFO)) - _log.info("selectWellIntegrated("+howMany+"), not enough integrated (" + matches.size() + ") going on to notFailing"); - selectNotFailingPeers(howMany, exclude, matches, mask, ipSet); - } else { - if (_log.shouldDebug()) - _log.debug("selectWellIntegrated("+howMany+"), found enough well integrated (" + matches.size() + ")"); - } - - return; - } - /** * Return a set of Hashes for peers that are not failing, preferring ones that * we are already talking with @@ -773,7 +737,7 @@ public class ProfileOrganizer { * I'm not quite sure why you'd want this... (other than for failover from the better results) * */ - public void selectFailingPeers(int howMany, Set exclude, Set matches) { + private void selectFailingPeers(int howMany, Set exclude, Set matches) { getReadLock(); try { locked_selectPeers(_failingPeers, howMany, exclude, matches); diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java index b311324ae..06f7dc7ac 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java @@ -82,22 +82,6 @@ public abstract class TunnelPeerSelector extends ConnectChecker { length = 0; else if (length > 7) // as documented in tunnel.html length = 7; - /* - if ( (ctx.tunnelManager().getOutboundTunnelCount() <= 0) || - (ctx.tunnelManager().getFreeTunnelCount() <= 0) ) { - Log log = ctx.logManager().getLog(TunnelPeerSelector.class); - // no tunnels to build tunnels with - if (settings.getAllowZeroHop()) { - if (log.shouldLog(Log.INFO)) - log.info("no outbound tunnels or free inbound tunnels, but we do allow zeroHop: " + settings); - return 0; - } else { - if (log.shouldLog(Log.WARN)) - log.warn("no outbound tunnels or free inbound tunnels, and we dont allow zeroHop: " + settings); - return -1; - } - } - */ return length; } @@ -247,90 +231,6 @@ public abstract class TunnelPeerSelector extends ConnectChecker { peers.add(peer.getIdentity().calculateHash()); continue; } - /* - String cap = peer.getCapabilities(); - if (cap == null) { - peers.add(peer.getIdentity().calculateHash()); - continue; - } - for (int j = 0; j < excl.length; j++) { - if (cap.indexOf(excl[j]) >= 0) { - peers.add(peer.getIdentity().calculateHash()); - continue; - } - } - int maxLen = 0; - if (cap.indexOf(FloodfillNetworkDatabaseFacade.CAPACITY_FLOODFILL) >= 0) - maxLen++; - if (cap.indexOf(Router.CAPABILITY_REACHABLE) >= 0) - maxLen++; - if (cap.indexOf(Router.CAPABILITY_UNREACHABLE) >= 0) - maxLen++; - if (cap.length() <= maxLen) - peers.add(peer.getIdentity().calculateHash()); - // otherwise, it contains flags we aren't trying to focus on, - // so don't exclude it based on published capacity - - if (filterUptime(ctx, isInbound, isExploratory)) { - Properties opts = peer.getOptions(); - if (opts != null) { - String val = opts.getProperty("stat_uptime"); - long uptimeMs = 0; - if (val != null) { - long factor = 1; - if (val.endsWith("ms")) { - factor = 1; - val = val.substring(0, val.length()-2); - } else if (val.endsWith("s")) { - factor = 1000l; - val = val.substring(0, val.length()-1); - } else if (val.endsWith("m")) { - factor = 60*1000l; - val = val.substring(0, val.length()-1); - } else if (val.endsWith("h")) { - factor = 60*60*1000l; - val = val.substring(0, val.length()-1); - } else if (val.endsWith("d")) { - factor = 24*60*60*1000l; - val = val.substring(0, val.length()-1); - } - try { uptimeMs = Long.parseLong(val); } catch (NumberFormatException nfe) {} - uptimeMs *= factor; - } else { - // not publishing an uptime, so exclude it - peers.add(peer.getIdentity().calculateHash()); - continue; - } - - long infoAge = ctx.clock().now() - peer.getPublished(); - if (infoAge < 0) { - infoAge = 0; - } else if (infoAge > 24*60*60*1000) { - // Only exclude long-unseen peers if we haven't just started up - long DONT_EXCLUDE_PERIOD = 15*60*1000; - if (ctx.router().getUptime() < DONT_EXCLUDE_PERIOD) { - if (log.shouldLog(Log.DEBUG)) - log.debug("Not excluding a long-unseen peer, since we just started up."); - } else { - if (log.shouldLog(Log.DEBUG)) - log.debug("Excluding a long-unseen peer."); - peers.add(peer.getIdentity().calculateHash()); - } - //peers.add(peer.getIdentity().calculateHash()); - continue; - } else { - if (infoAge + uptimeMs < 2*60*60*1000) { - // up for less than 2 hours, so exclude it - peers.add(peer.getIdentity().calculateHash()); - } - } - } else { - // not publishing stats, so exclude it - peers.add(peer.getIdentity().calculateHash()); - continue; - } - } - */ } } /* @@ -513,60 +413,6 @@ public abstract class TunnelPeerSelector extends ConnectChecker { return false; if (VersionComparator.comp(v, MIN_VERSION) < 0) return true; - - // uptime is always spoofed to 90m, so just remove all this - /****** - String val = peer.getOption("stat_uptime"); - if (val != null) { - long uptimeMs = 0; - long factor = 1; - if (val.endsWith("ms")) { - factor = 1; - val = val.substring(0, val.length()-2); - } else if (val.endsWith("s")) { - factor = 1000l; - val = val.substring(0, val.length()-1); - } else if (val.endsWith("m")) { - factor = 60*1000l; - val = val.substring(0, val.length()-1); - } else if (val.endsWith("h")) { - factor = 60*60*1000l; - val = val.substring(0, val.length()-1); - } else if (val.endsWith("d")) { - factor = 24*60*60*1000l; - val = val.substring(0, val.length()-1); - } - try { uptimeMs = Long.parseLong(val); } catch (NumberFormatException nfe) {} - uptimeMs *= factor; - - long infoAge = ctx.clock().now() - peer.getPublished(); - if (infoAge < 0) { - return false; - } else if (infoAge > 5*24*60*60*1000) { - // Only exclude long-unseen peers if we haven't just started up - if (ctx.router().getUptime() < DONT_EXCLUDE_PERIOD) { - if (log.shouldLog(Log.DEBUG)) - log.debug("Not excluding a long-unseen peer, since we just started up."); - return false; - } else { - if (log.shouldLog(Log.DEBUG)) - log.debug("Excluding a long-unseen peer."); - return true; - } - } else { - if ( (infoAge + uptimeMs < 90*60*1000) && (ctx.router().getUptime() > DONT_EXCLUDE_PERIOD) ) { - // up for less than 90 min (which is really 1h since an uptime of 1h-2h is published as 90m), - // so exclude it - return true; - } else { - return false; - } - } - } else { - // not publishing an uptime, so exclude it - return true; - } - ******/ return false; } @@ -631,33 +477,6 @@ public abstract class TunnelPeerSelector extends ConnectChecker { } } -/**** - private static final String PROP_OUTBOUND_EXPLORATORY_EXCLUDE_UPTIME = "router.outboundExploratoryExcludeUptime"; - private static final String PROP_OUTBOUND_CLIENT_EXCLUDE_UPTIME = "router.outboundClientExcludeUptime"; - private static final String PROP_INBOUND_EXPLORATORY_EXCLUDE_UPTIME = "router.inboundExploratoryExcludeUptime"; - private static final String PROP_INBOUND_CLIENT_EXCLUDE_UPTIME = "router.inboundClientExcludeUptime"; -****/ - - /** - * do we want to skip peers who haven't been up for long? - * @return true unless configured otherwise - */ -/**** - protected boolean filterUptime(boolean isInbound, boolean isExploratory) { - if (isExploratory) { - if (isInbound) - return ctx.getProperty(PROP_INBOUND_EXPLORATORY_EXCLUDE_UPTIME, true); - else - return ctx.getProperty(PROP_OUTBOUND_EXPLORATORY_EXCLUDE_UPTIME, true); - } else { - if (isInbound) - return ctx.getProperty(PROP_INBOUND_CLIENT_EXCLUDE_UPTIME, true); - else - return ctx.getProperty(PROP_OUTBOUND_CLIENT_EXCLUDE_UPTIME, true); - } - } -****/ - /** see HashComparator */ protected void orderPeers(List rv, SessionKey key) { if (rv.size() > 1)