All Implemented Interfaces:
Runnable, UpdateTask, EepGet.StatusListener

class PluginUpdateRunnerextends UpdateRunner
Check for an updated version of a plugin. A plugin is a standard .sud file with a 40-byte signature, a 16-byte version, and a .zip file.

So we get the current version and update URL for the installed plugin, then fetch the first 56 bytes of the URL, extract the version, and compare.

uri list must not be empty.

Moved from web/ and turned into an UpdateTask.

  • Field Details

    • _appName

      private String _appName
      The name of the app being updated.
    • _appDisplayName

      private final String _appDisplayName
      The display name of the app.
    • _uri

      private final URI _uri
      The URI of the update site.
    • _xpi2pURL

      private final String _xpi2pURL
      The URL of the xpi2p file.
    • _updated

      private boolean _updated
      True when the plugin was updated.
    • _errMsg

      private String _errMsg
      The error message to display.
    • XPI2P

      private static final String XPI2P
      File name of the downloaded plugin.
      See Also:
    • ZIP

      private static final String ZIP
      File name of the zipped plugin.
      See Also:
    • PLUGIN_DIR

      public static final String PLUGIN_DIR
      Directory plugins are installed into, relative to the router install.
      See Also:
    • PROP_ALLOW_NEW_KEYS

      private static final String PROP_ALLOW_NEW_KEYS
      Config key allowing untrusted plugins.
      See Also:
  • Constructor Details

    • PluginUpdateRunner

      public PluginUpdateRunner(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris, String appName, String oldVersion)
      Set up a single-URI plugin update; the first entry of uris is the only one used.
      Parameters:
      ctx - the router context
      mgr - the update manager
      uris - update source URIs
      appName - the plugin name
      oldVersion - current installed version
  • Method Details

    • getURI

      public URI getURI()
      The plugin's update URI.
      Specified by:
      getURI in interface UpdateTask
      Overrides:
      getURI in class UpdateRunner
      Returns:
      the u r i
    • getID

      public String getID()
      The plugin's update id.
      Specified by:
      getID in interface UpdateTask
      Overrides:
      getID in class UpdateRunner
      Returns:
      the i d
    • update

      protected void update()
      Download and install the plugin from the single configured URI.
      Overrides:
      update in class UpdateRunner
    • bytesTransferred

      public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url)
      Overridden to change the "Updating I2P" text in super.
      Specified by:
      bytesTransferred in interface EepGet.StatusListener
      Overrides:
      bytesTransferred in class UpdateRunner
      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)
      Handle completion of plugin download.
      Specified by:
      transferComplete in interface EepGet.StatusListener
      Overrides:
      transferComplete in class UpdateRunner
      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:
    • isSU3File

      private static boolean isSU3File(File f) throws IOException
      Whether the file has a SU3 magic header.
      Parameters:
      f - the file whose first bytes are compared with the SU3 magic
      Returns:
      true if the file begins with the SU3 magic header, false otherwise
      Throws:
      IOException - if the file cannot be opened or read
    • processSUD

      private void processSUD(File f, File appDir, String url)
      Install a .sud plugin update.
      Parameters:
      f - the downloaded .sud update file
      appDir - the applications directory to install into
      url - the source URL, used in status messages
    • processSU3

      private void processSU3(File f, File appDir, String url)
      Process a SU3 plugin file.
      Parameters:
      f - the downloaded SU3 file
      appDir - the applications directory to install into
      url - the source URL, used in status messages
    • getPluginConfig

      private Properties getPluginConfig(File f, File to, String url)
      Load the plugin's config for the update.
      Parameters:
      f - the downloaded update file, deleted on error
      to - the temporary zip extracted from the update
      url - the source URL, used in status messages
      Returns:
      null on error
    • processFinal

      private void processFinal(File to, File appDir, String url, Properties props, String sudVersion, String pubkey, String signer)
      Move the downloaded update into place.
      Parameters:
      to - the temporary zip holding the plugin to install
      appDir - the applications directory to install into
      url - the source URL, used in status messages
      props - the plugin config read from the update
      sudVersion - the version recorded in the update container, checked against the config version
      pubkey - null OK for su3
      signer - the name of the signature's signer, for status messages
    • transferFailed

      public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)
      Give up on this attempt: delete the partial download and report the failure.
      Specified by:
      transferFailed in interface EepGet.StatusListener
      Overrides:
      transferFailed in class UpdateRunner
      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:
    • statusDone

      private void statusDone(String msg)
      Marks the update done with a status message.
      Parameters:
      msg - the message to display