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; }
/** * 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; }
/** Caller must synch */ public void increment() { times.add(Long.valueOf(Clock.getInstance().now())); }
public LogWriter(LogManager manager) { _manager = manager; _lastReadConfig = Clock.getInstance().now(); }
public SetDateMessage() { super(); _date = new Date(Clock.getInstance().now()); }
public SessionConfig(Destination dest) { _destination = dest; _creationDate = new Date(Clock.getInstance().now()); }
public void setLastSeen() { lastSeen = Clock.getInstance().now(); fails = 0; }
/** has this lease already expired (giving allowing up the fudgeFactor milliseconds for clock skew)? */ public boolean isExpired(long fudgeFactor) { if (_end == null) return true; return _end.getTime() < Clock.getInstance().now() - fudgeFactor; }
/** * 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; }
/** Caller must synch */ public long getUntil() { if (until < Clock.getInstance().now()) until = 0; return until; } }
/** * Determine whether the router was published recently (within the given age milliseconds). * The age should be large enough to take into consideration any clock fudge factor, so * values such as 1 or 2 hours are probably reasonable. * * @param maxAgeMs milliseconds between the current time and publish date to check * @return true if it was published recently, false otherwise */ public boolean isCurrent(long maxAgeMs) { long earliestExpire = Clock.getInstance().now() - maxAgeMs; if (_published < earliestExpire) return false; return true; }
private void rereadConfig() { long now = Clock.getInstance().now(); if (now - _lastReadConfig > CONFIG_READ_INTERVAL) { _manager.rereadConfig(); _lastReadConfig = now; } }
public void timeReached() { synchronized(ConnThrottler.this) { if (_totalMax > 0) _currentTotal = 0; if (_max > 0 && !_peers.isEmpty()) { long then = Clock.getInstance().now() - _checkPeriod; for (Iterator<Record> iter = _peers.values().iterator(); iter.hasNext(); ) { Record rec = iter.next(); if (rec.getUntil() <= 0 && rec.countSince(then) <= 0) iter.remove(); } } } schedule(_checkPeriod); } }
private static void testFast(String host, int port, String conOptions) { String destName = "Alice" + Math.random(); long totalTime = 0; for (int i = 0; i < 10; i++) { long before = Clock.getInstance().now(); testDest(host, port, conOptions, destName); long after = Clock.getInstance().now(); long difference = after-before; _log.debug("Time to test destination: " + difference + " \n\n"); totalTime += difference; } _log.debug("\n\nTime to test fast reconnection: " + totalTime + " over 10 runs"); }
/** * Does NOT start itself. Caller must call start(). * * @param slock the socket lock, non-null * @param initialI2PData may be null * @param onTimeout May be null. If non-null and no data (except initial data) was received, it will be run before closing s. */ public I2PTunnelOutproxyRunner(Socket s, Socket i2ps, Object slock, byte[] initialI2PData, byte[] initialSocketData, I2PTunnelRunner.FailCallback onTimeout) { this.s = s; this.i2ps = i2ps; this.slock = slock; this.initialI2PData = initialI2PData; this.initialSocketData = initialSocketData; this.onTimeout = onTimeout; lastActivityOn = -1; startedOn = Clock.getInstance().now(); _log = I2PAppContext.getGlobalContext().logManager().getLog(getClass()); if (_log.shouldLog(Log.INFO)) _log.info("OutproxyRunner started"); _runnerId = __runnerId.incrementAndGet(); setName("OutproxyRunner " + _runnerId); }
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 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); } } }
/** * Overridden because we have a blinded key, not a dest */ @Override protected void writeHeader(OutputStream out) throws DataFormatException, IOException { DataHelper.writeLong(out, 2, _signingKey.getType().getCode()); _signingKey.writeBytes(out); if (_published <= 0) _published = Clock.getInstance().now(); DataHelper.writeLong(out, 4, _published / 1000); DataHelper.writeLong(out, 2, (_expires - _published) / 1000); DataHelper.writeLong(out, 2, _flags); if (isOffline()) writeOfflineBytes(out); }
static RouterInfo createRouterInfo(int num) { RouterInfo info = new RouterInfo(); try { info.setAddresses(createAddresses(num)); // not necessary, in constructor //info.setOptions(new Properties()); //info.setPeers(new HashSet()); info.setPublished(Clock.getInstance().now()); RouterIdentity ident = new RouterIdentity(); BigInteger bv = new BigInteger(""+num); Certificate cert = new Certificate(Certificate.CERTIFICATE_TYPE_NULL, bv.toByteArray()); ident.setCertificate(cert); ident.setPublicKey(pubkey); ident.setSigningPublicKey(signingPubKey); info.setIdentity(ident); info.sign(signingPrivKey); } catch (Exception e) { System.err.println("Error building router " + num + ": " + e.getMessage()); e.printStackTrace(); } return info; }
public DataStructure createDataStructure() throws DataFormatException { DatabaseStoreMessage msg = new DatabaseStoreMessage(I2PAppContext.getGlobalContext()); RouterInfo info = (RouterInfo)new RouterInfoTest().createDataStructure(); msg.setMessageExpiration(Clock.getInstance().now()); msg.setUniqueId(666); msg.setEntry(info); return msg; }