From fred at freenetproject.org Wed Aug 1 10:32:13 2007 From: fred at freenetproject.org (fred at freenetproject.org) Date: Wed, 1 Aug 2007 10:32:13 +0000 (UTC) Subject: [freenet-cvs] r14454 - in trunk/plugins/Echo/src: plugins/echo xml Message-ID: <20070801103213.3DCFE47AA5E@freenetproject.org> Author: fred Date: 2007-08-01 10:32:12 +0000 (Wed, 01 Aug 2007) New Revision: 14454 Added: trunk/plugins/Echo/src/xml/rss.xsl Modified: trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java Log: Adding RSS support Modified: trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java =================================================================== --- trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java 2007-08-01 03:20:42 UTC (rev 14453) +++ trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java 2007-08-01 10:32:12 UTC (rev 14454) @@ -15,6 +15,7 @@ private NodesManager nodesManager; private Builder parser; private XSLTransform transform; + private XSLTransform rssTransform; private Serializer serializer; private Document template; @@ -27,6 +28,8 @@ // template = parser.build("/home/fred/prog/soc/trunk/plugins/Echo/src/xml/test.xsl"); transform = new XSLTransform(template); transform.setParameter("basedir", BASE_DIR.getAbsolutePath() + "/"); + + rssTransform = new XSLTransform(parser.build("/home/fred/prog/soc/trunk/plugins/Echo/src/xml/rss.xsl")); serializer = new Serializer(System.out); serializer.setIndent(4); @@ -34,19 +37,13 @@ } - public void transformAndWrite(Document doc, String fileName) throws XSLException, IOException { + public void writeToFile(nu.xom.Nodes result, String fileName) throws XSLException, IOException { serializer.setOutputStream(new FileOutputStream(OUT_DIR.getPath() + File.separator + fileName)); - serializer.write(new Document((Element) transform.transform(doc).get(0))); + serializer.write(new Document((Element) result.get(0))); } - public void transformAndWrite(Element element, String fileName) throws XSLException, IOException { - - transformAndWrite(new Document(element), fileName); - - } - public void generate() throws Exception{ // TODO : Pfouille !! OUT_DIR.mkdirs(); @@ -54,7 +51,7 @@ Nodes nodes = nodesManager.getNodes(); for(Node node : nodes) { System.out.println(node.getId()); - transformAndWrite(node.render().getDoc(), node.getId() + ".html"); + writeToFile(transform.transform(node.render().getDoc()), node.getId() + ".html"); } Nodes posts = nodes.getPosts(); @@ -65,8 +62,9 @@ System.out.println(post.getId() + " (" + post.getCreationDate().toString() + ")"); index.appendChild(post.render().getRoot()); } - transformAndWrite(index, "index.html"); + writeToFile(transform.transform(new Document(index)), "index.html"); + writeToFile(rssTransform.transform(new Document(index)), "feed.rss"); System.out.println("\n * Categories *"); @@ -79,8 +77,10 @@ if(post.isInCategory(category)) index.appendChild(post.render().getRoot()); } - transformAndWrite(index, "category-" + category + ".html"); + writeToFile(transform.transform(new Document(index)), "category-" + category + ".html"); } + + } } \ No newline at end of file Added: trunk/plugins/Echo/src/xml/rss.xsl =================================================================== --- trunk/plugins/Echo/src/xml/rss.xsl (rev 0) +++ trunk/plugins/Echo/src/xml/rss.xsl 2007-08-01 10:32:12 UTC (rev 14454) @@ -0,0 +1,35 @@ + + + + + + + + + My blog + ./ + Just a blog + Echo 0.1-alpha + + + + + <xsl:value-of select="title/text()" /> + .html + + + + + + + \ No newline at end of file From fred at freenetproject.org Sun Aug 5 14:01:11 2007 From: fred at freenetproject.org (fred at freenetproject.org) Date: Sun, 5 Aug 2007 14:01:11 +0000 (UTC) Subject: [freenet-cvs] r14484 - in trunk/plugins/Echo/src: plugins/echo plugins/echo/i18n test xml Message-ID: <20070805140111.61D5647AA7E@freenetproject.org> Author: fred Date: 2007-08-05 14:01:10 +0000 (Sun, 05 Aug 2007) New Revision: 14484 Removed: trunk/plugins/Echo/src/test/blocks.xml Modified: trunk/plugins/Echo/src/plugins/echo/Echo.java trunk/plugins/Echo/src/plugins/echo/NodesManager.java trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties trunk/plugins/Echo/src/xml/edit.xsl Log: blocks management Modified: trunk/plugins/Echo/src/plugins/echo/Echo.java =================================================================== --- trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-08-05 03:28:31 UTC (rev 14483) +++ trunk/plugins/Echo/src/plugins/echo/Echo.java 2007-08-05 14:01:10 UTC (rev 14484) @@ -1,6 +1,8 @@ package plugins.echo; import plugins.echo.i18n.I18n; +import plugins.echo.block.BlockManager; +import plugins.echo.block.Block; import freenet.pluginmanager.FredPlugin; import freenet.pluginmanager.FredPluginHTTP; @@ -41,6 +43,7 @@ public static final File BASE_DIR = new File("plugins/Echo/"); public static final File NODES_DIR = new File(BASE_DIR.getPath() + File.separator + "nodes"); + public static final File BLOCKS_DIR = new File(BASE_DIR.getPath() + File.separator + "blocks"); public static final int NODE_ID_LENGTH = 4; public static final int CATEGORY_ID_LENGTH = 3; @@ -56,6 +59,7 @@ private I18n i18n; private Page page; private NodesManager nodesManager; + private BlockManager blockManager; private Node node; public Echo() throws PluginHTTPException @@ -71,9 +75,11 @@ i18n.translateXML(styleSheet); transform = new XSLTransform(styleSheet); - transform.setParameter("contextprefix", NODES_DIR.getAbsolutePath() + "/"); + transform.setParameter("baseDir", BASE_DIR.getAbsolutePath() + "/"); nodesManager = new NodesManager(BASE_DIR); + blockManager = new BlockManager(BLOCKS_DIR); + } catch (Exception e) { e.printStackTrace(System.err); } @@ -99,11 +105,11 @@ private String transform(Page page) { try { - return transform.transform(page.getDoc()).get(0).toXML(); +// return transform.transform(page.getDoc()).get(0).toXML(); /* Nice but input white space are not respected - + */ ByteArrayOutputStream baos = new ByteArrayOutputStream(); Serializer serializer = new Serializer(baos); serializer.setIndent(4); @@ -111,9 +117,9 @@ serializer.write(new Document((Element) transform.transform(page.getDoc()).get(0))); return baos.toString(); - */ + } catch (Exception e) { return e.getMessage(); } @@ -241,6 +247,10 @@ setCategoriesPage(); + } else if ("blocks".equals(fileName)) { + + setBlocksPage(); + } else { setDefaultPage(); @@ -309,6 +319,24 @@ } else { page.appendError("Fied \"name\" is empty"); } + + } else if (request.isPartSet("blocks")) { + + String[] blocksIds = blockManager.getIds(); + for(String id : blocksIds) { + Block block = blockManager.getBlockById(id); + + String position = request.getPartAsString("position-" + id, 8); + block.setPosition(position); + + String weight = request.getPartAsString("weight-" + id, 2); + block.setWeight(Integer.parseInt(weight)); + + blockManager.write(block); + } + + setBlocksPage(); + } else { String title = request.getPartAsString("title", MAX_TITLE_LENGTH).trim(); @@ -375,6 +403,28 @@ page.appendData(getFormPassword()); } + private void setBlocksPage() { + + Element blocksElement = new Element("blocks"); + Block[] blocks = blockManager.getBlocks(); + for(Block b : blocks) { + Element block = new Element("block"); + block.addAttribute(new Attribute("id", b.getId())); + block.addAttribute(new Attribute("type", i18n.getString("echo.block." + b.getType().toString()))); + block.addAttribute(new Attribute("position", b.getPosition())); + block.addAttribute(new Attribute("weight", String.valueOf(b.getWeight()))); + + if(b.isConfigurable()) + block.addAttribute(new Attribute("configurable", "true")); + + blocksElement.appendChild(block); + } + + page = new Page(blocksElement); + page.setTitle(i18n.getString("echo.common.blocks")); + page.appendData(getFormPassword()); + } + private Element getFormPassword() { Element formPassword = new Element("formpassword"); Modified: trunk/plugins/Echo/src/plugins/echo/NodesManager.java =================================================================== --- trunk/plugins/Echo/src/plugins/echo/NodesManager.java 2007-08-05 03:28:31 UTC (rev 14483) +++ trunk/plugins/Echo/src/plugins/echo/NodesManager.java 2007-08-05 14:01:10 UTC (rev 14484) @@ -38,7 +38,7 @@ File[] files = nodesDir.listFiles(); for(File f : files) { - if(f.getName().matches("[0-9]{4}.xml")) + if(f.getName().matches("[0-9]{" + Echo.NODE_ID_LENGTH + "}.xml")) nodes.put(f.getName().substring(0,4), f); } Modified: trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java =================================================================== --- trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java 2007-08-05 03:28:31 UTC (rev 14483) +++ trunk/plugins/Echo/src/plugins/echo/SiteGenerator.java 2007-08-05 14:01:10 UTC (rev 14484) @@ -80,7 +80,5 @@ writeToFile(transform.transform(new Document(index)), "category-" + category + ".html"); } - - } } \ No newline at end of file Modified: trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java =================================================================== --- trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java 2007-08-05 03:28:31 UTC (rev 14483) +++ trunk/plugins/Echo/src/plugins/echo/i18n/I18n.java 2007-08-05 14:01:10 UTC (rev 14484) @@ -12,6 +12,8 @@ import nu.xom.Text; import nu.xom.Document; +import java.io.*; // FIXME + /** * This class provides a trivial internationalization framework */ @@ -59,6 +61,7 @@ props = new Properties(); try { props.load(getClass().getResourceAsStream("/i18n/" + PREFIX + language + SUFFIX)); +// props.load(new FileInputStream("/home/fred/prog/soc/trunk/plugins/Echo/src/plugins/echo/i18n/" + PREFIX + language + SUFFIX)); } catch (IOException ioe) { Logger.error(this, "IOException while accessing the " + language +"file" + ioe.getMessage(), ioe); throw new MissingResourceException("Unable to load the translation file for " + language, "i18n", language); Modified: trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties =================================================================== --- trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties 2007-08-05 03:28:31 UTC (rev 14483) +++ trunk/plugins/Echo/src/plugins/echo/i18n/echo.i18n.en.properties 2007-08-05 14:01:10 UTC (rev 14484) @@ -14,6 +14,9 @@ echo.common.date=Date echo.common.title=Title echo.common.nodeType=Type +echo.common.blocks=Blocks +echo.common.position=Position +echo.common.weight=Weight echo.write.newPost=Create a new post echo.write.newPage=Create a new page Deleted: trunk/plugins/Echo/src/test/blocks.xml =================================================================== --- trunk/plugins/Echo/src/test/blocks.xml 2007-08-05 03:28:31 UTC (rev 14483) +++ trunk/plugins/Echo/src/test/blocks.xml 2007-08-05 14:01:10 UTC (rev 14484) @@ -1,7 +0,0 @@ - - - - - - - Modified: trunk/plugins/Echo/src/xml/edit.xsl =================================================================== --- trunk/plugins/Echo/src/xml/edit.xsl 2007-08-05 03:28:31 UTC (rev 14483) +++ trunk/plugins/Echo/src/xml/edit.xsl 2007-08-05 14:01:10 UTC (rev 14484) @@ -14,8 +14,14 @@ - + + categories.xml + nodes/ + blocks/ + + + @@ -70,18 +76,21 @@
+
+
+ - + - + @@ -133,9 +142,9 @@ - - - + + + @@ -148,6 +157,57 @@ + + +
+
+ + + + + + + + + + + alternate + + + + + + + + +
+ + + + + + configure + + +
+ + + + +
+
@@ -165,7 +225,7 @@ - +
@@ -224,7 +284,7 @@ - + @@ -238,4 +298,63 @@ + + + + + top + + + + bottom + + + + left + + + + right + + + + disabled + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From zothar at freenetproject.org Sun Aug 5 15:02:09 2007 From: zothar at freenetproject.org (zothar at freenetproject.org) Date: Sun, 5 Aug 2007 15:02:09 +0000 (UTC) Subject: [freenet-cvs] r14485 - trunk/freenet/src/freenet/node Message-ID: <20070805150209.5921547AA5F@freenetproject.org> Author: zothar Date: 2007-08-05 15:02:09 +0000 (Sun, 05 Aug 2007) New Revision: 14485 Modified: trunk/freenet/src/freenet/node/Node.java Log: Use the file-specified/default config value for node.passOpennetPeersThroughDarknet rather than ignoring the configuration and always using False on startup. Modified: trunk/freenet/src/freenet/node/Node.java =================================================================== --- trunk/freenet/src/freenet/node/Node.java 2007-08-05 14:01:10 UTC (rev 14484) +++ trunk/freenet/src/freenet/node/Node.java 2007-08-05 15:02:09 UTC (rev 14485) @@ -831,6 +831,8 @@ } }); + + passOpennetRefsThroughDarknet = nodeConfig.getBoolean("passOpennetPeersThroughDarknet"); // Extra Peer Data Directory nodeConfig.register("extraPeerDataDir", new File(nodeDir, "extra-peer-data-"+getDarknetPortNumber()).toString(), sortOrder++, true, false, "Node.extraPeerDir", "Node.extraPeerDirLong", From toad at freenetproject.org Mon Aug 6 21:21:41 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Mon, 6 Aug 2007 21:21:41 +0000 (UTC) Subject: [freenet-cvs] r14496 - trunk/freenet/src/freenet/node/fcp Message-ID: <20070806212141.4702E47A03C@freenetproject.org> Author: toad Date: 2007-08-06 21:21:41 +0000 (Mon, 06 Aug 2007) New Revision: 14496 Modified: trunk/freenet/src/freenet/node/fcp/TestDDACompleteMessage.java Log: comment: this shouldn't be a side-effect, it should be done somewhere closer to the main flow Modified: trunk/freenet/src/freenet/node/fcp/TestDDACompleteMessage.java =================================================================== --- trunk/freenet/src/freenet/node/fcp/TestDDACompleteMessage.java 2007-08-06 19:10:45 UTC (rev 14495) +++ trunk/freenet/src/freenet/node/fcp/TestDDACompleteMessage.java 2007-08-06 21:21:41 UTC (rev 14496) @@ -63,6 +63,7 @@ sfs.putSingle(WRITE_ALLOWED, String.valueOf(isWriteAllowed)); } + // FIXME this really shouldn't be a side-effect! handler.registerTestDDAResult(checkJob.directory.toString(), isReadAllowed, isWriteAllowed); return sfs; From toad at freenetproject.org Mon Aug 6 22:02:15 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Mon, 6 Aug 2007 22:02:15 +0000 (UTC) Subject: [freenet-cvs] r14497 - trunk/freenet/src/freenet/client/async Message-ID: <20070806220215.B0A5047AB15@freenetproject.org> Author: toad Date: 2007-08-06 22:02:15 +0000 (Mon, 06 Aug 2007) New Revision: 14497 Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java Log: Fix ArrayIndexOutOfBounds when a cancelled request is sent. Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java =================================================================== --- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java 2007-08-06 21:21:41 UTC (rev 14496) +++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java 2007-08-06 22:02:15 UTC (rev 14497) @@ -22,6 +22,7 @@ import freenet.keys.ClientCHK; import freenet.keys.ClientCHKBlock; import freenet.keys.ClientKeyBlock; +import freenet.keys.NodeCHK; import freenet.support.Logger; import freenet.support.api.Bucket; import freenet.support.io.BucketTools; @@ -323,7 +324,7 @@ if(logMINOR) Logger.minor(this, "Permanently failed block: "+blockNo+" on "+this+" : "+e, e); boolean allFailed; // Since we can't keep the key, we need to unregister for it at this point to avoid a memory leak - seg.unregisterKey(getBlockKey(blockNo).getNodeKey()); + seg.unregisterKey(getBlockNodeKey(blockNo)); synchronized(this) { if(isFinishing()) return; // this failure is now irrelevant, and cleanup will occur on the decoder thread if(blockNo < dataKeys.length) { @@ -455,11 +456,19 @@ } public ClientCHK getBlockKey(int blockNum) { - if(blockNum < dataKeys.length) + if(blockNum < 0) return null; + else if(blockNum < dataKeys.length) return dataKeys[blockNum]; - else + else if(blockNum < dataKeys.length + checkKeys.length) return checkKeys[blockNum - dataKeys.length]; + else return null; } + + public NodeCHK getBlockNodeKey(int blockNum) { + ClientCHK key = getBlockKey(blockNum); + if(key != null) return key.getNodeCHK(); + else return null; + } public synchronized void removeSeg(SplitFileFetcherSubSegment segment) { for(int i=0;i Author: toad Date: 2007-08-06 22:25:34 +0000 (Mon, 06 Aug 2007) New Revision: 14498 Modified: trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java trunk/freenet/src/freenet/clients/http/BrowserTestToadlet.java trunk/freenet/src/freenet/clients/http/ConfigToadlet.java trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java trunk/freenet/src/freenet/clients/http/FProxyToadlet.java trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java trunk/freenet/src/freenet/clients/http/LocalFileInsertToadlet.java trunk/freenet/src/freenet/clients/http/N2NTMToadlet.java trunk/freenet/src/freenet/clients/http/PluginToadlet.java trunk/freenet/src/freenet/clients/http/PproxyToadlet.java trunk/freenet/src/freenet/clients/http/QueueToadlet.java trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java trunk/freenet/src/freenet/clients/http/Toadlet.java trunk/freenet/src/freenet/clients/http/TranslationToadlet.java trunk/freenet/src/freenet/clients/http/TrivialToadlet.java trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java Log: Minor refactoring (writeHTML/TextReply rather than writeReply). => Fix charset issues on many pages in many cases. Also fix some HTTP status code / status code reason string issues. Modified: trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/BookmarkEditorToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -150,7 +150,7 @@ } catch (URLEncodedFormatException e) { HTMLNode errorBox = content.addChild(ctx.getPageMaker().getInfobox("infobox-error", error)); errorBox.addChild("#", L10n.getString("BookmarkEditorToadlet.urlDecodeError")); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } Bookmark bookmark; @@ -163,7 +163,7 @@ if(bookmark == null) { HTMLNode errorBox = content.addChild(ctx.getPageMaker().getInfobox("infobox-error", error)); errorBox.addChild("#", L10n.getString("BookmarkEditorToadlet.bookmarkDoesNotExist", new String[] { "bookmark" }, new String[] { bookmarkPath })); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else { @@ -242,7 +242,7 @@ HTMLNode bookmarksBox = content.addChild(ctx.getPageMaker().getInfobox("infobox-normal", L10n.getString("BookmarkEditorToadlet.myBookmarksTitle"))); bookmarksBox.addChild(getBookmarksList()); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } @@ -319,7 +319,7 @@ HTMLNode bookmarksBox = content.addChild(ctx.getPageMaker().getInfobox("infobox-normal", L10n.getString("BookmarkEditorToadlet.myBookmarksTitle"))); bookmarksBox.addChild(getBookmarksList()); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } public String supportedMethods() Modified: trunk/freenet/src/freenet/clients/http/BrowserTestToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/BrowserTestToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/BrowserTestToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -178,7 +178,7 @@ // Yes, we need that in order to test the browser (number of connections per server) if (request.isParameterSet("wontload")) return; else if (request.isParameterSet("mimeTest")){ - this.writeReply(ctx, 200, "text/html", "OK", imgWarningMime); + this.writeHTMLReply(ctx, 200, "OK", imgWarningMime); return; } @@ -210,7 +210,7 @@ jsTest.addChild("img", new String[]{"id", "src", "alt"}, new String[]{"JSTEST", "/static/themes/clean/success.gif", "fail!"}); jsTest.addChild("script", "type", "text/javascript").addChild("%", "document.getElementById('JSTEST').src = '/static/themes/clean/warning.gif';"); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } public String supportedMethods() { Modified: trunk/freenet/src/freenet/clients/http/ConfigToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/ConfigToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/ConfigToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -106,7 +106,7 @@ content.addChild("br"); addHomepageLink(content); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } @@ -191,7 +191,7 @@ formNode.addChild("input", new String[] { "type", "value" }, new String[] { "submit", l10n("apply")}); formNode.addChild("input", new String[] { "type", "value" }, new String[] { "reset", l10n("reset")}); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } public String supportedMethods() { Modified: trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/ConnectionsToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -145,7 +145,7 @@ SimpleFieldSet fs = getNoderef(); StringWriter sw = new StringWriter(); fs.writeTo(sw); - this.writeReply(ctx, 200, "text/plain", "OK", sw.toString()); + this.writeTextReply(ctx, 200, "OK", sw.toString()); return; } @@ -471,7 +471,7 @@ // ignore } - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } protected abstract boolean acceptRefPosts(); Modified: trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/DarknetConnectionsToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -167,7 +167,7 @@ } } N2NTMToadlet.createN2NTMSendForm( pageNode, contentNode, ctx, peers); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if (request.isPartSet("doAction") && request.getPartAsString("action",25).equals("update_notes")) { //int hashcode = Integer.decode(request.getParam("node")).intValue(); @@ -337,7 +337,7 @@ removeForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "remove", l10n("remove") }); removeForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "forceit", l10n("forceRemove") }); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; // FIXME: maybe it breaks multi-node removing } } else { Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -318,7 +318,7 @@ } return; }else if(ks.equals("/robots.txt") && ctx.doRobots()){ - this.writeReply(ctx, 200, "text/plain", "Ok", "User-agent: *\nDisallow: /"); + this.writeTextReply(ctx, 200, "Ok", "User-agent: *\nDisallow: /"); return; }else if(ks.startsWith("/darknet/")) { //TODO: remove when obsolete MultiValueTable headers = new MultiValueTable(); @@ -354,7 +354,7 @@ errorContent.addChild("br"); addHomepageLink(errorContent); - this.writeReply(ctx, 400, "text/html", l10n("invalidKeyTitle"), pageNode.generate()); + this.writeHTMLReply(ctx, 400, l10n("invalidKeyTitle"), pageNode.generate()); return; } String requestedMimeType = httprequest.getParam("type", null); @@ -415,7 +415,7 @@ } optionList.addChild("li").addChild("a", new String[] { "href", "title" }, new String[] { "/", "FProxy home page" }, l10n("abortToHomepage")); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } else { HTMLNode pageNode = ctx.getPageMaker().getPageNode(FetchException.getShortMessage(e.mode), ctx); HTMLNode contentNode = ctx.getPageMaker().getContentNode(pageNode); @@ -463,8 +463,8 @@ option = optionList.addChild("li"); option.addChild(ctx.getPageMaker().createBackLink(ctx, l10n("goBackToPrev"))); - this.writeReply(ctx, 500 /* close enough - FIXME probably should depend on status code */, - "text/html", FetchException.getShortMessage(e.mode), pageNode.generate()); + this.writeHTMLReply(ctx, 500 /* close enough - FIXME probably should depend on status code */, + "Internal Error", pageNode.generate()); } } catch (SocketException e) { // Probably irrelevant Modified: trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/FirstTimeWizardToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -68,7 +68,7 @@ opennetDiv.addChild("input", new String[] { "type", "name", "value" }, new String[] { "radio", "enableOpennet", "false" }, L10n.getString("Toadlet.no")); opennetForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "opennetF", L10n.getString("FirstTimeWizardToadlet.continue")}); opennetForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel")}); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if(currentStep == 2) { HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("step2Title"), false, ctx); @@ -85,7 +85,7 @@ nnameForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "nnameF", L10n.getString("FirstTimeWizardToadlet.continue")}); nnameForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel")}); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if(currentStep == 3) { HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("step3Title"), false, ctx); @@ -110,7 +110,7 @@ bandwidthForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "bwF", L10n.getString("FirstTimeWizardToadlet.continue")}); bandwidthForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel")}); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if(currentStep == 4) { HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("step4Title"), false, ctx); @@ -137,7 +137,7 @@ bandwidthForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "dsF", L10n.getString("FirstTimeWizardToadlet.continue")}); bandwidthForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel")}); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if(currentStep == 5) { HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("step5Title"), false, ctx); @@ -180,7 +180,7 @@ networkForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "networkF", L10n.getString("FirstTimeWizardToadlet.continue")}); networkForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel")}); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; }else if(currentStep == 6) { HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("step6Title"), true, ctx); @@ -193,7 +193,7 @@ congratzInfoboxHeader.addChild("#", l10n("congratz")); congratzInfoboxContent.addChild("#", l10n("congratzLong")); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } @@ -212,7 +212,7 @@ HTMLNode secondParagraph = welcomeInfoboxContent.addChild("p"); secondParagraph.addChild("a", "href", "/").addChild("#", l10n("skipWizard")); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } public void handlePost(URI uri, HTTPRequest request, ToadletContext ctx) throws ToadletContextClosedException, IOException { Modified: trunk/freenet/src/freenet/clients/http/LocalFileInsertToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/LocalFileInsertToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/LocalFileInsertToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -140,7 +140,7 @@ ulNode.addChild("li", l10n("checkPathReadable")); } - writeReply(toadletContext, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + writeHTMLReply(toadletContext, 200, "OK", pageNode.generate()); } private String l10n(String key, String pattern, String value) { Modified: trunk/freenet/src/freenet/clients/http/N2NTMToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/N2NTMToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/N2NTMToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -74,14 +74,14 @@ contentNode.addChild(createPeerInfobox("infobox-error", l10n("peerNotFoundTitle"), l10n("peerNotFoundWithHash", "hash", input_hashcode_string))); - this.writeReply(ctx, 200, "text/html", "OK", pageNode + this.writeHTMLReply(ctx, 200, "OK", pageNode .generate()); return; } HashMap peers = new HashMap(); peers.put(input_hashcode_string, peernode_name); createN2NTMSendForm(pageNode, contentNode, ctx, peers); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } MultiValueTable headers = new MultiValueTable(); @@ -135,7 +135,7 @@ String message = request.getPartAsString("message", 5 * 1024); message = message.trim(); if (message.length() > 1024) { - this.writeReply(ctx, 400, "text/plain", l10n("tooLongTitle"), + this.writeTextReply(ctx, 400, "Bad request", l10n("tooLong")); return; } @@ -152,7 +152,7 @@ if(!(filename.exists() && filename.canRead())) { peerTableInfobox.addChild("#", l10n("noSuchFileOrCannotRead")); Toadlet.addHomepageLink(peerTableInfobox); - this.writeReply(ctx, 400, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 400, "OK", pageNode.generate()); return; } } @@ -173,7 +173,7 @@ } catch (IOException e) { peerTableInfobox.addChild("#", l10n("noSuchFileOrCannotRead")); Toadlet.addHomepageLink(peerTableInfobox); - this.writeReply(ctx, 400, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } } else { @@ -223,7 +223,7 @@ list.addChild("li").addChild("a", new String[] { "href", "title" }, new String[] { "/friends/", l10n("returnToFriends") }, l10n("friends")); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } MultiValueTable headers = new MultiValueTable(); Modified: trunk/freenet/src/freenet/clients/http/PluginToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/PluginToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/PluginToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -73,11 +73,11 @@ if (plugin instanceof HttpPlugin) { ((HttpPlugin) plugin).handleGet(httpRequest, ctx); } else { - writeReply(ctx, 220, "text/html; charset=utf-8", "OK", createBox(ctx, l10n("noWebInterfaceTitle"), l10n("noWebInterface")).toString()); + writeHTMLReply(ctx, 220, "OK", createBox(ctx, l10n("noWebInterfaceTitle"), l10n("noWebInterface")).toString()); } return; } - writeReply(ctx, 220, "text/html; charset=utf-8", "OK", createBox(ctx, l10n("pluginNotFoundTitle"), l10n("pluginNotFound")).toString()); + writeHTMLReply(ctx, 220, "OK", createBox(ctx, l10n("pluginNotFoundTitle"), l10n("pluginNotFound")).toString()); return; } @@ -96,10 +96,10 @@ if ("list".equals(action)) { replyBuffer.append(listPlugins(ctx)); } else { - writeReply(ctx, 220, "text/html; charset=utf-8", "OK", createBox(ctx, l10n("unsupportedMethodTitle"), l10n("unsupportedMethod")).toString()); + writeHTMLReply(ctx, 220, "OK", createBox(ctx, l10n("unsupportedMethodTitle"), l10n("unsupportedMethod")).toString()); return; } - writeReply(ctx, 220, "text/html; charset=utf-8", "OK", replyBuffer.toString()); + writeHTMLReply(ctx, 220, "OK", replyBuffer.toString()); } private String l10n(String key) { @@ -119,11 +119,11 @@ if (plugin instanceof HttpPlugin) { ((HttpPlugin) plugin).handlePost(httpRequest, ctx); } else { - writeReply(ctx, 220, "text/html; charset=utf-8", "OK", createBox(ctx, l10n("noWebInterfaceTitle"), l10n("noWebInterface")).toString()); + writeHTMLReply(ctx, 220, "OK", createBox(ctx, l10n("noWebInterfaceTitle"), l10n("noWebInterface")).toString()); } return; } - writeReply(ctx, 220, "text/html; charset=utf-8", "OK", createBox(ctx, l10n("pluginNotFoundTitle") , l10n("pluginNotFound")).toString()); + writeHTMLReply(ctx, 220, "OK", createBox(ctx, l10n("pluginNotFoundTitle") , l10n("pluginNotFound")).toString()); return; } @@ -176,7 +176,7 @@ writePermanentRedirect(ctx, l10n("pluginList"), "?action=list"); return; } - writeReply(ctx, 220, "text/html; charset=utf-8", "OK", replyBuffer.toString()); + writeHTMLReply(ctx, 220, "OK", replyBuffer.toString()); } /** Modified: trunk/freenet/src/freenet/clients/http/PproxyToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/PproxyToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/PproxyToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -80,7 +80,7 @@ plugin = path.substring(0, to); } - writeReply(ctx, 200, "text/html", "OK", pm.handleHTTPPost(plugin, request)); + writeHTMLReply(ctx, 200, "OK", pm.handleHTTPPost(plugin, request)); } catch (RedirectPluginHTTPException e) { writeTemporaryRedirect(ctx, e.message, e.newLocation); @@ -136,7 +136,7 @@ infoboxContent.addChild("#", l10n("pluginUnloadedWithName", "name", request.getPartAsString("remove", MAX_PLUGIN_NAME_LENGTH))); infoboxContent.addChild("br"); infoboxContent.addChild("a", "href", "/plugins/", l10n("returnToPluginPage")); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; }if (request.getPartAsString("unload", MAX_PLUGIN_NAME_LENGTH).length() > 0) { HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("plugins"), ctx); @@ -150,7 +150,7 @@ unloadForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel") }); unloadForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "unloadconfirm", request.getPartAsString("unload", MAX_PLUGIN_NAME_LENGTH) }); unloadForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "confirm", l10n("unload") }); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; }else if (request.getPartAsString("reload", MAX_PLUGIN_NAME_LENGTH).length() > 0) { String fn = null; @@ -221,7 +221,7 @@ // Plugin may need to know where it was accessed from, so it can e.g. produce relative URLs. //writeReply(ctx, 200, "text/html", "OK", mkPage("plugin", pm.handleHTTPGet(plugin, data))); - writeReply(ctx, 200, "text/html", "OK", pm.handleHTTPGet(plugin, request)); + writeHTMLReply(ctx, 200, "OK", pm.handleHTTPGet(plugin, request)); } //FetchResult result = fetch(key); @@ -297,7 +297,7 @@ loadDiv.addChild("#", (l10n("loadPluginLabel") + ' ')); loadDiv.addChild("input", new String[] { "type", "name", "size" }, new String[] { "text", "load", "40" }); loadDiv.addChild("input", new String[] { "type", "value" }, new String[] { "submit", "Load" }); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } } } Modified: trunk/freenet/src/freenet/clients/http/QueueToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/QueueToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/QueueToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -298,7 +298,7 @@ optionForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "forceDownload", String.valueOf(System.currentTimeMillis()) }); optionForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "get", "Download anyway" }); optionForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "return", "Return to queue page" }); - writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } } @@ -326,7 +326,7 @@ HTMLNode infoboxContent = pageMaker.getContentNode(infobox); infoboxContent.addChild("#", message); infoboxContent.addChild("div").addChildren(new HTMLNode[] { new HTMLNode("#", "Return to "), new HTMLNode("a", "href", "/queue/", "queue page"), new HTMLNode("#", ".") }); - writeReply(context, 400, "text/html; charset=utf-8", "Error", pageNode.generate()); + writeHTMLReply(context, 400, "Bad request", pageNode.generate()); } public void handleGet(URI uri, final HTTPRequest request, ToadletContext ctx) @@ -396,7 +396,7 @@ HTMLNode infoboxContent = pageMaker.getContentNode(infobox); infoboxContent.addChild("#", L10n.getString("QueueToadlet.noTaskOnGlobalQueue")); contentNode.addChild(createInsertBox(pageMaker, ctx)); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } @@ -688,7 +688,7 @@ } MultiValueTable pageHeaders = new MultiValueTable(); - this.writeReply(ctx, 200, "text/html", "OK", pageHeaders, pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageHeaders, pageNode.generate()); } Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -289,7 +289,7 @@ addNodeCircle(nodeCircleTable); } - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } private void drawRejectReasonsBox(HTMLNode nextTableCell) { Modified: trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/SymlinkerToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -118,7 +118,7 @@ // TODO redirect to errorpage if ((foundtarget == null) || (foundkey == null)) { - writeReply(ctx, 404, "text/html", L10n.getString("StaticToadlet.pathNotFoundTitle"), + writeTextReply(ctx, 404, "Not found", L10n.getString("StaticToadlet.pathNotFound")); return; } @@ -130,7 +130,7 @@ path, uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { // TODO Handle error somehow - writeReply(ctx, 200, "text/html", "OK", e.getMessage()); + writeHTMLReply(ctx, 200, "OK", e.getMessage()); return; } Modified: trunk/freenet/src/freenet/clients/http/Toadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/Toadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/Toadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -147,6 +147,22 @@ writeReply(ctx, code, mimeType, desc, null, reply); } + protected void writeHTMLReply(ToadletContext ctx, int code, String desc, String reply) throws ToadletContextClosedException, IOException { + writeReply(ctx, code, "text/html; charset=utf-8", desc, null, reply); + } + + protected void writeTextReply(ToadletContext ctx, int code, String desc, String reply) throws ToadletContextClosedException, IOException { + writeReply(ctx, code, "text/plain; charset=utf-8", desc, null, reply); + } + + protected void writeHTMLReply(ToadletContext ctx, int code, String desc, MultiValueTable headers, String reply) throws ToadletContextClosedException, IOException { + writeReply(ctx, code, "text/html; charset=utf-8", desc, headers, reply); + } + + protected void writeTextReply(ToadletContext ctx, int code, String desc, MultiValueTable headers, String reply) throws ToadletContextClosedException, IOException { + writeReply(ctx, code, "text/plain; charset=utf-8", desc, headers, reply); + } + protected void writeReply(ToadletContext context, int code, String mimeType, String desc, MultiValueTable headers, String reply) throws ToadletContextClosedException, IOException { byte[] buffer = reply.getBytes("UTF-8"); writeReply(context, code, mimeType, desc, headers, buffer, 0, buffer.length); @@ -219,7 +235,7 @@ infoboxContent.addChild("a", "href", ".", l10n("returnToPrevPage")); addHomepageLink(infoboxContent); - writeReply(ctx, code, "text/html; charset=UTF-8", desc, pageNode.generate()); + writeHTMLReply(ctx, code, desc, pageNode.generate()); } /** @@ -250,7 +266,7 @@ infoboxContent.addChild("a", "href", ".", l10n("returnToPrevPage")); addHomepageLink(infoboxContent); - writeReply(ctx, 500, "text/html; charset=UTF-8", desc, pageNode.generate()); + writeHTMLReply(ctx, 500, desc, pageNode.generate()); } protected void writeInternalError(Throwable t, ToadletContext ctx) throws ToadletContextClosedException, IOException { @@ -262,7 +278,7 @@ t.printStackTrace(pw); pw.flush(); msg = msg + sw.toString() + ""; - writeReply(ctx, 500, "text/html", "Internal Error", msg); + writeHTMLReply(ctx, 500, "Internal Error", msg); } protected static void addHomepageLink(HTMLNode content) { Modified: trunk/freenet/src/freenet/clients/http/TranslationToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/TranslationToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/TranslationToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -83,7 +83,7 @@ footer.addChild("%", "  "); footer.addChild("a", "href", TOADLET_URL + (showEverything ? "" : "?toTranslateOnly")).addChild("#", l10n("returnToTranslations")); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if (request.isParameterSet("translate")) { String key = request.getParam("translate"); @@ -126,7 +126,7 @@ updateForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", "toTranslateOnly", key }); updateForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel") }); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if (request.isParameterSet("remove")) { String key = request.getParam("remove"); @@ -145,7 +145,7 @@ removeForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "remove_confirmed", l10n("remove") }); removeForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel") }); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } @@ -188,7 +188,7 @@ } } - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } public void handlePost(URI uri, HTTPRequest request, ToadletContext ctx) throws ToadletContextClosedException, IOException { Modified: trunk/freenet/src/freenet/clients/http/TrivialToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/TrivialToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/TrivialToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -19,7 +19,7 @@ String reply = "You requested "+encFetched+ "You fetched "+ encFetched+"."; - this.writeReply(ctx, 200, "text/html", "OK", reply); + this.writeHTMLReply(ctx, 200, "OK", reply); } public String supportedMethods() { Modified: trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2007-08-06 22:02:15 UTC (rev 14497) +++ trunk/freenet/src/freenet/clients/http/WelcomeToadlet.java 2007-08-06 22:25:34 UTC (rev 14498) @@ -109,7 +109,7 @@ HTMLNode content = ctx.getPageMaker().getContentNode(infobox); content.addChild("p").addChild("#", l10n("updating")); content.addChild("p").addChild("#", l10n("thanks")); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); Logger.normal(this, "Node is updating/restarting"); node.getNodeUpdater().arm(); }else if (request.getPartAsString(GenericReadFilterCallback.magicHTTPEscapeString, MAX_URL_LENGTH).length()>0){ @@ -132,7 +132,7 @@ HTMLNode updateForm = ctx.addFormChild(content, "/", "updateConfirmForm"); updateForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel")}); updateForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "updateconfirm", l10n("update") }); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); }else if(request.isPartSet("getThreadDump")) { if(noPassword) { redirectToRoot(ctx); @@ -149,7 +149,7 @@ HTMLNode infobox = contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-error",l10n("threadDumpSubTitle"))); ctx.getPageMaker().getContentNode(infobox).addChild("#", l10n("threadDumpNotUsingWrapper")); } - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); }else if(request.isPartSet("getJEStatsDump")) { if(noPassword) { redirectToRoot(ctx); @@ -164,7 +164,7 @@ System.out.println(">>>>>>>>>>>>>>>>>>>>>>> END DATABASE STATS <<<<<<<<<<<<<<<<<<<<<<<"); ctx.getPageMaker().getContentNode(infobox).addChild("#", l10n("writtenDatabaseStats")); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); }else if(request.isPartSet("disable")){ if(noPassword) { redirectToRoot(ctx); @@ -239,7 +239,7 @@ postForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel") }); postForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "finconfirm", l10n("post") }); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } @@ -282,7 +282,7 @@ content.addChild("br"); addHomepageLink(content); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); request.freeParts(); }else if(request.isPartSet("key")&&request.isPartSet("filename")){ if(noPassword) { @@ -335,7 +335,7 @@ content.addChild("br"); addHomepageLink(content); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); request.freeParts(); bucket.free(); }else if (request.isPartSet("shutdownconfirm")) { @@ -413,7 +413,7 @@ while((read = reader.read(buffer)) != -1) sw.write(buffer, 0, read); - this.writeReply(ctx, 200, "text/plain", "OK", sw.toString()); + this.writeHTMLReply(ctx, 200, "OK", sw.toString()); return; } else if (request.isParameterSet("terminated")) { if((!request.isParameterSet("formPassword")) || !request.getParam("formPassword").equals(core.formPassword)) { @@ -426,7 +426,7 @@ HTMLNode infobox = contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-information", l10n("shutdownDone"))); HTMLNode infoboxContent = ctx.getPageMaker().getContentNode(infobox); infoboxContent.addChild("#", l10n("thanks")); - this.writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if (request.isParameterSet("restarted")) { if((!request.isParameterSet("formPassword")) || !request.getParam("formPassword").equals(core.formPassword)) { @@ -439,7 +439,7 @@ HTMLNode infobox = contentNode.addChild(ctx.getPageMaker().getInfobox("infobox-information", l10n("restartingTitle"))); HTMLNode infoboxContent = ctx.getPageMaker().getContentNode(infobox); infoboxContent.addChild("#", l10n("restarting")); - writeReply(ctx, 200, "text/html; charset=utf-8", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); Logger.normal(this, "Node is restarting"); return; } else if (request.getParam("newbookmark").length() > 0) { @@ -457,7 +457,7 @@ addForm.addChild("input", new String[] {"type", "name", "value"}, new String[] {"hidden", "bookmark", "/"}); addForm.addChild("input", new String[] {"type", "name", "value"}, new String[] {"hidden", "action", "addItem"}); addForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "addbookmark", L10n.getString("BookmarkEditorToadlet.addBookmark") }); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if (request.getParam(GenericReadFilterCallback.magicHTTPEscapeString).length() > 0) { HTMLNode pageNode = ctx.getPageMaker().getPageNode( l10n("confirmExternalLinkTitle"), ctx); @@ -471,7 +471,7 @@ externalLinkForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "hidden", GenericReadFilterCallback.magicHTTPEscapeString, target }); externalLinkForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel") }); externalLinkForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "Go", l10n("goToExternalLink") }); - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } else if (request.isParameterSet("exit")) { HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("shutdownConfirmTitle"), ctx); @@ -482,7 +482,7 @@ HTMLNode shutdownForm = ctx.addFormChild(content.addChild("p"), "/", "confirmShutdownForm"); shutdownForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel") }); shutdownForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "shutdownconfirm", l10n("shutdown") }); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; }else if (request.isParameterSet("restart")) { HTMLNode pageNode = ctx.getPageMaker().getPageNode(l10n("restartConfirmTitle"), ctx); @@ -493,7 +493,7 @@ HTMLNode restartForm = ctx.addFormChild(content.addChild("p"), "/", "confirmRestartForm"); restartForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "cancel", L10n.getString("Toadlet.cancel") }); restartForm.addChild("input", new String[] { "type", "name", "value" }, new String[] { "submit", "restartconfirm", l10n("restart") }); - writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + writeHTMLReply(ctx, 200, "OK", pageNode.generate()); return; } } @@ -584,7 +584,7 @@ activityList.addChild("li", l10n("arkFetchCount", "total", Integer.toString(node.getNumARKFetchers()))); } - this.writeReply(ctx, 200, "text/html", "OK", pageNode.generate()); + this.writeHTMLReply(ctx, 200, "OK", pageNode.generate()); } public String supportedMethods() { From toad at freenetproject.org Mon Aug 6 23:50:29 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Mon, 6 Aug 2007 23:50:29 +0000 (UTC) Subject: [freenet-cvs] r14499 - trunk/freenet/src/freenet/node Message-ID: <20070806235029.60053479940@freenetproject.org> Author: toad Date: 2007-08-06 23:50:28 +0000 (Mon, 06 Aug 2007) New Revision: 14499 Modified: trunk/freenet/src/freenet/node/RequestHandler.java Log: If it's an opennet peer, we want to pass a ref to it anyway! Modified: trunk/freenet/src/freenet/node/RequestHandler.java =================================================================== --- trunk/freenet/src/freenet/node/RequestHandler.java 2007-08-06 22:25:34 UTC (rev 14498) +++ trunk/freenet/src/freenet/node/RequestHandler.java 2007-08-06 23:50:28 UTC (rev 14499) @@ -260,7 +260,7 @@ } private void finishOpennet(RequestSender rs) { - if(!node.passOpennetRefsThroughDarknet()) return; + if(!(node.passOpennetRefsThroughDarknet() || source.isOpennet())) return; byte[] noderef = rs.waitForOpennetNoderef(); if(noderef == null) { finishOpennetNoRelay(); From sback at freenetproject.org Tue Aug 7 06:46:18 2007 From: sback at freenetproject.org (sback at freenetproject.org) Date: Tue, 7 Aug 2007 06:46:18 +0000 (UTC) Subject: [freenet-cvs] r14500 - trunk/freenet/src/freenet/support Message-ID: <20070807064618.0C8064797E7@freenetproject.org> Author: sback Date: 2007-08-07 06:46:17 +0000 (Tue, 07 Aug 2007) New Revision: 14500 Modified: trunk/freenet/src/freenet/support/HTMLNode.java Log: Removed bugous and not used method. Made "attributes" private Modified: trunk/freenet/src/freenet/support/HTMLNode.java =================================================================== --- trunk/freenet/src/freenet/support/HTMLNode.java 2007-08-06 23:50:28 UTC (rev 14499) +++ trunk/freenet/src/freenet/support/HTMLNode.java 2007-08-07 06:46:17 UTC (rev 14500) @@ -15,7 +15,7 @@ private final String content; - protected final Map attributes = new HashMap(); + private final Map attributes = new HashMap(); protected final List children = new ArrayList(); @@ -75,10 +75,6 @@ return content; } - public void addAttribute(String attributeName) { - addAttribute(attributeName, attributeName); - } - public void addAttribute(String attributeName, String attributeValue) { attributes.put(attributeName, attributeValue); } From jflesch at freenetproject.org Tue Aug 7 13:54:38 2007 From: jflesch at freenetproject.org (jflesch at freenetproject.org) Date: Tue, 7 Aug 2007 13:54:38 +0000 (UTC) Subject: [freenet-cvs] r14504 - trunk/freenet/src/freenet/clients/http Message-ID: <20070807135438.DEA5147A699@freenetproject.org> Author: jflesch Date: 2007-08-07 13:54:38 +0000 (Tue, 07 Aug 2007) New Revision: 14504 Modified: trunk/freenet/src/freenet/clients/http/PluginToadlet.java trunk/freenet/src/freenet/clients/http/PproxyToadlet.java Log: Revert r14443 : It prevents to load plugins who are already in the classpath of the node Modified: trunk/freenet/src/freenet/clients/http/PluginToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/PluginToadlet.java 2007-08-07 13:04:30 UTC (rev 14503) +++ trunk/freenet/src/freenet/clients/http/PluginToadlet.java 2007-08-07 13:54:38 UTC (rev 14504) @@ -149,6 +149,7 @@ StringBuffer replyBuffer = new StringBuffer(); if ("add".equals(action)) { pluginName = httpRequest.getPartAsString("pluginName", MAX_PLUGIN_NAME_LENGTH); + boolean added = false; try { pluginManager.addPlugin(pluginName, true); Modified: trunk/freenet/src/freenet/clients/http/PproxyToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/PproxyToadlet.java 2007-08-07 13:04:30 UTC (rev 14503) +++ trunk/freenet/src/freenet/clients/http/PproxyToadlet.java 2007-08-07 13:54:38 UTC (rev 14504) @@ -113,10 +113,7 @@ if (request.isPartSet("load")) { if(Logger.shouldLog(Logger.MINOR, this)) Logger.minor(this, "Loading "+request.getPartAsString("load", MAX_PLUGIN_NAME_LENGTH)); - String toLoad = request.getPartAsString("load", MAX_PLUGIN_NAME_LENGTH); - if (toLoad.indexOf("@") < 0) - toLoad = "*@file://"+toLoad; - pm.startPlugin(toLoad, true); + pm.startPlugin(request.getPartAsString("load", MAX_PLUGIN_NAME_LENGTH), true); //writeReply(ctx, 200, "text/html", "OK", mkForwardPage("Loading plugin", "Loading plugin...", ".", 5)); headers.put("Location", "."); From toad at freenetproject.org Tue Aug 7 15:04:07 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Tue, 7 Aug 2007 15:04:07 +0000 (UTC) Subject: [freenet-cvs] r14505 - in trunk/freenet/src/freenet: clients/http node Message-ID: <20070807150407.4527647AAE7@freenetproject.org> Author: toad Date: 2007-08-07 15:04:06 +0000 (Tue, 07 Aug 2007) New Revision: 14505 Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java trunk/freenet/src/freenet/node/CHKInsertSender.java trunk/freenet/src/freenet/node/FailureTableEntry.java trunk/freenet/src/freenet/node/InsertHandler.java trunk/freenet/src/freenet/node/Location.java trunk/freenet/src/freenet/node/LocationManager.java trunk/freenet/src/freenet/node/NodeDispatcher.java trunk/freenet/src/freenet/node/PeerManager.java trunk/freenet/src/freenet/node/RequestHandler.java trunk/freenet/src/freenet/node/RequestSender.java trunk/freenet/src/freenet/node/SSKInsertHandler.java trunk/freenet/src/freenet/node/SSKInsertSender.java Log: Move distance(...) from PeerManager to Location Modified: trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/clients/http/StatisticsToadlet.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -17,6 +17,7 @@ import freenet.io.comm.IOStatisticCollector; import freenet.l10n.L10n; import freenet.node.DarknetPeerNodeStatus; +import freenet.node.Location; import freenet.node.Node; import freenet.node.NodeClientCore; import freenet.node.NodeStarter; @@ -871,7 +872,7 @@ for (int peerIndex = 0; peerIndex < peerCount; peerIndex++) { peerNodeStatus = peerNodeStatuses[peerIndex]; peerLocation = peerNodeStatus.getLocation(); - peerDistance = PeerManager.distance( myLocation, peerLocation ); + peerDistance = Location.distance( myLocation, peerLocation ); histogramIndex = (int) (Math.floor(peerDistance * HISTOGRAM_LENGTH * 2)); if (peerNodeStatus.isConnected()) { histogramConnected[histogramIndex]++; Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java =================================================================== --- trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -263,7 +263,7 @@ Message req; synchronized (this) { - if(PeerManager.distance(target, nextValue) > PeerManager.distance(target, closestLocation)) { + if(Location.distance(target, nextValue) > Location.distance(target, closestLocation)) { if(logMINOR) Logger.minor(this, "Backtracking: target="+target+" next="+nextValue+" closest="+closestLocation); htl = node.decrementHTL(source, htl); } Modified: trunk/freenet/src/freenet/node/FailureTableEntry.java =================================================================== --- trunk/freenet/src/freenet/node/FailureTableEntry.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/FailureTableEntry.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -271,7 +271,7 @@ PeerNode pn = (PeerNode) requestedNodes[i].get(); if(pn == null) continue; if(!(pn.isRoutable() && pn.isRoutingBackedOff())) continue; - double diff = PeerManager.distance(key.toNormalizedDouble(), requestedLocs[i]); + double diff = Location.distance(key.toNormalizedDouble(), requestedLocs[i]); if(diff < bestDiff) bestDiff = diff; } return bestDiff; Modified: trunk/freenet/src/freenet/node/InsertHandler.java =================================================================== --- trunk/freenet/src/freenet/node/InsertHandler.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/InsertHandler.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -58,7 +58,7 @@ closestLoc = req.getDouble(DMT.NEAREST_LOCATION); double targetLoc = key.toNormalizedDouble(); double myLoc = node.lm.getLocation().getValue(); - if(PeerManager.distance(targetLoc, myLoc) < PeerManager.distance(targetLoc, closestLoc)) { + if(Location.distance(targetLoc, myLoc) < Location.distance(targetLoc, closestLoc)) { closestLoc = myLoc; htl = node.maxHTL(); } Modified: trunk/freenet/src/freenet/node/Location.java =================================================================== --- trunk/freenet/src/freenet/node/Location.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/Location.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -4,6 +4,7 @@ package freenet.node; import freenet.crypt.RandomSource; +import freenet.support.Logger; /** * @author amphibian @@ -63,4 +64,28 @@ public synchronized void randomize(RandomSource r) { setValue(r.nextDouble()); } + + static double distance(PeerNode p, double loc) { + double d = distance(p.getLocation().getValue(), loc); + return d; + //return d * p.getBias(); + } + + /** + * Distance between two locations. + * Both parameters must be in [0.0, 1.0]. + */ + public static double distance(double a, double b) { + return distance(a, b, false); + } + + public static double distance(double a, double b, boolean allowCrazy) { + if(((a < 0.0 || a > 1.0)||(b < 0.0 || b > 1.0)) && !allowCrazy) { + Logger.error(PeerManager.class, "Invalid Location ! a = "+a +" b = "+ b + "Please report this bug!", new Exception("error")); + throw new NullPointerException(); + } + // Circular keyspace + if (a > b) return Math.min (a - b, 1.0 - a + b); + else return Math.min (b - a, 1.0 - b + a); + } } Modified: trunk/freenet/src/freenet/node/LocationManager.java =================================================================== --- trunk/freenet/src/freenet/node/LocationManager.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/LocationManager.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -640,22 +640,22 @@ double A = 1.0; for(int i=0;i Double.MIN_VALUE * 2) @@ -707,8 +707,8 @@ public int compare(Object arg0, Object arg1) { double d0 = ((Double) arg0).doubleValue(); double d1 = ((Double) arg1).doubleValue(); - double dist0 = PeerManager.distance(d0, target, true); - double dist1 = PeerManager.distance(d1, target, true); + double dist0 = Location.distance(d0, target, true); + double dist1 = Location.distance(d1, target, true); if(dist0 < dist1) return -1; // best at the beginning if(dist0 > dist1) return 1; return 0; // should not happen @@ -871,8 +871,8 @@ public int compare(Object arg0, Object arg1) { double d0 = ((Double) arg0).doubleValue(); double d1 = ((Double) arg1).doubleValue(); - double dist0 = PeerManager.distance(d0, target, true); - double dist1 = PeerManager.distance(d1, target, true); + double dist0 = Location.distance(d0, target, true); + double dist1 = Location.distance(d1, target, true); if(dist0 < dist1) return -1; // best at the beginning if(dist0 > dist1) return 1; return 0; // should not happen @@ -883,7 +883,7 @@ for(int i=0;i furthestDist) { furthestDist = dist; } Modified: trunk/freenet/src/freenet/node/PeerManager.java =================================================================== --- trunk/freenet/src/freenet/node/PeerManager.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/PeerManager.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -516,7 +516,7 @@ double peerloc = p.getLocation().getValue(); if(Math.abs(peerloc - ignoreLoc) < Double.MIN_VALUE*2) continue; - double diff = distance(peerloc, loc); + double diff = Location.distance(peerloc, loc); if(diff < bestDiff) { foundOne = true; bestDiff = diff; @@ -531,7 +531,7 @@ double peerloc = p.getLocation().getValue(); if(Math.abs(peerloc - ignoreLoc) < Double.MIN_VALUE*2) continue; - double diff = distance(peerloc, loc); + double diff = Location.distance(peerloc, loc); if(diff < bestDiff) { foundOne = true; bestDiff = diff; @@ -544,40 +544,16 @@ public boolean isCloserLocation(double loc) { double nodeLoc = node.lm.getLocation().getValue(); - double nodeDist = distance(nodeLoc, loc); + double nodeDist = Location.distance(nodeLoc, loc); double closest = closestPeerLocation(loc, nodeLoc); if(closest > 1.0) { // No peers found return false; } - double closestDist = distance(closest, loc); + double closestDist = Location.distance(closest, loc); return closestDist < nodeDist; } - static double distance(PeerNode p, double loc) { - double d = distance(p.getLocation().getValue(), loc); - return d; - //return d * p.getBias(); - } - - /** - * Distance between two locations. - * Both parameters must be in [0.0, 1.0]. - */ - public static double distance(double a, double b) { - return distance(a, b, false); - } - - public static double distance(double a, double b, boolean allowCrazy) { - if(((a < 0.0 || a > 1.0)||(b < 0.0 || b > 1.0)) && !allowCrazy) { - Logger.error(PeerManager.class, "Invalid Location ! a = "+a +" b = "+ b + "Please report this bug!", new Exception("error")); - throw new NullPointerException(); - } - // Circular keyspace - if (a > b) return Math.min (a - b, 1.0 - a + b); - else return Math.min (b - a, 1.0 - b + a); - } - public PeerNode closerPeer(PeerNode pn, Set routedTo, Set notIgnored, double loc, boolean ignoreSelf, boolean calculateMisrouting, int minVersion, Vector addUnpickedLocsTo) { return closerPeer(pn, routedTo, notIgnored, loc, ignoreSelf, calculateMisrouting, minVersion, addUnpickedLocsTo, 2.0); } @@ -593,7 +569,7 @@ if (calculateMisrouting) { PeerNode nbo = _closerPeer(pn, routedTo, notIgnored, loc, ignoreSelf, true, minVersion, null, maxDistance); if(nbo != null) { - node.nodeStats.routingMissDistance.report(distance(best, nbo.getLocation().getValue())); + node.nodeStats.routingMissDistance.report(Location.distance(best, nbo.getLocation().getValue())); int numberOfConnected = getPeerNodeStatusSize(PEER_NODE_STATUS_CONNECTED); int numberOfRoutingBackedOff = getPeerNodeStatusSize(PEER_NODE_STATUS_ROUTING_BACKED_OFF); if (numberOfRoutingBackedOff + numberOfConnected > 0 ) { @@ -627,7 +603,7 @@ double bestDiff = Double.MAX_VALUE; double maxDiff = 0.0; if(!ignoreSelf) - maxDiff = distance(node.lm.getLocation().getValue(), target); + maxDiff = Location.distance(node.lm.getLocation().getValue(), target); PeerNode best = null; double bestLoc = -2; int count = 0; @@ -654,9 +630,9 @@ continue; } count++; - double diff = distance(p, target); + double diff = Location.distance(p, target); if(diff > maxDistance) continue; - if(logMINOR) Logger.minor(this, "p.loc="+p.getLocation().getValue()+", target="+target+", d="+distance(p.getLocation().getValue(), target)+" usedD="+diff+" for "+p.getPeer()); + if(logMINOR) Logger.minor(this, "p.loc="+p.getLocation().getValue()+", target="+target+", d="+Location.distance(p.getLocation().getValue(), target)+" usedD="+diff+" for "+p.getPeer()); if((!ignoreSelf) && (diff > maxDiff)) { if(logMINOR) Logger.minor(this, "Ignoring because >maxDiff="+maxDiff); continue; Modified: trunk/freenet/src/freenet/node/RequestHandler.java =================================================================== --- trunk/freenet/src/freenet/node/RequestHandler.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/RequestHandler.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -57,7 +57,7 @@ double myLoc = n.lm.getLocation().getValue(); key = (Key) req.getObject(DMT.FREENET_ROUTING_KEY); double keyLoc = key.toNormalizedDouble(); - if(PeerManager.distance(keyLoc, myLoc) < PeerManager.distance(keyLoc, closestLoc)) { + if(Location.distance(keyLoc, myLoc) < Location.distance(keyLoc, closestLoc)) { closestLoc = myLoc; htl = node.maxHTL(); resetClosestLoc = true; Modified: trunk/freenet/src/freenet/node/RequestSender.java =================================================================== --- trunk/freenet/src/freenet/node/RequestSender.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/RequestSender.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -154,7 +154,7 @@ if(logMINOR) Logger.minor(this, "Routing request to "+next); nodesRoutedTo.add(next); - if(PeerManager.distance(target, nextValue) > PeerManager.distance(target, nearestLoc)) { + if(Location.distance(target, nextValue) > Location.distance(target, nearestLoc)) { htl = node.decrementHTL(source, htl); if(logMINOR) Logger.minor(this, "Backtracking: target="+target+" next="+nextValue+" closest="+nearestLoc+" so htl="+htl); } Modified: trunk/freenet/src/freenet/node/SSKInsertHandler.java =================================================================== --- trunk/freenet/src/freenet/node/SSKInsertHandler.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/SSKInsertHandler.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -56,7 +56,7 @@ closestLoc = req.getDouble(DMT.NEAREST_LOCATION); double targetLoc = key.toNormalizedDouble(); double myLoc = node.lm.getLocation().getValue(); - if(PeerManager.distance(targetLoc, myLoc) < PeerManager.distance(targetLoc, closestLoc)) { + if(Location.distance(targetLoc, myLoc) < Location.distance(targetLoc, closestLoc)) { closestLoc = myLoc; htl = node.maxHTL(); resetClosestLoc = true; Modified: trunk/freenet/src/freenet/node/SSKInsertSender.java =================================================================== --- trunk/freenet/src/freenet/node/SSKInsertSender.java 2007-08-07 13:54:38 UTC (rev 14504) +++ trunk/freenet/src/freenet/node/SSKInsertSender.java 2007-08-07 15:04:06 UTC (rev 14505) @@ -152,7 +152,7 @@ if(logMINOR) Logger.minor(this, "Routing insert to "+next); nodesRoutedTo.add(next); - if(PeerManager.distance(target, nextValue) > PeerManager.distance(target, closestLocation)) { + if(Location.distance(target, nextValue) > Location.distance(target, closestLocation)) { if(logMINOR) Logger.minor(this, "Backtracking: target="+target+" next="+nextValue+" closest="+closestLocation); htl = node.decrementHTL(source, htl); } From toad at freenetproject.org Tue Aug 7 15:35:39 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Tue, 7 Aug 2007 15:35:39 +0000 (UTC) Subject: [freenet-cvs] r14506 - trunk/freenet/src/freenet/node Message-ID: <20070807153539.0F18E47A209@freenetproject.org> Author: toad Date: 2007-08-07 15:35:38 +0000 (Tue, 07 Aug 2007) New Revision: 14506 Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java trunk/freenet/src/freenet/node/FailureTableEntry.java trunk/freenet/src/freenet/node/InsertHandler.java trunk/freenet/src/freenet/node/Location.java trunk/freenet/src/freenet/node/LocationManager.java trunk/freenet/src/freenet/node/Node.java trunk/freenet/src/freenet/node/NodeCrypto.java trunk/freenet/src/freenet/node/NodeDispatcher.java trunk/freenet/src/freenet/node/PeerManager.java trunk/freenet/src/freenet/node/PeerNode.java trunk/freenet/src/freenet/node/PeerNodeStatus.java trunk/freenet/src/freenet/node/RequestHandler.java trunk/freenet/src/freenet/node/RequestSender.java trunk/freenet/src/freenet/node/SSKInsertHandler.java trunk/freenet/src/freenet/node/SSKInsertSender.java Log: Refactor: Don't use Location objects, just use double's for locations. Keep some utility methods on Location. Modified: trunk/freenet/src/freenet/node/CHKInsertSender.java =================================================================== --- trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/CHKInsertSender.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -249,7 +249,7 @@ double nextValue; next = node.peers.closerPeer(source, nodesRoutedTo, nodesNotIgnored, target, true, node.isAdvancedModeEnabled(), -1, null); if(next != null) - nextValue = next.getLocation().getValue(); + nextValue = next.getLocation(); else nextValue = -1.0; Modified: trunk/freenet/src/freenet/node/FailureTableEntry.java =================================================================== --- trunk/freenet/src/freenet/node/FailureTableEntry.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/FailureTableEntry.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -55,7 +55,7 @@ requestorBootIDs[i] = requestors[i].getBootID(); } requestedNodes = new WeakReference[] { requested.myRef }; - requestedLocs = new double[] { requested.getLocation().getValue() }; + requestedLocs = new double[] { requested.getLocation() }; requestedBootIDs = new long[] { requested.getBootID() }; } @@ -188,7 +188,7 @@ if(got == req) { // Update existing entry requestorIncluded = true; - requestedLocs[j] = req.getLocation().getValue(); + requestedLocs[j] = req.getLocation(); requestedBootIDs[j] = req.getBootID(); requestedTimes[j] = now; break; @@ -209,7 +209,7 @@ if(requestedNodes[i] == null || requestedNodes[i].get() == null) { PeerNode pn = requestedFrom[x++]; requestedNodes[i] = pn.myRef; - requestedLocs[i] = pn.getLocation().getValue(); + requestedLocs[i] = pn.getLocation(); requestedTimes[i] = now; if(x == ptr) break; } @@ -238,7 +238,7 @@ newRequestedNodes[toIndex] = pn.myRef; newRequestedTimes[toIndex] = now; newRequestedBootIDs[toIndex] = pn.getBootID(); - newRequestedLocs[toIndex] = pn.getLocation().getValue(); + newRequestedLocs[toIndex] = pn.getLocation(); toIndex++; } } Modified: trunk/freenet/src/freenet/node/InsertHandler.java =================================================================== --- trunk/freenet/src/freenet/node/InsertHandler.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/InsertHandler.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -57,7 +57,7 @@ htl = req.getShort(DMT.HTL); closestLoc = req.getDouble(DMT.NEAREST_LOCATION); double targetLoc = key.toNormalizedDouble(); - double myLoc = node.lm.getLocation().getValue(); + double myLoc = node.lm.getLocation(); if(Location.distance(targetLoc, myLoc) < Location.distance(targetLoc, closestLoc)) { closestLoc = myLoc; htl = node.maxHTL(); Modified: trunk/freenet/src/freenet/node/Location.java =================================================================== --- trunk/freenet/src/freenet/node/Location.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/Location.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -13,60 +13,20 @@ * Simply a number from 0.0 to 1.0. */ public class Location { - private double loc; - private int hashCode; - - private Location(double location) { - setValue(location); - } - public Location(String init) throws FSParseException { - try { - setValue(Double.parseDouble(init)); - } catch (NumberFormatException e) { - throw new FSParseException(e); - } - } - - public double getValue() { - return loc; - } - - /** - * @return A random Location to initialize the node to. - */ - public static Location randomInitialLocation(RandomSource r) { - return new Location(r.nextDouble()); - } - - public void setValue(double newLoc) { - if((loc < 0.0) || (loc > 1.0)) - throw new IllegalArgumentException(); - this.loc = newLoc; - long l = Double.doubleToLongBits(newLoc); - hashCode = ((int)(l >>> 32)) ^ ((int)l); - } - - public boolean equals(Object o) { - if(o instanceof Location) { - return Math.abs(((Location)o).loc - loc) <= Double.MIN_VALUE; - } - return false; - } - - public int hashCode() { - return hashCode; - } - - /** - * Randomize the location. - */ - public synchronized void randomize(RandomSource r) { - setValue(r.nextDouble()); - } - + public static double getLocation(String init) throws FSParseException { + try { + if(init == null) throw new FSParseException("Null location"); + double d = Double.parseDouble(init); + if(d < 0.0 || d > 1.0) throw new FSParseException("Invalid location "+d); + return d; + } catch (NumberFormatException e) { + throw new FSParseException(e); + } + } + static double distance(PeerNode p, double loc) { - double d = distance(p.getLocation().getValue(), loc); + double d = distance(p.getLocation(), loc); return d; //return d * p.getBias(); } @@ -88,4 +48,8 @@ if (a > b) return Math.min (a - b, 1.0 - a + b); else return Math.min (b - a, 1.0 - b + a); } + + public static boolean equals(double newLoc, double currentLocation) { + return Math.abs(newLoc - currentLocation) < Double.MIN_VALUE * 2; + } } Modified: trunk/freenet/src/freenet/node/LocationManager.java =================================================================== --- trunk/freenet/src/freenet/node/LocationManager.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/LocationManager.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -57,14 +57,14 @@ long timeLastSuccessfullySwapped; public LocationManager(RandomSource r) { - loc = Location.randomInitialLocation(r); + loc = r.nextDouble(); sender = new SwapRequestSender(); this.r = r; recentlyForwardedIDs = new Hashtable(); logMINOR = Logger.shouldLog(Logger.MINOR, this); } - Location loc; + double loc; double locChangeSession = 0.0; int numberOfRemotePeerLocationsSeenInSwaps = 0; @@ -72,19 +72,23 @@ /** * @return The current Location of this node. */ - public Location getLocation() { + public double getLocation() { return loc; } /** * @param l */ - public void setLocation(Location l) { + public void setLocation(double l) { + if(l < 0.0 || l > 1.0) { + Logger.error(this, "Setting invalid location: "+l, new Exception("error")); + return; + } this.loc = l; } public void updateLocationChangeSession(double newLoc) { - double oldLoc = this.loc.getValue(); + double oldLoc = loc; // Patterned after PeerManager.distance( double, double ), but also need to know the direction of the change if (newLoc > oldLoc) { double directDifference = newLoc - oldLoc; @@ -154,12 +158,12 @@ if(System.currentTimeMillis() - timeLastSuccessfullySwapped > 30*1000) { try { boolean myFlag = false; - double myLoc = loc.getValue(); + double myLoc = loc; PeerNode[] peers = node.peers.connectedPeers; for(int i=0;i "+hisLoc+" - "+uid); swaps++; announceLocChange(); @@ -376,7 +380,7 @@ // We can't lock friends_locations, so lets just // pretend that they're locked long random = r.nextLong(); - double myLoc = loc.getValue(); + double myLoc = loc; LocationUIDPair[] friendLocsAndUIDs = node.peers.getPeerLocationsAndUIDs(); double[] friendLocs = extractLocs(friendLocsAndUIDs); long[] myValueLong = new long[1+1+friendLocs.length]; @@ -518,7 +522,7 @@ timeLastSuccessfullySwapped = System.currentTimeMillis(); // Swap updateLocationChangeSession(hisLoc); - loc.setValue(hisLoc); + setLocation(hisLoc); if(logMINOR) Logger.minor(this, "Swapped: "+myLoc+" <-> "+hisLoc+" - "+uid); swaps++; announceLocChange(); @@ -542,7 +546,7 @@ * Tell all connected peers that our location has changed */ private void announceLocChange() { - Message msg = DMT.createFNPLocChangeNotification(loc.getValue()); + Message msg = DMT.createFNPLocChangeNotification(loc); node.peers.localBroadcast(msg, false); } @@ -1126,7 +1130,7 @@ public static double[] extractLocs(PeerNode[] peers, boolean indicateBackoff) { double[] locs = new double[peers.length]; for(int i=0;i originated locally, keep full htl double target = m.getDouble(DMT.TARGET_LOCATION); if(logMINOR) Logger.minor(this, "id "+id+" from "+pn+" htl "+htl+" target "+target); - if(Math.abs(node.lm.getLocation().getValue() - target) <= Double.MIN_VALUE) { + if(Math.abs(node.lm.getLocation() - target) <= Double.MIN_VALUE) { if(logMINOR) Logger.minor(this, "Dispatching "+m.getSpec()+" on "+node.getDarknetPortNumber()); // Handle locally // Message type specific processing @@ -633,7 +633,7 @@ best = ctx.best; for(int i=0;i 1.0) { @@ -569,7 +569,7 @@ if (calculateMisrouting) { PeerNode nbo = _closerPeer(pn, routedTo, notIgnored, loc, ignoreSelf, true, minVersion, null, maxDistance); if(nbo != null) { - node.nodeStats.routingMissDistance.report(Location.distance(best, nbo.getLocation().getValue())); + node.nodeStats.routingMissDistance.report(Location.distance(best, nbo.getLocation())); int numberOfConnected = getPeerNodeStatusSize(PEER_NODE_STATUS_CONNECTED); int numberOfRoutingBackedOff = getPeerNodeStatusSize(PEER_NODE_STATUS_ROUTING_BACKED_OFF); if (numberOfRoutingBackedOff + numberOfConnected > 0 ) { @@ -603,7 +603,7 @@ double bestDiff = Double.MAX_VALUE; double maxDiff = 0.0; if(!ignoreSelf) - maxDiff = Location.distance(node.lm.getLocation().getValue(), target); + maxDiff = Location.distance(node.lm.getLocation(), target); PeerNode best = null; double bestLoc = -2; int count = 0; @@ -632,17 +632,17 @@ count++; double diff = Location.distance(p, target); if(diff > maxDistance) continue; - if(logMINOR) Logger.minor(this, "p.loc="+p.getLocation().getValue()+", target="+target+", d="+Location.distance(p.getLocation().getValue(), target)+" usedD="+diff+" for "+p.getPeer()); + if(logMINOR) Logger.minor(this, "p.loc="+p.getLocation()+", target="+target+", d="+Location.distance(p.getLocation(), target)+" usedD="+diff+" for "+p.getPeer()); if((!ignoreSelf) && (diff > maxDiff)) { if(logMINOR) Logger.minor(this, "Ignoring because >maxDiff="+maxDiff); continue; } - double loc = p.getLocation().getValue(); + double loc = p.getLocation(); if(diff < bestDiff) { bestLoc = loc; best = p; bestDiff = diff; - if(logMINOR) Logger.minor(this, "New best: "+diff+" ("+p.getLocation().getValue()+" for "+p.getPeer()); + if(logMINOR) Logger.minor(this, "New best: "+diff+" ("+p.getLocation()+" for "+p.getPeer()); } if(addUnpickedLocsTo != null) { Double d = new Double(loc); Modified: trunk/freenet/src/freenet/node/PeerNode.java =================================================================== --- trunk/freenet/src/freenet/node/PeerNode.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/PeerNode.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -151,7 +151,7 @@ private static final int MAX_HANDSHAKE_COUNT = 2; /** Current location in the keyspace */ - private Location currentLocation; + private double currentLocation; /** Node identity; for now a block of data, in future a * public key (FIXME). Cannot be changed. @@ -340,8 +340,7 @@ version = fs.get("version"); Version.seenVersion(version); String locationString = fs.get("location"); - if(locationString == null) throw new FSParseException("No location"); - currentLocation = new Location(locationString); + currentLocation = Location.getLocation(locationString); // FIXME make mandatory once everyone has upgraded lastGoodVersion = fs.get("lastGoodVersion"); @@ -375,7 +374,7 @@ throw new FSParseException(e1); } if(nominalPeer.isEmpty()) { - Logger.normal(this, "No IP addresses found for identity '"+Base64.encode(identity)+"', possibly at location '"+Double.toString(currentLocation.getValue())+": "+userToString()); + Logger.normal(this, "No IP addresses found for identity '"+Base64.encode(identity)+"', possibly at location '"+Double.toString(currentLocation)+": "+userToString()); detectedPeer = null; } else { detectedPeer = (Peer) nominalPeer.firstElement(); @@ -803,7 +802,7 @@ /** * What is my current keyspace location? */ - public synchronized Location getLocation() { + public synchronized double getLocation() { return currentLocation; } @@ -1238,8 +1237,13 @@ */ public void updateLocation(double newLoc) { logMINOR = Logger.shouldLog(Logger.MINOR, PeerNode.class); + if(newLoc < 0.0 || newLoc > 1.0) { + Logger.error(this, "Invalid location update for "+this, new Exception("error")); + // Ignore it + return; + } synchronized(this) { - currentLocation.setValue(newLoc); + currentLocation = newLoc; } node.peers.writePeers(); } @@ -1539,7 +1543,7 @@ * Send any high level messages that need to be sent on connect. */ private void sendInitialMessages() { - Message locMsg = DMT.createFNPLocChangeNotification(node.lm.loc.getValue()); + Message locMsg = DMT.createFNPLocChangeNotification(node.lm.loc); Message ipMsg = DMT.createFNPDetectedIPAddress(detectedPeer); Message timeMsg = DMT.createFNPTime(System.currentTimeMillis()); @@ -1713,9 +1717,11 @@ if(!forARK) throw new FSParseException("No location"); } else { - Location loc = new Location(locationString); - if(!loc.equals(currentLocation)) changedAnything = true; - currentLocation = loc; + double newLoc = Location.getLocation(locationString); + if(!Location.equals(newLoc, currentLocation)) { + changedAnything = true; + currentLocation = newLoc; + } } Vector oldNominalPeer = nominalPeer; @@ -1829,7 +1835,7 @@ } if((getPeerNodeStatus() == PeerManager.PEER_NODE_STATUS_NEVER_CONNECTED) && (getPeerAddedTime() > 1)) idle = (int) ((now - getPeerAddedTime()) / 1000); - return String.valueOf(getPeer())+ '\t' +getIdentityString()+ '\t' +getLocation().getValue()+ '\t' +getPeerNodeStatusString()+ '\t' +idle; + return String.valueOf(getPeer())+ '\t' +getIdentityString()+ '\t' +getLocation()+ '\t' +getPeerNodeStatusString()+ '\t' +idle; } public String getFreevizOutput() { @@ -1923,7 +1929,7 @@ } fs.put("auth.negTypes", negTypes); fs.putSingle("identity", getIdentityString()); - fs.putSingle("location", Double.toString(currentLocation.getValue())); + fs.putSingle("location", Double.toString(currentLocation)); fs.putSingle("testnet", Boolean.toString(testnetEnabled)); fs.putSingle("version", version); if(peerCryptoGroup != null) Modified: trunk/freenet/src/freenet/node/PeerNodeStatus.java =================================================================== --- trunk/freenet/src/freenet/node/PeerNodeStatus.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/PeerNodeStatus.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -92,7 +92,7 @@ this.statusValue = peerNode.getPeerNodeStatus(); this.statusName = peerNode.getPeerNodeStatusString(); this.statusCSSName = peerNode.getPeerNodeStatusCSSClassName(); - this.location = peerNode.getLocation().getValue(); + this.location = peerNode.getLocation(); this.version = peerNode.getVersion(); this.simpleVersion = peerNode.getSimpleVersion(); this.routingBackoffLength = peerNode.getRoutingBackoffLength(); Modified: trunk/freenet/src/freenet/node/RequestHandler.java =================================================================== --- trunk/freenet/src/freenet/node/RequestHandler.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/RequestHandler.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -54,7 +54,7 @@ htl = req.getShort(DMT.HTL); source = (PeerNode) req.getSource(); closestLoc = req.getDouble(DMT.NEAREST_LOCATION); - double myLoc = n.lm.getLocation().getValue(); + double myLoc = n.lm.getLocation(); key = (Key) req.getObject(DMT.FREENET_ROUTING_KEY); double keyLoc = key.toNormalizedDouble(); if(Location.distance(keyLoc, myLoc) < Location.distance(keyLoc, closestLoc)) { Modified: trunk/freenet/src/freenet/node/RequestSender.java =================================================================== --- trunk/freenet/src/freenet/node/RequestSender.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/RequestSender.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -142,7 +142,7 @@ double nextValue; next = node.peers.closerPeer(source, nodesRoutedTo, nodesNotIgnored, target, true, node.isAdvancedModeEnabled(), -1, null); if(next != null) - nextValue = next.getLocation().getValue(); + nextValue = next.getLocation(); else nextValue = -1.0; Modified: trunk/freenet/src/freenet/node/SSKInsertHandler.java =================================================================== --- trunk/freenet/src/freenet/node/SSKInsertHandler.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/SSKInsertHandler.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -55,7 +55,7 @@ htl = req.getShort(DMT.HTL); closestLoc = req.getDouble(DMT.NEAREST_LOCATION); double targetLoc = key.toNormalizedDouble(); - double myLoc = node.lm.getLocation().getValue(); + double myLoc = node.lm.getLocation(); if(Location.distance(targetLoc, myLoc) < Location.distance(targetLoc, closestLoc)) { closestLoc = myLoc; htl = node.maxHTL(); Modified: trunk/freenet/src/freenet/node/SSKInsertSender.java =================================================================== --- trunk/freenet/src/freenet/node/SSKInsertSender.java 2007-08-07 15:04:06 UTC (rev 14505) +++ trunk/freenet/src/freenet/node/SSKInsertSender.java 2007-08-07 15:35:38 UTC (rev 14506) @@ -139,7 +139,7 @@ synchronized(node.peers) { next = node.peers.closerPeer(source, nodesRoutedTo, nodesNotIgnored, target, true, node.isAdvancedModeEnabled(), -1, null); if(next != null) - nextValue = next.getLocation().getValue(); + nextValue = next.getLocation(); else nextValue = -1.0; } From toad at freenetproject.org Tue Aug 7 15:38:20 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Tue, 7 Aug 2007 15:38:20 +0000 (UTC) Subject: [freenet-cvs] r14507 - trunk/freenet/src/freenet/node Message-ID: <20070807153820.DA70047A31B@freenetproject.org> Author: toad Date: 2007-08-07 15:38:20 +0000 (Tue, 07 Aug 2007) New Revision: 14507 Modified: trunk/freenet/src/freenet/node/LocationManager.java trunk/freenet/src/freenet/node/Node.java trunk/freenet/src/freenet/node/PeerNode.java Log: Encapsulate LocationManager.loc/locChangeSession - make them private, use accessors, synchronize to access. Modified: trunk/freenet/src/freenet/node/LocationManager.java =================================================================== --- trunk/freenet/src/freenet/node/LocationManager.java 2007-08-07 15:35:38 UTC (rev 14506) +++ trunk/freenet/src/freenet/node/LocationManager.java 2007-08-07 15:38:20 UTC (rev 14507) @@ -64,22 +64,22 @@ logMINOR = Logger.shouldLog(Logger.MINOR, this); } - double loc; - double locChangeSession = 0.0; + private double loc; + private double locChangeSession = 0.0; int numberOfRemotePeerLocationsSeenInSwaps = 0; /** * @return The current Location of this node. */ - public double getLocation() { + public synchronized double getLocation() { return loc; } /** * @param l */ - public void setLocation(double l) { + public synchronized void setLocation(double l) { if(l < 0.0 || l > 1.0) { Logger.error(this, "Setting invalid location: "+l, new Exception("error")); return; @@ -1147,4 +1147,8 @@ uids[i] = peers[i].swapIdentifier; return uids; } + + public synchronized double getLocChangeSession() { + return locChangeSession; + } } Modified: trunk/freenet/src/freenet/node/Node.java =================================================================== --- trunk/freenet/src/freenet/node/Node.java 2007-08-07 15:35:38 UTC (rev 14506) +++ trunk/freenet/src/freenet/node/Node.java 2007-08-07 15:38:20 UTC (rev 14507) @@ -2501,11 +2501,11 @@ } public double getLocation() { - return lm.loc; + return lm.getLocation(); } public double getLocationChangeSession() { - return lm.locChangeSession; + return lm.getLocChangeSession(); } public int getNumberOfRemotePeerLocationsSeenInSwaps() { Modified: trunk/freenet/src/freenet/node/PeerNode.java =================================================================== --- trunk/freenet/src/freenet/node/PeerNode.java 2007-08-07 15:35:38 UTC (rev 14506) +++ trunk/freenet/src/freenet/node/PeerNode.java 2007-08-07 15:38:20 UTC (rev 14507) @@ -1543,7 +1543,7 @@ * Send any high level messages that need to be sent on connect. */ private void sendInitialMessages() { - Message locMsg = DMT.createFNPLocChangeNotification(node.lm.loc); + Message locMsg = DMT.createFNPLocChangeNotification(node.lm.getLocation()); Message ipMsg = DMT.createFNPDetectedIPAddress(detectedPeer); Message timeMsg = DMT.createFNPTime(System.currentTimeMillis()); From toad at freenetproject.org Tue Aug 7 15:40:31 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Tue, 7 Aug 2007 15:40:31 +0000 (UTC) Subject: [freenet-cvs] r14508 - trunk/freenet/src/freenet/node Message-ID: <20070807154031.4BA584793CF@freenetproject.org> Author: toad Date: 2007-08-07 15:40:31 +0000 (Tue, 07 Aug 2007) New Revision: 14508 Modified: trunk/freenet/src/freenet/node/LocationManager.java Log: Synchronize on access to loc/locChangeSession within LocationManager (locks are free if there's no contention, right?) Modified: trunk/freenet/src/freenet/node/LocationManager.java =================================================================== --- trunk/freenet/src/freenet/node/LocationManager.java 2007-08-07 15:38:20 UTC (rev 14507) +++ trunk/freenet/src/freenet/node/LocationManager.java 2007-08-07 15:40:31 UTC (rev 14508) @@ -87,7 +87,7 @@ this.loc = l; } - public void updateLocationChangeSession(double newLoc) { + public synchronized void updateLocationChangeSession(double newLoc) { double oldLoc = loc; // Patterned after PeerManager.distance( double, double ), but also need to know the direction of the change if (newLoc > oldLoc) { @@ -158,7 +158,7 @@ if(System.currentTimeMillis() - timeLastSuccessfullySwapped > 30*1000) { try { boolean myFlag = false; - double myLoc = loc; + double myLoc = getLocation(); PeerNode[] peers = node.peers.connectedPeers; for(int i=0;i Author: toad Date: 2007-08-07 15:44:58 +0000 (Tue, 07 Aug 2007) New Revision: 14509 Modified: trunk/freenet/src/freenet/node/PeerNode.java Log: Make location optional in noderefs Modified: trunk/freenet/src/freenet/node/PeerNode.java =================================================================== --- trunk/freenet/src/freenet/node/PeerNode.java 2007-08-07 15:40:31 UTC (rev 14508) +++ trunk/freenet/src/freenet/node/PeerNode.java 2007-08-07 15:44:58 UTC (rev 14509) @@ -340,7 +340,12 @@ version = fs.get("version"); Version.seenVersion(version); String locationString = fs.get("location"); - currentLocation = Location.getLocation(locationString); + try { + currentLocation = Location.getLocation(locationString); + } catch (FSParseException e) { + // Wait for them to send us an FNPLocChangeNotification + currentLocation = -1.0; + } // FIXME make mandatory once everyone has upgraded lastGoodVersion = fs.get("lastGoodVersion"); @@ -837,7 +842,8 @@ * PeerManager in e.g. verified. */ public boolean isRoutable() { - return isConnected() && isRoutingCompatible(); + return isConnected() && isRoutingCompatible() && + !(currentLocation < 0.0 || currentLocation > 1.0); } public boolean isRoutingCompatible(){ @@ -1717,10 +1723,16 @@ if(!forARK) throw new FSParseException("No location"); } else { - double newLoc = Location.getLocation(locationString); - if(!Location.equals(newLoc, currentLocation)) { - changedAnything = true; - currentLocation = newLoc; + try { + double newLoc = Location.getLocation(locationString); + if(!Location.equals(newLoc, currentLocation)) { + changedAnything = true; + currentLocation = newLoc; + } + } catch (FSParseException e) { + // Location is optional, we will wait for FNPLocChangeNotification + if(logMINOR) + Logger.minor(this, "Invalid or null location, waiting for FNPLocChangeNotification: "+e); } } From toad at freenetproject.org Tue Aug 7 16:11:06 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Tue, 7 Aug 2007 16:11:06 +0000 (UTC) Subject: [freenet-cvs] r14510 - trunk/freenet/src/freenet/l10n Message-ID: <20070807161106.BB3784798CE@freenetproject.org> Author: toad Date: 2007-08-07 16:11:06 +0000 (Tue, 07 Aug 2007) New Revision: 14510 Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties Log: Hmmm, has this already been applied? Modified: trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties =================================================================== --- trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties 2007-08-07 15:44:58 UTC (rev 14509) +++ trunk/freenet/src/freenet/l10n/freenet.l10n.fr.properties 2007-08-07 16:11:06 UTC (rev 14510) @@ -953,6 +953,7 @@ WelcomeToadlet.insertSucceededTitle=Insertion r?ussie WelcomeToadlet.insertedTitle=Insertion WelcomeToadlet.keyInsertedSuccessfullyWithKeyAndName=La cl? ${link}${name}${/link} a ?t? ins?r?e avec succ?s. +WelcomeToadlet.keyRequestLabel=Cl? : WelcomeToadlet.messageHeader=Message WelcomeToadlet.nodeUpdateConfirm=Etes-vous s?r de vouloir mettre ? jour votre noeud Freenet ? WelcomeToadlet.nodeUpdateConfirmTitle=Confirmation de mise ? jour From toad at freenetproject.org Tue Aug 7 16:16:40 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Tue, 7 Aug 2007 16:16:40 +0000 (UTC) Subject: [freenet-cvs] r14511 - trunk/freenet/src/freenet/clients/http Message-ID: <20070807161640.AE866479949@freenetproject.org> Author: toad Date: 2007-08-07 16:16:40 +0000 (Tue, 07 Aug 2007) New Revision: 14511 Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java trunk/freenet/src/freenet/clients/http/PageMaker.java Log: Dynamically update the language for the title bar. Also fixes it's-always-in-english bug. Modified: trunk/freenet/src/freenet/clients/http/FProxyToadlet.java =================================================================== --- trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2007-08-07 16:11:06 UTC (rev 14510) +++ trunk/freenet/src/freenet/clients/http/FProxyToadlet.java 2007-08-07 16:16:40 UTC (rev 14511) @@ -581,10 +581,10 @@ core.random.nextBytes(random); FProxyToadlet fproxy = new FProxyToadlet(client, core); core.setFProxy(fproxy); - server.register(fproxy, "/", false, l10n("welcomeTitle"), l10n("welcome"), false, null); + server.register(fproxy, "/", false, "FProxyToadlet.welcomeTitle", "FProxyToadlet.welcome", false, null); PproxyToadlet pproxy = new PproxyToadlet(client, node, core); - server.register(pproxy, "/plugins/", true, l10n("pluginsTitle"), l10n("plugins"), true, null); + server.register(pproxy, "/plugins/", true, "FProxyToadlet.pluginsTitle", "FProxyToadlet.plugins", true, null); WelcomeToadlet welcometoadlet = new WelcomeToadlet(client, core, node); server.register(welcometoadlet, "/welcome/", true, false); @@ -593,7 +593,7 @@ server.register(pluginToadlet, "/plugin/", true, true); ConfigToadlet configtoadlet = new ConfigToadlet(client, config, node, core); - server.register(configtoadlet, "/config/", true, l10n("configTitle"), l10n("config"), true, null); + server.register(configtoadlet, "/config/", true, "FProxyToadlet.configTitle", "FProxyToadlet.config", true, null); StaticToadlet statictoadlet = new StaticToadlet(client); server.register(statictoadlet, "/static/", true, false); @@ -603,20 +603,20 @@ DarknetConnectionsToadlet friendsToadlet = new DarknetConnectionsToadlet(node, core, client); // server.register(friendsToadlet, "/darknet/", true, l10n("friendsTitle"), l10n("friends"), true); - server.register(friendsToadlet, "/friends/", true, l10n("friendsTitle"), l10n("friends"), true, null); + server.register(friendsToadlet, "/friends/", true, "FProxyToadlet.friendsTitle", "FProxyToadlet.friends", true, null); OpennetConnectionsToadlet opennetToadlet = new OpennetConnectionsToadlet(node, core, client); // server.register(opennetToadlet, "/opennet/", true, l10n("opennetTitle"), l10n("opennet"), true, opennetToadlet); - server.register(opennetToadlet, "/strangers/", true, l10n("opennetTitle"), l10n("opennet"), true, opennetToadlet); + server.register(opennetToadlet, "/strangers/", true, "FProxyToadlet.opennetTitle", "FProxyToadlet.opennet", true, opennetToadlet); N2NTMToadlet n2ntmToadlet = new N2NTMToadlet(node, core, client); server.register(n2ntmToadlet, "/send_n2ntm/", true, true); QueueToadlet queueToadlet = new QueueToadlet(core, core.getFCPServer(), client); - server.register(queueToadlet, "/queue/", true, l10n("queueTitle"), l10n("queue"), false, null); + server.register(queueToadlet, "/queue/", true, "FProxyToadlet.queueTitle", "FProxyToadlet.queue", false, null); StatisticsToadlet statisticsToadlet = new StatisticsToadlet(node, core, client); - server.register(statisticsToadlet, "/stats/", true, l10n("statsTitle"), l10n("stats"), true, null); + server.register(statisticsToadlet, "/stats/", true, "FProxyToadlet.statsTitle", "FProxyToadlet.stats", true, null); LocalFileInsertToadlet localFileInsertToadlet = new LocalFileInsertToadlet(core, client); server.register(localFileInsertToadlet, "/files/", true, false); Modified: trunk/freenet/src/freenet/clients/http/PageMaker.java =================================================================== --- trunk/freenet/src/freenet/clients/http/PageMaker.java 2007-08-07 16:11:06 UTC (rev 14510) +++ trunk/freenet/src/freenet/clients/http/PageMaker.java 2007-08-07 16:16:40 UTC (rev 14511) @@ -117,7 +117,7 @@ String navigationTitle = (String) navigationLinkTitles.get(navigationLink); String navigationPath = (String) navigationLinks.get(navigationLink); HTMLNode listItem = navbarUl.addChild("li"); - listItem.addChild("a", new String[] { "href", "title" }, new String[] { navigationPath, navigationTitle }, navigationLink); + listItem.addChild("a", new String[] { "href", "title" }, new String[] { navigationPath, L10n.getString(navigationTitle) }, L10n.getString(navigationLink)); } } HTMLNode contentDiv = pageDiv.addChild("div", "id", "content"); From toad at freenetproject.org Tue Aug 7 16:32:31 2007 From: toad at freenetproject.org (toad at freenetproject.org) Date: Tue, 7 Aug 2007 16:32:31 +0000 (UTC) Subject: [freenet-cvs] r14512 - trunk/website/pages/en Message-ID: <20070807163231.954DD47A1CB@freenetproject.org> Author: toad Date: 2007-08-07 16:32:31 +0000 (Tue, 07 Aug 2007) New Revision: 14512 Modified: trunk/website/pages/en/download.php Log: Reference the mini-howto from the download page Modified: trunk/website/pages/en/download.php =================================================================== --- trunk/website/pages/en/download.php 2007-08-07 16:16:40 UTC (rev 14511) +++ trunk/website/pages/en/download.php 2007-08-07 16:32:31 UTC (rev 14512) @@ -57,6 +57,7 @@ ./run.sh start

+

You might find the mini-howto useful (it might be of interest to Windows users too).

Afer you start Freenet, wait a few seconds