Author: toad
Date: 2008-12-17 14:35:21 +0000 (Wed, 17 Dec 2008)
New Revision: 24436

Modified:
   branches/db4o/freenet/src/freenet/client/async/USKCallback.java
   branches/db4o/freenet/src/freenet/clients/http/FProxyToadlet.java
   branches/db4o/freenet/src/freenet/clients/http/LinkEnabledCallback.java
   branches/db4o/freenet/src/freenet/clients/http/OpennetConnectionsToadlet.java
   branches/db4o/freenet/src/freenet/clients/http/PageMaker.java
   branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java
   branches/db4o/freenet/src/freenet/clients/http/SimpleToadletServer.java
   branches/db4o/freenet/src/freenet/clients/http/ToadletContainer.java
   branches/db4o/freenet/src/freenet/clients/http/ToadletContextImpl.java
   
branches/db4o/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
   branches/db4o/freenet/src/freenet/l10n/freenet.l10n.en.properties
   branches/db4o/freenet/src/freenet/node/Announcer.java
   branches/db4o/freenet/src/freenet/node/DarknetPeerNode.java
   branches/db4o/freenet/src/freenet/node/FNPPacketMangler.java
   branches/db4o/freenet/src/freenet/node/KeyTracker.java
   branches/db4o/freenet/src/freenet/node/Node.java
   branches/db4o/freenet/src/freenet/node/NodeDispatcher.java
   branches/db4o/freenet/src/freenet/node/OpennetManager.java
   branches/db4o/freenet/src/freenet/node/OpennetPeerNode.java
   branches/db4o/freenet/src/freenet/node/OutgoingPacketMangler.java
   branches/db4o/freenet/src/freenet/node/PacketSender.java
   branches/db4o/freenet/src/freenet/node/PeerManager.java
   branches/db4o/freenet/src/freenet/node/PeerNode.java
   branches/db4o/freenet/src/freenet/node/RequestHandler.java
   branches/db4o/freenet/src/freenet/node/SeedClientPeerNode.java
   branches/db4o/freenet/src/freenet/node/SeedServerPeerNode.java
   branches/db4o/freenet/src/freenet/node/Version.java
   branches/db4o/freenet/src/freenet/support/MultiValueTable.java
Log:
Merge 1193 except for properties


Modified: branches/db4o/freenet/src/freenet/client/async/USKCallback.java
===================================================================
--- branches/db4o/freenet/src/freenet/client/async/USKCallback.java     
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/client/async/USKCallback.java     
2008-12-17 14:35:21 UTC (rev 24436)
@@ -13,9 +13,14 @@
  */
 public interface USKCallback {

-       /** Found the latest edition.
-        * @param l The edition number.
-        * @param key The key. */
+       /**
+        * Found the latest edition.
+        * 
+        * @param l
+        *            The edition number.
+        * @param key
+        *            A copy of the key with new edition set
+        */
        void onFoundEdition(long l, USK key, ObjectContainer container, 
ClientContext context, boolean metadata, short codec, byte[] data);

        /**

Modified: branches/db4o/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/FProxyToadlet.java   
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/clients/http/FProxyToadlet.java   
2008-12-17 14:35:21 UTC (rev 24436)
@@ -110,6 +110,7 @@
        }

        public static void handleDownload(ToadletContext context, Bucket data, 
BucketFactory bucketFactory, String mimeType, String requestedMimeType, String 
forceString, boolean forceDownload, String basePath, FreenetURI key, String 
extras, String referrer, boolean downloadLink, ToadletContext ctx, 
NodeClientCore core) throws ToadletContextClosedException, IOException {
+               ToadletContainer container = context.getContainer();
                if(Logger.shouldLog(Logger.MINOR, FProxyToadlet.class))
                        Logger.minor(FProxyToadlet.class, 
"handleDownload(data.size="+data.size()+", mimeType="+mimeType+", 
requestedMimeType="+requestedMimeType+", forceDownload="+forceDownload+", 
basePath="+basePath+", key="+key);
                String extrasNoMime = extras; // extras will not include MIME 
type to start with - REDFLAG maybe it should be an array
@@ -133,7 +134,7 @@
                Bucket toFree = null;
                try {
                        if((!force) && (!forceDownload)) {
-                               FilterOutput fo = ContentFilter.filter(data, 
bucketFactory, mimeType, key.toURI(basePath), 
context.getContainer().enableInlinePrefetch() ? prefetchHook : null);
+                               FilterOutput fo = ContentFilter.filter(data, 
bucketFactory, mimeType, key.toURI(basePath), container.enableInlinePrefetch() 
? prefetchHook : null);
                                if(data != fo.data) toFree = fo.data;
                                data = fo.data;
                                mimeType = fo.type;
@@ -248,7 +249,7 @@
                        option = optionList.addChild("li");
                        L10n.addL10nSubstitution(option, 
"FProxyToadlet.backToFProxy", new String[] { "link", "/link" },
                                        new String[] { "<a href=\"/\">", "</a>" 
});
-                       if(ctx.isAllowedFullAccess()) {
+                       if(ctx.isAllowedFullAccess() || 
!container.publicGatewayMode()) {
                                option = optionList.addChild("li");
                                HTMLNode optionForm = ctx.addFormChild(option, 
"/queue/", "tooBigQueueForm");
                                optionForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "hidden", "key", key.toString() });
@@ -399,8 +400,15 @@
                if(ks.startsWith("/"))
                        ks = ks.substring(1);

-               long maxSize = httprequest.getLongParam("max-size", MAX_LENGTH);
+               long maxSize;

+               boolean restricted = (container.publicGatewayMode() && 
!ctx.isAllowedFullAccess());
+               
+               if(restricted)
+                       maxSize = MAX_LENGTH;
+               else 
+                       maxSize = httprequest.getLongParam("max-size", 
MAX_LENGTH);
+               
                FreenetURI key;
                try {
                        key = new FreenetURI(ks);
@@ -473,13 +481,12 @@
                                infoboxContent = infobox.addChild("div", 
"class", "infobox-content");
                                infoboxContent.addChild("#", 
l10n("largeFileExplanationAndOptions"));
                                HTMLNode optionList = 
infoboxContent.addChild("ul");
-                               option = optionList.addChild("li");
-                               HTMLNode optionForm = option.addChild("form", 
new String[] { "action", "method" }, new String[] {'/' + key.toString(), "get" 
});
-                               optionForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "hidden", "max-size", 
String.valueOf(e.expectedSize == -1 ? Long.MAX_VALUE : e.expectedSize*2) });
-                               optionForm.addChild("input", new String[] { 
"type", "name", "value" }, new String[] { "submit", "fetch", 
l10n("fetchLargeFileAnywayAndDisplay") });
-                               optionList.addChild("li").addChild("a", new 
String[] { "href", "title" }, new String[] { "/", "FProxy home page" }, 
l10n("abortToHomepage"));
-                               if(ctx.isAllowedFullAccess()) {
+                               if(!restricted) {
                                        option = optionList.addChild("li");
+                                       HTMLNode optionForm = 
option.addChild("form", new String[] { "action", "method" }, new String[] {'/' 
+ key.toString(), "get" });
+                                       optionForm.addChild("input", new 
String[] { "type", "name", "value" }, new String[] { "hidden", "max-size", 
String.valueOf(e.expectedSize == -1 ? Long.MAX_VALUE : e.expectedSize*2) });
+                                       optionForm.addChild("input", new 
String[] { "type", "name", "value" }, new String[] { "submit", "fetch", 
l10n("fetchLargeFileAnywayAndDisplay") });
+                                       option = optionList.addChild("li");
                                        optionForm = ctx.addFormChild(option, 
"/queue/", "tooBigQueueForm");
                                        optionForm.addChild("input", new 
String[] { "type", "name", "value" }, new String[] { "hidden", "key", 
key.toString() });
                                        optionForm.addChild("input", new 
String[] { "type", "name", "value" }, new String[] { "hidden", "return-type", 
"disk" });
@@ -490,6 +497,11 @@
                                        optionForm.addChild("input", new 
String[] { "type", "name", "value" }, new String[] { "submit", "download", 
l10n("downloadInBackgroundToDisk") });
                                }

+                               optionList.addChild("li").addChild("a", new 
String[] { "href", "title" }, new String[] { "/", 
L10n.getString("Toadlet.homepage") }, l10n("abortToHomepage"));
+                               
+                               option = optionList.addChild("li");
+                               
option.addChild(ctx.getPageMaker().createBackLink(ctx, l10n("goBackToPrev")));
+                               
                                writeHTMLReply(ctx, 200, "OK", 
pageNode.generate());
                        } else {
                                HTMLNode pageNode = 
ctx.getPageMaker().getPageNode(FetchException.getShortMessage(e.mode), ctx);
@@ -524,7 +536,7 @@
                                        L10n.addL10nSubstitution(option, 
"FProxyToadlet.openWithKeyExplorer", new String[] { "link", "/link" }, new 
String[] { "<a href=\"/plugins/plugins.KeyExplorer.KeyExplorer/?key=" + 
key.toString() + "\">", "</a>" });
                                }

-                               if(!e.isFatal() && ctx.isAllowedFullAccess()) {
+                               if(!e.isFatal() && (ctx.isAllowedFullAccess() 
|| !container.publicGatewayMode())) {
                                        option = optionList.addChild("li");
                                        HTMLNode optionForm = 
ctx.addFormChild(option, "/queue/", "dnfQueueForm");
                                        optionForm.addChild("input", new 
String[] { "type", "name", "value" }, new String[] { "hidden", "key", 
key.toString() });
@@ -693,7 +705,7 @@
                server.register(n2ntmToadlet, "/send_n2ntm/", true, true);

                QueueToadlet queueToadlet = new QueueToadlet(core, 
core.getFCPServer(), client);
-               server.register(queueToadlet, "/queue/", true, 
"FProxyToadlet.queueTitle", "FProxyToadlet.queue", false, null);
+               server.register(queueToadlet, "/queue/", true, 
"FProxyToadlet.queueTitle", "FProxyToadlet.queue", false, queueToadlet);

                StatisticsToadlet statisticsToadlet = new 
StatisticsToadlet(node, core, client);
                server.register(statisticsToadlet, "/stats/", true, 
"FProxyToadlet.statsTitle", "FProxyToadlet.stats", true, null);

Modified: 
branches/db4o/freenet/src/freenet/clients/http/LinkEnabledCallback.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/LinkEnabledCallback.java     
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/clients/http/LinkEnabledCallback.java     
2008-12-17 14:35:21 UTC (rev 24436)
@@ -2,7 +2,8 @@

 public interface LinkEnabledCallback {

-       /** Whether to show the link? */
-       boolean isEnabled();
+       /** Whether to show the link? 
+        * @param ctx */
+       boolean isEnabled(ToadletContext ctx);

 }

