Transports:

- More transition to status enum
 - Don't set TCP keepalive for IPv6
This commit is contained in:
zzz
2015-04-28 03:21:28 +00:00
parent 2359b1edd2
commit ac76107752
10 changed files with 88 additions and 39 deletions

View File

@@ -922,17 +922,26 @@ public class Router implements RouterClock.ClockShiftListener {
}
switch (_context.commSystem().getStatus()) {
case OK:
case IPV4_OK_IPV6_UNKNOWN:
case IPV4_OK_IPV6_FIREWALLED:
case IPV4_FIREWALLED_IPV6_OK:
case IPV4_DISABLED_IPV6_OK:
case IPV4_UNKNOWN_IPV6_OK:
ri.addCapability(CAPABILITY_REACHABLE);
break;
case DIFFERENT:
case REJECT_UNSOLICITED:
case IPV4_DISABLED_IPV6_FIREWALLED:
ri.addCapability(CAPABILITY_UNREACHABLE);
break;
case DISCONNECTED:
case HOSED:
case UNKNOWN:
case IPV4_UNKNOWN_IPV6_FIREWALLED:
case IPV4_DISABLED_IPV6_UNKNOWN:
case IPV4_FIREWALLED_IPV6_UNKNOWN:
default:
// no explicit capability
break;

View File

@@ -13,7 +13,7 @@ import java.util.Set;
import net.i2p.data.DatabaseEntry;
import net.i2p.data.Hash;
import net.i2p.data.router.RouterInfo;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.CommSystemFacade.Status;
import net.i2p.router.JobImpl;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
@@ -43,7 +43,7 @@ class ExpireRoutersJob extends JobImpl {
public String getName() { return "Expire Routers Job"; }
public void runJob() {
if (getContext().commSystem().getReachabilityStatus() != CommSystemFacade.STATUS_DISCONNECTED) {
if (getContext().commSystem().getStatus() != Status.DISCONNECTED) {
int removed = expireKeys();
if (_log.shouldLog(Log.INFO))
_log.info("Routers expired: " + removed);

View File

@@ -18,7 +18,7 @@ import net.i2p.data.i2np.I2NPMessage;
import net.i2p.data.router.RouterInfo;
import net.i2p.kademlia.KBucketSet;
import net.i2p.kademlia.XORComparator;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.CommSystemFacade.Status;
import net.i2p.router.Job;
import net.i2p.router.MessageSelector;
import net.i2p.router.OutNetMessage;
@@ -509,7 +509,7 @@ class IterativeSearchJob extends FloodSearchJob {
_dead = true;
}
_facade.complete(_key);
if (getContext().commSystem().getReachabilityStatus() != CommSystemFacade.STATUS_DISCONNECTED)
if (getContext().commSystem().getStatus() != Status.DISCONNECTED)
_facade.lookupFailed(_key);
getContext().messageRegistry().unregisterPending(_out);
int tries;

View File

@@ -2,7 +2,7 @@ package net.i2p.router.tasks;
import net.i2p.data.DataHelper;
import net.i2p.router.Job;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.CommSystemFacade.Status;
import net.i2p.router.Router;
import net.i2p.router.RouterContext;
import net.i2p.router.util.EventLog;
@@ -133,7 +133,7 @@ public class RouterWatchdog implements Runnable {
boolean ok = verifyJobQueueLiveliness();
// If we aren't connected to the network that's why there's nobody to talk to
long netErrors = 0;
if (_context.commSystem().getReachabilityStatus() == CommSystemFacade.STATUS_DISCONNECTED) {
if (_context.commSystem().getStatus() == Status.DISCONNECTED) {
netErrors = 10;
} else {
RateStat rs = _context.statManager().getRate("udp.sendException");

View File

@@ -650,6 +650,11 @@ public class TransportManager implements TransportEventListener {
* will take many seconds if it has vanished.
*/
public void renderStatusHTML(Writer out, String urlBase, int sortFlags) throws IOException {
out.write("<p>");
out.write(_("Status"));
out.write(": ");
out.write(_(getReachabilityStatus().toStatusString()));
out.write("</p>");
TreeMap<String, Transport> transports = new TreeMap<String, Transport>();
for (Transport t : _transports.values()) {
transports.put(t.getStyle(), t);

View File

@@ -2,6 +2,7 @@ package net.i2p.router.transport.ntcp;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Inet6Address;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.CancelledKeyException;
@@ -24,7 +25,7 @@ import net.i2p.I2PAppContext;
import net.i2p.data.ByteArray;
import net.i2p.data.router.RouterAddress;
import net.i2p.data.router.RouterIdentity;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.CommSystemFacade.Status;
import net.i2p.router.RouterContext;
import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.util.Addresses;
@@ -546,7 +547,7 @@ class EventPumper implements Runnable {
}
// BUGFIX for firewalls. --Sponge
if (_context.commSystem().getReachabilityStatus() != CommSystemFacade.STATUS_OK)
if (shouldSetKeepAlive(chan))
chan.socket().setKeepAlive(true);
SelectionKey ckey = chan.register(_selector, SelectionKey.OP_READ);
@@ -567,7 +568,7 @@ class EventPumper implements Runnable {
_log.debug("processing connect for " + con + ": connected? " + connected);
if (connected) {
// BUGFIX for firewalls. --Sponge
if (_context.commSystem().getReachabilityStatus() != CommSystemFacade.STATUS_OK)
if (shouldSetKeepAlive(chan))
chan.socket().setKeepAlive(true);
con.setKey(key);
con.outboundConnected();
@@ -590,7 +591,21 @@ class EventPumper implements Runnable {
_log.warn("error connecting on " + con, ncpe);
}
}
/**
* @since 0.9.20
*/
private boolean shouldSetKeepAlive(SocketChannel chan) {
if (chan.socket().getInetAddress() instanceof Inet6Address)
return false;
Status status = _context.commSystem().getStatus();
if (status == Status.OK ||
status == Status.IPV4_OK_IPV6_UNKNOWN ||
status == Status.IPV4_OK_IPV6_FIREWALLED)
return false;
return true;
}
/**
* OP_READ will always be set before this is called.
* This method will disable the interest if no more reads remain because of inbound bandwidth throttling.

View File

@@ -11,7 +11,7 @@ import java.util.concurrent.ConcurrentHashMap;
import net.i2p.data.Hash;
import net.i2p.data.i2np.I2NPMessage;
import net.i2p.data.router.RouterInfo;
import net.i2p.router.CommSystemFacade;
import net.i2p.router.CommSystemFacade.Status;
import net.i2p.router.RouterContext;
import net.i2p.router.TunnelManagerFacade;
import net.i2p.stat.Rate;
@@ -106,7 +106,7 @@ class BuildExecutor implements Runnable {
}
private int allowed() {
if (_context.commSystem().getReachabilityStatus() == CommSystemFacade.STATUS_DISCONNECTED)
if (_context.commSystem().getStatus() == Status.DISCONNECTED)
return 0;
int maxKBps = _context.bandwidthLimiter().getOutboundKBytesPerSecond();
int allowed = maxKBps / 6; // Max. 1 concurrent build per 6 KB/s outbound