Author: toad
Date: 2006-04-04 20:18:20 +0000 (Tue, 04 Apr 2006)
New Revision: 8458

Modified:
   trunk/freenet/src/freenet/clients/http/StaticToadlet.java
   trunk/freenet/src/freenet/node/LocationManager.java
   trunk/freenet/src/freenet/node/Version.java
Log:
620: Static servlet fixes:
- Can serve things larger than a block.
- Use our own MIME guesser rather than the system one (GCJ doesn't have one, 
and anyway we do).

Modified: trunk/freenet/src/freenet/clients/http/StaticToadlet.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/StaticToadlet.java   2006-04-04 
18:59:05 UTC (rev 8457)
+++ trunk/freenet/src/freenet/clients/http/StaticToadlet.java   2006-04-04 
20:18:20 UTC (rev 8458)
@@ -2,11 +2,14 @@

 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.FileNameMap;
 import java.net.URI;
 import java.net.URLConnection;

+import freenet.client.DefaultMIMETypes;
 import freenet.client.HighLevelSimpleClient;
+import freenet.support.Bucket;

 /**
  * Static Toadlet.
@@ -42,21 +45,28 @@
                        return;
                }

-               
                InputStream strm = 
getClass().getResourceAsStream(rootPath+path);
                if (strm == null) {
                        this.sendErrorPage(ctx, 404, "Path not found", "The 
specified path does not exist.");
                        return;
                }
+               Bucket data = 
ctx.getBucketFactory().makeBucket(strm.available());
+               OutputStream os = data.getOutputStream();
+               byte[] cbuf = new byte[4096];
+               while(true) {
+                       int r = strm.read(cbuf);
+                       if(r == -1) break;
+                       os.write(cbuf, 0, r);
+               }
+               strm.close();
+               os.close();

-               
                FileNameMap map = URLConnection.getFileNameMap();

-               ctx.sendReplyHeaders(200, "OK", null, 
map.getContentTypeFor(path), strm.available());
-               
-               while ( (len = strm.read(buf)) > 0) {
-                       ctx.writeData(buf, 0, len);
-               }
+               ctx.sendReplyHeaders(200, "OK", null, 
DefaultMIMETypes.guessMIMEType(path), data.size());
+
+               ctx.writeData(data);
+               data.free();
        }

        public String supportedMethods() {

Modified: trunk/freenet/src/freenet/node/LocationManager.java
===================================================================
--- trunk/freenet/src/freenet/node/LocationManager.java 2006-04-04 18:59:05 UTC 
(rev 8457)
+++ trunk/freenet/src/freenet/node/LocationManager.java 2006-04-04 20:18:20 UTC 
(rev 8458)
@@ -3,6 +3,8 @@
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Vector;

@@ -276,7 +278,7 @@
                 Logger.error(this, "Bad loc: "+hisLoc+" on "+uid);
                 return;
             }
-            Logger.minor(this, "Known Location: "+hisLoc);
+            registerKnownLocation(hisLoc);

             double[] hisFriendLocs = new double[hisBufLong.length-2];
             for(int i=0;i<hisFriendLocs.length;i++) {
@@ -285,7 +287,7 @@
                     Logger.error(this, "Bad friend loc: "+hisFriendLocs[i]+" 
on "+uid);
                     return;
                 }
-                Logger.minor(this, "Known Location: "+hisFriendLocs[i]);
+                registerKnownLocation(hisFriendLocs[i]);
             }

             // Send our SwapComplete
@@ -457,7 +459,7 @@
                     Logger.error(this, "Bad loc: "+hisLoc+" on "+uid);
                     return;
                 }
-                Logger.minor(this, "Known Location: "+hisLoc);
+                registerKnownLocation(hisLoc);

                 double[] hisFriendLocs = new double[hisBufLong.length-2];
                 for(int i=0;i<hisFriendLocs.length;i++) {
@@ -466,7 +468,7 @@
                         Logger.error(this, "Bad friend loc: 
"+hisFriendLocs[i]+" on "+uid);
                         return;
                     }
-                    Logger.minor(this, "Known Location: "+hisFriendLocs[i]);
+                    registerKnownLocation(hisFriendLocs[i]);
                 }

                 if(shouldSwap(myLoc, friendLocs, hisLoc, hisFriendLocs, random 
^ hisRandom)) {
@@ -954,4 +956,15 @@
         recentlyForwardedIDs.remove(new Long(item.incomingID));
         recentlyForwardedIDs.remove(new Long(item.outgoingID));
     }
+    
+    private final HashMap knownLocs = new HashMap();
+    
+    void registerKnownLocation(double d) {
+        Logger.minor(this, "Known Location: "+d);
+        Double dd = new Double(d);
+        synchronized(knownLocs) {
+               
+        }
+    }
+    
 }

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-04-04 18:59:05 UTC (rev 
8457)
+++ trunk/freenet/src/freenet/node/Version.java 2006-04-04 20:18:20 UTC (rev 
8458)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

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

        /** Oldest build of Fred we will talk to */
        private static final int lastGoodBuild = 591;


Reply via email to