Synchronization? Might we end up making two NodeUpdater's?

On Sat, Jun 17, 2006 at 02:27:00PM +0000, [EMAIL PROTECTED] wrote:
> Author: nextgens
> Date: 2006-06-17 14:26:52 +0000 (Sat, 17 Jun 2006)
> New Revision: 9262
> 
> Modified:
>    trunk/freenet/src/freenet/node/Version.java
>    trunk/freenet/src/freenet/node/updater/AutoUpdateAllowedCallback.java
>    trunk/freenet/src/freenet/node/updater/NodeUpdater.java
>    trunk/freenet/src/freenet/node/updater/UpdaterEnabledCallback.java
> Log:
> 823: We allow the auto-updater to be enabled on the fly
> 
> Modified: trunk/freenet/src/freenet/node/Version.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/Version.java       2006-06-17 12:31:13 UTC 
> (rev 9261)
> +++ trunk/freenet/src/freenet/node/Version.java       2006-06-17 14:26:52 UTC 
> (rev 9262)
> @@ -18,7 +18,7 @@
>       public static final String protocolVersion = "1.0";
>  
>       /** The build number of the current revision */
> -     private static final int buildNumber = 822;
> +     private static final int buildNumber = 823;
>  
>       /** Oldest build of Fred we will talk to */
>       private static final int lastGoodBuild = 765;
> 
> Modified: 
> trunk/freenet/src/freenet/node/updater/AutoUpdateAllowedCallback.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/updater/AutoUpdateAllowedCallback.java     
> 2006-06-17 12:31:13 UTC (rev 9261)
> +++ trunk/freenet/src/freenet/node/updater/AutoUpdateAllowedCallback.java     
> 2006-06-17 14:26:52 UTC (rev 9262)
> @@ -3,6 +3,7 @@
>  import freenet.config.BooleanCallback;
>  import freenet.config.InvalidConfigValueException;
>  import freenet.node.Node;
> +import freenet.support.Logger;
>  
>  public class AutoUpdateAllowedCallback implements BooleanCallback {
>       
> @@ -13,13 +14,15 @@
>       }
>       
>       public boolean get() {
> -             NodeUpdater nu = node.getNodeUpdater();
> -             return nu.isAutoUpdateAllowed;
> +             if(node.getNodeUpdater()==null)
> +                     return false;
> +             else 
> +                     return node.getNodeUpdater().isAutoUpdateAllowed;
>       }
>       
>       public void set(boolean val) throws InvalidConfigValueException {
>               if(val == get()) return;
> -             // Good idea to prevent it ?
> -             throw new InvalidConfigValueException("Cannot be updated on the 
> fly for security reasons");
> +             node.getNodeUpdater().setAutoupdateAllowed(val);
> +             Logger.normal(this, "Node auto update is now allowed = "+val);
>       }
>  }
> \ No newline at end of file
> 
> Modified: trunk/freenet/src/freenet/node/updater/NodeUpdater.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/updater/NodeUpdater.java   2006-06-17 
> 12:31:13 UTC (rev 9261)
> +++ trunk/freenet/src/freenet/node/updater/NodeUpdater.java   2006-06-17 
> 14:26:52 UTC (rev 9262)
> @@ -54,7 +54,7 @@
>       private boolean isRunning = false;
>       private boolean isFetching = false;
>       
> -     public final boolean isAutoUpdateAllowed;
> +     public boolean isAutoUpdateAllowed;
>       
>       private final UpdatedVersionAvailableUserAlert alert;
>       private RevocationKeyFoundUserAlert revocationAlert;
> @@ -113,6 +113,7 @@
>       }
>       
>       public synchronized void onFoundEdition(long l, USK key){
> +             if(!isRunning) return;
>               int found = (int)key.suggestedEdition;
>               
>               if(found > availableVersion){
> @@ -122,7 +123,6 @@
>                                       maybeUpdate();
>                               }
>                       }, 60*1000); // leave some time in case we get later 
> editions
> -                     this.isRunning=true;
>               }
>       }
>  
> @@ -135,8 +135,6 @@
>                               isRunning=false;
>                               return;
>                       }
> -                     
> -                     isRunning=false;
>               }
>               
>               alert.set(availableVersion,false);
> @@ -162,6 +160,7 @@
>       private Object updateSync = new Object();
>       
>       public void Update() {
> +             if(!isRunning) return;
>               synchronized(updateSync) {
>                       innerUpdate();
>               }
> @@ -466,6 +465,10 @@
>               return isRunning;
>       }
>       
> +     protected synchronized void kill(){
> +             isRunning = false;
> +     }
> +     
>       public synchronized void blow(String msg){
>               if(hasBeenBlown){
>                       Logger.error(this, "The key has ALREADY been marked as 
> blown!");
> @@ -490,12 +493,16 @@
>               return revocationURI;
>       }
>       
> +     protected synchronized void  setAutoupdateAllowed(boolean b) {
> +             this.isAutoUpdateAllowed = b;
> +     }
> +     
>       public static NodeUpdater maybeCreate(Node node, Config config) throws 
> Exception {
>          SubConfig updaterConfig = new SubConfig("node.updater", config);
>           
>          updaterConfig.register("enabled", true, 1, false, "Enable Node's 
> updater?",
>                       "Whether to enable the node's updater. It won't 
> auto-update unless node.updater.autoupdate is true, it will just warn",
> -                     new UpdaterEnabledCallback(node));
> +                     new UpdaterEnabledCallback(node, config));
>          
>          boolean enabled = updaterConfig.getBoolean("enabled");
>  
> 
> Modified: trunk/freenet/src/freenet/node/updater/UpdaterEnabledCallback.java
> ===================================================================
> --- trunk/freenet/src/freenet/node/updater/UpdaterEnabledCallback.java        
> 2006-06-17 12:31:13 UTC (rev 9261)
> +++ trunk/freenet/src/freenet/node/updater/UpdaterEnabledCallback.java        
> 2006-06-17 14:26:52 UTC (rev 9262)
> @@ -1,24 +1,44 @@
>  package freenet.node.updater;
>  
>  import freenet.config.BooleanCallback;
> +import freenet.config.Config;
>  import freenet.config.InvalidConfigValueException;
> +import freenet.config.SubConfig;
> +import freenet.keys.FreenetURI;
>  import freenet.node.Node;
> +import freenet.support.Logger;
>  
>  public class UpdaterEnabledCallback implements BooleanCallback {
>       
>       final Node node;
> +     final Config nodeConfig;
>       
> -     UpdaterEnabledCallback(Node n) {
> +     UpdaterEnabledCallback(Node n, Config nc) {
>               this.node = n;
> +             this.nodeConfig = nc;
>       }
>       
>       public boolean get() {
> -             return node.getNodeUpdater() != null;
> +             if(node.nodeUpdater==null)
> +                     return false;
> +             else 
> +                     return node.nodeUpdater.isRunning();
>       }
>       
>       public void set(boolean val) throws InvalidConfigValueException {
>               if(val == get()) return;
> -             // FIXME implement
> -             throw new InvalidConfigValueException("Cannot be updated on the 
> fly");
> +             if(val){
> +                     try{
> +                             SubConfig sc = nodeConfig.get("node.updater");
> +                             node.nodeUpdater = new NodeUpdater(node , 
> sc.getBoolean("autoupdate"), new FreenetURI(sc.getString("URI")), new 
> FreenetURI(sc.getString("revocationURI")));
> +                             Logger.normal(this, "Starting up the node 
> updater");
> +                     }catch (Exception e){
> +                             Logger.error(this, "unable to start the node 
> updater up "+e);
> +                             throw new InvalidConfigValueException("Unable 
> to enable the Node Updater "+e);
> +                     }
> +             }else{
> +                     node.nodeUpdater.kill();
> +                     Logger.normal(this, "Shutting down the node updater");
> +             }
>       }
>  }
> \ No newline at end of file
> 
> _______________________________________________
> cvs mailing list
> [email protected]
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 

-- 
Matthew J Toseland - [EMAIL PROTECTED]
Freenet Project Official Codemonkey - http://freenetproject.org/
ICTHUS - Nothing is impossible. Our Boss says so.

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Devl mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl

Reply via email to