Package freenet.config

Examples of freenet.config.InvalidConfigValueException


        TextModeClientInterfaceServer server = core.getTextModeClientInterface();
        if(server != null) {
          try {
          server.networkInterface.setAllowedHosts(val);
          } catch(IllegalArgumentException e) {
            throw new InvalidConfigValueException(e);
          }
          server.allowedHosts = val;
        } else
          throw new InvalidConfigValueException("Setting allowedHosts for TMCI (console) server when TMCI is disabled");
      }
    }
View Full Code Here


      if(val.equalsIgnoreCase(ClientRequestScheduler.PRIORITY_HARD)){
        value = ClientRequestScheduler.PRIORITY_HARD;
      }else if(val.equalsIgnoreCase(ClientRequestScheduler.PRIORITY_SOFT)){
        value = ClientRequestScheduler.PRIORITY_SOFT;
      }else{
        throw new InvalidConfigValueException("Invalid priority scheme");
      }
      csBulk.setPriorityScheduler(value);
      csRT.setPriorityScheduler(value);
    }
View Full Code Here

      @Override
      protected void setValue(String val) throws InvalidConfigValueException {
        NETWORK_THREAT_LEVEL newValue = parseNetworkThreatLevel(val);
        if(newValue == null)
          throw new InvalidConfigValueException("Invalid value for network threat level: "+val);
        synchronized(SecurityLevels.this) {
          networkThreatLevel = newValue;
        }
      }

    };
    myConfig.register("networkThreatLevel", "HIGH", sortOrder++, false, true, "SecurityLevels.networkThreatLevelShort", "SecurityLevels.networkThreatLevel", networkThreatLevelCallback);
    NETWORK_THREAT_LEVEL netLevel = NETWORK_THREAT_LEVEL.valueOf(myConfig.getString("networkThreatLevel"));
    if(myConfig.getRawOption("networkThreatLevel") != null) {
      networkThreatLevel = netLevel;
    } else {
      // Call all the callbacks so that the config is consistent with the threat level.
      setThreatLevel(netLevel);
    }
    // FIXME remove back compat
    String s = myConfig.getRawOption("friendsThreatLevel");
    if(s != null) {
      friendsThreatLevel = parseFriendsThreatLevel(s);
    } else {
      friendsThreatLevel = null;
    }
    physicalThreatLevelCallback = new MyCallback<PHYSICAL_THREAT_LEVEL>() {

      @Override
      public String get() {
        synchronized(SecurityLevels.this) {
          return physicalThreatLevel.name();
        }
      }

      @Override
      public String[] getPossibleValues() {
        PHYSICAL_THREAT_LEVEL[] values = PHYSICAL_THREAT_LEVEL.values();
        String[] names = new String[values.length];
        for(int i=0;i<names.length;i++)
          names[i] = values[i].name();
        return names;
      }

      @Override
      protected PHYSICAL_THREAT_LEVEL getValue() {
        return physicalThreatLevel;
      }

      @Override
      protected void setValue(String val) throws InvalidConfigValueException {
        PHYSICAL_THREAT_LEVEL newValue = PHYSICAL_THREAT_LEVEL.valueOf(val);
        if(newValue != null)
          throw new InvalidConfigValueException("Invalid value for physical threat level: "+val);
        synchronized(SecurityLevels.this) {
          physicalThreatLevel = newValue;
        }
      }
View Full Code Here

                    }

                    @Override
                    public void set(Integer val) throws InvalidConfigValueException,
                            NodeNeedRestartException {
                        if(val < 1) throw new InvalidConfigValueException(l10n("memoryLimitedJobThreadLimitMustBe1Plus"));
                        memoryLimitedJobRunner.setMaxThreads(val);
                    }
       
    }, false);
    long defaultMemoryLimitedJobMemoryLimit = FECCodec.MIN_MEMORY_ALLOCATION;
    long overallMemoryLimit = NodeStarter.getMemoryLimitBytes();
    if(overallMemoryLimit > 512*1024*1024) {
        // FIXME review default memory limits
        defaultMemoryLimitedJobMemoryLimit += (overallMemoryLimit - 512*1024*1024) / 20;
    }
    nodeConfig.register("memoryLimitedJobMemoryLimit", defaultMemoryLimitedJobMemoryLimit, sortOrder++, true, false,
            "NodeClientCore.memoryLimitedJobMemoryLimit", "NodeClientCore.memoryLimitedJobMemoryLimitLong", new LongCallback() {

                    @Override
                    public Long get() {
                        return memoryLimitedJobRunner.getCapacity();
                    }

                    @Override
                    public void set(Long val) throws InvalidConfigValueException,
                            NodeNeedRestartException {
                        if(val < FECCodec.MIN_MEMORY_ALLOCATION) throw new InvalidConfigValueException(l10n("memoryLimitedJobMemoryLimitMustBeAtLeast", "min", SizeUtil.formatSize(FECCodec.MIN_MEMORY_ALLOCATION)));
                        memoryLimitedJobRunner.setCapacity(val);
                    }
       
    }, true);
    memoryLimitedJobRunner = new MemoryLimitedJobRunner(nodeConfig.getLong("memoryLimitedJobMemoryLimit"), nodeConfig.getInt("memoryLimitedJobThreadLimit"), node.executor);
    shutdownHook.addEarlyJob(new NativeThread("Shutdown FEC", NativeThread.HIGH_PRIORITY, true) {
       
        public void realRun() {
            System.out.println("Stopping FEC decode threads...");
            memoryLimitedJobRunner.shutdown();
        }
       
    });
    shutdownHook.addLateJob(new NativeThread("Shutdown FEC", NativeThread.HIGH_PRIORITY, true) {
       
        public void realRun() {
            memoryLimitedJobRunner.waitForShutdown();
            System.out.println("FEC decoding threads finished.");
        }
       
    });
    clientContext = new ClientContext(node.bootID, clientLayerPersister, node.executor,
            archiveManager, persistentTempBucketFactory, tempBucketFactory,
            persistentTempBucketFactory, healingQueue, uskManager, random, node.fastWeakRandom,
            node.getTicker(), memoryLimitedJobRunner, tempFilenameGenerator, persistentFilenameGenerator, tempBucketFactory,
            persistentRAFFactory, tempBucketFactory.getUnderlyingRAFFactory(), persistentDiskChecker,
            compressor, storeChecker, fcpPersistentRoot, cryptoSecretTransient, toadlets, defaultFetchContext, defaultInsertContext);
    compressor.setClientContext(clientContext);
    storeChecker.setContext(clientContext);
    clientLayerPersister.start(clientContext);
   
    try {
      requestStarters = new RequestStarterGroup(node, this, portNumber, random, config, throttleFS, clientContext, nodeDBHandle);
    } catch (InvalidConfigValueException e1) {
      throw new NodeInitException(NodeInitException.EXIT_BAD_CONFIG, e1.toString());
    }
   
        clientContext.init(requestStarters, alerts);
       
        if(persistentSecret != null) {
            setupMasterSecret(persistentSecret);
        }
       
        try {
            initStorage(databaseKey);
        } catch (MasterKeysWrongPasswordException e) {
            System.err.println("Cannot load persistent requests, awaiting password ...");
            node.setDatabaseAwaitingPassword();
        }
       
    node.securityLevels.addPhysicalThreatLevelListener(new SecurityLevelListener<PHYSICAL_THREAT_LEVEL>() {

      @Override
      public void onChange(PHYSICAL_THREAT_LEVEL oldLevel, PHYSICAL_THREAT_LEVEL newLevel) {
        if(newLevel == PHYSICAL_THREAT_LEVEL.LOW) {
          if(tempBucketFactory.isEncrypting()) {
            tempBucketFactory.setEncryption(false);
          }
          if(persistentTempBucketFactory != null) {
              if(persistentTempBucketFactory.isEncrypting()) {
                  persistentTempBucketFactory.setEncryption(false);
              }
          }
          persistentRAFFactory.setEncryption(false);
        } else { // newLevel >= PHYSICAL_THREAT_LEVEL.NORMAL
          if(!tempBucketFactory.isEncrypting()) {
            tempBucketFactory.setEncryption(true);
          }
          if(persistentTempBucketFactory != null) {
              if(!persistentTempBucketFactory.isEncrypting()) {
                  persistentTempBucketFactory.setEncryption(true);
              }
          }
          persistentRAFFactory.setEncryption(true);
        }
                if(clientLayerPersister.hasLoaded()) {
                    // May need to change filenames for client.dat* or even create them.
                    try {
                        initStorage(NodeClientCore.this.node.getDatabaseKey());
                    } catch (MasterKeysWrongPasswordException e) {
                        NodeClientCore.this.node.setDatabaseAwaitingPassword();
                    }
                }
      }

    });

    // Downloads directory

    this.downloadsDir = node.setupProgramDir(nodeConfig, "downloadsDir", node.userDir().file("downloads").getPath(),
      "NodeClientCore.downloadsDir", "NodeClientCore.downloadsDirLong", l10n("couldNotFindOrCreateDir"), (SubConfig)null);

    // Downloads allowed, uploads allowed

    nodeConfig.register("downloadAllowedDirs", new String[]{"all"}, sortOrder++, true, true, "NodeClientCore.downloadAllowedDirs",
      "NodeClientCore.downloadAllowedDirsLong",
      new StringArrCallback() {

        @Override
        public String[] get() {
          synchronized(NodeClientCore.this) {
            if(downloadAllowedEverywhere)
              return new String[]{"all"};
            String[] dirs = new String[downloadAllowedDirs.length + (includeDownloadDir ? 1 : 0)];
            for(int i = 0; i < downloadAllowedDirs.length; i++)
              dirs[i] = downloadAllowedDirs[i].getPath();
            if(includeDownloadDir)
              dirs[downloadAllowedDirs.length] = "downloads";
            return dirs;
          }
        }

        @Override
        public void set(String[] val) throws InvalidConfigValueException {
          setDownloadAllowedDirs(val);
        }
      });
    setDownloadAllowedDirs(nodeConfig.getStringArr("downloadAllowedDirs"));

    nodeConfig.register("uploadAllowedDirs", new String[]{"all"}, sortOrder++, true, true, "NodeClientCore.uploadAllowedDirs",
      "NodeClientCore.uploadAllowedDirsLong",
      new StringArrCallback() {

        @Override
        public String[] get() {
          synchronized(NodeClientCore.this) {
            if(uploadAllowedEverywhere)
              return new String[]{"all"};
            String[] dirs = new String[uploadAllowedDirs.length];
            for(int i = 0; i < uploadAllowedDirs.length; i++)
              dirs[i] = uploadAllowedDirs[i].getPath();
            return dirs;
          }
        }

        @Override
        public void set(String[] val) throws InvalidConfigValueException {
          setUploadAllowedDirs(val);
        }
      });
    setUploadAllowedDirs(nodeConfig.getStringArr("uploadAllowedDirs"));

    Logger.normal(this, "Initializing USK Manager");
    System.out.println("Initializing USK Manager");
    uskManager.init(clientContext);

    nodeConfig.register("maxBackgroundUSKFetchers", "64", sortOrder++, true, false, "NodeClientCore.maxUSKFetchers",
      "NodeClientCore.maxUSKFetchersLong", new IntCallback() {

      @Override
      public Integer get() {
        return maxBackgroundUSKFetchers;
      }

      @Override
      public void set(Integer uskFetch) throws InvalidConfigValueException {
        if(uskFetch <= 0)
          throw new InvalidConfigValueException(l10n("maxUSKFetchersMustBeGreaterThanZero"));
        maxBackgroundUSKFetchers = uskFetch;
      }
    }, false);

    maxBackgroundUSKFetchers = nodeConfig.getInt("maxBackgroundUSKFetchers");
