java.lang.Object
net.i2p.time.Timestamper
net.i2p.router.time.RouterTimestamper
All Implemented Interfaces:
Runnable

public class RouterTimestamperextends Timestamper
Periodically query a series of NTP servers and update any associated listeners. It tries the NTP servers in order, contacting them using SNTP (UDP port 123).
  • Field Details

    • PROP_QUERY_FREQUENCY

      public static final String PROP_QUERY_FREQUENCY
      Property key for the milliseconds between time queries.
      See Also:
    • PROP_SERVER_LIST

      public static final String PROP_SERVER_LIST
      Property key naming the SNTP servers to query.
      See Also:
    • PROP_DISABLED

      public static final String PROP_DISABLED
      Property key that turns time synchronization off.
      See Also:
    • PROP_CONCURRING_SERVERS

      public static final String PROP_CONCURRING_SERVERS
      Property key for how many SNTP servers are queried at once.
      See Also:
    • PROP_IP_COUNTRY

      public static final String PROP_IP_COUNTRY
      Property key holding the country of our last public IP address.
      See Also:
  • Constructor Details

    • RouterTimestamper

      public RouterTimestamper(I2PAppContext ctx)
      Does not start. Caller MUST call startTimestamper().
      Parameters:
      ctx - the application context used to read properties and locate the router
    • RouterTimestamper

      public RouterTimestamper(I2PAppContext ctx, Timestamper.UpdateListener lsnr)
      Does not start. Caller MUST call startTimestamper().
      Parameters:
      ctx - the application context used to read properties and locate the router
      lsnr - listener notified of each time update, or null to register none yet
    • RouterTimestamper

      public RouterTimestamper(I2PAppContext ctx, Timestamper.UpdateListener lsnr, boolean daemon)
      Does not start. Caller MUST call startTimestamper().
      Parameters:
      ctx - the application context used to read properties and locate the router
      lsnr - listener notified of each time update, or null to register none yet
      daemon - true to run the query thread as a daemon the JVM may abandon at shutdown
  • Method Details

    • getServerCount

      public int getServerCount()
      Number of NTP servers in the configured list.
      Returns:
      the server count
    • getServer

      public String getServer(int index)
      NTP server at the given index in the configured list.
      Parameters:
      index - zero-based position within the configured server list
      Returns:
      the NTP server address at that position in the configured list
    • getQueryFrequencyMs

      public int getQueryFrequencyMs()
      How often to query the NTP servers, in ms.
      Returns:
      the query frequency ms
    • getIsDisabled

      public boolean getIsDisabled()
      Whether NTP is disabled.
      Returns:
      true when NTP is switched off at startup, either by configuration or because the VM comm system is in use
    • addListener

      public void addListener(Timestamper.UpdateListener lsnr)
      Register a listener to be notified of time updates.
      Parameters:
      lsnr - the listener to add; adding the same listener twice registers it once
    • removeListener

      public void removeListener(Timestamper.UpdateListener lsnr)
      Unregister a listener from time update notifications.
      Parameters:
      lsnr - the listener to remove; absent listeners are ignored
    • getListenerCount

      public int getListenerCount()
      Number of registered time update listeners.
      Returns:
      the listener count
    • getListener

      public Timestamper.UpdateListener getListener(int index)
      Time update listener at the given index.
      Parameters:
      index - zero-based position within the registered listener list
      Returns:
      the registered time update listener at that position
    • startTimestamper

      public void startTimestamper()
      Start the SNTP query thread, unless disabled or already initialized.
    • waitForInitialization

      public void waitForInitialization()
      Wait until the initial time synchronization completes, or the timeout is reached.
      Overrides:
      waitForInitialization in class Timestamper
    • timestampNow

      public void timestampNow()
      Update the time immediately.
      Overrides:
      timestampNow in class Timestamper
    • run

      public void run()
      Run the main SNTP query loop, updating the time periodically.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Timestamper