Renamed handlers to be more desciptive.
Send RouterInfo netstatus via enumerators rather than status strings.
This commit is contained in:
@ -124,7 +124,7 @@ public class I2PControlController{
|
|||||||
ssl.setPassword(SecurityManager.getKeyStorePassword());
|
ssl.setPassword(SecurityManager.getKeyStorePassword());
|
||||||
ssl.setKeyPassword(SecurityManager.getKeyStorePassword());
|
ssl.setKeyPassword(SecurityManager.getKeyStorePassword());
|
||||||
ssl.setKeystoreType(SecurityManager.getKeyStoreType());
|
ssl.setKeystoreType(SecurityManager.getKeyStoreType());
|
||||||
ssl.setKeystore((new File(KeyStoreFactory.getKeyStoreLocation())).getAbsolutePath());
|
ssl.setKeystore(KeyStoreFactory.getKeyStoreLocation());
|
||||||
ssl.setName("SSL Listener");
|
ssl.setName("SSL Listener");
|
||||||
server.addListener(ssl);
|
server.addListener(ssl);
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.GetRateHandler;
|
|||||||
import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.I2PControlHandler;
|
import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.I2PControlHandler;
|
||||||
import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.NetworkSettingHandler;
|
import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.NetworkSettingHandler;
|
||||||
import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.RouterInfoHandler;
|
import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.RouterInfoHandler;
|
||||||
import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.RouterRunnerHandler;
|
import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.RouterManagerHandler;
|
||||||
|
|
||||||
import com.thetransactioncompany.jsonrpc2.*;
|
import com.thetransactioncompany.jsonrpc2.*;
|
||||||
import com.thetransactioncompany.jsonrpc2.server.*;
|
import com.thetransactioncompany.jsonrpc2.server.*;
|
||||||
@ -68,7 +68,7 @@ public class JSONRPC2Servlet extends HttpServlet{
|
|||||||
disp.register(new AuthenticateHandler());
|
disp.register(new AuthenticateHandler());
|
||||||
disp.register(new NetworkSettingHandler());
|
disp.register(new NetworkSettingHandler());
|
||||||
disp.register(new RouterInfoHandler());
|
disp.register(new RouterInfoHandler());
|
||||||
disp.register(new RouterRunnerHandler());
|
disp.register(new RouterManagerHandler());
|
||||||
disp.register(new I2PControlHandler());
|
disp.register(new I2PControlHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,11 +95,9 @@ public class RouterInfoHandler implements RequestHandler {
|
|||||||
if (inParams.containsKey("i2p.router.uptime")) {
|
if (inParams.containsKey("i2p.router.uptime")) {
|
||||||
Router router = _context.router();
|
Router router = _context.router();
|
||||||
if (router == null) {
|
if (router == null) {
|
||||||
outParams.put("i2p.router.uptime", "[not up]");
|
outParams.put("i2p.router.uptime", 0);
|
||||||
} else {
|
} else {
|
||||||
String uptime = DataHelper.formatDuration2(router.getUptime());
|
outParams.put("i2p.router.uptime", router.getUptime());
|
||||||
uptime = uptime.replace(" ", " ");
|
|
||||||
outParams.put("i2p.router.uptime", uptime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +106,7 @@ public class RouterInfoHandler implements RequestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inParams.containsKey("i2p.router.net.status")) {
|
if (inParams.containsKey("i2p.router.net.status")) {
|
||||||
outParams.put("i2p.router.net.status", getNetworkStatus());
|
outParams.put("i2p.router.net.status", getNetworkStatus().ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inParams.containsKey("i2p.router.net.bw.inbound.1s")) {
|
if (inParams.containsKey("i2p.router.net.bw.inbound.1s")) {
|
||||||
@ -132,71 +130,90 @@ public class RouterInfoHandler implements RequestHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (inParams.containsKey("i2p.router.net.netdb.knownpeers")) {
|
if (inParams.containsKey("i2p.router.net.netdb.knownpeers")) {
|
||||||
outParams.put("i2p.router.net.netdb.knownpeers", _context.netDb().getKnownRouters());
|
// Why max(-1, 0) is used I don't know, it is the implementation used in the router console.
|
||||||
|
outParams.put("i2p.router.netdb.knownpeers", Math.max(_context.netDb().getKnownRouters()-1,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inParams.containsKey("i2p.router.net.netdb.activepeers")) {
|
if (inParams.containsKey("i2p.router.net.netdb.activepeers")) {
|
||||||
outParams.put("i2p.router.net.netdb.activepeers", _context.commSystem().countActivePeers());
|
outParams.put("i2p.router.netdb.activepeers", _context.commSystem().countActivePeers());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inParams.containsKey("i2p.router.net.netdb.fastpeers")) {
|
if (inParams.containsKey("i2p.router.net.netdb.fastpeers")) {
|
||||||
outParams.put("i2p.router.net.netdb.fastpeers", _context.profileOrganizer().countFastPeers());
|
outParams.put("i2p.router.netdb.fastpeers", _context.profileOrganizer().countFastPeers());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inParams.containsKey("i2p.router.net.netdb.highcapacitypeers")) {
|
if (inParams.containsKey("i2p.router.net.netdb.highcapacitypeers")) {
|
||||||
outParams.put("i2p.router.net.netdb.highcapapcitypeers", _context.profileOrganizer().countHighCapacityPeers());
|
outParams.put("i2p.router.netdb.highcapapcitypeers", _context.profileOrganizer().countHighCapacityPeers());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (inParams.containsKey("i2p.router.net.netdb.isreseeding")) {
|
||||||
|
outParams.put("i2p.router.netdb.isreseeding", Boolean.valueOf(System.getProperty("net.i2p.router.web.ReseedHandler.reseedInProgress")).booleanValue());
|
||||||
|
}
|
||||||
return new JSONRPC2Response(outParams, req.getID());
|
return new JSONRPC2Response(outParams, req.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static enum NETWORK_STATUS{
|
||||||
|
OK,
|
||||||
|
TESTING,
|
||||||
|
FIREWALLED,
|
||||||
|
HIDDEN,
|
||||||
|
WARN_FIREWALLED_AND_FAST,
|
||||||
|
WARN_FIREWALLED_AND_FLOODFILL,
|
||||||
|
WARN_FIREWALLED_WITH_INBOUND_TCP,
|
||||||
|
WARN_FIREWALLED_WITH_UDP_DISABLED,
|
||||||
|
ERROR_I2CP,
|
||||||
|
ERROR_CLOCK_SKEW,
|
||||||
|
ERROR_PRIVATE_TCP_ADDRESS,
|
||||||
|
ERROR_SYMMETRIC_NAT,
|
||||||
|
ERROR_UDP_PORT_IN_USE,
|
||||||
|
ERROR_NO_ACTIVE_PEERS_CHECK_CONNECTION_AND_FIREWALL,
|
||||||
|
ERROR_UDP_DISABLED_AND_TCP_UNSET,
|
||||||
|
};
|
||||||
|
|
||||||
// Ripped out of SummaryHelper.java
|
// Ripped out of SummaryHelper.java
|
||||||
private String getNetworkStatus() {
|
private NETWORK_STATUS getNetworkStatus() {
|
||||||
if (_context.router().getUptime() > 60 * 1000
|
if (_context.router().getUptime() > 60 * 1000
|
||||||
&& (!_context.router().gracefulShutdownInProgress())
|
&& (!_context.router().gracefulShutdownInProgress())
|
||||||
&& !_context.clientManager().isAlive())
|
&& !_context.clientManager().isAlive())
|
||||||
return ("ERR-Client Manager I2CP Error - check logs");
|
return (NETWORK_STATUS.ERROR_I2CP);
|
||||||
long skew = _context.commSystem().getFramedAveragePeerClockSkew(33);
|
long skew = _context.commSystem().getFramedAveragePeerClockSkew(33);
|
||||||
// Display the actual skew, not the offset
|
// Display the actual skew, not the offset
|
||||||
if (Math.abs(skew) > 60 * 1000)
|
if (Math.abs(skew) > 60 * 1000)
|
||||||
return "ERR-Clock Skew of " + Math.abs(skew);
|
return NETWORK_STATUS.ERROR_CLOCK_SKEW;
|
||||||
if (_context.router().isHidden())
|
if (_context.router().isHidden())
|
||||||
return ("Hidden");
|
return (NETWORK_STATUS.HIDDEN);
|
||||||
|
|
||||||
int status = _context.commSystem().getReachabilityStatus();
|
int status = _context.commSystem().getReachabilityStatus();
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case CommSystemFacade.STATUS_OK:
|
case CommSystemFacade.STATUS_OK:
|
||||||
RouterAddress ra = _context.router().getRouterInfo().getTargetAddress("NTCP");
|
RouterAddress ra = _context.router().getRouterInfo().getTargetAddress("NTCP");
|
||||||
if (ra == null || (new NTCPAddress(ra)).isPubliclyRoutable())
|
if (ra == null || (new NTCPAddress(ra)).isPubliclyRoutable())
|
||||||
return "OK";
|
return NETWORK_STATUS.OK;
|
||||||
return "ERR-Private TCP Address";
|
return NETWORK_STATUS.ERROR_PRIVATE_TCP_ADDRESS;
|
||||||
case CommSystemFacade.STATUS_DIFFERENT:
|
case CommSystemFacade.STATUS_DIFFERENT:
|
||||||
return "ERR-SymmetricNAT";
|
return NETWORK_STATUS.ERROR_SYMMETRIC_NAT;
|
||||||
case CommSystemFacade.STATUS_REJECT_UNSOLICITED:
|
case CommSystemFacade.STATUS_REJECT_UNSOLICITED:
|
||||||
if (_context.router().getRouterInfo().getTargetAddress("NTCP") != null)
|
if (_context.router().getRouterInfo().getTargetAddress("NTCP") != null)
|
||||||
return "WARN-Firewalled with Inbound TCP Enabled";
|
return NETWORK_STATUS.WARN_FIREWALLED_WITH_INBOUND_TCP;
|
||||||
if (((FloodfillNetworkDatabaseFacade) _context.netDb())
|
if (((FloodfillNetworkDatabaseFacade) _context.netDb()).floodfillEnabled())
|
||||||
.floodfillEnabled())
|
return NETWORK_STATUS.WARN_FIREWALLED_AND_FLOODFILL;
|
||||||
return "WARN-Firewalled and Floodfill";
|
if (_context.router().getRouterInfo().getCapabilities().indexOf('O') >= 0)
|
||||||
if (_context.router().getRouterInfo().getCapabilities()
|
return NETWORK_STATUS.WARN_FIREWALLED_AND_FAST;
|
||||||
.indexOf('O') >= 0)
|
return NETWORK_STATUS.FIREWALLED;
|
||||||
return "WARN-Firewalled and Fast";
|
|
||||||
return "Firewalled";
|
|
||||||
case CommSystemFacade.STATUS_HOSED:
|
case CommSystemFacade.STATUS_HOSED:
|
||||||
return "ERR-UDP Port In Use";
|
return NETWORK_STATUS.ERROR_UDP_PORT_IN_USE;
|
||||||
case CommSystemFacade.STATUS_UNKNOWN: // fallthrough
|
case CommSystemFacade.STATUS_UNKNOWN: // fallthrough
|
||||||
default:
|
default:
|
||||||
ra = _context.router().getRouterInfo().getTargetAddress("SSU");
|
ra = _context.router().getRouterInfo().getTargetAddress("SSU");
|
||||||
if (ra == null && _context.router().getUptime() > 5 * 60 * 1000) {
|
if (ra == null && _context.router().getUptime() > 5 * 60 * 1000) {
|
||||||
if (_context.commSystem().countActivePeers() <= 0)
|
if (_context.commSystem().countActivePeers() <= 0)
|
||||||
return "ERR-No Active Peers, Check Network Connection and Firewall";
|
return NETWORK_STATUS.ERROR_NO_ACTIVE_PEERS_CHECK_CONNECTION_AND_FIREWALL;
|
||||||
else if (_context.getProperty(CommSystemFacadeImpl.PROP_I2NP_NTCP_HOSTNAME) == null || _context.getProperty(CommSystemFacadeImpl.PROP_I2NP_NTCP_PORT) == null)
|
else if (_context.getProperty(CommSystemFacadeImpl.PROP_I2NP_NTCP_HOSTNAME) == null || _context.getProperty(CommSystemFacadeImpl.PROP_I2NP_NTCP_PORT) == null)
|
||||||
return "ERR-UDP Disabled and Inbound TCP host/port not set";
|
return NETWORK_STATUS.ERROR_UDP_DISABLED_AND_TCP_UNSET;
|
||||||
else
|
else
|
||||||
return "WARN-Firewalled with UDP Disabled";
|
return NETWORK_STATUS.WARN_FIREWALLED_WITH_UDP_DISABLED;
|
||||||
}
|
}
|
||||||
return "Testing";
|
return NETWORK_STATUS.TESTING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import net.i2p.router.Router;
|
|||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.router.RouterVersion;
|
import net.i2p.router.RouterVersion;
|
||||||
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
||||||
|
import net.i2p.router.networkdb.reseed.Reseeder;
|
||||||
import net.i2p.router.transport.CommSystemFacadeImpl;
|
import net.i2p.router.transport.CommSystemFacadeImpl;
|
||||||
import net.i2p.router.transport.FIFOBandwidthRefiller;
|
import net.i2p.router.transport.FIFOBandwidthRefiller;
|
||||||
import net.i2p.router.transport.TransportManager;
|
import net.i2p.router.transport.TransportManager;
|
||||||
@ -47,9 +48,9 @@ import com.thetransactioncompany.jsonrpc2.server.RequestHandler;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class RouterRunnerHandler implements RequestHandler {
|
public class RouterManagerHandler implements RequestHandler {
|
||||||
private static RouterContext _context;
|
private static RouterContext _context;
|
||||||
private static final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(RouterRunnerHandler.class);
|
private static final Log _log = I2PAppContext.getGlobalContext().logManager().getLog(RouterManagerHandler.class);
|
||||||
|
|
||||||
private final static int SHUTDOWN_WAIT = 1500;
|
private final static int SHUTDOWN_WAIT = 1500;
|
||||||
|
|
||||||
@ -63,12 +64,12 @@ public class RouterRunnerHandler implements RequestHandler {
|
|||||||
|
|
||||||
// Reports the method names of the handled requests
|
// Reports the method names of the handled requests
|
||||||
public String[] handledRequests() {
|
public String[] handledRequests() {
|
||||||
return new String[] { "RouterRunner" };
|
return new String[] { "RouterManager" };
|
||||||
}
|
}
|
||||||
|
|
||||||
// Processes the requests
|
// Processes the requests
|
||||||
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
|
public JSONRPC2Response process(JSONRPC2Request req, MessageContext ctx) {
|
||||||
if (req.getMethod().equals("RouterRunner")) {
|
if (req.getMethod().equals("RouterManager")) {
|
||||||
return process(req);
|
return process(req);
|
||||||
} else {
|
} else {
|
||||||
// Method name not supported
|
// Method name not supported
|
||||||
@ -149,7 +150,17 @@ public class RouterRunnerHandler implements RequestHandler {
|
|||||||
return new JSONRPC2Response(outParams, req.getID());
|
return new JSONRPC2Response(outParams, req.getID());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no option was elected, return empty message.
|
if (inParams.containsKey("Reseed")){
|
||||||
|
outParams.put("Reseed", null);
|
||||||
|
(new Thread(){
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
Reseeder reseeder = new Reseeder(_context);
|
||||||
|
reseeder.requestReseed();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
return new JSONRPC2Response(outParams, req.getID());
|
return new JSONRPC2Response(outParams, req.getID());
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue
Block a user