2006-05-31 jrandom

* Only send netDb searches to the floodfill peers for the time being
    * Add some proof of concept filters for tunnel participation.  By default,
      it will skip peers with an advertised bandwith of less than 32KBps or
      an advertised uptime of less than 2 hours.  If this is sufficient, a
      safer implementation of these filters will be implemented.
This commit is contained in:
jrandom
2006-05-31 23:23:37 +00:00
committed by zzz
parent fcbea19478
commit f2fb87c88b
8 changed files with 230 additions and 13 deletions

View File

@ -1,4 +1,11 @@
$Id: history.txt,v 1.478 2006-05-17 22:42:57 complication Exp $
$Id: history.txt,v 1.479 2006-05-18 17:31:08 jrandom Exp $
2006-05-31 jrandom
* Only send netDb searches to the floodfill peers for the time being
* Add some proof of concept filters for tunnel participation. By default,
it will skip peers with an advertised bandwith of less than 32KBps or
an advertised uptime of less than 2 hours. If this is sufficient, a
safer implementation of these filters will be implemented.
* 2006-05-18 0.6.1.19 released

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.418 $ $Date: 2006-05-17 22:42:57 $";
public final static String ID = "$Revision: 1.419 $ $Date: 2006-05-18 17:31:10 $";
public final static String VERSION = "0.6.1.19";
public final static long BUILD = 0;
public final static long BUILD = 1;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@ -120,6 +120,22 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
else
return false;
}
public List getKnownRouterData() {
List rv = new ArrayList();
DataStore ds = getDataStore();
if (ds != null) {
Set keys = ds.getKeys();
if (keys != null) {
for (Iterator iter = keys.iterator(); iter.hasNext(); ) {
Object o = getDataStore().get((Hash)iter.next());
if (o instanceof RouterInfo)
rv.add(o);
}
}
}
return rv;
}
/**
* Begin a kademlia style search for the key specified, which can take up to timeoutMs and

View File

@ -87,6 +87,8 @@ class FloodfillPeerSelector extends PeerSelector {
if ( (!SearchJob.onlyQueryFloodfillPeers(_context)) && (_wanted > _matches) && (_key != null) ) {
BigInteger diff = getDistance(_key, entry);
_sorted.put(diff, entry);
} else {
return;
}
}
_matches++;

View File

@ -121,7 +121,7 @@ class SearchJob extends JobImpl {
public long getExpiration() { return _expiration; }
public long getTimeoutMs() { return _timeoutMs; }
private static final boolean DEFAULT_FLOODFILL_ONLY = false;
private static final boolean DEFAULT_FLOODFILL_ONLY = true;
static boolean onlyQueryFloodfillPeers(RouterContext ctx) {
if (isCongested(ctx))

View File

@ -15,9 +15,13 @@ import java.util.*;
import net.i2p.data.Hash;
import net.i2p.router.PeerSelectionCriteria;
import net.i2p.router.RouterContext;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.util.SimpleTimer;
import net.i2p.util.Log;
import net.i2p.data.RouterInfo;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
/**
* Manage the current state of the statistics
*
@ -204,12 +208,27 @@ class PeerManager {
return null;
}
public List getPeersByCapability(char capability) {
synchronized (_capabilitiesByPeer) {
List peers = locked_getPeers(capability);
if (peers != null)
return new ArrayList(peers);
if (false) {
synchronized (_capabilitiesByPeer) {
List peers = locked_getPeers(capability);
if (peers != null)
return new ArrayList(peers);
}
return null;
} else {
FloodfillNetworkDatabaseFacade f = (FloodfillNetworkDatabaseFacade)_context.netDb();
List routerInfos = f.getKnownRouterData();
List rv = new ArrayList();
for (Iterator iter = routerInfos.iterator(); iter.hasNext(); ) {
RouterInfo ri = (RouterInfo)iter.next();
String caps = ri.getCapabilities();
if (caps.indexOf(capability) >= 0)
rv.add(ri.getIdentity().calculateHash());
}
if (_log.shouldLog(Log.WARN))
_log.warn("Peers with capacity " + capability + ": " + rv.size());
return rv;
}
return null;
}
public void renderStatusHTML(Writer out) throws IOException {

View File

@ -2,11 +2,11 @@ package net.i2p.router.tunnel.pool;
import java.util.*;
import net.i2p.I2PAppContext;
import net.i2p.data.DataFormatException;
import net.i2p.data.Hash;
import net.i2p.data.*;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.router.TunnelPoolSettings;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.util.Log;
/**
@ -153,6 +153,103 @@ abstract class TunnelPeerSelector {
if (caps == null) return new HashSet(0);
HashSet rv = new HashSet(caps);
return rv;
} else if (filterSlow(ctx, isInbound, isExploratory)) {
Log log = ctx.logManager().getLog(TunnelPeerSelector.class);
String excludeCaps = ctx.getProperty("router.excludePeerCaps",
String.valueOf(Router.CAPABILITY_BW16) +
String.valueOf(Router.CAPABILITY_BW32));
Set peers = new HashSet();
if (excludeCaps != null) {
char excl[] = excludeCaps.toCharArray();
FloodfillNetworkDatabaseFacade fac = (FloodfillNetworkDatabaseFacade)ctx.netDb();
List known = fac.getKnownRouterData();
if (known != null) {
for (int i = 0; i < known.size(); i++) {
RouterInfo peer = (RouterInfo)known.get(i);
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) {
peers.add(peer.getIdentity().calculateHash());
continue;
} else {
if (infoAge + uptimeMs < 4*60*60*1000) {
// up for less than 4 hours, so exclude it
peers.add(peer.getIdentity().calculateHash());
}
}
} else {
// not publishing stats, so exclude it
peers.add(peer.getIdentity().calculateHash());
continue;
}
}
}
}
/*
for (int i = 0; i < excludeCaps.length(); i++) {
List matches = ctx.peerManager().getPeersByCapability(excludeCaps.charAt(i));
if (log.shouldLog(Log.INFO))
log.info("Filtering out " + matches.size() + " peers with capability " + excludeCaps.charAt(i));
peers.addAll(matches);
}
*/
}
return peers;
} else {
return new HashSet(1);
}
@ -162,6 +259,7 @@ abstract class TunnelPeerSelector {
private static final String PROP_OUTBOUND_CLIENT_EXCLUDE_UNREACHABLE = "router.outboundClientExcludeUnreachable";
private static final String PROP_INBOUND_EXPLORATORY_EXCLUDE_UNREACHABLE = "router.inboundExploratoryExcludeUnreachable";
private static final String PROP_INBOUND_CLIENT_EXCLUDE_UNREACHABLE = "router.inboundClientExcludeUnreachable";
private static final boolean DEFAULT_OUTBOUND_EXPLORATORY_EXCLUDE_UNREACHABLE = false;
private static final boolean DEFAULT_OUTBOUND_CLIENT_EXCLUDE_UNREACHABLE = false;
private static final boolean DEFAULT_INBOUND_EXPLORATORY_EXCLUDE_UNREACHABLE = false;
@ -186,4 +284,56 @@ abstract class TunnelPeerSelector {
//System.err.println("Filter unreachable? " + rv + " (inbound? " + isInbound + ", exploratory? " + isExploratory);
return rv;
}
private static final String PROP_OUTBOUND_EXPLORATORY_EXCLUDE_SLOW = "router.outboundExploratoryExcludeSlow";
private static final String PROP_OUTBOUND_CLIENT_EXCLUDE_SLOW = "router.outboundClientExcludeSlow";
private static final String PROP_INBOUND_EXPLORATORY_EXCLUDE_SLOW = "router.inboundExploratoryExcludeSlow";
private static final String PROP_INBOUND_CLIENT_EXCLUDE_SLOW = "router.inboundClientExcludeSlow";
protected boolean filterSlow(RouterContext ctx, boolean isInbound, boolean isExploratory) {
boolean def = true;
String val = null;
if (isExploratory)
if (isInbound)
val = ctx.getProperty(PROP_INBOUND_EXPLORATORY_EXCLUDE_SLOW);
else
val = ctx.getProperty(PROP_OUTBOUND_EXPLORATORY_EXCLUDE_SLOW);
else
if (isInbound)
val = ctx.getProperty(PROP_INBOUND_CLIENT_EXCLUDE_SLOW);
else
val = ctx.getProperty(PROP_OUTBOUND_CLIENT_EXCLUDE_SLOW);
boolean rv = (val != null ? Boolean.valueOf(val).booleanValue() : def);
//System.err.println("Filter unreachable? " + rv + " (inbound? " + isInbound + ", exploratory? " + isExploratory);
return rv;
}
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? */
protected boolean filterUptime(RouterContext ctx, boolean isInbound, boolean isExploratory) {
boolean def = true;
String val = null;
if (isExploratory)
if (isInbound)
val = ctx.getProperty(PROP_INBOUND_EXPLORATORY_EXCLUDE_UPTIME);
else
val = ctx.getProperty(PROP_OUTBOUND_EXPLORATORY_EXCLUDE_UPTIME);
else
if (isInbound)
val = ctx.getProperty(PROP_INBOUND_CLIENT_EXCLUDE_UPTIME);
else
val = ctx.getProperty(PROP_OUTBOUND_CLIENT_EXCLUDE_UPTIME);
boolean rv = (val != null ? Boolean.valueOf(val).booleanValue() : def);
//System.err.println("Filter unreachable? " + rv + " (inbound? " + isInbound + ", exploratory? " + isExploratory);
return rv;
}
}

