public long getLifetime() { long cso = _closeSentOn.get(); if (cso <= 0) return _context.clock().now() - _createdOn; else return cso - _createdOn; }
/** * Determine whether ANY lease is currently valid, at least within a given * fudge factor * * @param fudge milliseconds fudge factor to allow between the current time * @return true if there are current leases, false otherwise */ public boolean isCurrent(long fudge) { long now = Clock.getInstance().now(); return _lastExpiration > now - fudge; }
/** * Warning - overridden in RouterClock * * @param stratum ignored * @since 0.7.12 */ public void setNow(long realTime, int stratum) { setNow(realTime); }
public void timeReached() { // use the same % as in RouterClock so that check will never fail // This is their our offset w.r.t. them... long peerOffset = getFramedAveragePeerClockSkew(33); if (peerOffset == 0) return; long currentOffset = _context.clock().getOffset(); // ... so we subtract it to get in sync with them long newOffset = currentOffset - peerOffset; _context.clock().setOffset(newOffset); } }
long offset = now - ctx.clock().now(); if (ctx.clock().getUpdatedSuccessfully()) { ctx.clock().setNow(now, DEFAULT_STRATUM - 4); else ctx.clock().setNow(now, DEFAULT_STRATUM - 3); log("DNSOverHTTPS adjusting clock by " + DataHelper.formatDuration(Math.abs(offset))); ctx.clock().setNow(now, DEFAULT_STRATUM - 3); log("DNSOverHTTPS setting initial clock skew to " + DataHelper.formatDuration(Math.abs(offset)));
long now = _context.clock().now(); if (!_context.clock().getUpdatedSuccessfully()) { _context.clock().setOffset(1000 * (0 - _peerSkew), true); _peerSkew = 0; if (diff != 0)
_msg3p2len = (int) DataHelper.fromLong(options, 4, 2); long tsA = DataHelper.fromLong(options, 8, 4); long now = _context.clock().now(); _peerSkew = (now - (tsA * 1000) - (rtt / 2) + 500) / 1000; if ((_peerSkew > MAX_SKEW || _peerSkew < 0 - MAX_SKEW) && !_context.clock().getUpdatedSuccessfully()) {
public void handleMessage(I2CPMessage message, I2PSessionImpl session) { if (_log.shouldLog(Log.DEBUG)) _log.debug("Handle message " + message); SetDateMessage msg = (SetDateMessage) message; // Only do this if we are NOT in the router context; // otherwise, it sets getUpdatedSuccessfully() in Clock when all // we did was get the time from ourselves. if (!_context.isRouterContext()) Clock.getInstance().setNow(msg.getDate().getTime()); // This saves the various support capabilities based on // the router's version string for future reference session.dateUpdated(msg.getVersion()); if (session.isOffline() && !session.supportsLS2()) { // TODO check other options also? see RLSMH.requiresLS2() session.propogateError("Router does not support offline keys", new Exception()); session.destroySession(false); } } }
if (!_context.clock().getUpdatedSuccessfully()) { _context.clock().setOffset(1000 * (0 - _peerSkew), true); _peerSkew = 0; if (diff != 0)
public void setNow(long realTime) { if (realTime < BuildTime.getEarliestTime() || realTime > BuildTime.getLatestTime()) { Log log = getLog(); String msg = "Invalid time received: " + new Date(realTime); if (log.shouldWarn()) log.warn(msg, new Exception()); else log.logAlways(Log.WARN, msg); return; } long diff = realTime - System.currentTimeMillis(); setOffset(diff); }
if (skews == null || skews.isEmpty() || (skews.size() < 5 && _context.clock().getUpdatedSuccessfully())) { return _context.clock().getOffset();
/** * Specify how far away from the "correct" time the computer is - a positive * value means that the system time is slow, while a negative value means the system time is fast. * * @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now()) */ public void setOffset(long offsetMs) { setOffset(offsetMs, false); }
long offset = now - _context.clock().now(); if (_context.clock().getUpdatedSuccessfully()) { _context.clock().setNow(now, RouterClock.DEFAULT_STRATUM - 2); else _context.clock().setNow(now, RouterClock.DEFAULT_STRATUM - 1); if (_log.shouldLog(Log.WARN)) _log.warn("Reseed adjusting clock by " + _context.clock().setNow(now, RouterClock.DEFAULT_STRATUM - 1); _log.logAlways(Log.WARN, "NTP failure, Reseed adjusting clock by " + DataHelper.formatDuration(Math.abs(offset)));
if (skewOK && !_context.clock().getUpdatedSuccessfully()) { _context.clock().setOffset(0 - skew, true); if (skew != 0) { _log.logAlways(Log.WARN, "NTP failure, UDP adjusting clock by " + DataHelper.formatDuration(Math.abs(skew)));
/** * 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(); }
/** Caller must synch */ public long getUntil() { if (until < Clock.getInstance().now()) until = 0; return until; } }
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 LogRecord(Class<?> src, String name, String threadName, int priority, String msg, Throwable t) { _date = Clock.getInstance().now(); _source = src; _name = name; _threadName = threadName; _priority = priority; _message = msg; _throwable = t; }
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 */