Package freenet.support.math

Examples of freenet.support.math.TimeDecayingRunningAverage


  NodeStats(Node node, int sortOrder, SubConfig statsConfig, int obwLimit, int ibwLimit, int lastVersion) throws NodeInitException {
    this.node = node;
    this.peers = node.peers;
    this.hardRandom = node.random;
    this.routingMissDistanceLocal = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    this.routingMissDistanceRemote = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    this.routingMissDistanceOverall = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    this.routingMissDistanceBulk = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    this.routingMissDistanceRT = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    this.backedOffPercent = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    preemptiveRejectReasons = new StringCounter();
    localPreemptiveRejectReasons = new StringCounter();
    pInstantRejectIncomingOverall = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    pInstantRejectIncomingCHKRequestRT = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    pInstantRejectIncomingSSKRequestRT = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    pInstantRejectIncomingCHKInsertRT = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    pInstantRejectIncomingSSKInsertRT = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    pInstantRejectIncomingCHKRequestBulk = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    pInstantRejectIncomingSSKRequestBulk = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    pInstantRejectIncomingCHKInsertBulk = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    pInstantRejectIncomingSSKInsertBulk = new BootstrappingDecayingRunningAverage(0.0, 0.0, 1.0, 1000, null);
    REJECT_STATS_AVERAGERS = new RunningAverage[] {
          pInstantRejectIncomingCHKRequestBulk,
          pInstantRejectIncomingSSKRequestBulk,
          pInstantRejectIncomingCHKInsertBulk,
          pInstantRejectIncomingSSKInsertBulk
    };
    noisyRejectStats = new byte[4];
    ThreadGroup tg = Thread.currentThread().getThreadGroup();
    while(tg.getParent() != null) tg = tg.getParent();
    this.rootThreadGroup = tg;
    throttledPacketSendAverage =
      new BootstrappingDecayingRunningAverage(0, 0, Long.MAX_VALUE, 100, null);
    throttledPacketSendAverageRT =
      new BootstrappingDecayingRunningAverage(0, 0, Long.MAX_VALUE, 100, null);
    throttledPacketSendAverageBulk =
      new BootstrappingDecayingRunningAverage(0, 0, Long.MAX_VALUE, 100, null);
    nodePinger = new NodePinger(node);

    previous_input_stat = 0;
    previous_output_stat = 0;
    previous_io_stat_time = 1;
    last_input_stat = 0;
    last_output_stat = 0;
    last_io_stat_time = 3;

    int defaultThreadLimit;
    long memoryLimit = NodeStarter.getMemoryLimitMB();
   
    System.out.println("Memory is "+memoryLimit+"MB");
    if(memoryLimit > 0 && memoryLimit < 100) {
      defaultThreadLimit = 200;
      System.out.println("Severe memory pressure, setting 200 thread limit. Freenet may not work well!");
    } else if(memoryLimit > 0 && memoryLimit < 128) {
      defaultThreadLimit = 300;
      System.out.println("Moderate memory pressure, setting 300 thread limit. Increase your memory limit in wrapper.conf if possible.");
    } else if(memoryLimit > 0 && memoryLimit < 192) {
      defaultThreadLimit = 400;
      System.out.println("Setting 400 thread limit due to <=192MB memory limit. This should be enough but more memory is better.");
    } else {
      System.out.println("Setting standard 500 thread limit. This should be enough for most nodes but more memory is usually a good thing.");
      defaultThreadLimit = 500;
    }
    statsConfig.register("threadLimit", defaultThreadLimit, sortOrder++, true, true, "NodeStat.threadLimit", "NodeStat.threadLimitLong",
        new IntCallback() {
          @Override
          public Integer get() {
            return threadLimit;
          }
          @Override
          public void set(Integer val) throws InvalidConfigValueException {
            if (get().equals(val))
                  return;
            if(val < 100)
              throw new InvalidConfigValueException(l10n("valueTooLow"));
            threadLimit = val;
          }
    },false);
   
    threadLimit = statsConfig.getInt("threadLimit");

    // Yes it could be in seconds insteed of multiples of 0.12, but we don't want people to play with it :)
    statsConfig.register("aggressiveGC", aggressiveGCModificator, sortOrder++, true, false, "NodeStat.aggressiveGC", "NodeStat.aggressiveGCLong",
        new IntCallback() {
          @Override
          public Integer get() {
            return aggressiveGCModificator;
          }
          @Override
          public void set(Integer val) throws InvalidConfigValueException {
            if (get().equals(val))
                  return;
            Logger.normal(this, "Changing aggressiveGCModificator to "+val);
            aggressiveGCModificator = val;
          }
    },false);
    aggressiveGCModificator = statsConfig.getInt("aggressiveGC");

    myMemoryChecker = new MemoryChecker(node.getTicker(), aggressiveGCModificator);
    statsConfig.register("memoryChecker", true, sortOrder++, true, false, "NodeStat.memCheck", "NodeStat.memCheckLong",
        new BooleanCallback(){
          @Override
          public Boolean get() {
            return myMemoryChecker.isRunning();
          }

          @Override
          public void set(Boolean val) throws InvalidConfigValueException {
            if (get().equals(val))
                  return;

            if(val)
              myMemoryChecker.start();
            else
              myMemoryChecker.terminate();
          }
    });
    if(statsConfig.getBoolean("memoryChecker"))
      myMemoryChecker.start();

    statsConfig.register("ignoreLocalVsRemoteBandwidthLiability", false, sortOrder++, true, false, "NodeStat.ignoreLocalVsRemoteBandwidthLiability", "NodeStat.ignoreLocalVsRemoteBandwidthLiabilityLong", new BooleanCallback() {

      @Override
      public Boolean get() {
        synchronized(NodeStats.this) {
          return ignoreLocalVsRemoteBandwidthLiability;
        }
      }

      @Override
      public void set(Boolean val) throws InvalidConfigValueException {
        synchronized(NodeStats.this) {
          ignoreLocalVsRemoteBandwidthLiability = val;
        }
      }
    });
    ignoreLocalVsRemoteBandwidthLiability = statsConfig.getBoolean("ignoreLocalVsRemoteBandwidthLiability");

    statsConfig.register("maxPingTime", DEFAULT_MAX_PING_TIME, sortOrder++, true, true, "NodeStat.maxPingTime", "NodeStat.maxPingTimeLong", new LongCallback() {

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

      @Override
      public void set(Long val) throws InvalidConfigValueException, NodeNeedRestartException {
        maxPingTime = val;
      }

    }, false);
    maxPingTime = statsConfig.getLong("maxPingTime");

    statsConfig.register("subMaxPingTime", DEFAULT_SUB_MAX_PING_TIME, sortOrder++, true, true, "NodeStat.subMaxPingTime", "NodeStat.subMaxPingTimeLong", new LongCallback() {

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

      @Override
      public void set(Long val) throws InvalidConfigValueException, NodeNeedRestartException {
        subMaxPingTime = val;
      }

    }, false);
    subMaxPingTime = statsConfig.getLong("subMaxPingTime");

    // This is a *network* level setting, because it affects the rate at which we initiate local
    // requests, which could be seen by distant nodes.

    node.securityLevels.addNetworkThreatLevelListener(new SecurityLevelListener<NETWORK_THREAT_LEVEL>() {

      @Override
      public void onChange(NETWORK_THREAT_LEVEL oldLevel, NETWORK_THREAT_LEVEL newLevel) {
        if(newLevel == NETWORK_THREAT_LEVEL.MAXIMUM)
          ignoreLocalVsRemoteBandwidthLiability = true;
        if(oldLevel == NETWORK_THREAT_LEVEL.MAXIMUM)
          ignoreLocalVsRemoteBandwidthLiability = false;
        // Otherwise leave it as it was. It defaults to false.
      }

    });
   
    statsConfig.register("enableNewLoadManagementRT", false, sortOrder++, true, false, "Node.enableNewLoadManagementRT", "Node.enableNewLoadManagementRTLong", new BooleanCallback() {

      @Override
      public Boolean get() {
        return enableNewLoadManagementRT;
      }

      @Override
      public void set(Boolean val) throws InvalidConfigValueException,
          NodeNeedRestartException {
        enableNewLoadManagementRT = val;
      }
     
    });
    enableNewLoadManagementRT = statsConfig.getBoolean("enableNewLoadManagementRT");
    statsConfig.register("enableNewLoadManagementBulk", false, sortOrder++, true, false, "Node.enableNewLoadManagementBulk", "Node.enableNewLoadManagementBulkLong", new BooleanCallback() {

      @Override
      public Boolean get() {
        return enableNewLoadManagementBulk;
      }

      @Override
      public void set(Boolean val) throws InvalidConfigValueException,
          NodeNeedRestartException {
        enableNewLoadManagementBulk = val;
      }
     
    });
    enableNewLoadManagementBulk = statsConfig.getBoolean("enableNewLoadManagementBulk");
   
        if(node.lastVersion <= 1455 && (enableNewLoadManagementRT || enableNewLoadManagementBulk)) {
            // FIXME remove
            enableNewLoadManagementRT = false;
            enableNewLoadManagementBulk = false;
            System.err.println("Turning off NLM when upgrading from pre-1455. The load stats messages aren't being sent at the moment so it won't work anyway.");
            statsConfig.config.store();
        }

    persister = new ConfigurablePersister(this, statsConfig, "nodeThrottleFile", "node-throttle.dat", sortOrder++, true, false,
        "NodeStat.statsPersister", "NodeStat.statsPersisterLong", node.ticker, node.getRunDir());

    SimpleFieldSet throttleFS = persister.read();
    if(logMINOR) Logger.minor(this, "Read throttleFS:\n"+throttleFS);

    // Guesstimates. Hopefully well over the reality.
    localChkFetchBytesSentAverage = new TimeDecayingRunningAverage(500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("LocalChkFetchBytesSentAverage"), node);
    localSskFetchBytesSentAverage = new TimeDecayingRunningAverage(500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("LocalSskFetchBytesSentAverage"), node);
    localChkInsertBytesSentAverage = new TimeDecayingRunningAverage(32768, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("LocalChkInsertBytesSentAverage"), node);
    localSskInsertBytesSentAverage = new TimeDecayingRunningAverage(2048, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("LocalSskInsertBytesSentAverage"), node);
    localChkFetchBytesReceivedAverage = new TimeDecayingRunningAverage(32768+2048/*path folding*/, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("LocalChkFetchBytesReceivedAverage"), node);
    localSskFetchBytesReceivedAverage = new TimeDecayingRunningAverage(2048, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("LocalSskFetchBytesReceivedAverage"), node);
    localChkInsertBytesReceivedAverage = new TimeDecayingRunningAverage(1024, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("LocalChkInsertBytesReceivedAverage"), node);
    localSskInsertBytesReceivedAverage = new TimeDecayingRunningAverage(500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("LocalChkInsertBytesReceivedAverage"), node);

    remoteChkFetchBytesSentAverage = new TimeDecayingRunningAverage(32768+1024+500+2048/*path folding*/, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("RemoteChkFetchBytesSentAverage"), node);
    remoteSskFetchBytesSentAverage = new TimeDecayingRunningAverage(1024+1024+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("RemoteSskFetchBytesSentAverage"), node);
    remoteChkInsertBytesSentAverage = new TimeDecayingRunningAverage(32768+32768+1024, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("RemoteChkInsertBytesSentAverage"), node);
    remoteSskInsertBytesSentAverage = new TimeDecayingRunningAverage(1024+1024+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("RemoteSskInsertBytesSentAverage"), node);
    remoteChkFetchBytesReceivedAverage = new TimeDecayingRunningAverage(32768+1024+500+2048/*path folding*/, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("RemoteChkFetchBytesReceivedAverage"), node);
    remoteSskFetchBytesReceivedAverage = new TimeDecayingRunningAverage(2048+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("RemoteSskFetchBytesReceivedAverage"), node);
    remoteChkInsertBytesReceivedAverage = new TimeDecayingRunningAverage(32768+1024+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("RemoteChkInsertBytesReceivedAverage"), node);
    remoteSskInsertBytesReceivedAverage = new TimeDecayingRunningAverage(1024+1024+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("RemoteSskInsertBytesReceivedAverage"), node);

    successfulChkFetchBytesSentAverage = new TimeDecayingRunningAverage(32768+1024+500+2048/*path folding*/, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("SuccessfulChkFetchBytesSentAverage"), node);
    successfulSskFetchBytesSentAverage = new TimeDecayingRunningAverage(1024+1024+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("SuccessfulSskFetchBytesSentAverage"), node);
    successfulChkInsertBytesSentAverage = new TimeDecayingRunningAverage(32768+32768+1024, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("SuccessfulChkInsertBytesSentAverage"), node);
    successfulSskInsertBytesSentAverage = new TimeDecayingRunningAverage(1024+1024+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("SuccessfulSskInsertBytesSentAverage"), node);
    successfulChkOfferReplyBytesSentAverage = new TimeDecayingRunningAverage(32768+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("successfulChkOfferReplyBytesSentAverage"), node);
    successfulSskOfferReplyBytesSentAverage = new TimeDecayingRunningAverage(3072, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("successfulSskOfferReplyBytesSentAverage"), node);
    successfulChkFetchBytesReceivedAverage = new TimeDecayingRunningAverage(32768+1024+500+2048/*path folding*/, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("SuccessfulChkFetchBytesReceivedAverage"), node);
    successfulSskFetchBytesReceivedAverage = new TimeDecayingRunningAverage(2048+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("SuccessfulSskFetchBytesReceivedAverage"), node);
    successfulChkInsertBytesReceivedAverage = new TimeDecayingRunningAverage(32768+1024+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("SuccessfulChkInsertBytesReceivedAverage"), node);
    successfulSskInsertBytesReceivedAverage = new TimeDecayingRunningAverage(1024+1024+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("SuccessfulSskInsertBytesReceivedAverage"), node);
    successfulChkOfferReplyBytesReceivedAverage = new TimeDecayingRunningAverage(32768+500, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("successfulChkOfferReplyBytesReceivedAverage"), node);
    successfulSskOfferReplyBytesReceivedAverage = new TimeDecayingRunningAverage(3072, 180000, 0.0, 200*1024, throttleFS == null ? null : throttleFS.subset("successfulSskOfferReplyBytesReceivedAverage"), node);

    globalFetchPSuccess = new TrivialRunningAverage();
    chkLocalFetchPSuccess = new TrivialRunningAverage();
    chkRemoteFetchPSuccess = new TrivialRunningAverage();
    sskLocalFetchPSuccess = new TrivialRunningAverage();
View Full Code Here


    this.outgoingMangler = mangler;
    this.node = node2;
    this.crypto = crypto;
    assert(crypto.isOpennet == (isOpennet() || isSeed()));
    this.peers = peers;
    this.backedOffPercent = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    this.backedOffPercentRT = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    this.backedOffPercentBulk = new TimeDecayingRunningAverage(0.0, 180000, 0.0, 1.0, node);
    this.myBootID = node2.bootID;
    this.bootID = new AtomicLong();
    version = fs.get("version");
    Version.seenVersion(version);
    try {
      simpleVersion = Version.getArbitraryBuildNumber(version);
    } catch (VersionParseException e2) {
      throw new FSParseException("Invalid version "+version+" : "+e2);
    }
    String locationString = fs.get("location");

    location = new PeerLocation(locationString);
   
    disableRouting = disableRoutingHasBeenSetLocally = false;
    disableRoutingHasBeenSetRemotely = false; // Assume so

    lastGoodVersion = fs.get("lastGoodVersion");
    updateVersionRoutablity();

    testnetEnabled = fs.getBoolean("testnet", false);
    if(testnetEnabled) {
      String err = "Ignoring incompatible testnet node " + detectedPeer;
      Logger.error(this, err);
      throw new PeerParseException(err);
    }

    negTypes = fs.getIntArray("auth.negTypes");
    if(negTypes == null || negTypes.length == 0) {
      if(fromAnonymousInitiator)
        negTypes = mangler.supportedNegTypes(false); // Assume compatible. Anonymous initiator = short-lived, and we already connected so we know we are.
      else
        throw new FSParseException("No negTypes!");
    }

    if(fs.getBoolean("opennet", false) != isOpennet)
      throw new FSParseException("Trying to parse a darknet peer as opennet or an opennet peer as darknet isOpennet="+isOpennet+" boolean = "+fs.getBoolean("opennet", false)+" string = \""+fs.get("opennet")+"\"");

    /* Read the DSA key material for the peer */
    try {
      SimpleFieldSet sfs = fs.subset("dsaGroup");
      if(sfs == null) {
          this.peerCryptoGroup = Global.DSAgroupBigA;
        fs.put("dsaGroup", this.peerCryptoGroup.asFieldSet());
      } else
          this.peerCryptoGroup = DSAGroup.create(sfs);

      sfs = fs.subset("dsaPubKey");
      if(sfs == null || peerCryptoGroup == null)
        throw new FSParseException("No dsaPubKey - very old reference?");
      else {
        this.peerPubKey = DSAPublicKey.create(sfs, peerCryptoGroup);
        pubKeyHash = SHA256.digest(peerPubKey.asBytes());
        pubKeyHashHash = SHA256.digest(pubKeyHash);
      }
     
      parseECDSA(fs, fromAnonymousInitiator, true);
      if(noSig || verifyReferenceSignature(fs)) {
        this.isSignatureVerificationSuccessfull = true;
      }
    } catch(IllegalBase64Exception e) {
      Logger.error(this, "Caught " + e, e);
      throw new FSParseException(e);
    }

    // Identifier

    if(!generateIdentityFromPubkey()) {
      String identityString = fs.get("identity");
      if(identityString == null)
        throw new PeerParseException("No identity!");
      try {
        identity = Base64.decode(identityString);
      } catch(NumberFormatException e) {
        throw new FSParseException(e);
      } catch(IllegalBase64Exception e) {
        throw new FSParseException(e);
      }
    } else {
      identity = pubKeyHash;
    }

    if(identity == null)
      throw new FSParseException("No identity");
    identityAsBase64String = Base64.encode(identity);
    identityHash = SHA256.digest(identity);
    identityHashHash = SHA256.digest(identityHash);
    swapIdentifier = Fields.bytesToLong(identityHashHash);
    hashCode = Fields.hashCode(pubKeyHash);

    // Setup incoming and outgoing setup ciphers
    byte[] nodeKey = crypto.identityHash;
    byte[] nodeKeyHash = crypto.identityHashHash;

    int digestLength = SHA256.getDigestLength();
    incomingSetupKey = new byte[digestLength];
    for(int i = 0; i < incomingSetupKey.length; i++)
      incomingSetupKey[i] = (byte) (nodeKey[i] ^ identityHashHash[i]);
    outgoingSetupKey = new byte[digestLength];
    for(int i = 0; i < outgoingSetupKey.length; i++)
      outgoingSetupKey[i] = (byte) (nodeKeyHash[i] ^ identityHash[i]);
    if(logMINOR)
      Logger.minor(this, "Keys:\nIdentity:  " + HexUtil.bytesToHex(crypto.myIdentity) +
        "\nThisIdent: " + HexUtil.bytesToHex(identity) +
        "\nNode:      " + HexUtil.bytesToHex(nodeKey) +
        "\nNode hash: " + HexUtil.bytesToHex(nodeKeyHash) +
        "\nThis:      " + HexUtil.bytesToHex(identityHash) +
        "\nThis hash: " + HexUtil.bytesToHex(identityHashHash) +
        "\nFor:       " + getPeer());

    try {
      incomingSetupCipher = new Rijndael(256, 256);
      incomingSetupCipher.initialize(incomingSetupKey);
      outgoingSetupCipher = new Rijndael(256, 256);
      outgoingSetupCipher.initialize(outgoingSetupKey);
      anonymousInitiatorSetupCipher = new Rijndael(256, 256);
      anonymousInitiatorSetupCipher.initialize(identityHash);
    } catch(UnsupportedCipherException e1) {
      Logger.error(this, "Caught: " + e1);
      throw new Error(e1);
    }

    nominalPeer = new ArrayList<Peer>();
    try {
      String physical[] = fs.getAll("physical.udp");
      if(physical == null) {
        // Leave it empty
      } else {
        for(String phys: physical) {
          Peer p;
          try {
            p = new Peer(phys, true, true);
          } catch(HostnameSyntaxException e) {
            if(fromLocal)
              Logger.error(this, "Invalid hostname or IP Address syntax error while parsing peer reference in local peers list: " + phys);
            System.err.println("Invalid hostname or IP Address syntax error while parsing peer reference: " + phys);
            continue;
          } catch (PeerParseException e) {
            if(fromLocal)
              Logger.error(this, "Invalid hostname or IP Address syntax error while parsing peer reference in local peers list: " + phys);
            System.err.println("Invalid hostname or IP Address syntax error while parsing peer reference: " + phys);
            continue;
          } catch (UnknownHostException e) {
            if(fromLocal)
              Logger.error(this, "Invalid hostname or IP Address syntax error while parsing peer reference in local peers list: " + phys);
            System.err.println("Invalid hostname or IP Address syntax error while parsing peer reference: " + phys);
            continue;
          }
          if(!nominalPeer.contains(p))
            nominalPeer.add(p);
        }
      }
    } catch(Exception e1) {
      throw new FSParseException(e1);
    }
    if(nominalPeer.isEmpty()) {
      Logger.normal(this, "No IP addresses found for identity '" + identityAsBase64String + "', possibly at location '" + location + ": " + userToString());
      detectedPeer = null;
    } else {
      detectedPeer = nominalPeer.get(0);
    }
    updateShortToString();

    // Don't create trackers until we have a key
    currentTracker = null;
    previousTracker = null;

    timeLastSentPacket = -1;
    timeLastReceivedPacket = -1;
    timeLastReceivedSwapRequest = -1;
    timeLastRoutable = -1;
    timeAddedOrRestarted = System.currentTimeMillis();

    swapRequestsInterval = new SimpleRunningAverage(50, Node.MIN_INTERVAL_BETWEEN_INCOMING_SWAP_REQUESTS);
    probeRequestsInterval = new SimpleRunningAverage(50, Node.MIN_INTERVAL_BETWEEN_INCOMING_PROBE_REQUESTS);

    messageQueue = new PeerMessageQueue();

    decrementHTLAtMaximum = node.random.nextFloat() < Node.DECREMENT_AT_MAX_PROB;
    decrementHTLAtMinimum = node.random.nextFloat() < Node.DECREMENT_AT_MIN_PROB;

    pingNumber = node.random.nextLong();

    // A SimpleRunningAverage would be a bad choice because it would cause oscillations.
    // So go for a filter.
    pingAverage =
      // Short average otherwise we will reject for a *REALLY* long time after any spike.
      new TimeDecayingRunningAverage(1, SECONDS.toMillis(30), 0, NodePinger.CRAZY_MAX_PING_TIME, node);

    // TDRA for probability of rejection
    pRejected =
      new TimeDecayingRunningAverage(0, MINUTES.toMillis(4), 0.0, 1.0, node);

    // ARK stuff.

    parseARK(fs, true, false);

View Full Code Here

TOP

Related Classes of freenet.support.math.TimeDecayingRunningAverage

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.