2006-09-26 Complication
* Subclass from Clock a RouterClock which can access router transports, with the goal of developing it to second-guess NTP results * Make transports report clock skew in seconds * Adjust renderStatusHTML() methods accordingly * Show average for NTCP clock skews too * Give transports a getClockSkews() method to report clock skews * Give transport manager a getClockSkews() method to aggregate results * Give comm system facade a getMedianPeerClockSkew() method which RouterClock calls (to observe results, add "net.i2p.router.transport.CommSystemFacadeImpl=WARN" to logging) * Extra explicitness in NTCP classes to denote unit of time. * Fix some places in NTCPConnection where milliseconds and seconds were confused
This commit is contained in:
@ -68,7 +68,7 @@ public class I2PAppContext {
|
||||
private LogManager _logManager;
|
||||
private HMACGenerator _hmac;
|
||||
private SHA256Generator _sha;
|
||||
private Clock _clock;
|
||||
protected Clock _clock; // overridden in RouterContext
|
||||
private DSAEngine _dsa;
|
||||
private RoutingKeyGenerator _routingKeyGenerator;
|
||||
private RandomSource _random;
|
||||
@ -83,7 +83,7 @@ public class I2PAppContext {
|
||||
private volatile boolean _logManagerInitialized;
|
||||
private volatile boolean _hmacInitialized;
|
||||
private volatile boolean _shaInitialized;
|
||||
private volatile boolean _clockInitialized;
|
||||
protected volatile boolean _clockInitialized; // used in RouterContext
|
||||
private volatile boolean _dsaInitialized;
|
||||
private volatile boolean _routingKeyGeneratorInitialized;
|
||||
private volatile boolean _randomInitialized;
|
||||
@ -411,11 +411,11 @@ public class I2PAppContext {
|
||||
* enable simulators to play with clock skew among different instances.
|
||||
*
|
||||
*/
|
||||
public Clock clock() {
|
||||
public Clock clock() { // overridden in RouterContext
|
||||
if (!_clockInitialized) initializeClock();
|
||||
return _clock;
|
||||
}
|
||||
private void initializeClock() {
|
||||
protected void initializeClock() { // overridden in RouterContext
|
||||
synchronized (this) {
|
||||
if (_clock == null)
|
||||
_clock = new Clock(this);
|
||||
|
@ -13,12 +13,16 @@ import net.i2p.time.Timestamper;
|
||||
* between the local computer's current time and the time as known by some reference
|
||||
* (such as an NTP synchronized clock).
|
||||
*
|
||||
* Protected members are used in the subclass RouterClock,
|
||||
* which has access to a router's transports (particularly peer clock skews)
|
||||
* to second-guess the sanity of clock adjustments.
|
||||
*
|
||||
*/
|
||||
public class Clock implements Timestamper.UpdateListener {
|
||||
private I2PAppContext _context;
|
||||
protected I2PAppContext _context;
|
||||
private Timestamper _timestamper;
|
||||
private long _startedOn;
|
||||
private boolean _statCreated;
|
||||
protected long _startedOn;
|
||||
protected boolean _statCreated;
|
||||
|
||||
public Clock(I2PAppContext context) {
|
||||
_context = context;
|
||||
@ -36,10 +40,10 @@ public class Clock implements Timestamper.UpdateListener {
|
||||
public Timestamper getTimestamper() { return _timestamper; }
|
||||
|
||||
/** we fetch it on demand to avoid circular dependencies (logging uses the clock) */
|
||||
private Log getLog() { return _context.logManager().getLog(Clock.class); }
|
||||
protected Log getLog() { return _context.logManager().getLog(Clock.class); }
|
||||
|
||||
private volatile long _offset;
|
||||
private boolean _alreadyChanged;
|
||||
protected volatile long _offset;
|
||||
protected boolean _alreadyChanged;
|
||||
private Set _listeners;
|
||||
|
||||
/** if the clock is skewed by 3+ days, fuck 'em */
|
||||
@ -132,7 +136,7 @@ public class Clock implements Timestamper.UpdateListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void fireOffsetChanged(long delta) {
|
||||
protected void fireOffsetChanged(long delta) {
|
||||
synchronized (_listeners) {
|
||||
for (Iterator iter = _listeners.iterator(); iter.hasNext();) {
|
||||
ClockUpdateListener lsnr = (ClockUpdateListener) iter.next();
|
||||
|
Reference in New Issue
Block a user