Author: toad
Date: 2006-02-21 15:47:50 +0000 (Tue, 21 Feb 2006)
New Revision: 8082

Modified:
   trunk/freenet/src/freenet/config/Option.java
   trunk/freenet/src/freenet/config/SubConfig.java
   trunk/freenet/src/freenet/node/LoggingConfigHandler.java
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/Version.java
   trunk/freenet/src/freenet/support/Logger.java
Log:
452:
Config fixes related to logger.
- enabled and priority work now.
- testnet forces logging enabled, logLevel=minor or debug, and max zip files 
size >= 256M.
If we don't have an IP address, boot up anyway and don't include one in our 
reference.
IP detection still broken.
Start ip detector thread.
Comments.

Modified: trunk/freenet/src/freenet/config/Option.java
===================================================================
--- trunk/freenet/src/freenet/config/Option.java        2006-02-21 15:11:51 UTC 
(rev 8081)
+++ trunk/freenet/src/freenet/config/Option.java        2006-02-21 15:47:50 UTC 
(rev 8082)
@@ -27,8 +27,15 @@
                this.longDesc = longDesc;
        }

+       /**
+        * Set this option's current value to a string. Will call the callback. 
Does not care 
+        * whether the value of the option has changed.
+        */
        public abstract void setValue(String val) throws 
InvalidConfigValueException;

+       /**
+        * Get the current value of the option as a string.
+        */
        public abstract String getValueString();

        /** Set to a value from the config file; this is not passed on to the 
callback, as we
@@ -37,5 +44,12 @@
         * @throws InvalidConfigValueException 
         */
        public abstract void setInitialValue(String val) throws 
InvalidConfigValueException;
+
+       /**
+        * Call the callback with the current value of the option.
+        */
+       public void forceUpdate() throws InvalidConfigValueException {
+               setValue(getValueString());
+       }

 }

Modified: trunk/freenet/src/freenet/config/SubConfig.java
===================================================================
--- trunk/freenet/src/freenet/config/SubConfig.java     2006-02-21 15:11:51 UTC 
(rev 8081)
+++ trunk/freenet/src/freenet/config/SubConfig.java     2006-02-21 15:47:50 UTC 
(rev 8082)
@@ -165,4 +165,18 @@
                return fs;
        }

+       /**
+        * Force an option to be updated even if it hasn't changed.
+        * @throws InvalidConfigValueException 
+        */
+       public void forceUpdate(String optionName) throws 
InvalidConfigValueException {
+               Option o = (Option) map.get(optionName);
+               o.forceUpdate();
+       }
+
+       public void set(String name, String value) throws 
InvalidConfigValueException {
+               Option o = (Option) map.get(name);
+               o.setValue(value);
+       }
+
 }

Modified: trunk/freenet/src/freenet/node/LoggingConfigHandler.java
===================================================================
--- trunk/freenet/src/freenet/node/LoggingConfigHandler.java    2006-02-21 
15:11:51 UTC (rev 8081)
+++ trunk/freenet/src/freenet/node/LoggingConfigHandler.java    2006-02-21 
15:47:50 UTC (rev 8082)
@@ -90,6 +90,8 @@
                                        }
        });

+       maxZippedLogsSize = config.getLong("maxZippedLogsSize");
+       
        // priority

        // Node must override this to minor on testnet.
@@ -166,7 +168,8 @@

        maxCachedLogLines = config.getInt("maxCachedLines");

-       enableLogger();
+       if(loggingEnabled)
+               enableLogger();

        config.finishedInitialization();
        }
