/** * Debug info, HTML formatted */ public void renderStatusHTML(StringBuilder buf) { buf.append("<b>DHT tracker:</b> ").append(_torrentCount).append(" torrents ") .append(_peerCount).append(" peers ") .append(DataHelper.formatDuration(_expireTime)).append(" expiration<br>"); }
public static String estimateHashCashTime(int hashEffort) { if (hashEffort <= 0 || hashEffort > 160) return "Bad HashCash value: " + hashEffort; long low = Long.MAX_VALUE; try { low = HashCash.estimateTime(hashEffort); } catch (NoSuchAlgorithmException e) {} // takes a lot longer than the estimate usually... // maybe because the resource string is much longer than used in the estimate? return "It is estimated that generating a HashCash Certificate with value " + hashEffort + " for the Destination will take " + ((low < 1000l * 24l * 60l * 60l * 1000l) ? "approximately " + DataHelper.formatDuration(low) + " to " + DataHelper.formatDuration(4*low) : "longer than three years!" ); }
/** @since 0.8.5 */ public final static void addTime(StringBuilder buf, String prefix, String name, String description, long value) { String when = DataHelper.formatDuration(value); add(buf, prefix, name, description + ' ' + when, value); }
private static String getPeriod(Rate rate) { return DataHelper.formatDuration(rate.getPeriod()); }
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) { System.out.println("== " + new Date()); System.out.println("== Transfer of " + url + " failed after " + currentAttempt + " attempts"); System.out.println("== Transfer size: " + bytesTransferred + " with " + (bytesRemaining < 0 ? "unknown" : Long.toString(bytesRemaining)) + " remaining"); long timeToSend = _context.clock().now() - _startedOn; System.out.println("== Transfer time: " + DataHelper.formatDuration(timeToSend)); double kbps = (timeToSend > 0 ? (1000.0d*(bytesTransferred)/(timeToSend*1024.0d)) : 0); StringBuilder buf = new StringBuilder(50); buf.append("== Transfer rate: "); synchronized (_kbps) { buf.append(_kbps.format(kbps)); } buf.append("KBps"); System.out.println(buf.toString()); } public void attempting(String url) {}
public void store(OutputStream out, String prefix) throws IOException { StringBuilder buf = new StringBuilder(1024); buf.append(NL); buf.append("################################################################################").append(NL); buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL); buf.append("# ").append(_description).append(NL); buf.append("# ").append(NL).append(NL); out.write(buf.toString().getBytes("UTF-8")); buf.setLength(0); for (Rate r: _rates){ buf.append("#######").append(NL); buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ") .append(_groupName).append(" - ").append(_statName).append(NL); buf.append(NL); String curPrefix = prefix + "." + DataHelper.formatDuration(r.getPeriod()); r.store(curPrefix, buf); out.write(buf.toString().getBytes("UTF-8")); buf.setLength(0); } }
/** * Serializes this FrequencyStat to the provided OutputStream * @param out to write to * @param prefix to prepend to the stat * @throws IOException if something goes wrong * @since 0.9.23 */ public void store(OutputStream out, String prefix) throws IOException { StringBuilder buf = new StringBuilder(1024); buf.append(NL); buf.append("################################################################################").append(NL); buf.append("# Frequency: ").append(_groupName).append(": ").append(_statName).append(NL); buf.append("# ").append(_description).append(NL); buf.append("# ").append(NL).append(NL); out.write(buf.toString().getBytes("UTF-8")); buf.setLength(0); for (Frequency r: _frequencies){ buf.append("#######").append(NL); buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ") .append(_groupName).append(" - ").append(_statName).append(NL); buf.append(NL); r.store(buf); out.write(buf.toString().getBytes("UTF-8")); buf.setLength(0); } }
/** toString */ @Override public String toString() { StringBuilder buf = new StringBuilder(128); buf.append("Fragments for ").append(_messageId).append(": "); for (int i = 0; i <= _highFragmentNum; i++) { ByteArray ba = _fragments[i]; if (ba != null) buf.append(i).append(":").append(ba.getValid()).append(" bytes "); else buf.append(i).append(":missing "); } buf.append(" highest received: ").append(_highFragmentNum); buf.append(" last received? ").append(_lastReceived); buf.append(" lifetime: ").append(DataHelper.formatDuration(_context.clock().now()-_createdOn)); if (_toRouter != null) { buf.append(" targetting ").append(_toRouter.toBase64().substring(0,4)); if (_toTunnel != null) buf.append(":").append(_toTunnel.getTunnelId()); } if (_completed) buf.append(" completed"); if (_releasedAfter > 0) buf.append(" released after " + DataHelper.formatDuration(_releasedAfter)); return buf.toString(); }
@Override public String toString() { return "NTCP" + _version + " conn " + _connID + (_isInbound ? (" from " + _chan.socket().getInetAddress() + " port " + _chan.socket().getPort() + ' ') : (" to " + _remAddr.getHost() + " port " + _remAddr.getPort() + ' ')) + (_remotePeer == null ? "unknown" : _remotePeer.calculateHash().toBase64().substring(0,6)) + (isEstablished() ? "" : " not established") + " created " + DataHelper.formatDuration(getTimeSinceCreated()) + " ago," + " last send " + DataHelper.formatDuration(getTimeSinceSend()) + " ago," + " last recv " + DataHelper.formatDuration(getTimeSinceReceive()) + " ago," + " sent " + _messagesWritten + ',' + " rcvd " + _messagesRead; } }
/** * Load this rate stat from the properties, populating all of the rates contained * underneath it. The comes from the given prefix (e.g. if we are given the prefix * "profile.dbIntroduction", a series of rates may be found underneath * "profile.dbIntroduction.60s", "profile.dbIntroduction.60m", and "profile.dbIntroduction.24h"). * This RateStat must already be created, with the specified rate entries constructued - this * merely loads them with data. * * @param prefix prefix to the property entries (should NOT end with a period) * @param treatAsCurrent if true, we'll treat the loaded data as if no time has * elapsed since it was written out, but if it is false, we'll * treat the data with as much freshness (or staleness) as appropriate. * @throws IllegalArgumentException if the data was formatted incorrectly */ public void load(Properties props, String prefix, boolean treatAsCurrent) throws IllegalArgumentException { for (Rate r : _rates) { long period = r.getPeriod(); String curPrefix = prefix + "." + DataHelper.formatDuration(period); r.load(props, curPrefix, treatAsCurrent); } }
private synchronized void notifyMassive(long shift) { long nowNanos = System.nanoTime(); // try to prevent dups, not guaranteed // nanoTime() isn't guaranteed to be monotonic either :( if (nowNanos < _lastShiftNanos + (MASSIVE_SHIFT_FORWARD * 1000*1000L)) return; _lastShiftNanos = nowNanos; // reset these so the offset can be reset by the timestamper again _startedOn = System.currentTimeMillis(); _alreadyChanged = false; getTimestamper().timestampNow(); if (shift > 0) getLog().log(Log.CRIT, "Large clock shift forward by " + DataHelper.formatDuration(shift)); else getLog().log(Log.CRIT, "Large clock shift backward by " + DataHelper.formatDuration(0 - shift)); for (ClockShiftListener lsnr : _shiftListeners) { lsnr.clockShift(shift); } }
@Override public String toString() { return super.toString() + " started " + DataHelper.formatDuration((getContext().clock().now() - _startedOn)) + " ago"; }
/** * RFC 4941 * @since 0.9.34 */ private static String getPrivacyStatus() { // Windows: netsh interface ipv6 show privacy // Mac: sysctl net.inet6.ip6.use_tempaddr (1 is enabled) if (SystemVersion.isMac() || SystemVersion.isWindows()) return "unknown"; long t = getLong("/proc/sys/net/ipv6/conf/all/use_tempaddr"); if (t < 0) return "unknown"; String rv; if (t == 0) rv = "false"; else if (t == 2) rv = "true"; else rv = "unknown"; if (t == 2) { long pref = getLong("/proc/sys/net/ipv6/conf/all/temp_prefered_lft"); if (pref > 0) rv += ", preferred lifetime " + DataHelper.formatDuration(pref * 1000); long valid = getLong("/proc/sys/net/ipv6/conf/all/temp_valid_lft"); if (pref > 0) rv += ", valid lifetime " + DataHelper.formatDuration(valid * 1000); } return rv; }
public void timeReached() { if (!_isRunning) return; long now = _context.clock().now(); int peerCount = 0; for (Iterator<NodeInfo> iter = DHTNodes.this.values().iterator(); iter.hasNext(); ) { NodeInfo peer = iter.next(); if (peer.lastSeen() < now - _expireTime) { iter.remove(); _kad.remove(peer.getNID()); } else { peerCount++; } } if (peerCount > MAX_PEERS) _expireTime = Math.max(_expireTime - DELTA_EXPIRE_TIME, MIN_EXPIRE_TIME); else _expireTime = Math.min(_expireTime + DELTA_EXPIRE_TIME, MAX_EXPIRE_TIME); if (_log.shouldLog(Log.DEBUG)) _log.debug("DHT storage cleaner done, now with " + peerCount + " peers, " + DataHelper.formatDuration(_expireTime) + " expiration"); schedule(CLEAN_TIME); } }
/** * The clock shift listener. * Restart the router if we should. * * @since 0.8.8 */ public void clockShift(long delta) { if (delta > -60*1000 && delta < 60*1000) return; synchronized(_stateLock) { if (gracefulShutdownInProgress() || !isAlive()) return; } _eventLog.addEvent(EventLog.CLOCK_SHIFT, Long.toString(delta)); // update the routing key modifier _context.routerKeyGenerator().generateDateBasedModData(); // Commented because this check makes no sense (#1014) // .. and 'active' is relative to our broken time. //if (_context.commSystem().countActivePeers() <= 0) // return; if (delta > 0) _log.error("Restarting after large clock shift forward by " + DataHelper.formatDuration(delta)); else _log.error("Restarting after large clock shift backward by " + DataHelper.formatDuration(0 - delta)); restart(); }
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(); }
private boolean isValid(GarlicClove clove) { String invalidReason = _context.messageValidator().validateMessage(clove.getCloveId(), clove.getExpiration().getTime()); boolean rv = invalidReason == null; if (!rv) { String howLongAgo = DataHelper.formatDuration(_context.clock().now()-clove.getExpiration().getTime()); if (_log.shouldLog(Log.DEBUG)) _log.debug("Clove is NOT valid: id=" + clove.getCloveId() + " expiration " + howLongAgo + " ago", new Exception("Invalid within...")); else if (_log.shouldLog(Log.WARN)) _log.warn("Clove is NOT valid: id=" + clove.getCloveId() + " expiration " + howLongAgo + " ago: " + invalidReason + ": " + clove); _context.messageHistory().messageProcessingError(clove.getCloveId(), clove.getData().getClass().getSimpleName(), "Clove is not valid (expiration " + howLongAgo + " ago)"); } return rv; } }
private void drop(E entry) { long delay = _context.clock().now() - entry.getEnqueueTime(); // round down for the stat int priority = entry.getPriority() / 100 * 100; _context.statManager().addRateData(STAT_DROP + priority, delay); if (_log.shouldLog(Log.WARN)) _log.warn("CDPQ #" + _id + ' ' + _name + " dropped item with delay " + delay + ", priority " + entry.getPriority() + ", seq " + entry.getSeqNum() + ", " + 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(); }
public boolean verifyJobQueueLiveliness() { long when = _context.jobQueue().getLastJobBegin(); if (when < 0) return true; long howLongAgo = _context.clock().now() - when; if (howLongAgo > MAX_JOB_RUN_LAG) { Job cur = _context.jobQueue().getLastJob(); if (cur != null) { if (_log.shouldLog(Log.ERROR)) _log.error("Last job was queued up " + DataHelper.formatDuration(howLongAgo) + " ago: " + cur); return false; } else { // no prob, just normal lag return true; } } else { return true; } }
@Override public boolean verifyClientLiveliness() { if (_manager == null) return true; boolean lively = true; for (Destination dest : _manager.getRunnerDestinations()) { ClientConnectionRunner runner = _manager.getRunner(dest); if ( (runner == null) || (runner.getIsDead())) continue; LeaseSet ls = runner.getLeaseSet(dest.calculateHash()); if (ls == null) continue; // still building long howLongAgo = _context.clock().now() - ls.getEarliestLeaseDate(); if (howLongAgo > MAX_TIME_TO_REBUILD) { if (_log.shouldLog(Log.ERROR)) _log.error("Client " + dest.toBase32() + " has a leaseSet that expired " + DataHelper.formatDuration(howLongAgo) + " ago"); lively = false; } } return lively; }