Author: toad
Date: 2006-02-20 22:36:55 +0000 (Mon, 20 Feb 2006)
New Revision: 8073

Modified:
   branches/config/src/freenet/config/Config.java
   branches/config/src/freenet/config/FilePersistentConfig.java
   branches/config/src/freenet/config/SubConfig.java
   branches/config/src/freenet/node/Node.java
Log:
Not quite there yet with loading options from config file... will be soon 
though.

Modified: branches/config/src/freenet/config/Config.java
===================================================================
--- branches/config/src/freenet/config/Config.java      2006-02-20 22:13:39 UTC 
(rev 8072)
+++ branches/config/src/freenet/config/Config.java      2006-02-20 22:36:55 UTC 
(rev 8073)
@@ -1,5 +1,6 @@
 package freenet.config;

+import java.io.IOException;
 import java.util.HashMap;

 /** Global configuration object for a node. SubConfig's register here.
@@ -21,9 +22,15 @@
                }
        }

-       /** Write current config to disk */
+       /** Write current config to disk 
+        * @throws IOException */
        public void store() {
                // Do nothing
        }

+       /** Finished initialization */
+       public void finishedInit() {
+               // Do nothing
+       }
+       
 }

Modified: branches/config/src/freenet/config/FilePersistentConfig.java
===================================================================
--- branches/config/src/freenet/config/FilePersistentConfig.java        
2006-02-20 22:13:39 UTC (rev 8072)
+++ branches/config/src/freenet/config/FilePersistentConfig.java        
2006-02-20 22:36:55 UTC (rev 8073)
@@ -60,15 +60,20 @@

        public void register(SubConfig sc) {
                super.register(sc);
-               SimpleFieldSet sfs = origConfigFileContents.subset(sc.prefix);
-               // Set all the options
-               sc.setOptions(sfs);
+               if(origConfigFileContents != null) {
+                       SimpleFieldSet sfs = 
origConfigFileContents.subset(sc.prefix);
+                       Logger.minor(this, "Registering "+sc+": "+sfs);
+                       // Set all the options
+                       if(sfs != null)
+                               sc.setOptions(sfs);
+               }
        }

        /**
         * Finished initialization. So any remaining options must be invalid.
         */
        public void finishedInit() {
+               if(origConfigFileContents == null) return;
                Iterator i = origConfigFileContents.keyIterator();
                while(i.hasNext()) {
                        String key = (String) i.next();
@@ -76,11 +81,24 @@
                }
        }

+       public void store() {
+               try {
+                       innerStore();
+               } catch (IOException e) {
+                       String err = "Cannot store config: "+e;
+                       Logger.error(this, err, e);
+                       System.err.println(err);
+                       e.printStackTrace();
+               }
+       }
+       
        public void innerStore() throws IOException {
                SimpleFieldSet fs = exportFieldSet();
+               Logger.minor(this, "fs = "+fs);
                FileOutputStream fos = new FileOutputStream(tempFilename);
-               fs.writeTo(new BufferedWriter(new OutputStreamWriter(fos)));
-               fos.close();
+               BufferedWriter bw = new BufferedWriter(new 
OutputStreamWriter(fos));
+               fs.writeTo(bw);
+               bw.close();
                tempFilename.renameTo(filename);
        }


Modified: branches/config/src/freenet/config/SubConfig.java
===================================================================
--- branches/config/src/freenet/config/SubConfig.java   2006-02-20 22:13:39 UTC 
(rev 8072)
+++ branches/config/src/freenet/config/SubConfig.java   2006-02-20 22:36:55 UTC 
(rev 8073)
@@ -123,6 +123,7 @@
         */
        public void finishedInitialization() {
                hasInitialized = true;
+               config.register(this);
        }

        /**

Modified: branches/config/src/freenet/node/Node.java
===================================================================
--- branches/config/src/freenet/node/Node.java  2006-02-20 22:13:39 UTC (rev 
8072)
+++ branches/config/src/freenet/node/Node.java  2006-02-20 22:36:55 UTC (rev 
8073)
@@ -459,7 +459,8 @@
        nodeConfig.register("ipAddressOverride", "", 0, true, "IP address 
override", "IP address override (not usually needed)", new StringCallback() {

                        public String get() {
-                               return Peer.getHostName(overrideIPAddress);
+                               if(overrideIPAddress == null) return "";
+                               else return Peer.getHostName(overrideIPAddress);
                        }

                        public void set(String val) throws 
InvalidConfigValueException {
@@ -509,7 +510,7 @@
                                                throw new 
InvalidConfigValueException(msg);
                                        }
        });
-
+       
        int port = nodeConfig.getInt("listenPort");

        UdpSocketManager u = null;
@@ -549,22 +550,6 @@

         Logger.normal(Node.class, "Creating node...");

-        // Now pull the override IP address, if any, from the config
-        
-        nodeConfig.register("ipAddress", "", 2, true, "IP address", "IP 
address of the node (should not usually be necessary)", 
-                       new StringCallback() {
-                                       public String get() {
-                                               return 
Peer.getHostName(overrideIPAddress);
-                                       }
-                                       public void set(String val) throws 
InvalidConfigValueException {
-                                               overrideIPAddress = 
resolve(val);
-                                       }
-        });
-
-        String ip = nodeConfig.getString("ipAddress");
-        
-        overrideIPAddress = resolve(ip);
-        
         // Bandwidth limit

         // FIXME These should not be static !!!! Need a context object for BT 
for bwlimiting.
@@ -611,6 +596,7 @@
                Logger.error(this, msg);
                System.err.println(msg);
                testnetEnabled = true;
+               Logger.globalSetThreshold(Logger.MINOR);
         } else {
                Logger.normal(this, "Testnet mode DISABLED. You may have some 
level of anonymity. :)");
                testnetEnabled = false;
@@ -779,6 +765,8 @@
         }

         nodeConfig.finishedInitialization();
+        config.finishedInit();
+        config.store();

         // FIXME make all the below arbitrary constants configurable!



Reply via email to