public long getLifetime() { long cso = _closeSentOn.get(); if (cso <= 0) return _context.clock().now() - _createdOn; else return cso - _createdOn; }
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; }
/** incoming - save the token (arbitrary length) */ public Token(I2PAppContext ctx, byte[] data) { super(data); // lets not get carried away if (data.length > MAX_TOK_LEN) throw new IllegalArgumentException(); lastSeen = ctx.clock().now(); }
/** side effect: sets _currentHour */ private long getTimeTillNextHour() { long now = _context.clock().now(); long currentHour = now / HOUR; _currentHour = currentHour; long next = ((1 + currentHour) * HOUR) + LAG; return Math.max(5000, next - now); } }
/** * Update the last-changed timestamp to now. */ public void setLastChanged() { _lastChanged = _context.clock().now(); }
@Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append("[DeliveryStatusMessage: "); buf.append("\n\tMessage ID: ").append(getMessageId()); buf.append("\n\tArrival: ").append(_context.clock().now() - _arrival); buf.append("ms in the past"); buf.append("]"); return buf.toString(); } }
/** * Remove expired nonces from map * @since 0.9.6 */ private void cleanNonces() { long now = _context.clock().now(); for (Iterator<NonceInfo> iter = _nonces.values().iterator(); iter.hasNext(); ) { NonceInfo info = iter.next(); if (info.getExpires() <= now) iter.remove(); } }
void packetReceived() { _lastReceivedOn = _context.clock().now(); resetActivityTimer(); synchronized (_connectLock) { _connectLock.notifyAll(); } }
public void ackReceived() { final long now = _context.clock().now(); synchronized (this) { if (_ackOn <= 0) _ackOn = now; releasePayload(); notifyAll(); } cancelResend(); }
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")); }
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(); }
public boolean trim(KBucket<T> kbucket, T toAdd) { if (kbucket.getLastChanged() > _ctx.clock().now() - 5*60*1000) return false; return super.trim(kbucket, toAdd); } }
public void closed() { if (_closed) return; _closed = true; long lifetime = _context.clock().now() - _started; _context.statManager().addRateData("sink." + _connectionId + ".lifetime", lifetime, lifetime); try { _out.close(); } catch (IOException ioe) { _log.info("Error closing", ioe); } } public void received(byte data[], int offset, int len) {
public void cancelled() { synchronized (this) { _cancelledOn = _context.clock().now(); releasePayload(); notifyAll(); } cancelResend(); if (_log.shouldLog(Log.DEBUG)) _log.debug("Cancelled! " + toString(), new Exception("cancelled")); }
public boolean accept(Connection con) { if (con == null) return false; long timeSinceClose = _context.clock().now() - con.getCloseSentOn(); if (con.getResetSent()) timeSinceClose = _context.clock().now() - con.getResetSentOn(); boolean ok = (con.getHardDisconnected() || con.getResetSent()) && (timeSinceClose < Connection.DISCONNECT_TIMEOUT); return ok || con.getResetReceived(); }
private void drop(E entry) { long delay = _context.clock().now() - entry.getEnqueueTime(); _context.statManager().addRateData(STAT_DROP, delay); if (_log.shouldLog(Log.WARN)) _log.warn("CDQ #" + _id + ' ' + _name + " dropped item with delay " + delay + ", " + DataHelper.formatDuration(_context.clock().now() - _first_above_time) + " since first above, " + DataHelper.formatDuration(_context.clock().now() - _drop_next) + " since drop next, " + (_count+1) + " dropped in this phase, " + size() + " remaining in queue: " + entry); entry.drop(); }
/** bound to a connection */ public PacketLocal(I2PAppContext ctx, Destination to, Connection con) { super(con.getSession()); _context = ctx; _createdOn = ctx.clock().now(); _log = ctx.logManager().getLog(PacketLocal.class); _to = to; _connection = con; _lastSend = -1; _cancelledOn = -1; }
@Override public void run() { _expires = getTunnel().getContext().clock().now() + INBOUND_STOP_EXPIRE; notifyEvent(CONNECT_START_EVENT, I2PTunnelDCCClient.this); super.run(); _expires = getTunnel().getContext().clock().now() + INBOUND_STOP_EXPIRE; notifyEvent(CONNECT_STOP_EVENT, Integer.valueOf(getLocalPort())); } }
@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(); }
/** outgoing - generate a random token */ public Token(I2PAppContext ctx) { super(null); byte[] data = new byte[MY_TOK_LEN]; ctx.random().nextBytes(data); setData(data); setValid(MY_TOK_LEN); lastSeen = ctx.clock().now(); }