net.i2p.router
Class RouterClock
java.lang.Object
net.i2p.util.Clock
net.i2p.router.RouterClock
- All Implemented Interfaces:
- Timestamper.UpdateListener
public class RouterClock
- extends Clock
Alternate location for determining the time which takes into account an offset.
This offset will ideally be periodically updated so as to serve as the difference
between the local computer's current time and the time as known by some reference
(such as an NTP synchronized clock).
RouterClock is a subclass of Clock with access to router transports.
Configuration permitting, it will block clock offset changes
which would increase peer clock skew.
Method Summary |
long |
getDeltaOffset()
|
long |
now()
Retrieve the current time synchronized with whatever reference clock is in use. |
void |
setNow(long realTime,
int stratum)
|
void |
setOffset(long offsetMs,
boolean force)
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
_contextRC
RouterContext _contextRC
RouterClock
public RouterClock(RouterContext context)
setOffset
public void setOffset(long offsetMs,
boolean force)
- 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.
- Overrides:
setOffset
in class Clock
setNow
public void setNow(long realTime,
int stratum)
- Specified by:
setNow
in interface Timestamper.UpdateListener
- Overrides:
setNow
in class Clock
- Parameters:
stratum
- used to determine whether we should ignore- Since:
- 0.7.12
now
public long now()
- Retrieve the current time synchronized with whatever reference clock is in use.
Do really simple clock slewing, like NTP but without jitter prevention.
Slew the clock toward the desired offset, but only up to a maximum slew rate,
and never let the clock go backwards because of slewing.
Take care to only access the volatile variables once for speed and to
avoid having another thread change them
This is called about a zillion times a second, so we can do the slewing right
here rather than in some separate thread to keep it simple.
Avoiding backwards clocks when updating in a thread would be hard too.
- Overrides:
now
in class Clock
getDeltaOffset
public long getDeltaOffset()