From 4426cc359c5b8b1f70c6a9762f2d4c379090931c Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Thu, 21 May 2009 00:34:10 +0000 Subject: [PATCH] * ExpireRoutersJob: - Rewrite, not enabled yet * TunnelManager: - Remove now-unused isInUse() --- .../i2p/router/DummyTunnelManagerFacade.java | 1 - .../net/i2p/router/TunnelManagerFacade.java | 6 -- .../networkdb/kademlia/ExpireRoutersJob.java | 63 ++++++------------- .../router/tunnel/pool/TunnelPoolManager.java | 9 +-- 4 files changed, 21 insertions(+), 58 deletions(-) diff --git a/router/java/src/net/i2p/router/DummyTunnelManagerFacade.java b/router/java/src/net/i2p/router/DummyTunnelManagerFacade.java index aec0390fd3..3a19cd1178 100644 --- a/router/java/src/net/i2p/router/DummyTunnelManagerFacade.java +++ b/router/java/src/net/i2p/router/DummyTunnelManagerFacade.java @@ -27,7 +27,6 @@ class DummyTunnelManagerFacade implements TunnelManagerFacade { public TunnelInfo selectInboundTunnel(Hash destination) { return null; } public TunnelInfo selectOutboundTunnel() { return null; } public TunnelInfo selectOutboundTunnel(Hash destination) { return null; } - public boolean isInUse(Hash peer) { return false; } public boolean isValidTunnel(Hash client, TunnelInfo tunnel) { return false; } public int getParticipatingCount() { return 0; } public int getFreeTunnelCount() { return 0; } diff --git a/router/java/src/net/i2p/router/TunnelManagerFacade.java b/router/java/src/net/i2p/router/TunnelManagerFacade.java index 8ddc1e060f..e8bdc31d38 100644 --- a/router/java/src/net/i2p/router/TunnelManagerFacade.java +++ b/router/java/src/net/i2p/router/TunnelManagerFacade.java @@ -35,12 +35,6 @@ public interface TunnelManagerFacade extends Service { /** pick an outbound tunnel bound to the given destination */ TunnelInfo selectOutboundTunnel(Hash destination); - /** - * True if the peer currently part of a tunnel - * - */ - boolean isInUse(Hash peer); - /** Is a tunnel a valid member of the pool? */ public boolean isValidTunnel(Hash client, TunnelInfo tunnel); diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/ExpireRoutersJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/ExpireRoutersJob.java index e5957eaff8..25ac1c2003 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/ExpireRoutersJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/ExpireRoutersJob.java @@ -8,6 +8,7 @@ package net.i2p.router.networkdb.kademlia; * */ +import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -20,25 +21,20 @@ import net.i2p.router.RouterContext; import net.i2p.util.Log; /** - * Go through the routing table pick routers that are performing poorly or - * is out of date, but don't expire routers we're actively tunneling through. - * If a peer is performing worse than some threshold (via profile.rankLiveliness) - * drop it and don't ask any questions. If a peer isn't ranked really poorly, but - * we just haven't heard from it in a while, drop it and add it to the set of - * keys we want the netDb to explore. + * Go through the routing table pick routers that are + * is out of date, but don't expire routers we're actively connected to. + * + * We could in the future use profile data, netdb total size, a Kademlia XOR distance, + * or other criteria to minimize netdb size, but for now we just use _facade's + * validate(), which is a sliding expriation based on netdb size. * */ class ExpireRoutersJob extends JobImpl { private Log _log; private KademliaNetworkDatabaseFacade _facade; + /** rerun fairly often, so the fails don't queue up too many netdb searches at once */ private final static long RERUN_DELAY_MS = 120*1000; - /** - * If a routerInfo structure isn't updated within an hour, drop it - * and search for a later version. This value should be large enough - * to deal with the Router.CLOCK_FUDGE_FACTOR. - */ - public final static long EXPIRE_DELAY = 60*60*1000; public ExpireRoutersJob(RouterContext ctx, KademliaNetworkDatabaseFacade facade) { super(ctx); @@ -62,44 +58,25 @@ class ExpireRoutersJob extends JobImpl { /** * Run through all of the known peers and pick ones that have really old - * routerInfo publish dates, excluding ones that are in use by some tunnels, + * routerInfo publish dates, excluding ones that we are connected to, * so that they can be failed & queued for searching * + * @return nothing for now */ private Set selectKeysToExpire() { - Set possible = getNotInUse(); - Set expiring = new HashSet(16); - - for (Iterator iter = possible.iterator(); iter.hasNext(); ) { + for (Iterator iter = _facade.getAllRouters().iterator(); iter.hasNext(); ) { Hash key = (Hash)iter.next(); - RouterInfo ri = _facade.lookupRouterInfoLocally(key); - if (ri != null) { - if (!ri.isCurrent(EXPIRE_DELAY)) { - if (_log.shouldLog(Log.INFO)) - _log.info("Expiring RouterInfo for " + key.toBase64() + " [published on " + new Date(ri.getPublished()) + "]"); - expiring.add(key); - } else { - if (_log.shouldLog(Log.DEBUG)) - _log.debug("Not expiring routerInfo for " + key.toBase64() + " [published on " + new Date(ri.getPublished()) + "]"); - } + // Don't expire anybody we are connected to + if (!getContext().commSystem().isEstablished(key)) { + // This does a _facade.validate() and fail() which is sufficient... + // no need to impose our own expiration here. + // One issue is this will queue a ton of floodfill queries the first time it is run + // after the 1h router startup grace period. + RouterInfo ri = _facade.lookupRouterInfoLocally(key); } } - return expiring; - } - - /** all peers not in use by tunnels */ - private Set getNotInUse() { - Set possible = new HashSet(16); - for (Iterator iter = _facade.getAllRouters().iterator(); iter.hasNext(); ) { - Hash peer = (Hash)iter.next(); - if (!getContext().tunnelManager().isInUse(peer)) { - possible.add(peer); - } else { - if (_log.shouldLog(Log.DEBUG)) - _log.debug("Peer is in use: " + peer.toBase64()); - } - } - return possible; + // let _facade do all the work for now + return Collections.EMPTY_SET; } } diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java index 66dc455270..8820015af7 100644 --- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java +++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPoolManager.java @@ -195,13 +195,6 @@ public class TunnelPoolManager implements TunnelManagerFacade { public int getParticipatingCount() { return _context.tunnelDispatcher().getParticipatingCount(); } public long getLastParticipatingExpiration() { return _context.tunnelDispatcher().getLastParticipatingExpiration(); } - public boolean isInUse(Hash peer) { - // this lets peers that are in our tunnels expire (forcing us to refetch them) - // if the info is old - //!! no, dont. bad. - return true; - } - public boolean isValidTunnel(Hash client, TunnelInfo tunnel) { if (tunnel.getExpiration() < _context.clock().now()) return false; @@ -571,7 +564,7 @@ public class TunnelPoolManager implements TunnelManagerFacade { if (outPool != null) { List pending = outPool.listPending(); if (pending.size() > 0) - out.write("In progress: " + pending.size() + " outbound<br />\n"); + out.write("Build in progress: " + pending.size() + " outbound<br />\n"); live += pending.size(); } if (live <= 0) -- GitLab