From 70afd93f2fd1e3f297d01b39fd60d916d92e7732 Mon Sep 17 00:00:00 2001 From: dev Date: Fri, 22 Jul 2011 12:19:16 +0000 Subject: [PATCH] Cleaned up build scripts. Removed cruddy files from repo. Added support for API versioning. Version 1 is the current one. --- build.xml | 17 +- plugin/templates/help.html | 56 ------ plugin/templates/jetty.xml | 190 ------------------ src/build.xml | 45 +---- .../i2pcontrol/servlets/JSONRPC2Servlet.java | 4 + .../JSONRPC2ExtendedError.java | 7 + .../jsonrpc2handlers/JSONRPC2Helper.java | 34 +++- .../jsonrpc2handlers/RouterInfoHandler.java | 20 ++ 8 files changed, 72 insertions(+), 301 deletions(-) delete mode 100644 plugin/templates/help.html delete mode 100644 plugin/templates/jetty.xml diff --git a/build.xml b/build.xml index ffa5922..408767d 100644 --- a/build.xml +++ b/build.xml @@ -3,24 +3,26 @@ - + - + - + + - + + @@ -30,12 +32,7 @@ - + diff --git a/plugin/templates/help.html b/plugin/templates/help.html deleted file mode 100644 index 9208f85..0000000 --- a/plugin/templates/help.html +++ /dev/null @@ -1,56 +0,0 @@ -ZzzOT Plugin Help - -

Welcome to the ZzzOT I2P Plugin!

- -A new eepsite tunnel and Jetty server have been started for your open tracker. - -

Click here to see the current stats. -This link is also at the top of your router console when ZzzOT is running. - -

Report bugs or add comments on -the plugin forum on zzz.i2p. - -

Eepsite Key and Helpful Hints for I2P

- -

Your Base 32 address is $B32. - Others may access your eepsite using this address, even if you do not publish a hostname. -

Once you decide on a host name, you may - add the key to your local addressbook here. -

Your Base 64 key is:     -
You will need this key to register a hostname at stats.i2p. -

Your private key file is $PLUGIN/eepPriv.dat - back it up!!! -

Your eepsite document root is $PLUGIN/eepsite/docroot, - you may put other files there is you wish to have additional content on your eepsite. -

The supported announce URLs are: -

-

The supported scrape URLs are: -

-

Your eepsite tunnel is configured for 2 inbound and 2 outbound tunnels, 3 hops each. - You may change tunnel settings by editing $PLUGIN/i2ptunnel.config and restarting the plugin. - The tunnel will not appear in i2ptunnel. - If your tracker gets over 1000 peers, you will probably want to increase the number of tunnels. -

The Jetty webserver port is 7662. If you must change it, edit jetty.xml, i2ptunnel.config, and plugins.config - in the directory $PLUGIN. Then stop and restart the plugin. -

This help file is $PLUGIN/eepsite/docroot/help.html, you should probably move it - outside of the document root before you announce your eepsite as it may contain your user name. -