View Full Code Here

            }

            @Override
            public void set(Long val) throws InvalidConfigValueException, NodeNeedRestartException {
                synchronized(NodeClientCore.this) {
                    if(val < 0) throw new InvalidConfigValueException(l10n("minDiskFreeMustBePositive"));
                    minDiskFreeLongTerm = val;
                }
                updatePersistentRAFSpaceLimit();
            }
           
        }, true);
        minDiskFreeLongTerm = nodeConfig.getLong("minDiskFreeLongTerm");
       
        nodeConfig.register("minDiskFreeShortTerm", "512M", sortOrder++, true, true, "NodeClientCore.minDiskFreeShortTerm", "NodeClientCore.minDiskFreeShortTermLong", new LongCallback() {

            @Override
            public Long get() {
                synchronized(NodeClientCore.this) {
                    return minDiskFreeShortTerm;
                }
            }

            @Override
            public void set(Long val) throws InvalidConfigValueException, NodeNeedRestartException {
                synchronized(NodeClientCore.this) {
                    if(val < 0) throw new InvalidConfigValueException(l10n("minDiskFreeMustBePositive"));
                    minDiskFreeShortTerm = val;
                }
                tempBucketFactory.setMinDiskSpace(val);
            }
           
View Full Code Here

      }
      @Override
      public void set(Integer val) throws InvalidConfigValueException {
       
        if(portNumber < -1 || portNumber == 0 || portNumber > 65535) {
          throw new InvalidConfigValueException("Invalid port number");
        }
       
       
        synchronized(NodeCryptoConfig.class) {
          if(portNumber == val) return;
          // FIXME implement on the fly listenPort changing
          // Note that this sort of thing should be the exception rather than the rule!!!!
          if(crypto != null)
            throw new InvalidConfigValueException("Switching listenPort on the fly not yet supported");
          portNumber = val;
        }
      }
      @Override
      public boolean isReadOnly() {
                return true;
              }   
    }, false);
   
    try{
      portNumber = config.getInt("listenPort");
    }catch (Exception e){
      // FIXME is this really necessary?
      Logger.error(this, "Caught "+e, e);
      System.err.println(e);
      e.printStackTrace();
      portNumber = -1;
    }
   
    config.register("bindTo", "0.0.0.0", sortOrder++, true, true, "Node.bindTo", "Node.bindToLong", new NodeBindtoCallback());
   
    try {
      bindTo = new FreenetInetAddress(config.getString("bindTo"), false);
     
    } catch (UnknownHostException e) {
      throw new NodeInitException(NodeInitException.EXIT_COULD_NOT_BIND_USM, "Invalid bindTo: "+config.getString("bindTo"));
    }
   
    config.register("testingDropPacketsEvery", 0, sortOrder++, true, false, "Node.dropPacketEvery", "Node.dropPacketEveryLong",
        new IntCallback() {

          @Override
          public Integer get() {
            synchronized(NodeCryptoConfig.this) {
              return dropProbability;
            }
          }

          @Override
          public void set(Integer val) throws InvalidConfigValueException {
            if(val < 0) throw new InvalidConfigValueException("testingDropPacketsEvery must not be negative");
            synchronized(NodeCryptoConfig.this) {
              if(val == dropProbability) return;
              dropProbability = val;
              if(crypto == null) return;
            }
View Full Code Here

   
    @Override
    public void set(String val) throws InvalidConfigValueException {
      if(val.equals(get())) return;
      // FIXME why not? Can't we use freenet.io.NetworkInterface like everywhere else, just adapt it for UDP?
      throw new InvalidConfigValueException("Cannot be updated on the fly");
    }
View Full Code Here

          public void set(String val) throws InvalidConfigValueException {
            LoggerHookChain chain = Logger.getChain();
            try {
              chain.setDetailedThresholds(val);
            } catch (InvalidThresholdException e) {
              throw new InvalidConfigValueException(e.getMessage());
            }
          }
        });
     
    // interval
     
    config.register("interval", "1HOUR", 5, true, false, "LogConfigHandler.rotationInterval",
        "LogConfigHandler.rotationIntervalLong",
        new StringCallback() {
          @Override
          public String get() {
            return logRotateInterval;
          }

          @Override
          public void set(String val) throws InvalidConfigValueException {
            if (val.equals(logRotateInterval)) return;
            if (fileLoggerHook != null) {
              try {
                fileLoggerHook.setInterval(val);
              } catch (FileLoggerHook.IntervalParseException e) {
                throw new OptionFormatException(e.getMessage());
              }
            }
            logRotateInterval = val;
          }
        });
     
    logRotateInterval = config.getString("interval");
     
    // max cached bytes in RAM
    config.register("maxCachedBytes", "1M", 6, true, false, "LogConfigHandler.maxCachedBytes",
        "LogConfigHandler.maxCachedBytesLong",
        new LongCallback() {
          @Override
          public Long get() {
            return maxCachedLogBytes;
          }
          @Override
          public void set(Long val) throws InvalidConfigValueException {
            if (val < 0) val = 0L;
            if (val == maxCachedLogBytes) return;
            maxCachedLogBytes = val;
            if (fileLoggerHook != null) fileLoggerHook.setMaxListBytes(val);
          }
        }, true);
     
    maxCachedLogBytes = config.getLong("maxCachedBytes");
     
    // max cached lines in RAM
    config.register("maxCachedLines", "10k", 7, true, false, "LogConfigHandler.maxCachedLines",
        "LogConfigHandler.maxCachedLinesLong",
        new IntCallback() {
          @Override
          public Integer get() {
            return maxCachedLogLines;
          }
          @Override
          public void set(Integer val) throws InvalidConfigValueException, NodeNeedRestartException {
            if(val < 0) val = 0;
            if(val == maxCachedLogLines) return;
            maxCachedLogLines = val;
            throw new NodeNeedRestartException("logger.maxCachedLogLines");
          }
        }, false);
     
    maxCachedLogLines = config.getInt("maxCachedLines");
   
    config.register("maxBacklogNotBusy", "60000", 8, true, false, "LogConfigHandler.maxBacklogNotBusy",
        "LogConfigHandler.maxBacklogNotBusy",
        new LongCallback() {

          @Override
          public Long get() {
            return maxBacklogNotBusy;
          }

          @Override
          public void set(Long val) throws InvalidConfigValueException, NodeNeedRestartException {
            if(val < 0) throw new InvalidConfigValueException("Must be >= 0");
            if(val == maxBacklogNotBusy) return;
            maxBacklogNotBusy = val;
            if(fileLoggerHook != null) fileLoggerHook.setMaxBacklogNotBusy(val);
          }
     
View Full Code Here

  }
 
  protected void preSetLogDir(File f) throws InvalidConfigValueException {
    boolean exists = f.exists();
    if(exists && !f.isDirectory())
      throw new InvalidConfigValueException("Cannot overwrite a file with a log directory");
    if(!exists) {
      f.mkdir();
      exists = f.exists();
      if(!exists || !f.isDirectory())
        throw new InvalidConfigValueException("Cannot create log directory");
    }
  }
View Full Code Here

        }
        FreenetInetAddress addr;
        try {
          addr = new FreenetInetAddress(val, false, true);
        } catch (HostnameSyntaxException e) {
          throw new InvalidConfigValueException(l10n("unknownHostErrorInIPOverride", "error", "hostname or IP address syntax error"));
        } catch (UnknownHostException e) {
          throw new InvalidConfigValueException(l10n("unknownHostErrorInIPOverride", "error", e.getMessage()));
        }
        // Compare as IPs.
        if(addr.equals(overrideIPAddress)) return;
        overrideIPAddressString = val;
        overrideIPAddress = addr;
        lastIPAddress = null;
        synchronized(this) {
          hasValidAddressOverride = true;
        }
        if(!hadValidAddressOverride) {
          onGetValidAddressOverride();
        }
        redetectAddress();
      }
    });
   
    hasValidAddressOverride = true;
    overrideIPAddressString = nodeConfig.getString("ipAddressOverride");
    if(overrideIPAddressString.length() == 0)
      overrideIPAddress = null;
    else {
      try {
        overrideIPAddress = new FreenetInetAddress(overrideIPAddressString, false, true);
      } catch (HostnameSyntaxException e) {
        synchronized(this) {
          hasValidAddressOverride = false;
        }
        String msg = "Invalid IP override syntax: "+overrideIPAddressString+" in config: "+e.getMessage();
        Logger.error(this, msg);
        System.err.println(msg+" but starting up anyway, ignoring the configured IP override");
        overrideIPAddress = null;
      } catch (UnknownHostException e) {
        // **FIXME** This never happens for this reason with current FreenetInetAddress(String, boolean, boolean) code; perhaps it needs review?
        String msg = "Unknown host: "+overrideIPAddressString+" in config: "+e.getMessage();
        Logger.error(this, msg);
        System.err.println(msg+" but starting up anyway with no IP override");
        overrideIPAddress = null;
      }
    }
   
    // Temporary IP address hint
   
    nodeConfig.register("tempIPAddressHint", "", sortOrder++, true, false, "NodeIPDectector.tempAddressHint", "NodeIPDectector.tempAddressHintLong", new StringCallback() {

      @Override
      public String get() {
        return "";
      }
     
      @Override
      public void set(String val) throws InvalidConfigValueException {
        if(val.length() == 0) {
          return;
        }
        if(overrideIPAddress != null) return;
        try {
          oldIPAddress = new FreenetInetAddress(val, false);
        } catch (UnknownHostException e) {
          throw new InvalidConfigValueException("Unknown host: "+e.getMessage());
        }
        redetectAddress();
      }
    });
   
View Full Code Here

TOP

Related Classes of freenet.config.InvalidConfigValueException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.