Author: toad
Date: 2006-05-17 19:39:08 +0000 (Wed, 17 May 2006)
New Revision: 8749

Modified:
   trunk/freenet/src/freenet/client/Metadata.java
   trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
   trunk/freenet/src/freenet/node/Version.java
Log:
718: Store parsed Metadata, not byte[].

Modified: trunk/freenet/src/freenet/client/Metadata.java
===================================================================
--- trunk/freenet/src/freenet/client/Metadata.java      2006-05-17 19:38:46 UTC 
(rev 8748)
+++ trunk/freenet/src/freenet/client/Metadata.java      2006-05-17 19:39:08 UTC 
(rev 8749)
@@ -303,7 +303,7 @@

                        manifestEntries = new HashMap();

-                       // Don't validate, just keep the data; parse later
+                       // Parse the sub-Manifest.

                        for(int i=0;i<manifestEntryCount;i++) {
                                short nameLength = dis.readShort();
@@ -317,7 +317,12 @@
                                        throw new 
MetadataParseException("Impossibly long manifest entry: "+len+" - metadata size 
"+length);
                                byte[] data = new byte[len];
                                dis.readFully(data);
-                               manifestEntries.put(name, data);
+                               try {
+                                       Metadata m = Metadata.construct(data);
+                                       manifestEntries.put(name, m);
+                               } catch (Throwable t) {
+                                       Logger.error(this, "Could not parse 
sub-manifest: "+t, t);
+                               }
                        }
                }

@@ -364,8 +369,7 @@
                                target = new Metadata();
                                target.addRedirectionManifest((HashMap)o);
                        } else throw new IllegalArgumentException("Not String 
nor HashMap: "+o);
-                       byte[] data = target.writeToByteArray();
-                       manifestEntries.put(key, data);
+                       manifestEntries.put(key, target);
                }
                manifestEntryCount = count;

@@ -410,15 +414,15 @@
                                throw new IllegalArgumentException("Slashes in 
simple redirect manifest filenames! (slashes denote sub-manifests): "+key);
                        count++;
                        Object o = dir.get(key);
-                       if(o instanceof byte[]) {
-                               byte[] data = (byte[]) dir.get(key);
+                       if(o instanceof Metadata) {
+                               Metadata data = (Metadata) dir.get(key);
                                if(data == null)
                                        throw new NullPointerException();
                                manifestEntries.put(key, data);
                        } else if(o instanceof HashMap) {
                                HashMap hm = (HashMap)o;
                                Metadata subMap = 
mkRedirectionManifestWithMetadata(hm);
-                               manifestEntries.put(key, 
subMap.writeToByteArray());
+                               manifestEntries.put(key, subMap);
                        }
                }
                manifestEntryCount = count;
@@ -450,8 +454,7 @@
                        } else if(o instanceof HashMap) {
                                target = new Metadata((HashMap)o);
                        } else throw new IllegalArgumentException("Not String 
nor HashMap: "+o);
-                       byte[] data = target.writeToByteArray();
-                       manifestEntries.put(key, data);
+                       manifestEntries.put(key, target);
                }
                manifestEntryCount = count;
        }
@@ -482,8 +485,7 @@
                        } else if(o instanceof HashMap) {
                                target = new Metadata((HashMap)o);
                        } else throw new IllegalArgumentException("Not String 
nor HashMap: "+o);
-                       byte[] data = target.writeToByteArray();
-                       manifestEntries.put(key, data);
+                       manifestEntries.put(key, target);
                }
                manifestEntryCount = count;
        }
@@ -622,10 +624,8 @@
         * Get the sub-document in a manifest file with the given name.
         * @throws MetadataParseException 
         */