As you probably know, an open tracker does not require torrents to be registered, - and it does not host torrent files. You can, however, host torrent files elsewhere on - the eepsite, for example at /torrents. - - diff --git a/plugin/templates/jetty.xml b/plugin/templates/jetty.xml deleted file mode 100644 index 711070d..0000000 --- a/plugin/templates/jetty.xml +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 127.0.0.1 - 7662 - - - 3 - 10 - 60000 - 1000 - 8443 - 8443 - main - - - - - - - - - - - - - - - - - - root - - - $PLUGIN/eepsite/webapps/ - - true - - - - - - / - $PLUGIN/eepsite/docroot - - - - FALSE - - - - - - - - - true - - - - /a - /tracker/announce.jsp - - - /announce - /tracker/announce.jsp - - - /announce.jsp - /tracker/announce.jsp - - - /announce.php - /tracker/announce.jsp - - - - /scrape - /tracker/scrape.jsp - - - /scrape.jsp - /tracker/scrape.jsp - - - /scrape.php - /tracker/scrape.jsp - - - - /Seedless - /tracker/seedless.jsp - - - /Seedless/ - /tracker/seedless.jsp - - - /Seedless/index.jsp - /tracker/seedless.jsp - - - /Seedless/seedless - /tracker/seedless.jsp - - - - - - - - - - /cgi-bin/* - $PLUGIN/eepsite/cgi-bin - - Common Gateway Interface - / - org.mortbay.servlet.CGI - /usr/local/bin:/usr/ucb:/bin:/usr/bin - - - - - - - - - $PLUGIN/eepsite/logs/yyyy_mm_dd.request.log - 30 - true - false - false - GMT - - - - - - - 2000 - false - - diff --git a/src/build.xml b/src/build.xml index 56b8c20..233631a 100644 --- a/src/build.xml +++ b/src/build.xml @@ -23,7 +23,7 @@ - + @@ -48,49 +48,6 @@ - - - - - diff --git a/src/java/net/i2p/i2pcontrol/servlets/JSONRPC2Servlet.java b/src/java/net/i2p/i2pcontrol/servlets/JSONRPC2Servlet.java index 713448e..e13d5a4 100644 --- a/src/java/net/i2p/i2pcontrol/servlets/JSONRPC2Servlet.java +++ b/src/java/net/i2p/i2pcontrol/servlets/JSONRPC2Servlet.java @@ -22,6 +22,8 @@ import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; +import java.util.HashMap; + import javax.servlet.ServletException; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServlet; @@ -30,6 +32,7 @@ import javax.servlet.http.HttpServletResponse; import net.i2p.I2PAppContext; import net.i2p.util.Log; +import net.i2p.i2pcontrol.I2PControlVersion; import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.AuthenticateHandler; import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.EchoHandler; import net.i2p.i2pcontrol.servlets.jsonrpc2handlers.GetRateHandler; @@ -89,6 +92,7 @@ public class JSONRPC2Servlet extends HttpServlet{ if (msg instanceof JSONRPC2Request) { jsonResp = disp.dispatch((JSONRPC2Request)msg, null); + jsonResp.toJSON().put("API", I2PControlVersion.API_VERSION); _log.debug("Request: " + msg); _log.debug("Response: " + jsonResp); } diff --git a/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/JSONRPC2ExtendedError.java b/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/JSONRPC2ExtendedError.java index d65a87d..b566b9a 100644 --- a/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/JSONRPC2ExtendedError.java +++ b/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/JSONRPC2ExtendedError.java @@ -88,6 +88,13 @@ public class JSONRPC2ExtendedError extends JSONRPC2Error { /** Invalid JSON-RPC 2.0, implementation defined error (-32099 .. -32000) */ public static final JSONRPC2Error TOKEN_EXPIRED = new JSONRPC2ExtendedError(-32004, "Provided authentication token was expired and will be removed."); + /** Invalid JSON-RPC 2.0, implementation defined error (-32099 .. -32000) */ + public static final JSONRPC2Error UNSPECIFIED_API_VERSION = new JSONRPC2ExtendedError(-32005, "The version of the I2PControl API wasn't specified, but is required to be specified."); + + /** Invalid JSON-RPC 2.0, implementation defined error (-32099 .. -32000) */ + public static final JSONRPC2Error UNSUPPORTED_API_VERSION = new JSONRPC2ExtendedError(-32006, "The version of the I2PControl API specified is not supported by I2PControl."); + + /** * Creates a new JSON-RPC 2.0 error with the specified code and diff --git a/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/JSONRPC2Helper.java b/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/JSONRPC2Helper.java index 380d339..fba7572 100644 --- a/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/JSONRPC2Helper.java +++ b/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/JSONRPC2Helper.java @@ -1,5 +1,6 @@ package net.i2p.i2pcontrol.servlets.jsonrpc2handlers; +import net.i2p.i2pcontrol.I2PControlVersion; import net.i2p.i2pcontrol.security.*; import net.i2p.i2pcontrol.security.SecurityManager; @@ -54,7 +55,13 @@ public class JSONRPC2Helper { } } - // If there exist any required arguments + // Validate I2PControl API version. + JSONRPC2Error err = validateAPIVersion(params); + if (err != null){ + return err; + } + + // If there exist any required arguments. if (requiredArgs != null && requiredArgs.length > 0){ String missingArgs = ""; for (int i = 0; i < requiredArgs.length; i++){ @@ -103,4 +110,29 @@ public class JSONRPC2Helper { } return null; } + + /** + * Validate the provided I2PControl API version against the ones supported by I2PControl. + */ + private static JSONRPC2Error validateAPIVersion(HashMap params){ + + Integer apiVersion; + try { + Object input = params.get("API"); + apiVersion = ((Long) input).intValue(); + } catch (ClassCastException e){ + e.printStackTrace(); + return JSONRPC2ExtendedError.UNSPECIFIED_API_VERSION; + } + + if (!I2PControlVersion.SUPPORTED_API_VERSIONS.contains(apiVersion)){ + String supportedAPIVersions = ""; + for (Integer i : I2PControlVersion.SUPPORTED_API_VERSIONS){ + supportedAPIVersions += ", "+ i; + } + return new JSONRPC2Error(JSONRPC2ExtendedError.UNSUPPORTED_API_VERSION.getCode(), + "The provided API version \'" + apiVersion + "\' is not supported. The supported versions are" + supportedAPIVersions+"."); + } + return null; + } } diff --git a/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/RouterInfoHandler.java b/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/RouterInfoHandler.java index 10b0634..2121917 100644 --- a/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/RouterInfoHandler.java +++ b/src/java/net/i2p/i2pcontrol/servlets/jsonrpc2handlers/RouterInfoHandler.java @@ -109,6 +109,26 @@ public class RouterInfoHandler implements RequestHandler { if (inParams.containsKey("i2p.router.net.status")) { outParams.put("i2p.router.net.status", getNetworkStatus()); } + + if (inParams.containsKey("i2p.router.net.bw.inbound.1s")) { + outParams.put("i2p.router.net.bw.inbound.1s", _context.bandwidthLimiter().getReceiveBps()); + } + + if (inParams.containsKey("i2p.router.net.bw.outbound.1s")) { + outParams.put("i2p.router.net.bw.outbound.1s", _context.bandwidthLimiter().getSendBps()); + } + + if (inParams.containsKey("i2p.router.net.bw.inbound.15s")) { + outParams.put("i2p.router.net.bw.inbound.15s", _context.bandwidthLimiter().getReceiveBps15s()); + } + + if (inParams.containsKey("i2p.router.net.bw.outbound.15s")) { + outParams.put("i2p.router.net.bw.outbound.15s", _context.bandwidthLimiter().getSendBps15s()); + } + + if (inParams.containsKey("i2p.router.net.tunnels.participating")) { + outParams.put("i2p.router.net.tunnels.participating", _context.tunnelManager().getParticipatingCount()); + } return new JSONRPC2Response(outParams, req.getID()); }