diff --git a/apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java b/apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java index c3070913e..bf869f412 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java +++ b/apps/i2psnark/java/src/org/klomp/snark/PeerCoordinator.java @@ -522,6 +522,11 @@ public class PeerCoordinator implements PeerListener //Only request a piece we've requested before if there's no other choice. if (piece == null) { + // AND if there are almost no wanted pieces left (real end game). + // If we do end game all the time, we generate lots of extra traffic + // when the seeder is super-slow and all the peers are "caught up" + if (wantedPieces.size() > 4) + return -1; // nothing to request and not in end game // let's not all get on the same piece Collections.shuffle(requested); Iterator it2 = requested.iterator(); diff --git a/apps/i2psnark/java/src/org/klomp/snark/Snark.java b/apps/i2psnark/java/src/org/klomp/snark/Snark.java index 12c299840..5b7d32d0e 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Snark.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Snark.java @@ -734,7 +734,7 @@ public class Snark //if (debug >= INFO && t != null) // t.printStackTrace(); stopTorrent(); - throw new RuntimeException("die bart die"); + throw new RuntimeException(s + (t == null ? "" : ": " + t.getMessage())); } /** diff --git a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java index 63921f7f1..dd0db4337 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java +++ b/apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.text.Collator; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.Enumeration; import java.util.Iterator; @@ -37,7 +38,10 @@ import org.klomp.snark.SnarkManager; import org.klomp.snark.Storage; import org.klomp.snark.TrackerClient; +import org.mortbay.http.HttpResponse; import org.mortbay.jetty.servlet.Default; +import org.mortbay.util.Resource; +import org.mortbay.util.URI; /** * We extend Default instead of HTTPServlet so we can handle @@ -105,13 +109,52 @@ public class I2PSnarkServlet extends Default { super.destroy(); } + /** + * Some parts modified from: + *
+ // ======================================================================== + // $Id: Default.java,v 1.51 2006/10/08 14:13:18 gregwilkins Exp $ + // Copyright 199-2004 Mort Bay Consulting Pty. Ltd. + // ------------------------------------------------------------------------ + // Licensed under the Apache License, Version 2.0 (the "License"); + // you may not use this file except in compliance with the License. + // You may obtain a copy of the License at + // http://www.apache.org/licenses/LICENSE-2.0 + // Unless required by applicable law or agreed to in writing, software + // distributed under the License is distributed on an "AS IS" BASIS, + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + // See the License for the specific language governing permissions and + // limitations under the License. + // ======================================================================== + *+ * + */ @Override public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // this is the part after /i2psnark String path = req.getServletPath(); // index.jsp doesn't work, it is grabbed by the war handler before here if (!(path == null || path.equals("/") || path.equals("/index.jsp") || path.equals("/index.html"))) { - super.service(req, resp); + if (path.endsWith("/")) { + // bypass the horrid Resource.getListHTML() + String pathInfo = req.getPathInfo(); + String pathInContext = URI.addPaths(path, pathInfo); + resp.setCharacterEncoding("UTF-8"); + resp.setContentType("text/html; charset=UTF-8"); + Resource resource = getResource(pathInContext); + if (resource == null || (!resource.exists()) || !resource.isDirectory()) { + resp.sendError(HttpResponse.__404_Not_Found); + } else { + String base = URI.addPaths(req.getRequestURI(), "/"); + String listing = getListHTML(resource, base, true); + if (listing != null) + resp.getWriter().write(listing); + else // shouldn't happen + resp.sendError(HttpResponse.__404_Not_Found); + } + } else { + super.service(req, resp); + } return; } @@ -305,7 +348,7 @@ public class I2PSnarkServlet extends Default { } } else if (newURL != null) { if (newURL.startsWith("http://")) { - _manager.addMessage(_("Fetching {0}", newURL)); + _manager.addMessage(_("Fetching {0}", urlify(newURL))); I2PAppThread fetch = new I2PAppThread(new FetchAndAdd(_manager, newURL), "Fetch and add"); fetch.start(); } else { @@ -689,7 +732,7 @@ public class I2PSnarkServlet extends Default { out.write("\n\t"); out.write("