@@ -177,9 +180,21 @@
         * Turn on the logger.
         */
        private void enableLogger() {
+               try {
+                       preSetLogDir(logDir);
+               } catch (InvalidConfigValueException e3) {
+                       System.err.println("Cannot set log dir: "+logDir+": 
"+e3);
+                       e3.printStackTrace();
+               }
                synchronized(enableLoggerLock) {
                        if(fileLoggerHook != null) return;
                        Logger.setupChain();
+                       try {
+                               config.forceUpdate("priority");
+                       } catch (InvalidConfigValueException e2) {
+                               System.err.println("Invalid config value for 
logger.priority in config file: "+config.getString("priority"));
+                               // Leave it at the default.
+                       }
                        FileLoggerHook hook;
                        try {
                                hook = 
@@ -202,6 +217,7 @@
                        }
                        hook.setMaxListBytes(maxCachedLogBytes);
                        hook.setMaxListLength(maxCachedLogLines);
+                       fileLoggerHook = hook;
                        Logger.globalAddHook(hook);
                        hook.start();
                }
@@ -274,5 +290,17 @@
        public FileLoggerHook getFileLoggerHook() {
                return fileLoggerHook;
        }
+
+       public void forceEnableLogging() {
+               enableLogger();
+       }
+
+       public long getMaxZippedLogFiles() {
+               return maxZippedLogsSize;
+       }
+
+       public void setMaxZippedLogFiles(String maxSizeAsString) throws 
InvalidConfigValueException {
+               config.set("maxZippedLogsSize", maxSizeAsString);
+       }

 }

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2006-02-21 15:11:51 UTC (rev 
8081)
+++ trunk/freenet/src/freenet/node/Node.java    2006-02-21 15:47:50 UTC (rev 
8082)
@@ -153,6 +153,9 @@
     // 900ms
     static final int MIN_INTERVAL_BETWEEN_INCOMING_SWAP_REQUESTS = 900;
     public static final int SYMMETRIC_KEY_LENGTH = 32; // 256 bits - note that 
this isn't used everywhere to determine it
+    /** Minimum space for zipped logfiles on testnet */
+       static final long TESTNET_MIN_MAX_ZIPPED_LOGFILES = 256*1024*1024;
+       static final String TESTNET_MIN_MAX_ZIPPED_LOGFILES_STRING = "256M";

     // FIXME: abstract out address stuff? Possibly to something like 
NodeReference?
     final int portNumber;
@@ -274,17 +277,19 @@
         br.close();
         // Read contents
         String physical = fs.get("physical.udp");
-        Peer myOldPeer;
-        try {
-            myOldPeer = new Peer(physical);
-        } catch (PeerParseException e) {
-            IOException e1 = new IOException();
-            e1.initCause(e);
-            throw e1;
+        if(physical != null) {
+               Peer myOldPeer;
+               try {
+                       myOldPeer = new Peer(physical);
+               } catch (PeerParseException e) {
+                       IOException e1 = new IOException();
+                       e1.initCause(e);
+                       throw e1;
+               }
+               if(myOldPeer.getPort() != portNumber)
+                       throw new IllegalArgumentException("Wrong port number "+
+                                       myOldPeer.getPort()+" should be 
"+portNumber);
         }
-        if(myOldPeer.getPort() != portNumber)
-            throw new IllegalArgumentException("Wrong port number "+
-                    myOldPeer.getPort()+" should be "+portNumber);
         // FIXME: we ignore the IP for now, and hardcode it to localhost
         String identity = fs.get("identity");
         if(identity == null)
@@ -594,7 +599,23 @@
                Logger.error(this, msg);
                System.err.println(msg);
                testnetEnabled = true;
-               Logger.globalSetThreshold(Logger.MINOR);
+               if(logConfigHandler.getFileLoggerHook() == null) {
+                       System.err.println("Forcing logging enabled (essential 
for testnet)");
+                       logConfigHandler.forceEnableLogging();
+               }
+               int x = Logger.globalGetThreshold();
+               if(!(x == Logger.MINOR || x == Logger.DEBUG)) {
+                       System.err.println("Forcing log threshold to MINOR for 
testnet, was "+x);
+                       Logger.globalSetThreshold(Logger.MINOR);
+               }
+               if(logConfigHandler.getMaxZippedLogFiles() < 
TESTNET_MIN_MAX_ZIPPED_LOGFILES) {
+                       System.err.println("Forcing max zipped logfiles space 
to 256MB for testnet");
+                       try {
+                                       
logConfigHandler.setMaxZippedLogFiles(TESTNET_MIN_MAX_ZIPPED_LOGFILES_STRING);
+                               } catch (InvalidConfigValueException e) {
+                                       throw new Error("Impossible: "+e);
+                               }
+               }
         } else {
                Logger.normal(this, "Testnet mode DISABLED. You may have some 
level of anonymity. :)");
                testnetEnabled = false;
@@ -847,6 +868,9 @@
                if(testnetHandler != null)
                        testnetHandler.start();

+               Thread t = new Thread(ipDetector, "IP address re-detector");
+               t.setDaemon(true);
+               t.start();
     }

     public ClientKeyBlock realGetKey(ClientKey key, boolean localOnly, boolean 
cache, boolean ignoreStore) throws LowLevelGetException {
@@ -1278,7 +1302,9 @@
      */
     public SimpleFieldSet exportFieldSet() {
         SimpleFieldSet fs = new SimpleFieldSet(false);
-        fs.put("physical.udp", 
Peer.getHostName(getPrimaryIPAddress())+":"+portNumber);
+        InetAddress ip = getPrimaryIPAddress();
+        if(ip != null)
+               fs.put("physical.udp", Peer.getHostName(ip)+":"+portNumber);
         fs.put("identity", HexUtil.bytesToHex(myIdentity));
         fs.put("location", Double.toString(lm.getLocation().getValue()));
         fs.put("version", Version.getVersionString());

Modified: trunk/freenet/src/freenet/node/Version.java
===================================================================
--- trunk/freenet/src/freenet/node/Version.java 2006-02-21 15:11:51 UTC (rev 
8081)
+++ trunk/freenet/src/freenet/node/Version.java 2006-02-21 15:47:50 UTC (rev 
8082)
@@ -20,7 +20,7 @@
        public static final String protocolVersion = "1.0";

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

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

Modified: trunk/freenet/src/freenet/support/Logger.java
===================================================================
--- trunk/freenet/src/freenet/support/Logger.java       2006-02-21 15:11:51 UTC 
(rev 8081)
+++ trunk/freenet/src/freenet/support/Logger.java       2006-02-21 15:47:50 UTC 
(rev 8082)
@@ -214,6 +214,10 @@
         logger.setThreshold(i);
     }

+       public static int globalGetThreshold() {
+               return logger.getThreshold();
+       }
+       
        public synchronized static void globalRemoveHook(FileLoggerHook hook) {
                if(logger instanceof LoggerHookChain)
                        ((LoggerHookChain)logger).removeHook(hook);


Reply via email to