View File

@ -495,11 +495,12 @@ public class TunnelPoolManager implements TunnelManagerFacade {
out.write("<td align=right>" + info.getProcessedMessagesCount() + "KB</td>\n");
for (int j = 0; j < info.getLength(); j++) {
Hash peer = info.getPeer(j);
String cap = getCapacity(peer);
TunnelId id = (info.isInbound() ? info.getReceiveTunnelId(j) : info.getSendTunnelId(j));
if (_context.routerHash().equals(peer))
out.write("<td><i>" + peer.toBase64().substring(0,4) + (id == null ? "" : ":" + id) + "</i></td>");
out.write("<td><i>" + peer.toBase64().substring(0,4) + (id == null ? "" : ":" + id) + "</i>" + cap + "</td>");
else
out.write("<td>" + peer.toBase64().substring(0,4) + (id == null ? "" : ":" + id) + "</td>");
out.write("<td>" + peer.toBase64().substring(0,4) + (id == null ? "" : ":" + id) + cap + "</td>");
}
out.write("</tr>\n");
@ -526,4 +527,26 @@ public class TunnelPoolManager implements TunnelManagerFacade {
out.write("<b>No tunnels, waiting for the grace period to end</b><br />\n");
out.write("Lifetime bandwidth usage: " + processedIn + "KB in, " + processedOut + "KB out<br />");
}
private String getCapacity(Hash peer) {
RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
if (info != null) {
String caps = info.getCapabilities();
if (caps.indexOf(Router.CAPABILITY_BW16) >= 0) {
return "[&lt;16&nbsp;]";
} else if (caps.indexOf(Router.CAPABILITY_BW32) >= 0) {
return "[&lt;32&nbsp;]";
} else if (caps.indexOf(Router.CAPABILITY_BW64) >= 0) {
return "[&lt;64&nbsp;]";
} else if (caps.indexOf(Router.CAPABILITY_BW128) >= 0) {
return "<b>[&lt;128]</b>";
} else if (caps.indexOf(Router.CAPABILITY_BW256) >= 0) {
return "<b>[&gt;128]</b>";
} else {
return "[&nbsp;&nbsp;&nbsp;&nbsp;]";
}
} else {
return "[&nbsp;&nbsp;&nbsp;&nbsp;]";
}
}
}