Modified: 
branches/db4o/freenet/src/freenet/clients/http/OpennetConnectionsToadlet.java
===================================================================
--- 
branches/db4o/freenet/src/freenet/clients/http/OpennetConnectionsToadlet.java   
    2008-12-17 14:34:16 UTC (rev 24435)
+++ 
branches/db4o/freenet/src/freenet/clients/http/OpennetConnectionsToadlet.java   
    2008-12-17 14:35:21 UTC (rev 24436)
@@ -50,7 +50,7 @@
                return node.peers.getOpennetPeerNodeStatuses(noHeavy);
        }

-       public boolean isEnabled() {
+       public boolean isEnabled(ToadletContext ctx) {
                return node.isOpennetEnabled();
        }


Modified: branches/db4o/freenet/src/freenet/clients/http/PageMaker.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/PageMaker.java       
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/clients/http/PageMaker.java       
2008-12-17 14:35:21 UTC (rev 24436)
@@ -163,7 +163,7 @@
                        HTMLNode navbarUl = navbarDiv.addChild("ul", "id", 
"navlist");
                        for (String navigationLink :  fullAccess ? 
navigationLinkTexts : navigationLinkTextsNonFull) {
                                LinkEnabledCallback cb = 
navigationLinkCallbacks.get(navigationLink);
-                               if(cb != null && !cb.isEnabled()) continue;
+                               if(cb != null && !cb.isEnabled(ctx)) continue;
                                String navigationTitle = 
navigationLinkTitles.get(navigationLink);
                                String navigationPath = 
navigationLinks.get(navigationLink);
                                HTMLNode listItem = navbarUl.addChild("li");

Modified: branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java    
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/clients/http/QueueToadlet.java    
2008-12-17 14:35:21 UTC (rev 24436)
@@ -64,7 +64,7 @@
 import freenet.support.io.NativeThread;
 import java.util.StringTokenizer;

-public class QueueToadlet extends Toadlet implements RequestCompletionCallback 
{
+public class QueueToadlet extends Toadlet implements 
RequestCompletionCallback, LinkEnabledCallback {

        private static final int LIST_IDENTIFIER = 1;
        private static final int LIST_SIZE = 2;
@@ -106,6 +106,11 @@
                        return;
                }

+               if(container.publicGatewayMode() && !ctx.isAllowedFullAccess()) 
{
+                       super.sendErrorPage(ctx, 403, 
L10n.getString("Toadlet.unauthorizedTitle"), 
L10n.getString("Toadlet.unauthorized"));
+                       return;
+               }
+               
                boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);

                try {
@@ -463,6 +468,11 @@
                        return;
                }

+               if(container.publicGatewayMode() && !ctx.isAllowedFullAccess()) 
{
+                       super.sendErrorPage(ctx, 403, 
L10n.getString("Toadlet.unauthorizedTitle"), 
L10n.getString("Toadlet.unauthorized"));
+                       return;
+               }
+               
                final String requestPath = 
request.getPath().substring("/queue/".length());

                boolean countRequests = false;
@@ -1501,4 +1511,8 @@
                saveCompletedIdentifiersOffThread();
        }

+       public boolean isEnabled(ToadletContext ctx) {
+               return (!container.publicGatewayMode()) || 
ctx.isAllowedFullAccess();
+       }
+
 }

Modified: 
branches/db4o/freenet/src/freenet/clients/http/SimpleToadletServer.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/SimpleToadletServer.java     
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/clients/http/SimpleToadletServer.java     
2008-12-17 14:35:21 UTC (rev 24436)
@@ -65,6 +65,7 @@

        // ACL
        private final AllowedHosts allowedFullAccess;
+       private boolean publicGatewayMode;

        // Theme 
        private THEME cssTheme;
@@ -366,6 +367,21 @@
                                }
                });

+               fproxyConfig.register("publicGatewayMode", false, 
configItemOrder++, true, true, "SimpleToadletServer.publicGatewayMode", 
"SimpleToadletServer.publicGatewayModeLong", new BooleanCallback() {
+
+                       @Override
+                       public Boolean get() {
+                               return publicGatewayMode;
+                       }
+
+                       @Override
+                       public void set(Boolean val) throws 
InvalidConfigValueException, NodeNeedRestartException {
+                               publicGatewayMode = val;
+                       }
+                       
+               });
+               publicGatewayMode = 
fproxyConfig.getBoolean("publicGatewayMode");
+               
                // This is OFF BY DEFAULT because for example firefox has a 
limit of 2 persistent 
                // connections per server, but 8 non-persistent connections per 
server. We need 8 conns
                // more than we need the efficiency gain of reusing connections 
- especially on first
@@ -515,6 +531,10 @@
                return doRobots;
        }

+       public boolean publicGatewayMode() {
+               return publicGatewayMode;
+       }
+       
        public void start() {
                if(myThread != null) try {
                        maybeGetNetworkInterface();

Modified: branches/db4o/freenet/src/freenet/clients/http/ToadletContainer.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/ToadletContainer.java        
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/clients/http/ToadletContainer.java        
2008-12-17 14:35:21 UTC (rev 24436)
@@ -56,4 +56,10 @@

        /** Can we deal with POSTs yet? */
        public boolean allowPosts();
+       
+       /** Is public-gateway mode enabled? 
+        * If so, users with full access will still be able to configure the 
+        * node etc, but everyone else will not have access to the download 
+        * queue or anything else that might conceivably result in a DoS. */
+       public boolean publicGatewayMode();
 }

Modified: branches/db4o/freenet/src/freenet/clients/http/ToadletContextImpl.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/ToadletContextImpl.java      
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/clients/http/ToadletContextImpl.java      
2008-12-17 14:35:21 UTC (rev 24436)
@@ -325,7 +325,8 @@
                                                
sendError(sock.getOutputStream(), 400, "Bad Request", 
l10n("cannotParseContentLengthWithError", "error", e.toString()), true, null);
                                                return;
                                        }
