From c47bfce010a3e9822a8d0f011c48aa9d44cc3cf6 Mon Sep 17 00:00:00 2001
From: shendaras <shendaras>
Date: Sat, 10 Apr 2004 06:27:18 +0000
Subject: [PATCH] Some crappy, half-assed attempt at javadoc stuff;  removed
 (commented out, rather) the fromProxy stuff for *Handler.java.  Feel free to
 put it back in if it's really needed.... (shendaras)

---
 .../src/net/i2p/httptunnel/HTTPListener.java  | 26 +++++++++++++++++-
 .../net/i2p/httptunnel/HTTPSocketHandler.java |  9 +++++++
 .../src/net/i2p/httptunnel/HTTPTunnel.java    |  5 ++++
 .../java/src/net/i2p/httptunnel/Request.java  | 26 ++++++++++++++++++
 .../i2p/httptunnel/SocketManagerProducer.java | 11 ++++++++
 .../i2p/httptunnel/filter/ChainFilter.java    | 12 ++++++++-
 .../src/net/i2p/httptunnel/filter/Filter.java |  3 +++
 .../net/i2p/httptunnel/filter/NullFilter.java |  6 +++++
 .../i2p/httptunnel/handler/EepHandler.java    | 19 ++++++++++++-
 .../i2p/httptunnel/handler/ErrorHandler.java  |  7 +++++
 .../i2p/httptunnel/handler/LocalHandler.java  | 27 ++++++++++++++++---
 .../i2p/httptunnel/handler/ProxyHandler.java  | 10 +++++--
 .../i2p/httptunnel/handler/RootHandler.java   | 25 ++++++++++++-----
 .../src/net/i2p/i2ptunnel/BufferLogger.java   |  1 +
 14 files changed, 171 insertions(+), 16 deletions(-)

diff --git a/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPListener.java b/apps/httptunnel/java/src/net/i2p/httptunnel/HTTPListener.java
index b1bedcbd31..97e4e252dd 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 2ff714fa2c..5ae52223d4 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 1e012e75c7..9ff301ec94 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 e46abf785c..0405f01ee9 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 4ad3a4642b..5ccb741015 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 14d240187f..a9a94b6454 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 200059a354..770542afcd 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 2ea1833c85..fc351c5a40 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 31e9c69b2a..27d9da235a 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 fe63256cdd..0f85b74a77 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 9632edacb3..f3808dda06 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 5177dfcf62..2541bf32e0 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 154a172db8..af94f5029c 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 e9642bf092..f61e8af515 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;
-- 
GitLab