Author: toad
Date: 2009-04-01 19:43:11 +0000 (Wed, 01 Apr 2009)
New Revision: 26320

Added:
   branches/db4o/freenet/test/freenet/client/
   branches/db4o/freenet/test/freenet/client/CodeTest.java
Removed:
   branches/db4o/freenet/test/freenet/client/CodeTest.java
Modified:
   branches/db4o/freenet/
   branches/db4o/freenet/build.xml
   branches/db4o/freenet/devnotes/specs/metadata-v0.txt
   branches/db4o/freenet/src/freenet/client/
   branches/db4o/freenet/src/freenet/clients/http/ConfigToadlet.java
   branches/db4o/freenet/src/freenet/clients/http/ConnectionsToadlet.java
   branches/db4o/freenet/src/freenet/clients/http/FProxyToadlet.java
   branches/db4o/freenet/src/freenet/keys/FreenetURI.java
   branches/db4o/freenet/src/freenet/l10n/freenet.l10n.en.properties
   branches/db4o/freenet/src/freenet/node/DarknetPeerNode.java
   branches/db4o/freenet/src/freenet/node/NodeStats.java
   branches/db4o/freenet/src/freenet/node/OpennetPeerNode.java
   branches/db4o/freenet/src/freenet/node/PeerNode.java
   branches/db4o/freenet/src/freenet/node/SSKInsertSender.java
   branches/db4o/freenet/src/freenet/node/SeedClientPeerNode.java
   branches/db4o/freenet/src/freenet/node/SeedServerPeerNode.java
   
branches/db4o/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
   branches/db4o/freenet/src/freenet/support/BinaryBloomFilter.java
   branches/db4o/freenet/src/freenet/support/BloomFilter.java
   branches/db4o/freenet/src/freenet/support/CountingBloomFilter.java
   branches/db4o/freenet/test/freenet/clients/http/filter/ContentFilterTest.java
   branches/db4o/freenet/test/freenet/support/io/MockInputStream.java
Log:
Merge trunk to SVN r26318



Property changes on: branches/db4o/freenet
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/db4o:25594
/trunk/freenet:19964-26118,26139
   + /branches/db4o:25594
/trunk/freenet:19964-26318

Modified: branches/db4o/freenet/build.xml
===================================================================
--- branches/db4o/freenet/build.xml     2009-04-01 18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/build.xml     2009-04-01 19:43:11 UTC (rev 26320)
@@ -87,11 +87,8 @@
                        <compilerarg value="-Xlint"/>
 
                        <!-- following a very temporary list of files to be 
build -->
-                       <include name="org/**/*.java"/>
                        <include name="freenet/**/*.java"/>
                        <include name="net/i2p/util/*.java"/>
-                       <exclude name="org/**/MersenneTwisterTest.java"/>
-                       <exclude name="freenet/node/*Test.java"/>
                        <exclude name="**/package-info.java"/>
                </javac>
                <!-- Copy web interface static files to the build dir -->

Modified: branches/db4o/freenet/devnotes/specs/metadata-v0.txt
===================================================================
--- branches/db4o/freenet/devnotes/specs/metadata-v0.txt        2009-04-01 
18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/devnotes/specs/metadata-v0.txt        2009-04-01 
19:43:11 UTC (rev 26320)
@@ -2,7 +2,7 @@
 
 Ian has agreed that binary metadata is probably the best thing. I
 therefore propose a simple, extensible binary metadata format, primarily
-aimed at implementing splitfiles in the not too distant future. It
+aimed at implementing splitfiles in the not-too-distant future. It
 provides limited extension capabilities in the areas of metadata,
 splitfile codecs, document types, and ZIP manifests, and is reasonably
 compact. It allows for various tricks which may be provided for in


Property changes on: branches/db4o/freenet/src/freenet/client
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/db4o/src/freenet/client:25594
/trunk/freenet/src/freenet/client:25873-26118,26139
   + /branches/db4o/src/freenet/client:25594
/trunk/freenet/src/freenet/client:25873-26318

