diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPListener.java b/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPListener.java index b1bedcbd31894ec35df1d17890e24647366d4fd4..97e4e252dd338d9cedf403d635f262c3b84a62e8 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPListener.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPListener.java @@ -19,6 +19,15 @@ public class HTTPListener extends Thread { private String listenHost; private SocketManagerProducer smp; + /** + * A public constructor. It contstructs things. In this case, + * it constructs a nice HTTPListener, for all your listening on + * HTTP needs. Yep. That's right. + * @param smp A SocketManagerProducer, producing Sockets, no doubt + * @param port A port, to connect to. + * @param listenHost A host, to connect to. + */ + public HTTPListener(SocketManagerProducer smp, int port, String listenHost) { this.smp = smp; @@ -26,6 +35,9 @@ public class HTTPListener extends Thread { start(); } + /* (non-Javadoc) + * @see java.lang.Thread#run() + */ public void run() { try { InetAddress lh = listenHost == null @@ -43,6 +55,10 @@ public class HTTPListener extends Thread { private boolean proxyUsed=false; + /** + * Query whether this is the first use of the proxy or not . . . + * @return Whether this is the first proxy use, no doubt. + */ public boolean firstProxyUse() { // FIXME: check a config option here if (true) return false; @@ -54,11 +70,19 @@ public class HTTPListener extends Thread { } } + /** + * @return The SocketManagerProducer being used. + */ public SocketManagerProducer getSMP() { return smp; } - /** @deprecated */ + /** + * Outputs with HTTP 1.1 flair that a feature isn't implemented. + * @param out The stream the text goes to. + * @deprecated + * @throws IOException + */ public void handleNotImplemented(OutputStream out) throws IOException { out.write(("HTTP/1.1 200 Document following\n\n"+ "<h1>Feature not implemented</h1>").getBytes("ISO-8859-1")); diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPSocketHandler.java b/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPSocketHandler.java index 2ff714fa2c6097c9381fc6eee04c28879ab87060..5ae52223d4ee0979e520a5a762d670f9f0ece6da 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPSocketHandler.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPSocketHandler.java @@ -21,6 +21,11 @@ public class HTTPSocketHandler extends Thread { private HTTPListener httpl; private RootHandler h; + /** + * A public constructor. + * @param httpl An HTTPListener, to listen for HTTP, no doubt + * @param s A socket. + */ public HTTPSocketHandler(HTTPListener httpl, Socket s) { this.httpl = httpl; this.s=s; @@ -28,6 +33,10 @@ public class HTTPSocketHandler extends Thread { start(); } + + /* (non-Javadoc) + * @see java.lang.Thread#run() + */ public void run() { InputStream in = null; OutputStream out = null; diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPTunnel.java b/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPTunnel.java index 1e012e75c7dcd2315b884e042cd4cc89c19e0f28..9ff301ec94ca3743b8e9fb8b9b8534109d3c575b 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPTunnel.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPTunnel.java @@ -69,6 +69,11 @@ public class HTTPTunnel { new HTTPListener(smp, listenPort, "127.0.0.1"); } + /** + * The all important main function, allowing HTTPTunnel to be + * stand-alone, a program in it's own right, and all that jazz. + * @param args A list of String passed to the program + */ public static void main(String[] args) { String host = "127.0.0.1"; int port = 7654, max = 1; diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/Request.java b/apps/httptunnel/java/src/net/i2p/httptunnel/Request.java index e46abf785ca1cf27868baccadb312a7788313e11..0405f01ee978afbbbc210b52444ac7743a668b77 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/Request.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/Request.java @@ -23,6 +23,11 @@ public class Request { private String params; private String postData; + /** + * A constructor, creating a request from an InputStream + * @param in InputStream from which we "read-in" a Request + * @throws IOException + */ public Request(InputStream in) throws IOException { BufferedReader br = new BufferedReader (new InputStreamReader(in, "ISO-8859-1")); @@ -70,6 +75,10 @@ public class Request { } } + /** + * @return A Request as an array of bytes of a String in ISO-8859-1 format + * @throws IOException + */ public byte[] toByteArray() throws IOException { if (method == null) return null; return toISO8859_1String().getBytes("ISO-8859-1"); @@ -81,14 +90,26 @@ public class Request { return method+" "+url+proto+"\r\n"+params+"\r\n"+postData; } + /** + * @return the URL of the request + */ public String getURL() { return url; } + /** + * Sets the URL of the Request + * @param newURL the new URL + */ public void setURL(String newURL) { url=newURL; } + /** + * Retrieves the value of a param. + * @param name The name of the param + * @return The value of the param, or null + */ public String getParam(String name) { try { BufferedReader br= new BufferedReader(new StringReader(params)); @@ -105,6 +126,11 @@ public class Request { } } + /** + * Sets the value of a param. + * @param name the name of the param + * @param value the value to be set + */ public void setParam(String name, String value) { try { StringBuffer sb = new StringBuffer(params.length()+value.length()); diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/SocketManagerProducer.java b/apps/httptunnel/java/src/net/i2p/httptunnel/SocketManagerProducer.java index 4ad3a4642b0902b967a3e2dfc5bc72618590f046..5ccb7410152cff6e1e334b97d6d329719ff59584 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/SocketManagerProducer.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/SocketManagerProducer.java @@ -16,6 +16,14 @@ public class SocketManagerProducer extends Thread { private int maxManagers; private boolean mcDonalds; + /** + * Public constructor creating a SocketManagerProducer + * @param initialManagers a list of socket managers to use + * @param maxManagers how many managers to have in the cache + * @param mcDonaldsMode whether to throw away a manager after use + * @param host which host to listen on + * @param port which port to listen on + */ public SocketManagerProducer(I2PSocketManager[] initialManagers, int maxManagers, boolean mcDonaldsMode, @@ -101,6 +109,9 @@ public class SocketManagerProducer extends Thread { return result; } + /** + * Wait until InterruptedException + */ public void myWait() { try { wait(); diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/filter/ChainFilter.java b/apps/httptunnel/java/src/net/i2p/httptunnel/filter/ChainFilter.java index 14d240187fc1a2f3e7eca11257ceb37a3e06e191..a9a94b6454d19209da434c904373ac419c96f067 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/filter/ChainFilter.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/filter/ChainFilter.java @@ -12,12 +12,19 @@ public class ChainFilter implements Filter { private static final Log _log = new Log(ChainFilter.class); - public Collection filters; + private Collection filters; // perhaps protected? + + /** + * @param filters A collection (list) of filters to chain to + */ public ChainFilter(Collection filters) { this.filters=filters; } + /* (non-Javadoc) + * @see net.i2p.httptunnel.filter.Filter#filter(byte[]) + */ public byte[] filter(byte[] toFilter) { byte[] buf = toFilter; for (Iterator it = filters.iterator(); it.hasNext();) { @@ -27,6 +34,9 @@ public class ChainFilter implements Filter { return buf; } + /* (non-Javadoc) + * @see net.i2p.httptunnel.filter.Filter#finish() + */ public byte[] finish() { // this is a bit complicated. Think about it... try { diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/filter/Filter.java b/apps/httptunnel/java/src/net/i2p/httptunnel/filter/Filter.java index 200059a354c6ef87087977496f889c8212f5b6a5..770542afcda72e91a08c139b3e09fab1d4b90ce2 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/filter/Filter.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/filter/Filter.java @@ -12,11 +12,14 @@ public interface Filter { /** * Filter some data. Not all filtered data need to be returned. + * @param toFilter the bytes that are to be filtered. + * @return the filtered data */ public byte[] filter(byte[] toFilter); /** * Data stream has finished. Return all of the rest data. + * @return the rest of the data */ public byte[] finish(); } diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/filter/NullFilter.java b/apps/httptunnel/java/src/net/i2p/httptunnel/filter/NullFilter.java index 2ea1833c85aa7424629c99c21bfbc5830bffcd51..fc351c5a404fbc54a686a5a2482a37f4fcc45d12 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/filter/NullFilter.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/filter/NullFilter.java @@ -5,10 +5,16 @@ package net.i2p.httptunnel.filter; */ public class NullFilter implements Filter { + /* (non-Javadoc) + * @see net.i2p.httptunnel.filter.Filter#filter(byte[]) + */ public byte[] filter(byte[] toFilter) { return toFilter; } + /* (non-Javadoc) + * @see net.i2p.httptunnel.filter.Filter#finish() + */ public byte[] finish() { return EMPTY; } diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/EepHandler.java b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/EepHandler.java index 31e9c69b2aa0aab25cfb1d3864dc13d51ac6b54f..27d9da235a580a193a99b572547e1624a6303706 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/EepHandler.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/EepHandler.java @@ -31,8 +31,16 @@ public class EepHandler { errorHandler=eh; } + /** + * @param req the Request + * @param httpl an HTTPListener + * @param out where to write the results + * @param destination destination as a string, (subject to naming + * service lookup) + * @throws IOException + */ public void handle(Request req, HTTPListener httpl, OutputStream out, - boolean fromProxy, String destination) + /* boolean fromProxy, */ String destination) throws IOException { SocketManagerProducer smp = httpl.getSMP(); Destination dest = NamingService.getInstance().lookup(destination); @@ -49,6 +57,15 @@ public class EepHandler { } } + /** + * @param req the Request to send out + * @param f a Filter to apply to the bytes retrieved from the Destination + * @param out where to write the results + * @param dest the Destination of the Request + * @param sm an I2PSocketManager, to get a socket for the Destination + * @return boolean, true if something was written, false otherwise. + * @throws IOException + */ public boolean handle(Request req, Filter f, OutputStream out, Destination dest, I2PSocketManager sm) throws IOException { diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/ErrorHandler.java b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/ErrorHandler.java index fe63256cdd8e1c0b41e08c5814de9e52336a6d1b..0f85b74a77c26229c9755d98fb7209a6581eebd8 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/ErrorHandler.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/ErrorHandler.java @@ -17,6 +17,13 @@ public class ErrorHandler { } + /** + * @param req the Request + * @param httpl an HTTPListener + * @param out where to write the results + * @param error the error that happened + * @throws IOException + */ public void handle(Request req, HTTPListener httpl, OutputStream out, String error) throws IOException { // FIXME: Make nicer messages for more likely errors. diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/LocalHandler.java b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/LocalHandler.java index 9632edacb31c1279f6e4d188b1fd990a641d1254..f3808dda06e5dae48b97ea71c238a754e08c6e39 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/LocalHandler.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/LocalHandler.java @@ -15,11 +15,16 @@ public class LocalHandler { private static final Log _log = new Log(LocalHandler.class); /* package private */ LocalHandler() { - } - public void handle(Request req, HTTPListener httpl, OutputStream out, - boolean fromProxy) throws IOException { + /** + * @param req the Request + * @param httpl an HTTPListener + * @param out where to write the results + * @throws IOException + */ + public void handle(Request req, HTTPListener httpl, OutputStream out + /*, boolean fromProxy */) throws IOException { //FIXME: separate multiple pages, not only a start page //FIXME: provide some info on this page out.write(("HTTP/1.1 200 Document following\r\n"+ @@ -31,6 +36,13 @@ public class LocalHandler { out.flush(); } + /** + * Currently always throws an IO Exception + * @param req the Request + * @param httpl an HTTPListener + * @param out where to write the results + * @throws IOException + */ public void handleProxyConfWarning(Request req, HTTPListener httpl, OutputStream out) throws IOException { //FIXME @@ -39,8 +51,15 @@ public class LocalHandler { } + /** + * Currently always throws an IO Exception + * @param req the Request + * @param httpl an HTTPListener + * @param out where to write the results + * @throws IOException + */ public void handleHTTPWarning(Request req, HTTPListener httpl, - OutputStream out, boolean fromProxy) + OutputStream out /*, boolean fromProxy */) throws IOException { // FIXME throw new IOException("jrandom ate the deprecated method. mooo"); diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/ProxyHandler.java b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/ProxyHandler.java index 5177dfcf6292b245c3b2f5f30fa8ffbd43c60dfa..2541bf32e01840c958a1fd20f4f1ac3c63b49282 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/ProxyHandler.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/ProxyHandler.java @@ -23,8 +23,14 @@ public class ProxyHandler extends EepHandler { super(eh); } - public void handle(Request req, HTTPListener httpl, OutputStream out, - boolean fromProxy) throws IOException { + /** + * @param req a Request + * @param httpl an HTTPListener + * @param out where to write the results + * @throws IOException + */ + public void handle(Request req, HTTPListener httpl, OutputStream out + /*, boolean fromProxy */) throws IOException { SocketManagerProducer smp = httpl.getSMP(); Destination dest = findProxy(); if (dest == null) { diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/RootHandler.java b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/RootHandler.java index 154a172db82251282bbce3903c9906bcd8ee5f4b..af94f5029cf450d6aff6b8a6e7bf80551e3efb55 100644 --- a/apps/httptunnel/java/src/net/i2p/httptunnel/handler/RootHandler.java +++ b/apps/httptunnel/java/src/net/i2p/httptunnel/handler/RootHandler.java @@ -27,6 +27,10 @@ public class RootHandler { private static RootHandler instance; + /** + * Singleton stuff . . . + * @return the one and only instance, yay! + */ public static synchronized RootHandler getInstance() { if (instance == null) { instance = new RootHandler(); @@ -34,14 +38,21 @@ public class RootHandler { return instance; } + /** + * The _ROOT_ handler: it passes its workload off to the other handlers. + * @param req a Request + * @param httpl an HTTPListener + * @param out where to write the results + * @throws IOException + */ public void handle(Request req, HTTPListener httpl, OutputStream out) throws IOException { String url=req.getURL(); System.out.println(url); - boolean byProxy = false; + /* boolean byProxy = false; */ int pos; if (url.startsWith("http://")) { // access via proxy - byProxy=true; + /* byProxy=true; */ if (httpl.firstProxyUse()) { localHandler.handleProxyConfWarning(req,httpl,out); return; @@ -66,7 +77,7 @@ public class RootHandler { return; } else { // this is for proxying to the real web - proxyHandler.handle(req, httpl, out, true); + proxyHandler.handle(req, httpl, out /*, true */); return; } } @@ -92,18 +103,18 @@ public class RootHandler { if (dest.equals("_")) { // no eepsite if (url.startsWith("/local/")) { // local request req.setURL(url.substring(6)); - localHandler.handle(req, httpl, out, byProxy); + localHandler.handle(req, httpl, out /*, byProxy */); } else if (url.startsWith("/http/")) { // http warning - localHandler.handleHTTPWarning(req, httpl, out, byProxy); + localHandler.handleHTTPWarning(req, httpl, out /*, byProxy */); } else if (url.startsWith("/proxy/")) { // http proxying req.setURL("http://"+url.substring(7)); - proxyHandler.handle(req, httpl, out, byProxy); + proxyHandler.handle(req, httpl, out /*, byProxy */); } else { errorHandler.handle(req, httpl, out, "No local handler for this URL: "+url); } } else { - eepHandler.handle(req, httpl, out, byProxy, dest); + eepHandler.handle(req, httpl, out, /* byProxy, */ dest); } } } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/BufferLogger.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/BufferLogger.java index e9642bf0927767eab1bc4fd69c1b2c7aed4b2182..f61e8af5157b98f34ca7c724ff81e2764415e7fa 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/BufferLogger.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/BufferLogger.java @@ -45,6 +45,7 @@ class BufferLogger implements Logging { /** * Pass in some random data + * @param s String containing what we're logging. */ public void log(String s) { if (_ignore) return;