-       public Metadata getDocument(String name) throws MetadataParseException {
-               byte[] data = (byte[]) manifestEntries.get(name);
-               if(data == null) return null;
-               return construct(data);
+       public Metadata getDocument(String name) {
+               return (Metadata) manifestEntries.get(name);
        }

        /**
@@ -789,7 +789,8 @@
                                if(nameData.length > Short.MAX_VALUE) throw new 
IllegalArgumentException("Manifest name too long");
                                dos.writeShort(nameData.length);
                                dos.write(nameData);
-                               byte[] data = (byte[]) 
manifestEntries.get(name);
+                               Metadata meta = (Metadata) 
manifestEntries.get(name);
+                               byte[] data = meta.writeToByteArray();
                                if(data.length > Short.MAX_VALUE) throw new 
IllegalArgumentException("Manifest data too long");
                                dos.writeShort(data.length);
                                dos.write(data);

Modified: trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2006-05-17 19:38:46 UTC (rev 8748)
+++ trunk/freenet/src/freenet/client/async/SimpleManifestPutter.java    
2006-05-17 19:39:08 UTC (rev 8749)
@@ -42,7 +42,7 @@
                        this.cm = cm;
                        Metadata m = new Metadata(Metadata.SIMPLE_REDIRECT, 
target, cm);
                        cm = null;
-                       metadata = m.writeToByteArray();
+                       metadata = m;
                        origSFI = null;
                        currentState = null;
                }
@@ -51,7 +51,7 @@
                private ClientPutState currentState;
                private ClientMetadata cm;
                private final String name;
-               private byte[] metadata;
+               private Metadata metadata;
                private boolean finished;

                public void start() throws InserterException {
@@ -110,7 +110,7 @@
                                Logger.error(this, "Reassigning metadata", new 
Exception("debug"));
                                return;
                        }
-                       metadata = m.writeToByteArray();
+                       metadata = m;
                        synchronized(SimpleManifestPutter.this) {
                                putHandlersWaitingForMetadata.remove(this);
                                if(!putHandlersWaitingForMetadata.isEmpty()) 
return;
@@ -192,16 +192,19 @@
        }

        public void start() throws InserterException {
-               Iterator it = runningPutHandlers.iterator();
-               while(it.hasNext()) {
-                       PutHandler ph = (PutHandler) it.next();
-                       try {
-                               ph.start();
-                       } catch (InserterException e) {
-                               cancelAndFinish();
-                               throw e;
+               PutHandler[] running;
+               synchronized(this) {
+                       running = (PutHandler[]) runningPutHandlers.toArray(new 
PutHandler[runningPutHandlers.size()]);
+               }
+
+               try {
+                       for(int i=0;i<running.length;i++) {
+                               running[i].start();
                        }
-               }               
+               } catch (InserterException e) {
+                       cancelAndFinish();
+                       throw e;
+               }
        }

        private void makePutHandlers(HashMap manifestElements, HashMap 
putHandlersByName) throws InserterException {
@@ -258,7 +261,7 @@
                HashMap namesToByteArrays = new HashMap();
                namesToByteArrays(putHandlersByName, namesToByteArrays);
                if(defaultName != null) {
-                       byte[] meta = (byte[]) 
namesToByteArrays.get(defaultName);
+                       Metadata meta = (Metadata) 
namesToByteArrays.get(defaultName);
                        if(meta == null) {
                                fail(new 
InserterException(InserterException.INVALID_URI, "Default name "+defaultName+" 
does not exist", null));
                                return;
@@ -267,7 +270,7 @@
                } else {
                        for(int j=0;j<defaultDefaultNames.length;j++) {
                                String name = defaultDefaultNames[j];
-                               byte[] meta = (byte[]) 
namesToByteArrays.get(name);
+                               Metadata meta = (Metadata) 
namesToByteArrays.get(name);
                                if(meta != null) {
                                        namesToByteArrays.put("", meta);
                                        break;
@@ -302,7 +305,7 @@
                        Object o = putHandlersByName.get(name);
                        if(o instanceof PutHandler) {
                                PutHandler ph = (PutHandler) o;
-                               byte[] meta = ph.metadata;
+                               Metadata meta = ph.metadata;
                                namesToByteArrays.put(name, meta);
                        } else if(o instanceof HashMap) {
                                HashMap subMap = new HashMap();

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-05-17 19:38:46 UTC (rev 
8748)
+++ trunk/freenet/src/freenet/node/Version.java 2006-05-17 19:39:08 UTC (rev 
8749)
@@ -18,7 +18,7 @@
        public static final String protocolVersion = "1.0";

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

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


Reply via email to