forked from I2P_Developers/i2p.i2p
* Clock: Cleanups and javadocs
* EepGet: Cleanups and javadocs * Reseed: Use the reseeder as a clock source
This commit is contained in:
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.I2PThread;
|
||||
@ -56,7 +57,7 @@ public class Timestamper implements Runnable {
|
||||
public Timestamper(I2PAppContext ctx, UpdateListener lsnr, boolean daemon) {
|
||||
// moved here to prevent problems with synchronized statements.
|
||||
_servers = new ArrayList(3);
|
||||
_listeners = new ArrayList(1);
|
||||
_listeners = new CopyOnWriteArrayList();
|
||||
// Don't bother starting a thread if we are disabled.
|
||||
// This means we no longer check every 5 minutes to see if we got enabled,
|
||||
// so the property must be set at startup.
|
||||
@ -92,24 +93,16 @@ public class Timestamper implements Runnable {
|
||||
public boolean getIsDisabled() { return _disabled; }
|
||||
|
||||
public void addListener(UpdateListener lsnr) {
|
||||
synchronized (_listeners) {
|
||||
_listeners.add(lsnr);
|
||||
}
|
||||
}
|
||||
public void removeListener(UpdateListener lsnr) {
|
||||
synchronized (_listeners) {
|
||||
_listeners.remove(lsnr);
|
||||
}
|
||||
}
|
||||
public int getListenerCount() {
|
||||
synchronized (_listeners) {
|
||||
return _listeners.size();
|
||||
}
|
||||
}
|
||||
public UpdateListener getListener(int index) {
|
||||
synchronized (_listeners) {
|
||||
return _listeners.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
private void startTimestamper() {
|
||||
@ -257,11 +250,8 @@ public class Timestamper implements Runnable {
|
||||
*/
|
||||
private void stampTime(long now, int stratum) {
|
||||
long before = _context.clock().now();
|
||||
synchronized (_listeners) {
|
||||
for (int i = 0; i < _listeners.size(); i++) {
|
||||
UpdateListener lsnr = _listeners.get(i);
|
||||
lsnr.setNow(now, stratum);
|
||||
}
|
||||
for (UpdateListener lsnr : _listeners) {
|
||||
lsnr.setNow(now, stratum);
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Stamped the time as " + now + " (delta=" + (now-before) + ")");
|
||||
|
@ -49,14 +49,22 @@ public class Clock implements Timestamper.UpdateListener {
|
||||
/** if the clock skewed changes by less than this, ignore the update (so we don't slide all over the place) */
|
||||
public final static long MIN_OFFSET_CHANGE = 5 * 1000;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify how far away from the "correct" time the computer is - a positive
|
||||
* value means that we are slow, while a negative value means we are fast.
|
||||
* value means that the system time is slow, while a negative value means the system time is fast.
|
||||
* Warning - overridden in RouterClock
|
||||
*
|
||||
* @param offsetMs the delta from System.currentTimeMillis() (NOT the delta from now())
|
||||
*/
|
||||
public void setOffset(long offsetMs, boolean force) {
|
||||
if (false) return;
|
||||
@ -101,6 +109,9 @@ public class Clock implements Timestamper.UpdateListener {
|
||||
fireOffsetChanged(delta);
|
||||
}
|
||||
|
||||
/*
|
||||
* @return the current delta from System.currentTimeMillis() in milliseconds
|
||||
*/
|
||||
public long getOffset() {
|
||||
return _offset;
|
||||
}
|
||||
|
@ -28,21 +28,21 @@ import net.i2p.util.InternalSocket;
|
||||
* Bug: a malformed url http://example.i2p (no trailing '/') fails cryptically
|
||||
*/
|
||||
public class EepGet {
|
||||
protected I2PAppContext _context;
|
||||
protected Log _log;
|
||||
protected boolean _shouldProxy;
|
||||
private String _proxyHost;
|
||||
private int _proxyPort;
|
||||
protected int _numRetries;
|
||||
private long _minSize; // minimum and maximum acceptable response size, -1 signifies unlimited,
|
||||
private long _maxSize; // applied both against whole responses and chunks
|
||||
protected String _outputFile;
|
||||
protected OutputStream _outputStream;
|
||||
protected final I2PAppContext _context;
|
||||
protected final Log _log;
|
||||
protected final boolean _shouldProxy;
|
||||
private final String _proxyHost;
|
||||
private final int _proxyPort;
|
||||
protected final int _numRetries;
|
||||
private final long _minSize; // minimum and maximum acceptable response size, -1 signifies unlimited,
|
||||
private final long _maxSize; // applied both against whole responses and chunks
|
||||
protected final String _outputFile;
|
||||
protected final OutputStream _outputStream;
|
||||
/** url we were asked to fetch */
|
||||
protected String _url;
|
||||
protected final String _url;
|
||||
/** the URL we actually fetch from (may differ from the _url in case of redirect) */
|
||||
protected String _actualURL;
|
||||
private String _postData;
|
||||
private final String _postData;
|
||||
private boolean _allowCaching;
|
||||
protected final List<StatusListener> _listeners;
|
||||
|
||||
@ -106,7 +106,7 @@ public class EepGet {
|
||||
String outputFile, OutputStream outputStream, String url, boolean allowCaching,
|
||||
String etag, String lastModified, String postData) {
|
||||
_context = ctx;
|
||||
_log = ctx.logManager().getLog(EepGet.class);
|
||||
_log = ctx.logManager().getLog(getClass());
|
||||
_shouldProxy = (proxyHost != null) && (proxyHost.length() > 0) && (proxyPort > 0) && shouldProxy;
|
||||
_proxyHost = proxyHost;
|
||||
_proxyPort = proxyPort;
|
||||
@ -118,13 +118,7 @@ public class EepGet {
|
||||
_url = url;
|
||||
_actualURL = url;
|
||||
_postData = postData;
|
||||
_alreadyTransferred = 0;
|
||||
_bytesTransferred = 0;
|
||||
_bytesRemaining = -1;
|
||||
_currentAttempt = 0;
|
||||
_transferFailed = false;
|
||||
_headersRead = false;
|
||||
_aborted = false;
|
||||
_fetchHeaderTimeout = CONNECT_TIMEOUT;
|
||||
_listeners = new ArrayList(1);
|
||||
_etag = etag;
|
||||
@ -255,9 +249,9 @@ public class EepGet {
|
||||
public void attempting(String url);
|
||||
}
|
||||
protected class CLIStatusListener implements StatusListener {
|
||||
private int _markSize;
|
||||
private int _lineSize;
|
||||
private long _startedOn;
|
||||
private final int _markSize;
|
||||
private final int _lineSize;
|
||||
private final long _startedOn;
|
||||
private long _written;
|
||||
private long _previousWritten;
|
||||
private long _discarded;
|
||||
@ -271,9 +265,6 @@ public class EepGet {
|
||||
public CLIStatusListener(int markSize, int lineSize) {
|
||||
_markSize = markSize;
|
||||
_lineSize = lineSize;
|
||||
_written = 0;
|
||||
_previousWritten = 0;
|
||||
_discarded = 0;
|
||||
_lastComplete = _context.clock().now();
|
||||
_startedOn = _lastComplete;
|
||||
_firstTime = true;
|
||||
|
Reference in New Issue
Block a user