Compare commits

...

3 Commits

3 changed files with 54 additions and 4 deletions

View File

@ -34,6 +34,11 @@ class CapacityCalculator {
private static final double PENALTY_NO_R_CAP = 1;
private static final double PENALTY_U_CAP = 2;
private static final double PENALTY_LAST_SEND_FAIL = 4;
// congestion cap penalty not yet applied
//private static final double PENALTY_D_CAP = 0;
// congestion cap penalty not yet applied
//private static final double PENALTY_E_CAP = 0;
//private static final double PENALTY_G_CAP = 0;
private static final double PENALTY_RECENT_SEND_FAIL = 4;
private static final double BONUS_LAST_SEND_SUCCESS = 1;
private static final double BONUS_RECENT_SEND_SUCCESS = 1;
@ -124,11 +129,13 @@ class CapacityCalculator {
capacity -= PENALTY_U_CAP;
if (caps.indexOf(Router.CAPABILITY_BW32) >= 0)
capacity -= PENALTY_L_CAP;
/* TODO
if (caps.indexOf(Router.CAPABILITY_CONGESTION_MODERATE) >= 0)
/* TODO */
/*if (caps.indexOf(Router.CAPABILITY_CONGESTION_MODERATE) >= 0)
capacity -= PENALTY_D_CAP;
else if (caps.indexOf(Router.CAPABILITY_CONGESTION_SEVERE) >= 0)
capacity -= PENALTY_E_CAP;
capacity -= PENALTY_E_CAP;*/
/* TODO: G caps can be excluded in TunnelPeerSelector by adding it to DEFAULT_EXCLUDE_CAPS
decide what other handling if any is needed here.
else if (caps.indexOf(Router.CAPABILITY_NO_TUNNELS) >= 0)
capacity -= PENALTY_G_CAP;
*/

View File

@ -11,6 +11,7 @@ import net.i2p.data.Base64;
import net.i2p.data.DataHelper;
import net.i2p.data.EmptyProperties;
import net.i2p.data.Hash;
import net.i2p.data.i2np.DatabaseStoreMessage;
import net.i2p.data.router.RouterIdentity;
import net.i2p.data.router.RouterInfo;
import net.i2p.data.TunnelId;
@ -470,6 +471,48 @@ class BuildHandler implements Runnable {
_context.commSystem().mayDisconnect(from);
return -1;
}
// get my own RouterInfo
RouterInfo myRI = _context.router().getRouterInfo();
if (myRI != null) {
String caps = myRI.getCapabilities();
if (caps != null) {
if (caps.indexOf(Router.CAPABILITY_NO_TUNNELS) >= 0){
_context.statManager().addRateData("tunnel.dropTunnelFromCongestionCapability", 1);
if (_log.shouldLog(Log.WARN))
_log.warn("Drop request, we are denying tunnels due to congestion: " + from);
RouterInfo fromRI = _context.floodfillNetDb().lookupRouterInfoLocally(from);
if (fromRI != null){
String fromVersion = fromRI.getVersion();
// if fromVersion is greater than 0.9.58, then then ban the router due to it disrespecting our
// congestion flags
if (fromVersion != null){
if (VersionComparator.comp(fromVersion, MIN_VERSION_HONOR_CAPS) >= 0) {
_context.statManager().addRateData("tunnel.dropTunnelFromVersion"+from, 1);
long knocks = _context.statManager().getRate("tunnel.dropTunnelFromVersion"+from).getLifetimeEventCount();
if (knocks > 10) {
if (_log.shouldLog(Log.WARN))
_log.warn("Banning peer: " + fromRI.getHash() + " due to it disrespecting our congestion flags");
_context.banlist().banlistRouter(from, "disrespected our tunnel flags", null, false);
} else if (knocks <= 1) {
if (_log.shouldLog(Log.WARN))
_log.warn("Replying with our RouterInfo to peer:" +fromRI.getHash() +
" to give it a chance to update their own netDb and stop asking for new tunnels");
// send the peer our RouterInfo
int TIMEOUT = 10*1000;
DatabaseStoreMessage dsm = new DatabaseStoreMessage(_context);
dsm.setMessageExpiration(_context.clock().now() + TIMEOUT);
dsm.setEntry(myRI);
OutNetMessage outMsg = new OutNetMessage(_context, dsm, _context.clock().now() + TIMEOUT, PRIORITY, fromRI);
_context.outNetMessagePool().add(outMsg);
}
}
}
}
return -1;
}
}
}
if (timeSinceReceived > (BuildRequestor.REQUEST_TIMEOUT*3)) {
// don't even bother, since we are so overloaded locally

View File

@ -42,7 +42,7 @@ import net.i2p.util.VersionComparator;
*/
public abstract class TunnelPeerSelector extends ConnectChecker {
private static final String DEFAULT_EXCLUDE_CAPS = String.valueOf(Router.CAPABILITY_BW12);
private static final String DEFAULT_EXCLUDE_CAPS = String.valueOf(Router.CAPABILITY_BW12)+String.valueOf(Router.CAPABILITY_CONGESTION_SEVERE);
protected TunnelPeerSelector(RouterContext context) {
super(context);