From 5195a5c1fc0e9b165588e7048a2c1bc5d2c42a66 Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 2 Jan 2008 22:08:48 +0000 Subject: [PATCH] 2008-01-02 zzz * Add stats.i2p to the jump list * Impose 20MB limit on POSTs and catch OOMs in POST * eepsite_index.html: add stats.i2p services * addressbook: log source of new keys; disallow dests > 516 bytes * addressbook: convert hostnames to lower case to prevent duplicates * susidns: generalize references to orion --- .../java/src/addressbook/AddressBook.java | 4 +- .../java/src/addressbook/ConfigParser.java | 5 ++- .../i2p/i2ptunnel/I2PTunnelHTTPClient.java | 38 +++++++++++++++++-- apps/susidns/src/jsp/index.jsp | 9 ++--- apps/susidns/src/jsp/subscriptions.jsp | 7 ++-- history.txt | 10 ++++- installer/resources/eepsite_index.html | 38 ++++++++++--------- .../src/net/i2p/router/RouterVersion.java | 4 +- 8 files changed, 77 insertions(+), 38 deletions(-) diff --git a/apps/addressbook/java/src/addressbook/AddressBook.java b/apps/addressbook/java/src/addressbook/AddressBook.java index db4c33f5b..6184111d4 100644 --- a/apps/addressbook/java/src/addressbook/AddressBook.java +++ b/apps/addressbook/java/src/addressbook/AddressBook.java @@ -170,7 +170,7 @@ public class AddressBook { String otherKey = (String) otherIter.next(); String otherValue = (String) other.addresses.get(otherKey); - if (otherKey.endsWith(".i2p") && otherValue.length() >= 516) { + if (otherKey.endsWith(".i2p") && otherValue.length() == 516) { if (this.addresses.containsKey(otherKey) && !overwrite) { if (!this.addresses.get(otherKey).equals(otherValue) && log != null) { @@ -185,7 +185,7 @@ public class AddressBook { this.modified = true; if (log != null) { log.append("New address " + otherKey - + " added to address book."); + + " added to address book. From: " + other.location); } } } diff --git a/apps/addressbook/java/src/addressbook/ConfigParser.java b/apps/addressbook/java/src/addressbook/ConfigParser.java index 084f435d9..bc8920e18 100644 --- a/apps/addressbook/java/src/addressbook/ConfigParser.java +++ b/apps/addressbook/java/src/addressbook/ConfigParser.java @@ -60,6 +60,7 @@ public class ConfigParser { * a single key, value pair on each line, in the format: key=value. Lines * starting with '#' or ';' are considered comments, and ignored. Lines that * are obviously not in the format key=value are also ignored. + * The key is converted to lower case. * * @param input * A BufferedReader with lines in key=value format to parse into @@ -77,7 +78,7 @@ public class ConfigParser { inputLine = ConfigParser.stripComments(inputLine); String[] splitLine = inputLine.split("="); if (splitLine.length == 2) { - result.put(splitLine[0].trim(), splitLine[1].trim()); + result.put(splitLine[0].trim().toLowerCase(), splitLine[1].trim()); } inputLine = input.readLine(); } @@ -301,4 +302,4 @@ public class ConfigParser { new FileWriter(file, false))); } -} \ No newline at end of file +} diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index 50af725c3..e45538b76 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -131,6 +131,16 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable "Your browser is misconfigured. Do not use the proxy to access the router console or other localhost destinations.
") .getBytes(); + private final static int MAX_POSTBYTES = 20*1024*1024; // arbitrary but huge - all in memory, no temp file + private final static byte[] ERR_MAXPOST = + ("HTTP/1.1 503 Bad POST\r\n"+ + "Content-Type: text/html; charset=iso-8859-1\r\n"+ + "Cache-control: no-cache\r\n"+ + "\r\n"+ + "

I2P ERROR: REQUEST DENIED

