Author: toad
Date: 2006-11-09 20:14:56 +0000 (Thu, 09 Nov 2006)
New Revision: 10848

Modified:
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/support/SimpleFieldSet.java
Log:
Recover better from invalid stored N2NTMs.

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-11-09 19:56:46 UTC (rev 
10847)
+++ trunk/freenet/src/freenet/node/Node.java    2006-11-09 20:14:56 UTC (rev 
10848)
@@ -2836,7 +2836,12 @@
                        Logger.error( this, "Failed to write N2NTM to extra 
peer data file for peer "+source.getPeer());
                }
                // Keep track of the fileNumber so we can potentially delete 
the extra peer data file later, the file is authoritative
-               handleNodeToNodeTextMessageSimpleFieldSet(fs, source, 
fileNumber);
+               try {
+                       handleNodeToNodeTextMessageSimpleFieldSet(fs, source, 
fileNumber);
+               } catch (FSParseException e) {
+                       // Shouldn't happen
+                       throw new Error(e);
+               }
          } else {
                Logger.error(this, "Received unknown node to node message type 
'"+type+"' from "+source.getPeer());
          }
@@ -2844,9 +2849,10 @@

        /**
         * Handle a node to node text message SimpleFieldSet
+        * @throws FSParseException 
         */
-       public void handleNodeToNodeTextMessageSimpleFieldSet(SimpleFieldSet 
fs, PeerNode source, int fileNumber) {
-         int type = Integer.parseInt(fs.get("type"));
+       public void handleNodeToNodeTextMessageSimpleFieldSet(SimpleFieldSet 
fs, PeerNode source, int fileNumber) throws FSParseException {
+         int type = fs.getInt("type");
          if(type == Node.N2N_TEXT_MESSAGE_TYPE_USERALERT) {
                String source_nodename = null;
                String target_nodename = null;

Modified: trunk/freenet/src/freenet/support/SimpleFieldSet.java
===================================================================
--- trunk/freenet/src/freenet/support/SimpleFieldSet.java       2006-11-09 
19:56:46 UTC (rev 10847)
+++ trunk/freenet/src/freenet/support/SimpleFieldSet.java       2006-11-09 
20:14:56 UTC (rev 10848)
@@ -16,6 +16,7 @@
 import java.util.Iterator;
 import java.util.Map;

+import freenet.node.FSParseException;
 import freenet.support.io.LineReader;

 /**
@@ -512,6 +513,16 @@
                }
        }

+       public int getInt(String key) throws FSParseException {
+               String s = get(key);
+               if(s == null) throw new FSParseException("No key "+key);
+               try {
+                       return Integer.parseInt(s);
+               } catch (NumberFormatException e) {
+                       throw new FSParseException("Cannot parse "+s+" for 
integer "+key);
+               }
+       }
+
        public double getDouble(String key, double def) {
                String s = get(key);
                if(s == null) return def;


Reply via email to