* Console: Add a tunnel share ratio estimate

This commit is contained in:
zzz
2010-01-18 14:57:03 +00:00
parent f8d9af871a
commit 5f12688a90
6 changed files with 46 additions and 1 deletions

View File

@@ -35,6 +35,7 @@ class DummyTunnelManagerFacade implements TunnelManagerFacade {
public int getFreeTunnelCount() { return 0; }
public int getOutboundTunnelCount() { return 0; }
public int getInboundClientTunnelCount() { return 0; }
public double getShareRatio() { return 0d; }
public int getOutboundClientTunnelCount() { return 0; }
public long getLastParticipatingExpiration() { return -1; }
public void buildTunnels(Destination client, ClientTunnelSettings settings) {}

View File

@@ -51,6 +51,7 @@ public interface TunnelManagerFacade extends Service {
public int getInboundClientTunnelCount();
/** how many outbound client tunnels do we have available? */
public int getOutboundClientTunnelCount();
public double getShareRatio();
/** When does the last tunnel we are participating in expire? */
public long getLastParticipatingExpiration();

View File

@@ -193,6 +193,29 @@ public class TunnelPoolManager implements TunnelManagerFacade {
public int getParticipatingCount() { return _context.tunnelDispatcher().getParticipatingCount(); }
public long getLastParticipatingExpiration() { return _context.tunnelDispatcher().getLastParticipatingExpiration(); }
/**
* @return (number of part. tunnels) / (estimated total number of hops in our expl.+client tunnels)
* 100 max.
* We just use length setting, not variance, for speed
* @since 0.7.10
*/
public double getShareRatio() {
int part = getParticipatingCount();
if (part <= 0)
return 0d;
List<TunnelPool> pools = new ArrayList();
listPools(pools);
int count = 0;
for (int i = 0; i < pools.size(); i++) {
TunnelPool pool = pools.get(i);
count += pool.size() * pool.getSettings().getLength();
}
if (count <= 0)
return 100d;
return Math.min(part / (double) count, 100d);
}
public boolean isValidTunnel(Hash client, TunnelInfo tunnel) {
if (tunnel.getExpiration() < _context.clock().now())
return false;