"+ + "The maximum POST size is " + MAX_POSTBYTES + " bytes.
") + .getBytes(); + /** used to assign unique IDs to the threads / clients. no logic or functionality */ private static volatile long __clientId = 0; @@ -503,12 +513,25 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable if (_log.shouldLog(Log.DEBUG)) _log.debug(getPrefix(requestId) + "NewRequest header: [" + newRequest.toString() + "]"); + int postbytes = 0; while (br.ready()) { // empty the buffer (POST requests) int i = br.read(); if (i != -1) { newRequest.append((char) i); + if (++postbytes > MAX_POSTBYTES) { + if (out != null) { + out.write(ERR_MAXPOST); + out.write("

Generated on: ".getBytes()); + out.write(new Date().toString().getBytes()); + out.write("\n".getBytes()); + out.flush(); + } + s.close(); + return; + } } } + if (method == null || destination == null) { l.log("No HTTP method found in the request."); if (out != null) { @@ -578,6 +601,12 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable l.log(ex.getMessage()); handleHTTPClientException(ex, out, targetRequest, usingWWWProxy, currentProxy, requestId); closeSocket(s); + } catch (OutOfMemoryError oom) { // mainly for huge POSTs + IOException ex = new IOException("OOM (in POST?)"); + _log.info("getPrefix(requestId) + Error trying to connect", ex); + l.log(ex.getMessage()); + handleHTTPClientException(ex, out, targetRequest, usingWWWProxy, currentProxy, requestId); + closeSocket(s); } } @@ -616,10 +645,11 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable } } - private static String jumpServers[] = {"http://orion.i2p/jump/", - "http://trevorreznik.i2p/cgi-bin/jump.php?hostname=", - "http://i2host.i2p/cgi-bin/i2hostjump?" - + private static String jumpServers[] = { + "http://i2host.i2p/cgi-bin/i2hostjump?", + "http://orion.i2p/jump/", + "http://stats.i2p/cgi-bin/jump.cgi?a=", + "http://trevorreznik.i2p/cgi-bin/jump.php?hostname=" }; private static void writeErrorMessage(byte[] errMessage, OutputStream out, String targetRequest, boolean usingWWWProxy, String wwwProxy, boolean showAddrHelper) throws IOException { diff --git a/apps/susidns/src/jsp/index.jsp b/apps/susidns/src/jsp/index.jsp index 1a29759b3..db3694b51 100644 --- a/apps/susidns/src/jsp/index.jsp +++ b/apps/susidns/src/jsp/index.jsp @@ -52,14 +52,13 @@

Huh? what addressbook?

The addressbook application is part of your i2p installation. It regularly updates your hosts.txt file -from distributed sources. It keeps your hosts.txt up to date, so it automatically contains all new -eepsites announced on orion -or in the forum. +from distributed sources. It keeps your hosts.txt up to date, so it can automatically add +eepsites announced on other sites if you subscribe to those sites' addressbooks.

(To speak the truth: In its default configuration the addressbook does not poll -orion, but dev.i2p only. Subscribing to orion is an easy task, -just add http://orion.i2p/hosts.txt to your subscriptions file.) +additional sites, but dev.i2p only. Subscribing to additional sites is an easy task, +just add them to your subscriptions file.)

If you have questions about naming in i2p, there is an excellent introduction from duck in the forum.

diff --git a/apps/susidns/src/jsp/subscriptions.jsp b/apps/susidns/src/jsp/subscriptions.jsp index 9e78de8a1..76c3780a1 100644 --- a/apps/susidns/src/jsp/subscriptions.jsp +++ b/apps/susidns/src/jsp/subscriptions.jsp @@ -20,7 +20,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Revision: 1.7 $ + * $Revision: 1.1 $ */ %> <%@ page contentType="text/html"%> @@ -66,9 +66,8 @@

The subscription file contains a list of (i2p) URLs. The addressbook application regularly (once per hour) checks this list for new eepsites. Those URLs simply contain the published hosts.txt -file of other people. Default subscription is the hosts.txt from dev.i2p. The most -popular collaboration site for eepsite is orion.i2p. So its a good idea to add http://orion.i2p/hosts.txt -as a 2nd subscription. +file of other people. The default subscription is the hosts.txt from dev.i2p, which is updated infrequently. +So it is a good idea to add additional subscriptions to sites that have the latest addresses.