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.
  • Field Details

  • Constructor Details

  • Method Details

    • start

      public void start()
      Cannot be stopped, but RouterTimestamper registers a shutdown task.
      Since:
      0.9.20
    • getTimestamper

      public Timestamper getTimestamper()
      The RouterTimestamper
      Overrides:
      getTimestamper in class Clock
    • setOffset

      public void setOffset​(long offsetMs, boolean force)
      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.
      Overrides:
      setOffset in class Clock
      Parameters:
      offsetMs - the delta from System.currentTimeMillis() (NOT the delta from now())
    • setNow

      public void setNow​(long realTime, int stratum)
      Description copied from class: Clock
      Warning - overridden in RouterClock
      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
    • addShiftListener

      public void addShiftListener​(RouterClock.ClockShiftListener lsnr)
    • removeShiftListener

      public void removeShiftListener​(RouterClock.ClockShiftListener lsnr)
    • getDeltaOffset

      @Deprecated public long getDeltaOffset()
      Deprecated.