java.lang.Object
org.klomp.snark.UpdateRunner
All Implemented Interfaces:
UpdateTask, CompleteListener

class UpdateRunnerextends Object implements UpdateTask, CompleteListener
The downloader for router signed updates.
  • Field Details

    • _context

      private final I2PAppContext _context
      The app context.
    • _log

      private final Log _log
      Logger for the plugin update.
    • _umgr

      private final UpdateManager _umgr
      The update manager that started us.
    • _smgr

      private final SnarkManager _smgr
      The snark manager being updated.
    • _type

      private final UpdateType _type
      The type of update being run.
    • _urls

      private final List<URI> _urls
      The URLs to download from.
    • _isRunning

      private volatile boolean _isRunning
      True while the runner is running.
    • _hasMetaInfo

      private volatile boolean _hasMetaInfo
      True once the metainfo has been fetched.
    • _isComplete

      private volatile boolean _isComplete
      True once the download is complete.
    • _newVersion

      private final String _newVersion
      The new version string being fetched.
    • _currentURI

      private URI _currentURI
      The URL being fetched now.
    • _snark

      private Snark _snark
      The download doing the work.
    • MAX_LENGTH

      private static final long MAX_LENGTH
      Largest update download accepted, in bytes.
      See Also:
    • METAINFO_TIMEOUT

      private static final long METAINFO_TIMEOUT
      Time allowed to fetch the metainfo.
      See Also:
    • COMPLETE_TIMEOUT

      private static final long COMPLETE_TIMEOUT
      Time allowed for the download to complete.
      See Also:
    • CHECK_INTERVAL

      private static final long CHECK_INTERVAL
      Interval between progress checks.
      See Also:
  • Constructor Details

    • UpdateRunner

      public UpdateRunner(I2PAppContext ctx, UpdateManager umgr, SnarkManager smgr, UpdateType type, List<URI> uris, String newVersion)
      Update runner.
      Parameters:
      ctx - the application context, whose log manager supplies the log
      umgr - the update manager, told when the download completes or fails
      smgr - the SnarkManager, which installs and starts the downloaded torrents
      type - the update category to fetch, e.g. NEWS or PLUGIN
      uris - the mirrors to try in turn when none are configured
      newVersion - the version string the downloaded file must report
  • Method Details

    • isRunning

      public boolean isRunning()
      Whether the runner is running.
      Specified by:
      isRunning in interface UpdateTask
      Returns:
      true while the update task is in progress, false once it has finished or been shut down
    • shutdown

      public void shutdown()
      Shut down the runner.
      Specified by:
      shutdown in interface UpdateTask
    • getType

      public UpdateType getType()
      The type.
      Specified by:
      getType in interface UpdateTask
      Returns:
      the UpdateType this runner was created for, telling the manager which kind of update the torrent delivers
    • getMethod

      public UpdateMethod getMethod()
      The method.
      Specified by:
      getMethod in interface UpdateTask
      Returns:
      UpdateMethod.TORRENT, the only method this runner uses
    • getURI

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

      public String getID()
      The ID.
      Specified by:
      getID in interface UpdateTask
      Returns:
      the i d
    • start

      public void start()
      Start the runner.
      Specified by:
      start in interface UpdateTask
    • update

      private 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.
    • fatal

      private void fatal(String error)
      Marks the update as failed.
      Parameters:
      error - the error message to show
    • processComplete

      private void processComplete(Snark snark)
      Handles a completed update download.
      Parameters:
      snark - the finished download
    • notifyProgress

      private void notifyProgress()
      Reports the download progress to the manager.
    • torrentComplete

      public void torrentComplete(Snark snark)
      Handle torrent completion.
      Specified by:
      torrentComplete in interface CompleteListener
      Parameters:
      snark - the Snark instance that completed
    • updateStatus

      public void updateStatus(Snark snark)
      This is called by stopTorrent() among others.
      Specified by:
      updateStatus in interface CompleteListener
      Parameters:
      snark - the Snark instance to update status for
    • gotMetaInfo

      public String gotMetaInfo(Snark snark)
      Handle received metainfo.
      Specified by:
      gotMetaInfo in interface CompleteListener
      Parameters:
      snark - the Snark instance that just initialized its metainfo and storage
      Returns:
      the new name for the torrent or null on error
    • fatal

      public void fatal(Snark snark, String error)
      Handle a fatal error.
      Specified by:
      fatal in interface CompleteListener
      Parameters:
      snark - the Snark instance that stopped
      error - the description of the failure, already localized for display
    • addMessage

      public void addMessage(Snark snark, String message)
      Add a message to the console.
      Specified by:
      addMessage in interface CompleteListener
      Parameters:
      snark - the Snark instance raising the message
      message - the text to show in the torrent UI, already localized
    • gotPiece

      public void gotPiece(Snark snark)
      Handle a received piece.
      Specified by:
      gotPiece in interface CompleteListener
      Parameters:
      snark - the Snark instance that downloaded the piece
    • getSavedTorrentTime

      public long getSavedTorrentTime(Snark snark)
      The saved torrent time.
      Specified by:
      getSavedTorrentTime in interface CompleteListener
      Parameters:
      snark - the Snark instance holding the stored timestamp
      Returns:
      the last saved torrent time, ms since epoch
    • getSavedTorrentBitField

      public BitField getSavedTorrentBitField(Snark snark)
      The saved torrent bit field.
      Specified by:
      getSavedTorrentBitField in interface CompleteListener
      Parameters:
      snark - the Snark instance holding the stored bitfield
      Returns:
      the saved completion state, or null if none
    • getSavedUploaded

      public long getSavedUploaded(Snark snark)
      The saved uploaded bytes.
      Specified by:
      getSavedUploaded in interface CompleteListener
      Parameters:
      snark - the Snark instance to read the uploaded byte count from
      Returns:
      the saved uploaded
    • getSavedComments

      public CommentSet getSavedComments(Snark snark)
      Add a message from the torrent to the console.
      Specified by:
      getSavedComments in interface CompleteListener
      Parameters:
      snark - the Snark instance whose saved comments are returned
      Returns:
      the comment text as saved, or null
    • locked_saveComments

      public void locked_saveComments(Snark snark, CommentSet comments)
      Save comments for the torrent.
      Specified by:
      locked_saveComments in interface CompleteListener
      Parameters:
      snark - the Snark instance whose torrent lock is held
      comments - the comment set to write out while the lock is held
    • shouldAutoStart

      public boolean shouldAutoStart()
      Whether to auto-start.
      Specified by:
      shouldAutoStart in interface CompleteListener
      Returns:
      whether auto start
    • getBandwidthListener

      public BandwidthListener getBandwidthListener()
      The bandwidth listener.
      Specified by:
      getBandwidthListener in interface CompleteListener
      Returns:
      the bandwidth listener
    • linkify

      private static String linkify(String url)
      Convert a URL to an HTML link.
      Parameters:
      url - the address to link to, escaped for the href and shown in full if 28 characters or shorter
      Returns:
      the HTML link
    • updateStatus

      private void updateStatus(String s)
      Updates the status message shown in the console.
      Parameters:
      s - the status text
    • toString

      public String toString()
      String form of the runner.
      Overrides:
      toString in class Object