-                                       if(allowPost) {
+                                       if(allowPost && 
((!container.publicGatewayMode()) || ctx.isAllowedFullAccess())) { 
+
                                        data = bf.makeBucket(len);
                                        BucketTools.copyFrom(data, is, len);
                                        } else {

Modified: 
branches/db4o/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat
===================================================================
--- 
branches/db4o/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat 
    2008-12-17 14:34:16 UTC (rev 24435)
+++ 
branches/db4o/freenet/src/freenet/clients/http/staticfiles/defaultbookmarks.dat 
    2008-12-17 14:35:21 UTC (rev 24436)
@@ -7,26 +7,26 @@
 BookmarkCategory0.Content.Bookmark0.Name=The Ultimate FreeNet Index
 BookmarkCategory0.Content.Bookmark0.Description=A new one-page index with a 
menu including categories
 BookmarkCategory0.Content.Bookmark0.hasAnActivelink=true
-BookmarkCategory0.Content.Bookmark0.URI=USK at 
0I8gctpUE32CM0iQhXaYpCMvtPPGfT4pjXm01oid5Zc,3dAcn4fX2LyxO6uCnWFTx-2HKZ89uruurcKwLSCxbZ4,AQACAAE/Ultimate-Freenet-Index/35/
+BookmarkCategory0.Content.Bookmark0.URI=USK at 
0I8gctpUE32CM0iQhXaYpCMvtPPGfT4pjXm01oid5Zc,3dAcn4fX2LyxO6uCnWFTx-2HKZ89uruurcKwLSCxbZ4,AQACAAE/Ultimate-Freenet-Index/37/
 BookmarkCategory0.Content.Bookmark3.Name=Index des sites Fran?ais
 BookmarkCategory0.Content.Bookmark3.Description=A small French index with 
descriptions
 BookmarkCategory0.Content.Bookmark3.hasAnActivelink=true
-BookmarkCategory0.Content.Bookmark3.URI=USK at 
RJnh1EnvOSPwOWVRS2nyhC4eIQkKoNE5hcTv7~yY-sM,pOloLxnKWM~AL24iDMHOAvTvCqMlB-p2BO9zK96TOZA,AQACAAE/index_fr/73/
+BookmarkCategory0.Content.Bookmark3.URI=USK at 
RJnh1EnvOSPwOWVRS2nyhC4eIQkKoNE5hcTv7~yY-sM,pOloLxnKWM~AL24iDMHOAvTvCqMlB-p2BO9zK96TOZA,AQACAAE/index_fr/77/
 BookmarkCategory0.Content.Bookmark2.Name=Freenet Activelink Index (SLOW: 
graphical index, preloads all the sites, so takes *ages* to load)
 BookmarkCategory0.Content.Bookmark2.hasAnActivelink=true
 BookmarkCategory0.Content.Bookmark2.Description=A graphical freenet index 
(this will take a long time to load as it preloads the sites)
-BookmarkCategory0.Content.Bookmark2.URI=USK at 
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/activelink-index/93/
+BookmarkCategory0.Content.Bookmark2.URI=USK at 
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/activelink-index/95/
 BookmarkCategory0.Content.Bookmark1.Name=Freenet Activelink Index Text Version 
(a quick-loading non-graphical index site, no porn)
 BookmarkCategory0.Content.Bookmark1.hasAnActivelink=true
 BookmarkCategory0.Content.Bookmark1.Description=Text version of the Activelink 
Index
-BookmarkCategory0.Content.Bookmark1.URI=USK at 
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/activelink-index-text/54/
+BookmarkCategory0.Content.Bookmark1.URI=USK at 
qd-hk0vHYg7YvK2BQsJMcUD5QSF0tDkgnnF6lnWUH0g,xTFOV9ddCQQk6vQ6G~jfL6IzRUgmfMcZJ6nuySu~NUc,AQACAAE/activelink-index-text/56/
 BookmarkCategory1.Name=Freenet related software and documentation
 BookmarkCategory1.Content.BookmarkCategory=0
 BookmarkCategory1.Content.Bookmark=5
 BookmarkCategory1.Content.Bookmark0.Name=Freenet Message System
 BookmarkCategory1.Content.Bookmark0.Description=The official freesite of FMS, 
a spam resistant message board system for Freenet
 BookmarkCategory1.Content.Bookmark0.hasAnActivelink=true
-BookmarkCategory1.Content.Bookmark0.URI=USK at 
0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/84/
+BookmarkCategory1.Content.Bookmark0.URI=USK at 
0npnMrqZNKRCRoGojZV93UNHCMN-6UU3rRSAmP6jNLE,~BG-edFtdCC1cSH4O3BWdeIYa8Sw5DfyrSV-TKdO5ec,AQACAAE/fms/85/
 BookmarkCategory1.Content.Bookmark1.Name=Freemail
 BookmarkCategory1.Content.Bookmark1.Description=The official site for Freemail 
- email over Freenet
 BookmarkCategory1.Content.Bookmark1.hasAnActivelink=true
@@ -39,7 +39,7 @@
 BookmarkCategory1.Content.Bookmark3.Name=Freesite HOWTO
 BookmarkCategory1.Content.Bookmark3.Description=A more detailed explanation of 
publishing freesites
 BookmarkCategory1.Content.Bookmark3.hasAnActivelink=true
-BookmarkCategory1.Content.Bookmark4.URI=USK at 
ugb~uuscsidMI-Ze8laZe~o3BUIb3S50i25RIwDH99M,9T20t3xoG-dQfMO94LGOl9AxRTkaz~TykFY-voqaTQI,AQACAAE/FAFS/4/
+BookmarkCategory1.Content.Bookmark4.URI=USK at 
ugb~uuscsidMI-Ze8laZe~o3BUIb3S50i25RIwDH99M,9T20t3xoG-dQfMO94LGOl9AxRTkaz~TykFY-voqaTQI,AQACAAE/FAFS/44/
 BookmarkCategory1.Content.Bookmark4.hasAnActivelink=true
 BookmarkCategory1.Content.Bookmark4.Name=The Freenet Applications Freesite
 BookmarkCategory1.Content.Bookmark4.Description=Various links to Freenet 
applications, and instructions for using them

Modified: branches/db4o/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- branches/db4o/freenet/src/freenet/l10n/freenet.l10n.en.properties   
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/l10n/freenet.l10n.en.properties   
2008-12-17 14:35:21 UTC (rev 24436)
@@ -1154,6 +1154,8 @@
 SimpleToadletServer.passthroughMaxSizeLong=Maximum size of a file for 
transparent pass-through in fproxy
 SimpleToadletServer.port=FProxy port
 SimpleToadletServer.portLong=The TCP port FProxy should listen on
+SimpleToadletServer.publicGatewayMode=Public gateway mode? (Only applies to 
allowed but non-full-access connections)
+SimpleToadletServer.publicGatewayModeLong=Should we enable public gateway 
mode? For IPs which are allowed to access the node, but are not allowed full 
access, this option disables the download queue and anything else that might 
conceivably be abused to attack the node, while still allowing browsing 
freesites. IP addresses with full access will be allowed to configure the node.
 SimpleToadletServer.ssl=Enable SSL?
 SimpleToadletServer.sslLong=Enable SSL on FProxy
 SSL.enable=Activate SSL support?

Modified: branches/db4o/freenet/src/freenet/node/Announcer.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/Announcer.java       2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/Announcer.java       2008-12-17 
14:35:21 UTC (rev 24436)
@@ -331,7 +331,7 @@
                                        }
                                        if(enoughPeers()) {
                                                for(SeedServerPeerNode pn : 
node.peers.getConnectedSeedServerPeersVector(null)) {
-                                                       
node.peers.disconnect(pn, true, true);
+                                                       
node.peers.disconnect(pn, true, true, false);
                                                }
                                                // Re-check every minute. 
Something bad might happen (e.g. cpu starvation), causing us to have to reseed.
                                                
node.getTicker().queueTimedJob(new Runnable() {
@@ -511,7 +511,7 @@
                                // If it takes more than COOLING_OFF_PERIOD to 
disconnect, we might not be able to reannounce to this
                                // node. However, we can't reannounce to it 
anyway until announcedTo is cleared, which probably will
                                // be more than that period in the future.
-                               node.peers.disconnect(seed, true, false);
+                               node.peers.disconnect(seed, true, false, false);
                                System.out.println("Announcement to 
"+seed.userToString()+" completed.");
                                if(announceNow)
                                        maybeSendAnnouncement();

Modified: branches/db4o/freenet/src/freenet/node/DarknetPeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/DarknetPeerNode.java 2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/DarknetPeerNode.java 2008-12-17 
14:35:21 UTC (rev 24436)
@@ -16,6 +16,7 @@
 import java.util.LinkedHashSet;

 import freenet.client.DefaultMIMETypes;
+import freenet.crypt.BlockCipher;
 import freenet.io.comm.DMT;
 import freenet.io.comm.DisconnectedException;
 import freenet.io.comm.FreenetInetAddress;
@@ -772,6 +773,7 @@
         */
        @Override
        protected void onConnect() {
+               super.onConnect();
                sendQueuedN2NMs();
        }

@@ -1596,4 +1598,5 @@
        public final boolean shouldDisconnectAndRemoveNow() {
                return false;
        }
+       
 }

Modified: branches/db4o/freenet/src/freenet/node/FNPPacketMangler.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/FNPPacketMangler.java        
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/FNPPacketMangler.java        
2008-12-17 14:35:21 UTC (rev 24436)
@@ -303,7 +303,7 @@
                OpennetManager opennet = node.getOpennet();
                if(opennet != null) {
                        // Try old opennet connections.
-                       if(opennet.wantPeer(null, false, true)) {
+                       if(opennet.wantPeer(null, false, true, true)) {
                                // We want a peer.
                                // Try old connections.
                                PeerNode[] oldPeers = opennet.getOldPeers();
@@ -1201,9 +1201,14 @@
                                Logger.normal(this, "Dumping incoming 
old-opennet peer as opennet just turned off: "+pn+".");
                                return;
                        }
-                       if(!opennet.wantPeer(pn, true, false)) {
+                       /* When an old-opennet-peer connects, add it at the top 
of the LRU, so that it isn't
+                        * immediately dropped when there is no droppable peer 
to drop. If it was dropped 
+                        * from the bottom of the LRU list, we would not have 
added it to the LRU; so it was
+                        * somewhere in the middle. */
+                       if(!opennet.wantPeer(pn, false, false, true)) {
                                Logger.normal(this, "No longer want peer "+pn+" 
- dumping it after connecting");
                                dontWant = true;
+                               opennet.purgeOldOpennetPeer(pn);
                        }
                        // wantPeer will call node.peers.addPeer(), we don't 
have to.
                }
@@ -1217,7 +1222,7 @@
                                        c, Ke, Ka, authenticator, hisRef, pn, 
replyTo, unknownInitiator, setupType, newTrackerID, newTrackerID == trackerID);

                        if(dontWant)
-                               node.peers.disconnect(pn, true, false); // Let 
it connect then tell it to remove it.
+                               node.peers.disconnect(pn, true, false, true); 
// Let it connect then tell it to remove it.
                        else
                                pn.maybeSendInitialMessages();
                } else {
@@ -1417,9 +1422,14 @@
                                Logger.normal(this, "Dumping incoming 
old-opennet peer as opennet just turned off: "+pn+".");
                                return true;
                        }
-                       if(!opennet.wantPeer(pn, true, false)) {
+                       /* When an old-opennet-peer connects, add it at the top 
of the LRU, so that it isn't
+                        * immediately dropped when there is no droppable peer 
to drop. If it was dropped 
+                        * from the bottom of the LRU list, we would not have 
added it to the LRU; so it was
+                        * somewhere in the middle. */
+                       if(!opennet.wantPeer(pn, false, false, true)) {
                                Logger.normal(this, "No longer want peer "+pn+" 
- dumping it after connecting");
                                dontWant = true;
+                               opennet.purgeOldOpennetPeer(pn);
                        }
                        // wantPeer will call node.peers.addPeer(), we don't 
have to.
                }
@@ -1428,7 +1438,7 @@
                c.initialize(pn.jfkKs);
                if(pn.completedHandshake(bootID, hisRef, 0, hisRef.length, c, 
pn.jfkKs, replyTo, false, negType, trackerID, true, reusedTracker) >= 0) {
                        if(dontWant)
-                               node.peers.disconnect(pn, true, false);
+                               node.peers.disconnect(pn, true, false, true);
                        else
                                pn.maybeSendInitialMessages();
                } else {
@@ -1486,6 +1496,7 @@
                        else trackerID = pn.getReusableTrackerID();
                        System.arraycopy(Fields.longToBytes(trackerID), 0, 
data, ptr, 8);
                        ptr += 8;
+                       if(logMINOR) Logger.minor(this, "Sending tracker ID 
"+trackerID+" in JFK(3)");
                }
                System.arraycopy(Fields.longToBytes(node.bootID), 0, data, ptr, 
8);
                ptr += 8;
@@ -2835,7 +2846,7 @@
        /* (non-Javadoc)
         * @see 
freenet.node.OutgoingPacketMangler#sendHandshake(freenet.node.PeerNode)
         */
-       public void sendHandshake(PeerNode pn) {
+       public void sendHandshake(PeerNode pn, boolean notRegistered) {
                int negType = pn.selectNegType(this);
                if(negType == -1) {
                        // Pick a random negType from what I do support
@@ -2847,13 +2858,13 @@

                Peer peer = pn.getHandshakeIP();
                if(peer == null) {
-                       pn.couldNotSendHandshake();
+                       pn.couldNotSendHandshake(notRegistered);
                        return;
                }
                sendJFKMessage1(pn, peer, pn.handshakeUnknownInitiator(), 
pn.handshakeSetupType(), negType);
                if(logMINOR)
                        Logger.minor(this, "Sending handshake to "+peer+" for 
"+pn);
-               pn.sentHandshake();
+               pn.sentHandshake(notRegistered);
        }

        /* (non-Javadoc)
@@ -2870,7 +2881,7 @@
        }

        public int[] supportedNegTypes() {
-               return new int[] { 2, 3, 4 };
+               return new int[] { 2, 4 };
        }

        public int fullHeadersLengthOneMessage() {

Modified: branches/db4o/freenet/src/freenet/node/KeyTracker.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/KeyTracker.java      2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/KeyTracker.java      2008-12-17 
14:35:21 UTC (rev 24436)
@@ -33,5 +33,9 @@
                this.sessionCipher = cipher;
                this.sessionKey = sessionKey;
        }
+       
+       public String toString() {
+               return super.toString()+":"+packets.toString();
+       }

 }

Modified: branches/db4o/freenet/src/freenet/node/Node.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/Node.java    2008-12-17 14:34:16 UTC 
(rev 24435)
+++ branches/db4o/freenet/src/freenet/node/Node.java    2008-12-17 14:35:21 UTC 
(rev 24436)
@@ -3375,7 +3375,7 @@
        }

        public void removePeerConnection(PeerNode pn) {
-               peers.disconnect(pn, true, false);
+               peers.disconnect(pn, true, false, false);
        }

        public void onConnectedPeer() {

Modified: branches/db4o/freenet/src/freenet/node/NodeDispatcher.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/NodeDispatcher.java  2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/NodeDispatcher.java  2008-12-17 
14:35:21 UTC (rev 24436)
@@ -314,7 +314,7 @@
                // Otherwise just dump all current connection state and keep 
trying to connect.
                boolean remove = m.getBoolean(DMT.REMOVE);
                if(remove)
-                       node.peers.disconnect(source, false, false);
+                       node.peers.disconnect(source, false, false, false);
                // If true, purge all references to this node. Otherwise, we 
can keep the node
                // around in secondary tables etc in order to more easily 
reconnect later. 
                // (Mostly used on opennet)

Modified: branches/db4o/freenet/src/freenet/node/OpennetManager.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/OpennetManager.java  2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/OpennetManager.java  2008-12-17 
14:35:21 UTC (rev 24436)
@@ -58,7 +58,7 @@
         * if we have no other option. */
        private final LRUQueue oldPeers;
        /** Maximum number of old peers */
-       static final int MAX_OLD_PEERS = 50;
+       static final int MAX_OLD_PEERS = 25;
        /** Time at which last dropped a peer */
        private long timeLastDropped;
        /** Number of successful CHK requests since last added a node */
@@ -101,6 +101,8 @@
        public static final int MIN_PEERS_FOR_SCALING = 10;
        /** Maximum number of peers */
        public static final int MAX_PEERS_FOR_SCALING = 20;
+       /** Stop trying to reconnect to an old-opennet-peer after a month. */
+       public static final long MAX_TIME_ON_OLD_OPENNET_PEERS = 31 * 24 * 60 * 
60 * 1000;

        private final long creationTime;

@@ -246,7 +248,7 @@
                        if(logMINOR) Logger.minor(this, "Not adding 
"+pn.userToString()+" to opennet list as already there");
                        return null;
                }
-               if(wantPeer(pn, true, false)) return pn;
+               if(wantPeer(pn, true, false, false)) return pn;
                else return null;
                // Start at bottom. Node must prove itself.
        }
@@ -265,6 +267,10 @@
                dropExcessPeers();
        }

+       private long timeLastAddedOldOpennetPeer = -1;
+       
+       private static final int OLD_OPENNET_PEER_INTERVAL = 30*1000;
+       
        /**
         * Trim the peers list and possibly add a new node. Note that if we are 
not adding a new node,
         * we will only return true every MIN_TIME_BETWEEN_OFFERS, to prevent 
problems caused by many
@@ -273,11 +279,19 @@
         * @param addAtLRU If there is a node to add, add it at the bottom 
rather than the top. Normally
         * we set this on new path folded nodes so that they will be replaced 
if during the trial period,
         * plus the time it takes to get a new path folding offer, they don't 
have a successful request.
-        * @param justChecking If true, and nodeToAddNow == null, we don't 
actually send an offer, we
-        * just want to know if there is space for a node.
+        * @param justChecking If true, we want to know whether there is space 
for a node to be added
+        * RIGHT NOW. If false, the normal behaviour applies: if nodeToAddNow 
is passed in, we decide
+        * whether to add that node, if it's null, we decide whether to send an 
offer subject to the
+        * inter-offer time.
+        * @param oldOpennetPeer If true, we are trying to add an 
old-opennet-peer which has reconnected.
+        * There is a throttle, we accept no more than one old-opennet-peer 
every 30 seconds. On receiving
+        * a packet, we call once to decide whether to try to parse it against 
the old-opennet-peers, and
+        * then again to decide whether it is worth keeping; in the latter case 
if we decide not, the
+        * old-opennet-peer will be told to disconnect and go away, but 
normally we don't reach that point
+        * because of the first check.
         * @return True if the node was added / should be added.
         */
-       public boolean wantPeer(PeerNode nodeToAddNow, boolean addAtLRU, 
boolean justChecking) {
+       public boolean wantPeer(PeerNode nodeToAddNow, boolean addAtLRU, 
boolean justChecking, boolean oldOpennetPeer) {
                boolean notMany = false;
                boolean noDisconnect;
                synchronized(this) {
@@ -301,6 +315,9 @@
                                if(nodeToAddNow != null || !justChecking)
                                        timeLastOffered = 
System.currentTimeMillis();
                                notMany = true;
+                               // Don't check timeLastAddedOldOpennetPeer, 
since we want it anyway. But do update it.
+                               if(oldOpennetPeer)
+                                       timeLastAddedOldOpennetPeer = 
System.currentTimeMillis();
                        }
                        noDisconnect = successCount < 
MIN_SUCCESS_BETWEEN_DROP_CONNS;
                }
@@ -316,13 +333,13 @@
                        // If we have dropped a disconnected peer, then the 
inter-peer offer cooldown doesn't apply: we can accept immediately.
                        boolean hasDisconnected = false;
                        if(peersLRU.size() == maxPeers && nodeToAddNow == null) 
{
-                               PeerNode toDrop = peerToDrop(true);
+                               PeerNode toDrop = peerToDrop(true, false);
                                if(toDrop != null)
                                        hasDisconnected = !toDrop.isConnected();
                        } else while(peersLRU.size() > maxPeers - (nodeToAddNow 
== null ? 0 : 1)) {
                                OpennetPeerNode toDrop;
                                // can drop peers which are over the limit
-                               toDrop = peerToDrop(noDisconnect || 
nodeToAddNow == null);
+                               toDrop = peerToDrop(noDisconnect || 
nodeToAddNow == null, false);
                                if(toDrop == null) {
                                        if(logMINOR)
                                                Logger.minor(this, "No more 
peers to drop, still "+peersLRU.size()+" peers, cannot accept 
peer"+(nodeToAddNow == null ? "" : nodeToAddNow.toString()));
@@ -336,8 +353,12 @@
                                peersLRU.remove(toDrop);
                                dropList.add(toDrop);
                        }
-                       if(canAdd) {
-                               long now = System.currentTimeMillis();
+                       long now = System.currentTimeMillis();
+                       if(canAdd && oldOpennetPeer) {
+                               if(timeLastAddedOldOpennetPeer > 0 && now - 
timeLastAddedOldOpennetPeer > OLD_OPENNET_PEER_INTERVAL)
+                                       canAdd = false;
+                       }
+                       if(canAdd && !justChecking) {
                                if(nodeToAddNow != null) {
                                        successCount = 0;
                                        if(addAtLRU)
@@ -348,6 +369,8 @@
                                        oldPeers.remove(nodeToAddNow);
                                        if(!dropList.isEmpty())
                                                timeLastDropped = now;
+                                       if(oldOpennetPeer)
+                                               timeLastAddedOldOpennetPeer = 
now;
                                } else {
                                        if(now - timeLastOffered <= 
MIN_TIME_BETWEEN_OFFERS && !hasDisconnected) {
                                                if(logMINOR)
@@ -374,26 +397,27 @@
                }
                for(OpennetPeerNode pn : dropList) {
                        if(logMINOR) Logger.minor(this, "Dropping LRU opennet 
peer: "+pn);
-                       node.peers.disconnect(pn, true, true);
+                       node.peers.disconnect(pn, true, true, true);
                }
                return canAdd;
        }

-       private void dropExcessPeers() {
+       void dropExcessPeers() {
                while(peersLRU.size() > getNumberOfConnectedPeersToAim()) {
                        if(logMINOR)
                                Logger.minor(this, "Dropping opennet peers: 
currently "+peersLRU.size());
                        PeerNode toDrop;
-                       toDrop = peerToDrop(false);
+                       toDrop = peerToDrop(false, false);
+                       if(toDrop == null) toDrop = peerToDrop(false, true);
                        if(toDrop == null) return;
                        peersLRU.remove(toDrop);
                        if(logMINOR)
                                Logger.minor(this, "Dropping "+toDrop);
-                       node.peers.disconnect(toDrop, true, true);
+                       node.peers.disconnect(toDrop, true, true, true);
                }
        }

-       synchronized OpennetPeerNode peerToDrop(boolean noDisconnect) {
+       synchronized OpennetPeerNode peerToDrop(boolean noDisconnect, boolean 
force) {
                if(peersLRU.size() < getNumberOfConnectedPeersToAim()) {
                        // Don't drop any peers
                        return null;
@@ -403,11 +427,12 @@
                        for(int i=0;i<peers.length;i++) {
                                OpennetPeerNode pn = peers[i];
                                if(pn == null) continue;
-                               if(!pn.isDroppable()) continue;
+                               if((!pn.isDroppable(false)) && !force) continue;
                                // LOCKING: Always take the OpennetManager lock 
first
                                if(!pn.isConnected()) {
                                        if(Logger.shouldLog(Logger.MINOR, this))
                                                Logger.minor(this, "Possibly 
dropping opennet peer "+pn+" as is disconnected");
+                                       pn.setWasDropped();
                                        return pn;
                                }
                        }
@@ -417,10 +442,11 @@
                        for(int i=0;i<peers.length;i++) {
                                OpennetPeerNode pn = peers[i];
                                if(pn == null) continue;
-                               if(!pn.isDroppable()) continue;
+                               if((!pn.isDroppable(false)) && !force) continue;
                                if(Logger.shouldLog(Logger.MINOR, this))
                                        Logger.minor(this, "Possibly dropping 
opennet peer "+pn+" "+
                                                        
(System.currentTimeMillis() - timeLastDropped)+" ms since last dropped peer");
+                               pn.setWasDropped();
                                return pn;
                        }
                }
@@ -439,16 +465,19 @@
                                // Re-add it: nasty race condition when we have 
few peers
                        }
                }
-               if(!wantPeer(pn, false, false)) // Start at top as it just 
succeeded
-                       node.peers.disconnect(pn, true, false);
+               if(!wantPeer(pn, false, false, false)) // Start at top as it 
just succeeded
+                       node.peers.disconnect(pn, true, false, true);
        }

        public void onRemove(OpennetPeerNode pn) {
                synchronized (this) {
                        peersLRU.remove(pn);
-                       oldPeers.push(pn);
-                       while (oldPeers.size() > MAX_OLD_PEERS)
-                               oldPeers.pop();
+                       if(pn.isDroppable(true) && !pn.grabWasDropped()) {
+                               if(logMINOR) Logger.minor(this, "onRemove() for 
"+pn);
+                               oldPeers.push(pn);
+                               while (oldPeers.size() > MAX_OLD_PEERS)
+                                       oldPeers.pop();
+                       }
                }
        }


Modified: branches/db4o/freenet/src/freenet/node/OpennetPeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/OpennetPeerNode.java 2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/OpennetPeerNode.java 2008-12-17 
14:35:21 UTC (rev 24436)
@@ -35,13 +35,14 @@
                return true;
        }

-       public boolean isDroppable() {
+       public boolean isDroppable(boolean ignoreDisconnect) {
                long now = System.currentTimeMillis();
                if(now - getPeerAddedTime() < OpennetManager.DROP_MIN_AGE)
                        return false; // New node
                if(now - node.usm.getStartedTime() < 
OpennetManager.DROP_STARTUP_DELAY)
                        return false; // Give them time to connect after we 
startup
                int status = getPeerNodeStatus();
+               if(!ignoreDisconnect) {
                synchronized(this) {
                        if((status == 
PeerManager.PEER_NODE_STATUS_DISCONNECTED) && (!super.neverConnected()) && 
                                        now - timeLastDisconnect < 
OpennetManager.DROP_DISCONNECT_DELAY &&
@@ -50,6 +51,7 @@
                                return false;
                        }
                }
+               }
                return true;
        }

@@ -116,7 +118,24 @@

        @Override
        protected void onConnect() {
+               super.onConnect();
                
opennet.crypto.socket.getAddressTracker().setPresumedGuiltyAt(System.currentTimeMillis()+60*60*1000);
        }

+       private boolean wasDropped;
+
+       synchronized void setWasDropped() {
+               wasDropped = true;
+       }
+       
+       synchronized boolean wasDropped() {
+               return wasDropped;
+       }
+       
+       synchronized boolean grabWasDropped() {
+               boolean ret = wasDropped;
+               wasDropped = false;
+               return ret;
+       }
+       
 }

Modified: branches/db4o/freenet/src/freenet/node/OutgoingPacketMangler.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/OutgoingPacketMangler.java   
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/OutgoingPacketMangler.java   
2008-12-17 14:35:21 UTC (rev 24436)
@@ -77,7 +77,7 @@
         * Send a handshake, if possible, to the node.
         * @param pn
         */
-       public void sendHandshake(PeerNode pn);
+       public void sendHandshake(PeerNode pn, boolean notRegistered);

        /**
         * Is a peer disconnected?

Modified: branches/db4o/freenet/src/freenet/node/PacketSender.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/PacketSender.java    2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/PacketSender.java    2008-12-17 
14:35:21 UTC (rev 24436)
@@ -236,7 +236,7 @@
                        pn.maybeOnConnect();
                        if(pn.shouldDisconnectAndRemoveNow() && 
!pn.isDisconnecting()) {
                                // Might as well do it properly.
-                               node.peers.disconnect(pn, true, true);
+                               node.peers.disconnect(pn, true, true, false);
                        }
                        if(pn.shouldThrottle() && !canSendThrottled)
                                continue;
@@ -261,7 +261,7 @@
                                }

                                try {
-                               if(pn.maybeSendPacket(now, rpiTemp, rpiIntTemp) 
&& canSendThrottled) {
+                               if(canSendThrottled && pn.maybeSendPacket(now, 
rpiTemp, rpiIntTemp)) {
                                        canSendThrottled = false;
                                        count = node.outputThrottle.getCount();
                                        if(count > MAX_PACKET_SIZE)
@@ -295,7 +295,7 @@
                        if(pn.shouldSendHandshake()) {
                                // Send handshake if necessary
                                long beforeHandshakeTime = 
System.currentTimeMillis();
-                               pn.getOutgoingMangler().sendHandshake(pn);
+                               pn.getOutgoingMangler().sendHandshake(pn, 
false);
                                long afterHandshakeTime = 
System.currentTimeMillis();
                                if((afterHandshakeTime - beforeHandshakeTime) > 
(2 * 1000))
                                        Logger.error(this, "afterHandshakeTime 
is more than 2 seconds past beforeHandshakeTime (" + (afterHandshakeTime - 
beforeHandshakeTime) + ") in PacketSender working with " + pn.userToString());
@@ -307,28 +307,39 @@
                }
                brokeAt = newBrokeAt;

-               // Consider sending connect requests to our opennet old-peers.
-               // No point if they are NATed, of course... but we don't know 
whether they are.
+               /* Attempt to connect to old-opennet-peers.
+                * Constantly send handshake packets, in order to get through a 
NAT.
+                * Most JFK(1)'s are less than 300 bytes. 25*300/15 = avg 
500B/sec bandwidth cost.
+                * Well worth it to allow us to reconnect more quickly. */
+               
                OpennetManager om = node.getOpennet();
-               if(om != null) {
-                       int connCount = node.peers.quickCountConnectedPeers();
-                       int minDelay = connCount == 0 ? 
MIN_OLD_OPENNET_CONNECT_DELAY_NO_CONNS : MIN_OLD_OPENNET_CONNECT_DELAY;
-                       if(logDEBUG)
-                               Logger.debug(this, "Conns " + connCount + " 
minDelay " + minDelay + " old opennet peers " + om.countOldOpennetPeers() + " 
last sent " + (now - timeLastSentOldOpennetConnectAttempt) + " startup " + (now 
- node.startupTime));
-                       if(now - timeLastSentOldOpennetConnectAttempt > 
minDelay &&
-                               connCount <= 
MIN_CONNECTIONS_TRY_OLD_OPENNET_PEERS &&
-                               om.countOldOpennetPeers() > 0 &&
-                               now - node.startupTime > 
OpennetManager.DROP_STARTUP_DELAY) {
-                               PeerNode pn = om.randomOldOpennetNode();
-                               if(pn != null) {
-                                       if(logMINOR)
-                                               Logger.minor(this, "Sending 
old-opennet connect attempt to " + pn);
-                                       
pn.getOutgoingMangler().sendHandshake(pn);
-                                       timeLastSentOldOpennetConnectAttempt = 
now;
-                                       if(pn.noContactDetails() && 
node.getPeerNodes().length > 0 && connCount > 0 && node.random.nextBoolean())
-                                               pn.startARKFetcher();
+               if(om != null && node.getUptime() > 30*1000) {
+                       PeerNode[] peers = om.getOldPeers();
+                       
+                       for(PeerNode pn : peers) {
+                               if(pn.timeLastConnected() <= 0)
+                                       Logger.error(this, "Last connected is 
zero or negative for old-opennet-peer "+pn);
+                               // Will be removed by next line.
+                               if(now - pn.timeLastConnected() > 
OpennetManager.MAX_TIME_ON_OLD_OPENNET_PEERS) {
+                                       om.purgeOldOpennetPeer(pn);
+                                       if(logMINOR) Logger.minor(this, 
"Removing old opennet peer (too old): "+pn);
+                                       continue;
                                }
+                               if(pn.isConnected()) continue; // Race 
condition??
+                               if(pn.noContactDetails()) {
+                                       pn.startARKFetcher();
+                                       continue;
+                               }
+                               if(pn.shouldSendHandshake()) {
+                                       // Send handshake if necessary
+                                       long beforeHandshakeTime = 
System.currentTimeMillis();
+                                       
pn.getOutgoingMangler().sendHandshake(pn, true);
+                                       long afterHandshakeTime = 
System.currentTimeMillis();
+                                       if((afterHandshakeTime - 
beforeHandshakeTime) > (2 * 1000))
+                                               Logger.error(this, 
"afterHandshakeTime is more than 2 seconds past beforeHandshakeTime (" + 
(afterHandshakeTime - beforeHandshakeTime) + ") in PacketSender working with " 
+ pn.userToString());
+                               }
                        }
+                       
                }

                if(now - lastClearedOldSwapChains > 10000) {

Modified: branches/db4o/freenet/src/freenet/node/PeerManager.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/PeerManager.java     2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/PeerManager.java     2008-12-17 
14:35:21 UTC (rev 24436)
@@ -477,7 +477,7 @@
        /**
         * Disconnect from a specified node
         */
-       public void disconnect(final PeerNode pn, boolean 
sendDisconnectMessage, final boolean waitForAck) {
+       public void disconnect(final PeerNode pn, boolean 
sendDisconnectMessage, final boolean waitForAck, boolean purge) {
                if(logMINOR)
                        Logger.minor(this, "Disconnecting " + 
pn.shortToString());
                synchronized(this) {
@@ -486,7 +486,7 @@
                }
                pn.notifyDisconnecting();
                if(sendDisconnectMessage) {
-                       Message msg = DMT.createFNPDisconnect(true, false, -1, 
new ShortBuffer(new byte[0]));
+                       Message msg = DMT.createFNPDisconnect(true, purge, -1, 
new ShortBuffer(new byte[0]));
                        try {
                                pn.sendAsync(msg, new AsyncMessageCallback() {

@@ -1768,6 +1768,7 @@
                                continue;
                        count++;
                }
+               if(logMINOR) Logger.minor(this, "countConnectedDarknetPeers() 
returning "+count);
                return count;
        }


Modified: branches/db4o/freenet/src/freenet/node/PeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/PeerNode.java        2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/PeerNode.java        2008-12-17 
14:35:21 UTC (rev 24436)
@@ -166,7 +166,7 @@
        private boolean isRoutable;

        /** Used by maybeOnConnect */
-       private boolean wasDisconnected;
+       private boolean wasDisconnected = true;
        /**
        * ARK fetcher.
        */
@@ -1364,25 +1364,25 @@
                if(isBurstOnly())
                        return calcNextHandshakeBurstOnly(now);
                synchronized(this) {
-               long delay;
-               if(unroutableOlderVersion || unroutableNewerVersion || 
disableRouting) {
-                       // Let them know we're here, but have no hope of 
routing general data to them.
-                       delay = Node.MIN_TIME_BETWEEN_VERSION_SENDS + 
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_VERSION_SENDS);
-               } else if(invalidVersion() && !firstHandshake) {
-                       delay = Node.MIN_TIME_BETWEEN_VERSION_PROBES + 
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_VERSION_PROBES);
-               } else {
-                       delay = Node.MIN_TIME_BETWEEN_HANDSHAKE_SENDS + 
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_HANDSHAKE_SENDS);
+                       long delay;
+                       if(unroutableOlderVersion || unroutableNewerVersion || 
disableRouting) {
+                               // Let them know we're here, but have no hope 
of routing general data to them.
+                               delay = Node.MIN_TIME_BETWEEN_VERSION_SENDS + 
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_VERSION_SENDS);
+                       } else if(invalidVersion() && !firstHandshake) {
+                               delay = Node.MIN_TIME_BETWEEN_VERSION_PROBES + 
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_VERSION_PROBES);
+                       } else {
+                               delay = Node.MIN_TIME_BETWEEN_HANDSHAKE_SENDS + 
node.random.nextInt(Node.RANDOMIZED_TIME_BETWEEN_HANDSHAKE_SENDS);
+                       }
+                       // FIXME proper multi-homing support!
+                       delay /= (handshakeIPs == null ? 1 : 
handshakeIPs.length);
+                       if(delay < 3000) delay = 3000;
+                       sendHandshakeTime = now + delay;
+                       
+                       if(successfulHandshakeSend)
+                               firstHandshake = false;
+                       handshakeCount++;
+                       return handshakeCount == MAX_HANDSHAKE_COUNT;
                }
-               sendHandshakeTime = now + delay;
-               // FIXME proper multi-homing support!
-               delay /= (handshakeIPs == null ? 1 : handshakeIPs.length);
-               if(delay < 3000) delay = 3000;
-               
-               if(successfulHandshakeSend)
-                       firstHandshake = false;
-               handshakeCount++;
-               return handshakeCount == MAX_HANDSHAKE_COUNT;
-               }
        }

        private synchronized boolean calcNextHandshakeBurstOnly(long now) {
@@ -1414,11 +1414,12 @@
                return fetchARKFlag;
        }

-       protected void calcNextHandshake(boolean successfulHandshakeSend, 
boolean dontFetchARK) {
+       protected void calcNextHandshake(boolean successfulHandshakeSend, 
boolean dontFetchARK, boolean notRegistered) {
                long now = System.currentTimeMillis();
                boolean fetchARKFlag = false;
                fetchARKFlag = innerCalcNextHandshake(successfulHandshakeSend, 
dontFetchARK, now);
-               setPeerNodeStatus(now);  // Because of isBursting being set 
above and it can't hurt others
+               if(!notRegistered)
+                       setPeerNodeStatus(now);  // Because of isBursting being 
set above and it can't hurt others
                // Don't fetch ARKs for peers we have verified (through 
handshake) to be incompatible with us
                if(fetchARKFlag && !dontFetchARK) {
                        long arkFetcherStartTime1 = System.currentTimeMillis();
@@ -1457,20 +1458,20 @@
        * Call this method when a handshake request has been
        * sent.
        */
-       public void sentHandshake() {
+       public void sentHandshake(boolean notRegistered) {
                if(logMINOR)
                        Logger.minor(this, "sentHandshake(): " + this);
-               calcNextHandshake(true, false);
+               calcNextHandshake(true, false, notRegistered);
        }

        /**
        * Call this method when a handshake request could not be sent (i.e. no 
IP address available)
        * sent.
        */
-       public void couldNotSendHandshake() {
+       public void couldNotSendHandshake(boolean notRegistered) {
                if(logMINOR)
                        Logger.minor(this, "couldNotSendHandshake(): " + this);
-               calcNextHandshake(false, false);
+               calcNextHandshake(false, false, notRegistered);
        }

        /**
@@ -1830,7 +1831,7 @@

                // Update sendHandshakeTime; don't send another handshake for a 
while.
                // If unverified, "a while" determines the timeout; if not, 
it's just good practice to avoid a race below.
-               calcNextHandshake(true, true);
+               calcNextHandshake(true, true, false);
                stopARKFetcher();
                try {
                        // First, the new noderef
@@ -1905,7 +1906,6 @@
                        } else if(bootIDChanged && logMINOR)
                                Logger.minor(this, "Changed boot ID from " + 
bootID + " to " + thisBootID + " for " + getPeer());
                        this.bootID = thisBootID;
-                       boolean newPacketTracker = false;
                        if(currentTracker != null && 
currentTracker.packets.trackerID == trackerID && 
!currentTracker.packets.isDeprecated()) {
                                if(isJFK4 && !jfk4SameAsOld)
                                        Logger.error(this, "In JFK(4), found 
tracker ID "+trackerID+" but other side says is new! for "+this);
@@ -1923,7 +1923,6 @@
                        } else if(trackerID == -1) {
                                // Create a new tracker unconditionally
                                packets = new PacketTracker(this);
-                               newPacketTracker = true;
                                if(logMINOR) Logger.minor(this, "Creating new 
PacketTracker as instructed for "+this);
                        } else if(trackerID == -2 && !bootIDChanged) {
                                // Reuse if not deprecated and not boot ID 
changed
@@ -1935,7 +1934,6 @@
                                        if(logMINOR) Logger.minor(this, 
"Re-using packet tracker (not given an ID): "+packets.trackerID+" on "+this+" 
from prev "+previousTracker);
                                } else {
                                        packets = new PacketTracker(this);
-                                       newPacketTracker = true;
                                        if(logMINOR) Logger.minor(this, "Cannot 
reuse trackers (not given an ID) on "+this);
                                }
                        } else {
@@ -1946,11 +1944,9 @@
                                        packets = new PacketTracker(this, 
trackerID);
                                } else
                                        packets = new PacketTracker(this);
-                               newPacketTracker = true;
                                if(logMINOR) Logger.minor(this, "Creating new 
tracker (last resort) on "+this);
                        }
                        if(bootIDChanged) {
-                               newPacketTracker = true;
                                oldPrev = previousTracker;
                                oldCur = currentTracker;
                                previousTracker = null;
@@ -1964,7 +1960,7 @@
                                // else it's a rekey
                        }
                        newTracker = new KeyTracker(this, packets, encCipher, 
encKey);
-                       if(logMINOR) Logger.minor(this, "New key tracker in 
completedHandshake: "+newTracker+" for "+shortToString()+" neg type "+negType+" 
new packet tracker: "+newPacketTracker);
+                       if(logMINOR) Logger.minor(this, "New key tracker in 
completedHandshake: "+newTracker+" for "+packets+" for "+shortToString()+" neg 
type "+negType);
                        if(unverified) {
                                if(unverifiedTracker != null) {
                                        // Keep the old unverified tracker if 
possible.
@@ -2031,7 +2027,7 @@
                        node.peers.disconnected(this);
                else if(!wasARekey) {
                        node.peers.addConnectedPeer(this);
-                       onConnect();
+                       maybeOnConnect();
                }

                return packets.trackerID;
@@ -2236,6 +2232,7 @@
                maybeSendInitialMessages();
                setPeerNodeStatus(now);
                node.peers.addConnectedPeer(this);
+               maybeOnConnect();
                if(completelyDeprecatedTracker != null) {
                        if(completelyDeprecatedTracker.packets != 
tracker.packets)
                                
completelyDeprecatedTracker.packets.completelyDeprecated(tracker);
@@ -3303,7 +3300,9 @@
         * A method to be called once at the beginning of every time 
isConnected() is true
         */
        protected void onConnect() {
-               // Do nothing in the default impl
+               OpennetManager om = node.getOpennet();
+               if(om != null)
+                       om.dropExcessPeers();
        }

        public void onFound(long edition, FetchResult result) {
@@ -4254,8 +4253,15 @@
                synchronized(this) {
                        cur = currentTracker;
                }
-               if(cur == null) return -1;
-               if(cur.packets.isDeprecated()) return -1;
+               if(cur == null) {
+                       if(logMINOR) Logger.minor(this, 
"getReusableTrackerID(): cur = null on "+this);
+                       return -1;
+               }
+               if(cur.packets.isDeprecated()) {
+                       if(logMINOR) Logger.minor(this, 
"getReusableTrackerID(): cur.packets.isDeprecated on "+this);
+                       return -1;
+               }
+               if(logMINOR) Logger.minor(this, "getReusableTrackerID(): 
"+cur.packets.trackerID+" on "+this);
                return cur.packets.trackerID;
        }
 }

Modified: branches/db4o/freenet/src/freenet/node/RequestHandler.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/RequestHandler.java  2008-12-17 
14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/RequestHandler.java  2008-12-17 
14:35:21 UTC (rev 24436)
@@ -558,7 +558,7 @@
        private boolean finishOpennetNoRelayInner(OpennetManager om) {
                if(logMINOR)
                        Logger.minor(this, "Finishing opennet: sending own 
reference");
-               if(!om.wantPeer(null, false, false))
+               if(!om.wantPeer(null, false, false, false))
                        return false; // Don't want a reference

                try {

Modified: branches/db4o/freenet/src/freenet/node/SeedClientPeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SeedClientPeerNode.java      
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/SeedClientPeerNode.java      
2008-12-17 14:35:21 UTC (rev 24436)
@@ -85,7 +85,7 @@
        @Override
        public boolean disconnected(boolean dumpMessageQueue, boolean 
dumpTrackers) {
                boolean ret = super.disconnected(dumpMessageQueue, 
dumpTrackers);
-               node.peers.disconnect(this, false, false);
+               node.peers.disconnect(this, false, false, false);
                return ret;
        }


Modified: branches/db4o/freenet/src/freenet/node/SeedServerPeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SeedServerPeerNode.java      
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/node/SeedServerPeerNode.java      
2008-12-17 14:35:21 UTC (rev 24436)
@@ -73,7 +73,7 @@
                final OpennetManager om = node.getOpennet();
                if(om == null) {
                        Logger.normal(this, "Opennet turned off while 
connecting to seednodes");
-                       node.peers.disconnect(this, true, true);
+                       node.peers.disconnect(this, true, true, true);
                } else {
                        // Wait 5 seconds. Another node may connect first, we 
don't want all the
                        // announcements to go to the node which we connect to 
most quickly.
@@ -113,7 +113,7 @@
        @Override
        public boolean disconnected(boolean dumpMessageQueue, boolean 
dumpTrackers) {
                boolean ret = super.disconnected(dumpMessageQueue, 
dumpTrackers);
-               node.peers.disconnect(this, false, false);
+               node.peers.disconnect(this, false, false, false);
                return ret;
        }


Modified: branches/db4o/freenet/src/freenet/node/Version.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/Version.java 2008-12-17 14:34:16 UTC 
(rev 24435)
+++ branches/db4o/freenet/src/freenet/node/Version.java 2008-12-17 14:35:21 UTC 
(rev 24436)
@@ -24,17 +24,17 @@
        public static final String protocolVersion = "1.0";

        /** The build number of the current revision */
-       private static final int buildNumber = 1192;
+       private static final int buildNumber = 1193;

        /** Oldest build of Fred we will talk to */
-       private static final int oldLastGoodBuild = 1190;
-       private static final int newLastGoodBuild = 1192;
+       private static final int oldLastGoodBuild = 1192;
+       private static final int newLastGoodBuild = 1193;
        static final long transitionTime;

        static {
                final Calendar _cal = 
Calendar.getInstance(TimeZone.getTimeZone("GMT"));
                // year, month - 1 (or constant), day, hour, minute, second
-               _cal.set( 2008, Calendar.DECEMBER, 12, 0, 0, 0 );
+               _cal.set( 2008, Calendar.DECEMBER, 16, 0, 0, 0 );
                transitionTime = _cal.getTimeInMillis();
        }


Modified: branches/db4o/freenet/src/freenet/support/MultiValueTable.java
===================================================================
--- branches/db4o/freenet/src/freenet/support/MultiValueTable.java      
2008-12-17 14:34:16 UTC (rev 24435)
+++ branches/db4o/freenet/src/freenet/support/MultiValueTable.java      
2008-12-17 14:35:21 UTC (rev 24436)
@@ -74,6 +74,15 @@
                 v.elements());
     }

+    /**
+     * To be used in for(x : y).
+     */
+    public Iterable<V> iterateAll(K key) {
+               synchronized (table) {
+                       return(table.get(key));
+               }
+    }
+    
     public int countAll(K key) {
        Vector<V> v;
                synchronized (table) {


Reply via email to