Modified: branches/db4o/freenet/src/freenet/clients/http/ConfigToadlet.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/ConfigToadlet.java   
2009-04-01 18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/clients/http/ConfigToadlet.java   
2009-04-01 19:43:11 UTC (rev 26320)
@@ -71,9 +71,10 @@
 
                        if (node.isUsingWrapper()) {
                                alertNode.addChild("br");
-                               HTMLNode restartForm = 
alertNode.addChild("form", //
-                                               new String[] { "action", 
"method" },//
-                                       new String[] { "/", "get" });
+                               HTMLNode restartForm = 
alertNode.addChild("form", new String[] { "action", "method", "enctype", "id",  
"accept-charset" },
+                                               new String[] { "/", "post", 
"multipart/form-data", "restartForm", "utf-8"} ).addChild("div");
+                               restartForm.addChild("input", new String[] { 
"type", "name", "value" },
+                                               new String[] { "hidden", 
"formPassword", node.clientCore.formPassword });
                                restartForm.addChild("div");
                                restartForm.addChild("input",//
                                                new String[] { "type", "name" 
},//
@@ -297,9 +298,7 @@
 
                                if (node.isUsingWrapper()) {
                                        content.addChild("br");
-                                       HTMLNode restartForm = 
content.addChild("form",//
-                                               new String[] { "action", 
"method" }, new String[] { "/", "get" }//
-                                               ).addChild("div");
+                                       HTMLNode restartForm = 
ctx.addFormChild(content, "/", "restartForm");
                                        restartForm.addChild("input",//
                                                new String[] { "type", "name" 
},//
                                                new String[] { "hidden", 
"restart" });

Modified: branches/db4o/freenet/src/freenet/clients/http/ConnectionsToadlet.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/ConnectionsToadlet.java      
2009-04-01 18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/clients/http/ConnectionsToadlet.java      
2009-04-01 19:43:11 UTC (rev 26320)
@@ -145,6 +145,7 @@
        protected final PeerManager peers;
        protected boolean isReversed = false;
        protected final DecimalFormat fix1 = new DecimalFormat("##0.0%");
+       public enum PeerAdditionReturnCodes{ OK, WRONG_ENCODING, CANT_PARSE, 
INTERNAL_ERROR, INVALID_SIGNATURE, TRY_TO_ADD_SELF, ALREADY_IN_REFERENCE}
        
        @Override
        public String supportedMethods() {
@@ -511,7 +512,7 @@
                        String reftext = request.getPartAsString("ref", 
Integer.MAX_VALUE);
                        reftext = reftext.trim();
                        if (reftext.length() < 200) {
-                               reftext = request.getPartAsString("reffile", 
2000);
+                               reftext = request.getPartAsString("reffile", 
Integer.MAX_VALUE);
                                reftext = reftext.trim();
                        }
                        String privateComment = null;
@@ -551,60 +552,47 @@
                        ref = new StringBuilder(ref.toString().trim());
 
                        request.freeParts();
-                       // we have a node reference in ref
-                       SimpleFieldSet fs;
-                       
-                       try {
-                               fs = new SimpleFieldSet(ref.toString(), false, 
true);
-                               if(!fs.getEndMarker().endsWith("End")) {
-                                       sendErrorPage(ctx, 200, 
l10n("failedToAddNodeTitle"),
-                                                       
L10n.getString("DarknetConnectionsToadlet.cantParseWrongEnding", new String[] { 
"end" }, new String[] { fs.getEndMarker() }));
-                                       return;
+
+                       //Split the references string, because the peers are 
added individually
+                       String[] nodesToAdd=ref.toString().split("End");
+                       //The peer's additions results
+                       Map<PeerAdditionReturnCodes,Integer> results=new 
HashMap<PeerAdditionReturnCodes, Integer>();
+                       for(int i=0;i<nodesToAdd.length;i++){
+                               //We need to trim then concat 'End' to the 
node's reference, this way we have a normal reference(the split() removes the 
'End'-s!)
+                               PeerAdditionReturnCodes 
result=addNewNode(nodesToAdd[i].trim().concat("\nEnd"), privateComment);
+                               //Store the result
+                               if(results.containsKey(result)==false){
+                                       results.put(result, new Integer(0));
                                }
-                               fs.setEndMarker("End"); // It's always End ; 
the regex above doesn't always grok this
-                       } catch (IOException e) {
-                               this.sendErrorPage(ctx, 200, 
l10n("failedToAddNodeTitle"), 
-                                               
L10n.getString("DarknetConnectionsToadlet.cantParseTryAgain", new String[] { 
"error" }, new String[] { e.toString() }));
-                               return;
-                       } catch (Throwable t) {
-                               this.sendErrorPage(ctx, 
l10n("failedToAddNodeInternalErrorTitle"), 
l10n("failedToAddNodeInternalError"), t);
-                               return;
+                               results.put(result, results.get(result)+1);
                        }
-                       PeerNode pn;
-                       try {
-                               if(isOpennet()) {
-                                       pn = node.createNewOpennetNode(fs);
-                               } else {
-                                       pn = node.createNewDarknetNode(fs);
-                                       
((DarknetPeerNode)pn).setPrivateDarknetCommentNote(privateComment);
+                       
+                       HTMLNode pageNode = 
ctx.getPageMaker().getPageNode(l10n("reportOfNodeAddition"), ctx);
+                       HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);
+                       
+                       //We create a table to show the results
+                       HTMLNode detailedStatusBox=new HTMLNode("table");
+                       //Header of the table
+                       detailedStatusBox.addChild(new 
HTMLNode("tr")).addChildren(new HTMLNode[]{new 
HTMLNode("th",l10n("resultName")),new HTMLNode("th",l10n("numOfResults"))});
+                       HTMLNode statusBoxTable=detailedStatusBox.addChild(new 
HTMLNode("tbody"));
+                       //Iterate through the return codes
+                       for(PeerAdditionReturnCodes 
returnCode:PeerAdditionReturnCodes.values()){
+                               if(results.containsKey(returnCode)){
+                                       //Add a <tr> and 2 <td> with the name 
of the code and the number of occasions it happened. If the code is OK, we use 
green, red elsewhere.
+                                       statusBoxTable.addChild(new 
HTMLNode("tr","style","color:"+(returnCode==PeerAdditionReturnCodes.OK?"green":"red"))).addChildren(new
 HTMLNode[]{new 
HTMLNode("td",l10n("peerAdditionCode."+returnCode.toString())),new 
HTMLNode("td",results.get(returnCode).toString())});
                                }
-                       } catch (FSParseException e1) {
-                               this.sendErrorPage(ctx, 200, 
l10n("failedToAddNodeTitle"),
-                                               
L10n.getString("DarknetConnectionsToadlet.cantParseTryAgain", new String[] { 
"error" }, new String[] { e1.toString() }));
-                               return;
-                       } catch (PeerParseException e1) {
-                               this.sendErrorPage(ctx, 200, 
l10n("failedToAddNodeTitle"), 
-                                               
L10n.getString("DarknetConnectionsToadlet.cantParseTryAgain", new String[] { 
"error" }, new String[] { e1.toString() }));
-                               return;
-                       } catch (ReferenceSignatureVerificationException e1){
-                               HTMLNode node = new HTMLNode("div");
-                               node.addChild("#", 
L10n.getString("DarknetConnectionsToadlet.invalidSignature", new String[] { 
"error" }, new String[] { e1.toString() }));
-                               node.addChild("br");
-                               this.sendErrorPage(ctx, 200, 
l10n("failedToAddNodeTitle"), node);
-                               return;
-                       } catch (Throwable t) {
-                               this.sendErrorPage(ctx, 
l10n("failedToAddNodeInternalErrorTitle"), 
l10n("failedToAddNodeInternalError"), t);
-                               return;
                        }
-                       if(Arrays.equals(pn.getIdentity(), 
node.getDarknetIdentity())) {
-                               this.sendErrorPage(ctx, 200, 
l10n("failedToAddNodeTitle"), l10n("triedToAddSelf"));
-                               return;
-                       }
-                       if(!this.node.addPeerConnection(pn)) {
-                               this.sendErrorPage(ctx, 200, 
l10n("failedToAddNodeTitle"), l10n("alreadyInReferences"));
-                               return;
-                       }
+
+                       HTMLNode infobox = 
contentNode.addChild(ctx.getPageMaker().getInfobox("infobox",l10n("reportOfNodeAddition")));
+                       HTMLNode infoboxContent = 
ctx.getPageMaker().getContentNode(infobox);
+                       infoboxContent.addChild(detailedStatusBox);
+                       infoboxContent.addChild("br");
+                       infoboxContent.addChild("a", "href", ".", 
l10n("returnToPrevPage"));
+                       infoboxContent.addChild("br");
+                       addHomepageLink(infoboxContent);
                        
+                       writeHTMLReply(ctx, 500, l10n("reportOfNodeAddition"), 
pageNode.generate());
+                       
                        MultiValueTable<String, String> headers = new 
MultiValueTable<String, String>();
                        headers.put("Location", defaultRedirectLocation());
                        ctx.sendReplyHeaders(302, "Found", headers, null, 0);
@@ -613,6 +601,50 @@
                
                
        }
+       
+       /** Adds a new node. If any error arises, it returns the appropriate 
return code.
+        * @param nodeReference - The reference to the new node
+        * @param privateComment - The private comment when adding a Darknet 
node
+        * @return The result of the addition*/
+       private PeerAdditionReturnCodes addNewNode(String nodeReference,String 
privateComment){
+               SimpleFieldSet fs;
+               
+               try {
+                       fs = new SimpleFieldSet(nodeReference.toString(), 
false, true);
+                       if(!fs.getEndMarker().endsWith("End")) {
+                               return PeerAdditionReturnCodes.WRONG_ENCODING;
+                       }
+                       fs.setEndMarker("End"); // It's always End ; the regex 
above doesn't always grok this
+               } catch (IOException e) {
+                       return PeerAdditionReturnCodes.CANT_PARSE;
+               } catch (Throwable t) {
+                       return PeerAdditionReturnCodes.INTERNAL_ERROR;
+               }
+               PeerNode pn;
+               try {
+                       if(isOpennet()) {
+                               pn = node.createNewOpennetNode(fs);
+                       } else {
+                               pn = node.createNewDarknetNode(fs);
+                               
((DarknetPeerNode)pn).setPrivateDarknetCommentNote(privateComment);
+                       }
+               } catch (FSParseException e1) {
+                       return PeerAdditionReturnCodes.CANT_PARSE;
+               } catch (PeerParseException e1) {
+                       return PeerAdditionReturnCodes.CANT_PARSE;
+               } catch (ReferenceSignatureVerificationException e1){
+                       return PeerAdditionReturnCodes.INVALID_SIGNATURE;
+               } catch (Throwable t) {
+                       return PeerAdditionReturnCodes.INTERNAL_ERROR;
+               }
+               if(Arrays.equals(pn.getIdentity(), node.getDarknetIdentity())) {
+                       return PeerAdditionReturnCodes.TRY_TO_ADD_SELF;
+               }
+               if(!this.node.addPeerConnection(pn)) {
+                       return PeerAdditionReturnCodes.ALREADY_IN_REFERENCE;
+               }
+               return PeerAdditionReturnCodes.OK;
+       }
 
        /** Adding a darknet node or an opennet node? */
        protected abstract boolean isOpennet();

Modified: branches/db4o/freenet/src/freenet/clients/http/FProxyToadlet.java
===================================================================
--- branches/db4o/freenet/src/freenet/clients/http/FProxyToadlet.java   
2009-04-01 18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/clients/http/FProxyToadlet.java   
2009-04-01 19:43:11 UTC (rev 26320)
@@ -378,13 +378,9 @@
                                }
                                
                                if(logMINOR) Logger.minor(this, "Redirecting to 
FreenetURI: "+newURI);
-                               String type = httprequest.getParam("type");
-                               String location;
-                               if ((type != null) && (type.length() > 0)) {
-                                       location =  "/"+newURI + "?type=" + 
type;
-                               } else {
-                                       location =  "/"+newURI;
-                               }
+                               String requestedMimeType = 
httprequest.getParam("type");
+                               long maxSize = 
httprequest.getLongParam("max-size", MAX_LENGTH);
+                               String location = getLink(newURI, 
requestedMimeType, maxSize, httprequest.getParam("force", null), 
httprequest.isParameterSet("forcedownload"));
                                writeTemporaryRedirect(ctx, null, location);
                                return;
                        }
@@ -508,7 +504,8 @@
                        if(Logger.shouldLog(Logger.MINOR, this))
                                Logger.minor(this, "Failed to fetch "+uri+" : 
"+e);
                        if(e.newURI != null) {
-                               Toadlet.writePermanentRedirect(ctx, msg, '/' 
+e.newURI.toASCIIString() + override);
+                               Toadlet.writePermanentRedirect(ctx, msg,
+                                       getLink(e.newURI, requestedMimeType, 
maxSize, httprequest.getParam("force", null), 
httprequest.isParameterSet("forcedownload")));
                        } else if(e.mode == FetchException.TOO_BIG) {
                                HTMLNode pageNode = 
ctx.getPageMaker().getPageNode(l10n("fileInformationTitle"), ctx);
                                HTMLNode contentNode = 
ctx.getPageMaker().getContentNode(pageNode);
@@ -660,7 +657,7 @@
                if(requestedMimeType != null) {
                        
sb.append(c).append("type=").append(URLEncoder.encode(requestedMimeType,false));
 c = '&';
                }
-               if(maxSize > 0) {
+               if(maxSize > 0 && maxSize != MAX_LENGTH) {
                        sb.append(c).append("max-size=").append(maxSize); c = 
'&';
                }
                if(force != null) {

Modified: branches/db4o/freenet/src/freenet/keys/FreenetURI.java
===================================================================
--- branches/db4o/freenet/src/freenet/keys/FreenetURI.java      2009-04-01 
18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/keys/FreenetURI.java      2009-04-01 
19:43:11 UTC (rev 26320)
@@ -287,10 +287,15 @@
                if(!validKeyType)
                        throw new MalformedURLException("Invalid key type: " + 
keyType);
 
+               boolean isSSK = "SSK".equals(keyType);
+               boolean isUSK = "USK".equals(keyType);
+               boolean isKSK = "KSK".equals(keyType);
+
                // decode metaString
                ArrayList<String> sv = null;
                int slash2;
                sv = new ArrayList<String>();
+               if (isKSK) URI = "/" + URI; // ensure that KSK docNames are 
decoded
                while ((slash2 = URI.lastIndexOf('/')) != -1) {
                        String s;
                        try {
@@ -308,12 +313,8 @@
                // sv is *backwards*
                // this makes for more efficient handling
 
-               boolean isSSK = "SSK".equals(keyType);
-               boolean isUSK = "USK".equals(keyType);
-               boolean isKSK = "KSK".equals(keyType);
+               if(isSSK || isUSK || isKSK) {
 
-               if(isSSK || isUSK) {
-
                        if(sv.isEmpty())
                                throw new MalformedURLException("No docname for 
" + keyType);
                        docName = sv.remove(sv.size() - 1);
@@ -329,10 +330,6 @@
                                }
                        } else
                                suggestedEdition = -1;
-               } else if(isKSK) {
-                       // Deal with KSKs
-                       docName = URI;
-                       suggestedEdition = -1;
                } else {
                        // docName not necessary, nor is it supported, for CHKs.
                        docName = null;

Modified: branches/db4o/freenet/src/freenet/l10n/freenet.l10n.en.properties
===================================================================
--- branches/db4o/freenet/src/freenet/l10n/freenet.l10n.en.properties   
2009-04-01 18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/l10n/freenet.l10n.en.properties   
2009-04-01 19:43:11 UTC (rev 26320)
@@ -168,7 +168,7 @@
 ContentFilter.textPlainWriteAdvice=Plain text - not dangerous unless you 
include compromizing information
 DarknetConnectionsToadlet.activityTitle=Current Activity
 DarknetConnectionsToadlet.add=Add
-DarknetConnectionsToadlet.addPeerTitle=Add another peer
+DarknetConnectionsToadlet.addPeerTitle=Add another peers
 DarknetConnectionsToadlet.alreadyInReferences=We already have the given 
reference.
 DarknetConnectionsToadlet.backedOff=Connected but backed off: These peers are 
connected but we're backed off from them, so the node is not routing requests 
to them.
 DarknetConnectionsToadlet.backedOffShort=Backed off
@@ -254,6 +254,17 @@
 DarknetConnectionsToadlet.updateChangedPrivnotes=Update changed private notes
 DarknetConnectionsToadlet.urlReference=OR enter the URL of the node reference 
here:
 DarknetConnectionsToadlet.versionTitle=Version
+DarknetConnectionsToadlet.reportOfNodeAddition=Report of node additions
+DarknetConnectionsToadlet.returnToPrevPage=Return to previous page
+DarknetConnectionsToadlet.peerAdditionCode.OK=Added successfully
+DarknetConnectionsToadlet.peerAdditionCode.TRY_TO_ADD_SELF=Tried to add self
+DarknetConnectionsToadlet.peerAdditionCode.WRONG_ENCODING=Wrong encoding
+DarknetConnectionsToadlet.peerAdditionCode.CANT_PARSE=Can't parse
+DarknetConnectionsToadlet.peerAdditionCode.INTERNAL_ERROR=Internal error
+DarknetConnectionsToadlet.peerAdditionCode.INVALID_SIGNATURE=Invalid signature
+DarknetConnectionsToadlet.peerAdditionCode.ALREADY_IN_REFERENCE=Already in 
reference
+DarknetConnectionsToadlet.resultName=Name of result
+DarknetConnectionsToadlet.numOfResults=Number of results
 ExtOldAgeUserAlert.extTooOld=Your freenet-ext.jar file seems to be outdated: 
we strongly advise you to update it using 
http://downloads.freenetproject.org/alpha/freenet-ext.jar.
 ExtOldAgeUserAlert.extTooOldTitle=Freenet-ext too old
 ExtOldAgeUserAlert.extTooOldShort=Your freenet-ext.jar is out of date. Please 
upgrade.

Modified: branches/db4o/freenet/src/freenet/node/DarknetPeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/DarknetPeerNode.java 2009-04-01 
18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/node/DarknetPeerNode.java 2009-04-01 
19:43:11 UTC (rev 26320)
@@ -1559,6 +1559,11 @@
        }
 
        @Override
+       public boolean isSeed() {
+               return false;
+       }
+
+       @Override
        public void onSuccess(boolean insert, boolean ssk) {
                // Ignore it
        }

Modified: branches/db4o/freenet/src/freenet/node/NodeStats.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/NodeStats.java       2009-04-01 
18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/node/NodeStats.java       2009-04-01 
19:43:11 UTC (rev 26320)
@@ -1052,6 +1052,7 @@
                synchronized(this) {
                        fs.put("startupTime", node.startupTime);
                        nodeUptimeSeconds = (now - node.startupTime) / 1000;
+                       if (nodeUptimeSeconds == 0) nodeUptimeSeconds = 1;      
// prevent division by zero
                        fs.put("uptimeSeconds", nodeUptimeSeconds);
                }
                fs.put("averagePingTime", getNodeAveragePingTime());
@@ -1117,7 +1118,7 @@
                long total_input_rate = (total[1]) / nodeUptimeSeconds;
                long totalPayloadOutput = node.getTotalPayloadSent();
                long total_payload_output_rate = totalPayloadOutput / 
nodeUptimeSeconds;
-               int total_payload_output_percent = (int) (100 * 
totalPayloadOutput / total[0]);
+               int total_payload_output_percent = (total[0]==0)?-1:(int) (100 
* totalPayloadOutput / total[0]);
                fs.put("totalOutputBytes", total[0]);
                fs.put("totalOutputRate", total_output_rate);
                fs.put("totalPayloadOutputBytes", totalPayloadOutput);
@@ -1128,8 +1129,8 @@
 
                long[] rate = getNodeIOStats();
                long deltaMS = (rate[5] - rate[2]);
-               double recent_output_rate = 1000.0 * (rate[3] - rate[0]) / 
deltaMS;
-               double recent_input_rate = 1000.0 * (rate[4] - rate[1]) / 
deltaMS;
+               double recent_output_rate = deltaMS==0?0:(1000.0 * (rate[3] - 
rate[0]) / deltaMS);
+               double recent_input_rate = deltaMS==0?0:(1000.0 * (rate[4] - 
rate[1]) / deltaMS);
                fs.put("recentOutputRate", recent_output_rate);
                fs.put("recentInputRate", recent_input_rate);
 

Modified: branches/db4o/freenet/src/freenet/node/OpennetPeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/OpennetPeerNode.java 2009-04-01 
18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/node/OpennetPeerNode.java 2009-04-01 
19:43:11 UTC (rev 26320)
@@ -34,7 +34,12 @@
        public boolean isOpennet() {
                return true;
        }
-       
+
+       @Override
+       public boolean isSeed() {
+               return false;
+       }
+
        public boolean isDroppable(boolean ignoreDisconnect) {
                long now = System.currentTimeMillis();
                if(now - getPeerAddedTime() < OpennetManager.DROP_MIN_AGE)

Modified: branches/db4o/freenet/src/freenet/node/PeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/PeerNode.java        2009-04-01 
18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/node/PeerNode.java        2009-04-01 
19:43:11 UTC (rev 26320)
@@ -2705,6 +2705,7 @@
                        fs.putSingle("ark.pubURI", 
myARK.getBaseSSK().toString(false, false));
                }
                fs.put("opennet", isOpennet());
+               fs.put("seed", isSeed());
                return fs;
        }
 
@@ -2712,6 +2713,8 @@
 
        public abstract boolean isOpennet();
 
+       public abstract boolean isSeed();
+
        /**
        * @return The time at which we last connected (or reconnected).
        */


Property changes on: branches/db4o/freenet/src/freenet/node/SSKInsertSender.java
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/db4o/src/freenet/node/SSKInsertSender.java:25594

Modified: branches/db4o/freenet/src/freenet/node/SeedClientPeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SeedClientPeerNode.java      
2009-04-01 18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/node/SeedClientPeerNode.java      
2009-04-01 19:43:11 UTC (rev 26320)
@@ -33,6 +33,11 @@
        }
 
        @Override
+       public boolean isSeed() {
+               return true;
+       }
+
+       @Override
        public boolean isRealConnection() {
                return false; // We may be connected to the same node as a seed 
and as a regular connection.
        }

Modified: branches/db4o/freenet/src/freenet/node/SeedServerPeerNode.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/SeedServerPeerNode.java      
2009-04-01 18:57:00 UTC (rev 26319)
+++ branches/db4o/freenet/src/freenet/node/SeedServerPeerNode.java      
2009-04-01 19:43:11 UTC (rev 26320)
@@ -39,6 +39,11 @@
        }
 
        @Override
+       public boolean isSeed() {
+               return true;
+       }
+
+       @Override
        public boolean isRealConnection() {
                return false;
        }

Modified: 
branches/db4o/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
===================================================================
--- 
branches/db4o/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java  
    2009-04-01 18:57:00 UTC (rev 26319)
+++ 
branches/db4o/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java  
    2009-04-01 19:43:11 UTC (rev 26320)
@@ -43,6 +43,7 @@
 import freenet.support.HTMLNode;
 import freenet.support.HexUtil;
 import freenet.support.Logger;
+import freenet.support.io.Closer;
 import freenet.support.io.FileUtil;
 import freenet.support.io.NativeThread;
 
@@ -849,34 +850,53 @@
                        writeConfigFile();
                        return true;
                } else {
-                       // try to load
-                       RandomAccessFile raf = new RandomAccessFile(configFile, 
"r");
-                       byte[] salt = new byte[0x10];
-                       raf.readFully(salt);
-                       cipherManager = new CipherManager(salt);
+                       try {
+                               // try to load
+                               RandomAccessFile raf = new 
RandomAccessFile(configFile, "r");
+                               try {
+                                       byte[] salt = new byte[0x10];
+                                       raf.readFully(salt);
+                                       cipherManager = new CipherManager(salt);
 
-                       storeSize = raf.readLong();
-                       prevStoreSize = raf.readLong();
-                       keyCount.set(raf.readLong());
-                       generation = raf.readInt();
-                       flags = raf.readInt();
+                                       storeSize = raf.readLong();
+                                       prevStoreSize = raf.readLong();
+                                       keyCount.set(raf.readLong());
+                                       generation = raf.readInt();
+                                       flags = raf.readInt();
 
-                       if ((flags & FLAG_DIRTY) != 0)
-                               flags |= FLAG_REBUILD_BLOOM;
+                                       if ((flags & FLAG_DIRTY) != 0)
+                                               flags |= FLAG_REBUILD_BLOOM;
 
-                       try {
-                               bloomFilterK = raf.readInt();
-                               if (bloomFilterK == 0) {
-                                       bloomFilterK = 
BloomFilter.optimialK(bloomFilterSize, storeSize);
-                                       flags |= FLAG_REBUILD_BLOOM;
-                                       checkBloom = false;
+                                       try {
+                                               bloomFilterK = raf.readInt();
+                                               if (bloomFilterK == 0) {
+                                                       bloomFilterK = 
BloomFilter.optimialK(bloomFilterSize, storeSize);
+                                                       flags |= 
FLAG_REBUILD_BLOOM;
+                                                       checkBloom = false;
+                                               }
+                                       } catch (IOException e) {
+                                               flags |= FLAG_REBUILD_BLOOM;
+                                       }
+
+                                       return false;
+                               } finally {
+                                       Closer.close(raf);
                                }
                        } catch (IOException e) {
-                               flags |= FLAG_REBUILD_BLOOM;
+                               // corrupted? delete it and try again
+                               Logger.error(this, "config file corrupted, 
trying to create a new store: " + name, e);
+                               System.err.println("config file corrupted, 
trying to create a new store: " + name);
+                               if (configFile.exists() && configFile.delete()) 
{
+                                       File metaFile = new File(baseDir, name 
+ ".metadata");
+                                       metaFile.delete();
+                                       return loadConfigFile();
+                               }
+
+                               // last restore
+                               Logger.error(this, "can't delete config file, 
please delete the store manually: " + name, e);
+                               System.err.println( "can't delete config file, 
please delete the store manually: " + name);
+                               throw e;
                        }
-
-                       raf.close();
-                       return false;
                }
        }
 


Property changes on: 
branches/db4o/freenet/src/freenet/support/BinaryBloomFilter.java
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk/freenet/src/freenet/support/BinaryBloomFilter.java:22002-26118,26139
   + /trunk/freenet/src/freenet/support/BinaryBloomFilter.java:22002-26318


Property changes on: branches/db4o/freenet/src/freenet/support/BloomFilter.java
___________________________________________________________________
Modified: svn:mergeinfo
   - /trunk/freenet/src/freenet/support/BloomFilter.java:22002-26118,26139
   + /trunk/freenet/src/freenet/support/BloomFilter.java:22002-26318


Property changes on: 
branches/db4o/freenet/src/freenet/support/CountingBloomFilter.java
___________________________________________________________________
Modified: svn:mergeinfo
   - 
/trunk/freenet/src/freenet/support/CountingBloomFilter.java:22002-26118,26139
   + /trunk/freenet/src/freenet/support/CountingBloomFilter.java:22002-26318

Deleted: branches/db4o/freenet/test/freenet/client/CodeTest.java
===================================================================
--- trunk/freenet/test/freenet/client/CodeTest.java     2009-04-01 18:56:06 UTC 
(rev 26318)
+++ branches/db4o/freenet/test/freenet/client/CodeTest.java     2009-04-01 
19:43:11 UTC (rev 26320)
@@ -1,85 +0,0 @@
-package freenet.client;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import com.onionnetworks.fec.FECCode;
-import com.onionnetworks.fec.FECCodeFactory;
-import com.onionnetworks.fec.FECMath;
-import com.onionnetworks.fec.PureCode;
-import com.onionnetworks.util.Buffer;
-import com.onionnetworks.util.Util;
-
-public class CodeTest extends TestCase {
-
-       public static FECMath fecMath = new FECMath(8);
-
-       public static final int KK = 192;
-       public static final int PACKET_SIZE = 4096;
-
-       /**
-        * Creates k packets of size sz of random data, encodes them, and tries 
to decode. Index
-        * contains the permutation entry.
-        */
-       private static final void encodeDecode(FECCode encode, FECCode decode, 
int index[]) {
-               byte[] src = new byte[KK * PACKET_SIZE];
-               Util.rand.nextBytes(src);
-               Buffer[] srcBufs = new Buffer[KK];
-               for (int i = 0; i < srcBufs.length; i++)
-                       srcBufs[i] = new Buffer(src, i * PACKET_SIZE, 
PACKET_SIZE);
-
-               byte[] repair = new byte[KK * PACKET_SIZE];
-               Buffer[] repairBufs = new Buffer[KK];
-               for (int i = 0; i < repairBufs.length; i++) {
-                       repairBufs[i] = new Buffer(repair, i * PACKET_SIZE, 
PACKET_SIZE);
-               }
-
-               encode.encode(srcBufs, repairBufs, index);
-               decode.decode(repairBufs, index);
-
-               for (int i = 0; i < src.length; i++)
-                       Assert.assertEquals(src[i], repair[i]);
-       }
-
-       public void testSimpleRev() {
-               int lim = fecMath.gfSize + 1;
-               FECCode code = FECCodeFactory.getDefault().createFECCode(KK, 
lim);
-               FECCode code2 = new PureCode(KK, lim);
-               int[] index = new int[KK];
-
-               for (int i = 0; i < KK; i++)
-                       index[i] = lim - i - 1;
-               encodeDecode(code, code2, index);
-               encodeDecode(code2, code, index);
-       }
-
-       public void testSimple() {
-               int lim = fecMath.gfSize + 1;
-               FECCode code = FECCodeFactory.getDefault().createFECCode(KK, 
lim);
-               FECCode code2 = new PureCode(KK, lim);
-               int[] index = new int[KK];
-
-               for (int i = 0; i < KK; i++)
-                       index[i] = KK - i;
-               encodeDecode(code, code2, index);
-               encodeDecode(code2, code, index);
-       }
-
-       public void testShifted() {
-               int lim = fecMath.gfSize + 1;
-               FECCode code = FECCodeFactory.getDefault().createFECCode(KK, 
lim);
-               FECCode code2 = new PureCode(KK, lim);
-               int[] index = new int[KK];
-
-               int max_i0 = KK / 2;
-               if (max_i0 + KK > lim)
-                       max_i0 = lim - KK;
-
-               for (int s = max_i0 - 2; s <= max_i0; s++) {
-                       for (int i = 0; i < KK; i++)
-                               index[i] = i + s;
-                       encodeDecode(code, code2, index);
-                       encodeDecode(code2, code, index);
-               }
-       }
-}

Copied: branches/db4o/freenet/test/freenet/client/CodeTest.java (from rev 
26318, trunk/freenet/test/freenet/client/CodeTest.java)
===================================================================
--- branches/db4o/freenet/test/freenet/client/CodeTest.java                     
        (rev 0)
+++ branches/db4o/freenet/test/freenet/client/CodeTest.java     2009-04-01 
19:43:11 UTC (rev 26320)
@@ -0,0 +1,85 @@
+package freenet.client;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import com.onionnetworks.fec.FECCode;
+import com.onionnetworks.fec.FECCodeFactory;
+import com.onionnetworks.fec.FECMath;
+import com.onionnetworks.fec.PureCode;
+import com.onionnetworks.util.Buffer;
+import com.onionnetworks.util.Util;
+
+public class CodeTest extends TestCase {
+
+       public static FECMath fecMath = new FECMath(8);
+
+       public static final int KK = 192;
+       public static final int PACKET_SIZE = 4096;
+
+       /**
+        * Creates k packets of size sz of random data, encodes them, and tries 
to decode. Index
+        * contains the permutation entry.
+        */
+       private static final void encodeDecode(FECCode encode, FECCode decode, 
int index[]) {
+               byte[] src = new byte[KK * PACKET_SIZE];
+               Util.rand.nextBytes(src);
+               Buffer[] srcBufs = new Buffer[KK];
+               for (int i = 0; i < srcBufs.length; i++)
+                       srcBufs[i] = new Buffer(src, i * PACKET_SIZE, 
PACKET_SIZE);
+
+               byte[] repair = new byte[KK * PACKET_SIZE];
+               Buffer[] repairBufs = new Buffer[KK];
+               for (int i = 0; i < repairBufs.length; i++) {
+                       repairBufs[i] = new Buffer(repair, i * PACKET_SIZE, 
PACKET_SIZE);
+               }
+
+               encode.encode(srcBufs, repairBufs, index);
+               decode.decode(repairBufs, index);
+
+               for (int i = 0; i < src.length; i++)
+                       Assert.assertEquals(src[i], repair[i]);
+       }
+
+       public void testSimpleRev() {
+               int lim = fecMath.gfSize + 1;
+               FECCode code = FECCodeFactory.getDefault().createFECCode(KK, 
lim);
+               FECCode code2 = new PureCode(KK, lim);
+               int[] index = new int[KK];
+
+               for (int i = 0; i < KK; i++)
+                       index[i] = lim - i - 1;
+               encodeDecode(code, code2, index);
+               encodeDecode(code2, code, index);
+       }
+
+       public void testSimple() {
+               int lim = fecMath.gfSize + 1;
+               FECCode code = FECCodeFactory.getDefault().createFECCode(KK, 
lim);
+               FECCode code2 = new PureCode(KK, lim);
+               int[] index = new int[KK];
+
+               for (int i = 0; i < KK; i++)
+                       index[i] = KK - i;
+               encodeDecode(code, code2, index);
+               encodeDecode(code2, code, index);
+       }
+
+       public void testShifted() {
+               int lim = fecMath.gfSize + 1;
+               FECCode code = FECCodeFactory.getDefault().createFECCode(KK, 
lim);
+               FECCode code2 = new PureCode(KK, lim);
+               int[] index = new int[KK];
+
+               int max_i0 = KK / 2;
+               if (max_i0 + KK > lim)
+                       max_i0 = lim - KK;
+
+               for (int s = max_i0 - 2; s <= max_i0; s++) {
+                       for (int i = 0; i < KK; i++)
+                               index[i] = i + s;
+                       encodeDecode(code, code2, index);
+                       encodeDecode(code2, code, index);
+               }
+       }
+}

Modified: 
branches/db4o/freenet/test/freenet/clients/http/filter/ContentFilterTest.java
===================================================================
--- 
branches/db4o/freenet/test/freenet/clients/http/filter/ContentFilterTest.java   
    2009-04-01 18:57:00 UTC (rev 26319)
+++ 
branches/db4o/freenet/test/freenet/clients/http/filter/ContentFilterTest.java   
    2009-04-01 19:43:11 UTC (rev 26320)
@@ -52,6 +52,10 @@
        private static final String POUNT_CHARACTER_ENCODING_TEST_RESULT = "<a 
href=\"/c...@duigc5d1zsnfph07wgknvdujnlxhtggxxbkrmt-9rkw,~GrAWp02o9YylpxL1Fr4fPDozWmebhGv4qUoFlrxnY4,AAIC--8/Testing%20-%20%5bblah%5d%20Apostrophe%27%20-%20gratuitous%201%20AND%20CAPITAL%20LETTERS%21%21%21%21.ogg\"
 />";
        // @see bug #2297
        private static final String PREVENT_FPROXY_ACCESS = "<a 
href=\""+BASE_URI+"\"/>";
+       // @see bug #2921
+       private static final String PREVENT_EXTERNAL_ACCESS_CSS_SIMPLE = 
"<style>div { background: url("+BASE_URI+") }</style>";
+       private static final String PREVENT_EXTERNAL_ACCESS_CSS_CASE = 
"<style>div { background: uRl("+BASE_URI+") }</style>";
+       private static final String PREVENT_EXTERNAL_ACCESS_CSS_ESCAPE = 
"<style>div { background: \\u\\r\\l("+BASE_URI+") }</style>";
        private static final String WHITELIST_STATIC_CONTENT = "<a 
href=\"/static/themes/clean/theme.css\" />";
 
        private final BucketFactory bf = new ArrayBucketFactory();
@@ -83,6 +87,10 @@
                assertEquals(POUNT_CHARACTER_ENCODING_TEST_RESULT, 
HTMLFilter(POUNT_CHARACTER_ENCODING_TEST));
                // bug #2297
                
assertTrue(HTMLFilter(PREVENT_FPROXY_ACCESS).contains(GenericReadFilterCallback.magicHTTPEscapeString));
+               // bug #2921
+               
assertTrue(HTMLFilter(PREVENT_EXTERNAL_ACCESS_CSS_SIMPLE).contains("CHECKED_HTTP"));
+               
assertFalse(HTMLFilter(PREVENT_EXTERNAL_ACCESS_CSS_ESCAPE).contains("http"));
+               
assertTrue(HTMLFilter(PREVENT_EXTERNAL_ACCESS_CSS_CASE).contains("CHECKED_HTTP"));
                assertEquals(WHITELIST_STATIC_CONTENT, 
HTMLFilter(WHITELIST_STATIC_CONTENT));
        }
                


Property changes on: 
branches/db4o/freenet/test/freenet/support/io/MockInputStream.java
___________________________________________________________________
Modified: svn:mergeinfo
   - 
/trunk/freenet/test/freenet/support/io/MockInputStream.java:22002-26118,26139
   + /trunk/freenet/test/freenet/support/io/MockInputStream.java:22002-26318

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to