public long getLifetime() { long cso = _closeSentOn.get(); if (cso <= 0) return _context.clock().now() - _createdOn; else return cso - _createdOn; }
/** * We probably don't want to expose the exact time at which a router published its info. * perhaps round down to the nearest minute? 10 minutes? 30 minutes? day? * */ static long getCurrentPublishDate(RouterContext context) { //_log.info("Setting published date to /now/"); return context.clock().now(); }
public synchronized void setRTT(int ms) { _rtt = (int)(_rttDampening*_rtt + (1-_rttDampening)*ms); if (_rtt > MAX_RTT) _rtt = MAX_RTT; _updated = _context.clock().now(); } public synchronized int getRTTDev() { return _rttDev; }
public void addPending(Collection<Hash> pending) { synchronized (_pendingPeers) { _pendingPeers.addAll(pending); for (Hash peer : pending) _pendingPeerTimes.put(peer, Long.valueOf(_context.clock().now())); } synchronized (_attemptedPeers) { _attemptedPeers.addAll(pending); } } /** we aren't even going to try to contact this peer */
/** * Misnamed, could be too old or too far in the future. */ public boolean tooOld() { long now = Clock.getInstance().now(); long earliestValid = now - OFFSET_VALIDITY; long latestValid = now + OFFSET_VALIDITY; if (_creationDate == null) return true; if (_creationDate.getTime() < earliestValid) return true; if (_creationDate.getTime() > latestValid) return true; return false; }
void packetReceived() { _lastReceivedOn = _context.clock().now(); resetActivityTimer(); synchronized (_connectLock) { _connectLock.notifyAll(); } }
private void rereadConfig() { long now = Clock.getInstance().now(); if (now - _lastReadConfig > CONFIG_READ_INTERVAL) { _manager.rereadConfig(); _lastReadConfig = now; } }
public boolean isValidTunnel(Hash client, TunnelInfo tunnel) { if (tunnel.getExpiration() < _context.clock().now()) return false; TunnelPool pool; if (tunnel.isInbound()) pool = _clientInboundPools.get(client); else pool = _clientOutboundPools.get(client); if (pool == null) return false; return pool.listTunnels().contains(tunnel); }
public void ackReceived() { final long now = _context.clock().now(); synchronized (this) { if (_ackOn <= 0) _ackOn = now; releasePayload(); notifyAll(); } cancelResend(); }
public Cleanup(RouterContext ctx) { super(ctx); _toUnbanlist = new ArrayList<Hash>(4); getTiming().setStartAfter(ctx.clock().now() + BANLIST_CLEANER_START_DELAY); } public String getName() { return "Expire banned peers"; }
protected int getPerPeerTimeoutMs(Hash peer) { int timeout = 0; if (_floodfillPeersExhausted && _floodfillSearchesOutstanding <= 0) timeout = _facade.getPeerTimeout(peer); else timeout = PER_FLOODFILL_PEER_TIMEOUT; long now = getContext().clock().now(); if (now + timeout > _expiration) return (int) Math.max(_expiration - now, MIN_TIMEOUT); else return timeout; }
private void removeSession(PublicKey target) { if (target == null) return; OutboundSession session = null; synchronized (_outboundSessions) { session = _outboundSessions.remove(target); } if ( (session != null) && (_log.shouldLog(Log.WARN)) ) _log.warn("Removing session tags with " + session.availableTags() + " available for " + (session.getLastExpirationDate()-_context.clock().now()) + "ms more", new Exception("Removed by")); }
/** * Note that the router failed to send a message to the peer over any transport. * Non-blocking. Will not update the profile if we can't get the lock. */ public void messageFailed(Hash peer) { PeerProfile data = getProfileNonblocking(peer); if (data == null) return; data.setLastSendFailed(_context.clock().now()); }
public FragmentedMessage(I2PAppContext ctx, long messageId) { _context = ctx; _log = ctx.logManager().getLog(FragmentedMessage.class); _messageId = messageId; _fragments = new ByteArray[MAX_FRAGMENTS]; _highFragmentNum = -1; _releasedAfter = -1; _createdOn = ctx.clock().now(); }
@Override public String toString() { return super.toString() + " started " + DataHelper.formatDuration((getContext().clock().now() - _startedOn)) + " ago"; }
private void setMocks(int now, int discSchOn, int connTimeout, int lifetime, int sendStreamId) { when(clock.now()).thenReturn((long) now); when(con.getDisconnectScheduledOn()).thenReturn((long) discSchOn); when(con.getOptions()).thenReturn(opts); when(opts.getConnectTimeout()).thenReturn((long) connTimeout); when(con.getLifetime()).thenReturn((long) lifetime); when(con.getSendStreamId()).thenReturn((long) sendStreamId); }
public void complete(FIFOBandwidthLimiter.Request req) { removeOBRequest(req); ByteBuffer buf = (ByteBuffer)req.attachment(); if (!_closed.get()) { _context.statManager().addRateData("ntcp.throttledWriteComplete", (_context.clock().now()-req.getRequestTime())); write(buf); } } }
@Override public void startRunning() { super.startRunning(); // Would be better if this was set when the inbound tunnel becomes alive. _startedOn = getTunnel().getContext().clock().now(); setupPostThrottle(); }
protected void writeHeader(OutputStream out) throws DataFormatException, IOException { _destination.writeBytes(out); if (_published <= 0) _published = Clock.getInstance().now(); long pub1k = _published / 1000; DataHelper.writeLong(out, 4, pub1k); // Divide separately to prevent rounding errors DataHelper.writeLong(out, 2, ((_expires / 1000) - pub1k)); DataHelper.writeLong(out, 2, _flags); if (isOffline()) writeOfflineBytes(out); }
public void runJob() { File configFile = new File(getContext().router().getConfigFilename()); if (shouldReread(configFile)) { getContext().router().readConfig(); _lastRead = getContext().clock().now(); Log log = getContext().logManager().getLog(ReadConfigJob.class); if (log.shouldDebug()) log.debug("Reloaded " + configFile); } requeue(DELAY); }