private double calculateMedianPing(PeerNode[] peers) { double[] allPeers = new double[peers.length]; for(int i = 0; i < peers.length; i++) { PeerNode peer = peers[i]; allPeers[i] = peer.averagePingTime(); } Arrays.sort(allPeers); return allPeers[peers.length / 2]; }
this.isFetchingARK = peerNode.isFetchingARK(); this.isOpennet = peerNode.isOpennet(); this.averagePingTime = peerNode.averagePingTime(); this.averagePingTimeCorrected = peerNode.averagePingTimeCorrected(); this.publicInvalidVersion = peerNode.publicInvalidVersion();
public boolean isRoutingBackedOffEither() { long now = System.currentTimeMillis(); double pingTime; synchronized(this) { long routingBackedOffUntil = Math.max(routingBackedOffUntilRT, routingBackedOffUntilBulk); long transferBackedOffUntil = Math.max(transferBackedOffUntilRT, transferBackedOffUntilBulk); if(now < routingBackedOffUntil || now < transferBackedOffUntil) return true; pingTime = averagePingTime(); } if(pingTime > maxPeerPingTime()) return true; return false; }
public boolean isRoutingBackedOff(boolean realTime) { long now = System.currentTimeMillis(); double pingTime; synchronized(this) { long routingBackedOffUntil = realTime ? routingBackedOffUntilRT : routingBackedOffUntilBulk; long transferBackedOffUntil = realTime ? transferBackedOffUntilRT : transferBackedOffUntilBulk; if(now < routingBackedOffUntil || now < transferBackedOffUntil) return true; pingTime = averagePingTime(); } if(pingTime > maxPeerPingTime()) return true; return false; }
public boolean isRoutingBackedOff(long ignoreBackoffUnder, boolean realTime) { long now = System.currentTimeMillis(); double pingTime; synchronized(this) { long routingBackedOffUntil = realTime ? routingBackedOffUntilRT : routingBackedOffUntilBulk; if(now < routingBackedOffUntil) { if(routingBackedOffUntil - now >= ignoreBackoffUnder) return true; } long transferBackedOffUntil = realTime ? transferBackedOffUntilRT : transferBackedOffUntilBulk; if(now < transferBackedOffUntil) { if(transferBackedOffUntil - now >= ignoreBackoffUnder) return true; } if(isInMandatoryBackoff(now, realTime)) return true; pingTime = averagePingTime(); } if(pingTime > maxPeerPingTime()) return true; return false; }
/** * Export volatile data about the node as a SimpleFieldSet */ public SimpleFieldSet exportVolatileFieldSet() { SimpleFieldSet fs = new SimpleFieldSet(true); long now = System.currentTimeMillis(); synchronized(this) { fs.put("averagePingTime", averagePingTime()); long idle = now - lastReceivedPacketTime(); if(idle > SECONDS.toMillis(60) && -1 != lastReceivedPacketTime()) fs.put("idle", idle); if(peerAddedTime > 1) fs.put("peerAddedTime", peerAddedTime); fs.putSingle("lastRoutingBackoffReasonRT", lastRoutingBackoffReasonRT); fs.putSingle("lastRoutingBackoffReasonBulk", lastRoutingBackoffReasonBulk); fs.put("routingBackoffPercent", backedOffPercent.currentValue() * 100); fs.put("routingBackoffRT", Math.max(Math.max(routingBackedOffUntilRT, transferBackedOffUntilRT) - now, 0)); fs.put("routingBackoffBulk", Math.max(Math.max(routingBackedOffUntilBulk, transferBackedOffUntilBulk) - now, 0)); fs.put("routingBackoffLengthRT", routingBackoffLengthRT); fs.put("routingBackoffLengthBulk", routingBackoffLengthBulk); fs.put("overloadProbability", getPRejected() * 100); fs.put("percentTimeRoutableConnection", getPercentTimeRoutableConnection() * 100); } fs.putSingle("status", getPeerNodeStatusString()); return fs; }
public int setPeerNodeStatus(long now, boolean noLog) { long localRoutingBackedOffUntilRT = getRoutingBackedOffUntil(true); long localRoutingBackedOffUntilBulk = getRoutingBackedOffUntil(true); int oldPeerNodeStatus; long threshold = maxPeerPingTime(); boolean noLoadStats = noLoadStats(); synchronized(this) { oldPeerNodeStatus = peerNodeStatus; peerNodeStatus = getPeerNodeStatus(now, localRoutingBackedOffUntilRT, localRoutingBackedOffUntilBulk, averagePingTime() > threshold, noLoadStats); if(peerNodeStatus != oldPeerNodeStatus && recordStatus()) { peers.changePeerNodeStatus(this, oldPeerNodeStatus, peerNodeStatus, noLog); } } if(logMINOR) Logger.minor(this, "Peer node status now "+peerNodeStatus+" was "+oldPeerNodeStatus); if(peerNodeStatus!=oldPeerNodeStatus){ if(oldPeerNodeStatus == PeerManager.PEER_NODE_STATUS_ROUTING_BACKED_OFF) { outputLoadTrackerRealTime.maybeNotifySlotWaiter(); outputLoadTrackerBulk.maybeNotifySlotWaiter(); } notifyPeerNodeStatusChangeListeners(); } if(peerNodeStatus == PeerManager.PEER_NODE_STATUS_ROUTING_BACKED_OFF) { long delta = Math.max(localRoutingBackedOffUntilRT, localRoutingBackedOffUntilBulk) - now + 1; if(delta > 0) node.ticker.queueTimedJob(checkStatusAfterBackoff, "Update status for "+this, delta, true, true); } return peerNodeStatus; }