All Implemented Interfaces:
Runnable, UpdateTask, EepGet.StatusListener
Direct Known Subclasses:
DevSU3UpdateChecker, DevSU3UpdateRunner, DummyHandler.DummyRunner, NewsFetcher, PluginUpdateChecker, PluginUpdateRunner, UnsignedUpdateChecker, UnsignedUpdateRunner

class UpdateRunnerextends I2PAppThread implements UpdateTask, EepGet.StatusListener
The downloader for router signed updates, and the base class for all the other Checkers and Runners.
  • Field Details

    • _context

      protected final RouterContext _context
      Router context.
    • _log

      protected final Log _log
      Class logger.
    • _mgr

      protected final ConsoleUpdateManager _mgr
      Update manager.
    • _type

      protected final UpdateType _type
      Update type.
    • _method

      protected final UpdateMethod _method
      Update method.
    • _urls

      protected final List<URI> _urls
      List of update URIs.
    • _updateFile

      protected final String _updateFile
      Temporary file for the update download.
    • _isRunning

      protected volatile boolean _isRunning
      Whether the runner is currently running.
    • done

      protected boolean done
      Whether the update completed.
    • _get

      protected EepGet _get
      The current EepGet instance.
    • _isPartial

      protected boolean _isPartial
      Tells the listeners what mode we are in - set to true in extending classes for checks.
    • _newVersion

      protected String _newVersion
      Set by the listeners on completion.
    • _baos

      protected final ByteArrayOutputStream _baos
      56 byte header, only used for suds.
    • _currentURI

      protected URI _currentURI
      Current URI being fetched.
    • _currentVersion

      private final String _currentVersion
      Current router version for comparison.
    • CONNECT_TIMEOUT

      protected static final long CONNECT_TIMEOUT
      Connect timeout in ms.
      See Also:
    • INACTIVITY_TIMEOUT

      protected static final long INACTIVITY_TIMEOUT
      Inactivity timeout with proxy in ms.
      See Also:
    • NOPROXY_INACTIVITY_TIMEOUT

      protected static final long NOPROXY_INACTIVITY_TIMEOUT
      Inactivity timeout without proxy in ms.
      See Also:
  • Constructor Details

    • UpdateRunner

      public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, List<URI> uris)
      Uses router version for partial checks.
      Parameters:
      ctx - the router context supplying the logger and temp directory
      mgr - the update manager notified of progress and results
      type - what is being updated, as an UpdateType constant
      uris - list of update URIs
    • UpdateRunner

      public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, UpdateMethod method, List<URI> uris)
      Uses router version for partial checks.
      Parameters:
      ctx - the router context supplying the logger and temp directory
      mgr - the update manager notified of progress and results
      type - what is being updated, as an UpdateType constant
      method - how to fetch the update, as an UpdateMethod constant
      uris - list of update URIs
    • UpdateRunner

      public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, List<URI> uris, String currentVersion)
      Constructor with explicit current version.
      Parameters:
      ctx - the router context supplying the logger and temp directory
      mgr - the update manager notified of progress and results
      type - what is being updated, as an UpdateType constant
      uris - list of update URIs
      currentVersion - used for partial checks
    • UpdateRunner

      public UpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, UpdateType type, UpdateMethod method, List<URI> uris, String currentVersion)
      Full constructor.
      Parameters:
      ctx - the router context supplying the logger and temp directory
      mgr - the update manager notified of progress and results
      type - what is being updated, as an UpdateType constant
      method - HTTP, HTTP_CLEARNET, or HTTPS_CLEARNET
      uris - list of update URIs
      currentVersion - used for partial checks
  • Method Details

    • isRunning

      public boolean isRunning()
      Whether running.
      Specified by:
      isRunning in interface UpdateTask
      Returns:
      true while an update is in progress
    • shutdown

      public void shutdown()
      Clears the running flag and interrupts any update in progress.
      Specified by:
      shutdown in interface UpdateTask
    • getType

      public UpdateType getType()
      Returns what kind of update this runner handles.
      Specified by:
      getType in interface UpdateTask
      Returns:
      the UpdateType this runner was created for
    • getMethod

      public UpdateMethod getMethod()
      Returns how the update is fetched, such as HTTP or torrent.
      Specified by:
      getMethod in interface UpdateTask
      Returns:
      the UpdateMethod this runner was created for
    • getURI

      public URI getURI()
      U r i.
      Specified by:
      getURI in interface UpdateTask
      Returns:
      the u r i
    • getID

      public String getID()
      I d.
      Specified by:
      getID in interface UpdateTask
      Returns:
      the i d
    • run

      public void run()
      Runs the update, reporting any failure to the update manager.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class I2PThread
    • update

      protected void update()
      Loop through the entire list of update URLs. For each one, first get the version from the first 56 bytes and see if it is newer than what we are running now. If it is, get the whole thing.
    • attemptFailed

      public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)
      An attempt failed. We do not abort here - EepGet retries on its own - so this only reports the failure to the user.
      Specified by:
      attemptFailed in interface EepGet.StatusListener
      Parameters:
      url - the address whose fetch attempt failed
      bytesTransferred - bytes received so far, counted across every attempt and including response headers
      bytesRemaining - bytes still owed, or -1 if unknown
      currentAttempt - zero-based index of the attempt that failed
      numRetries - total attempts this fetch is allowed
      cause - the exception that ended the attempt
      See Also:
    • bytesTransferred

      public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url)
      Subclasses should override.
      Specified by:
      bytesTransferred in interface EepGet.StatusListener
      Parameters:
      alreadyTransferred - total of all attempts, not including currentWrite If nonzero on the first call, a partial file of that length was found, _and_ the server supports resume. If zero on a subsequent call after some bytes are transferred (and presumably after an attemptFailed), the server does _not_ support resume and we had to start over. To track _actual_ transfer if the output file could already exist, the listener should keep its own counter, or subtract the initial alreadyTransferred value. And watch out for alreadyTransferred resetting if a resume failed...
      currentWrite - since last call to the listener
      bytesTransferred - includes headers, retries, redirects, discarded partial downloads, ...
      bytesRemaining - on this attempt only, currentWrite already subtracted - or -1 if chunked encoding or server does not return a length
      url - the URL being fetched
    • transferComplete

      public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified)
      Subclasses should override.
      Specified by:
      transferComplete in interface EepGet.StatusListener
      Parameters:
      alreadyTransferred - total bytes transferred
      bytesTransferred - total incl headers
      bytesRemaining - bytes still owed by the server, or -1 if chunked encoding or no Content-Length was returned
      url - the address the transfer was reading
      outputFile - null if unknown (output stream constructor)
      notModified - whether 304
      See Also:
    • transferFailed

      public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)
      Subclasses should override.
      Specified by:
      transferFailed in interface EepGet.StatusListener
      Parameters:
      url - the address whose transfer failed
      bytesTransferred - bytes received so far, counted across every attempt and including response headers
      bytesRemaining - bytes still owed, or -1 if unknown
      currentAttempt - zero-based index of the attempt that failed
      See Also:
    • headerReceived

      public void headerReceived(String url, int attemptNum, String key, String val)
      HTTP response headers are not used to determine the update version.
      Specified by:
      headerReceived in interface EepGet.StatusListener
      Parameters:
      url - the address the header arrived on
      attemptNum - zero-based index of the attempt the header arrived on
      key - header key
      val - header value
    • attempting

      public void attempting(String url)
      A retry is starting. Retries are counted by EepGet, which reports the final failure through transferFailed(String, long, long, int), so there is nothing to do.
      Specified by:
      attempting in interface EepGet.StatusListener
      Parameters:
      url - the URL being attempted
    • updateStatus

      protected void updateStatus(String s)
      Report progress to the user.
      Parameters:
      s - the progress line to show, already translated
    • linkify

      protected static String linkify(String url)
      Wrap a URL in an anchor tag for display.
      Parameters:
      url - the URL to link to
      Returns:
      the anchor-tagged HTML for that URL
    • _t

      protected String _t(String s)
      Translate a string.
      Parameters:
      s - the message key to look up
      Returns:
      the translated text, or the key itself if there is no translation
    • _t

      protected String _t(String s, Object o)
      Translate a string with a parameter.
      Parameters:
      s - the message key to look up
      o - substituted for {0} in the message
      Returns:
      the translated text, or the key itself if there is no translation
    • toString

      public String toString()
      Handler summary for log messages.
      Overrides:
      toString in class Thread
      Returns:
      the class name, type, ID, method and URI