java.lang.Object
java.lang.Thread
net.i2p.util.I2PThread
net.i2p.util.I2PAppThread
net.i2p.router.update.UpdateRunner
net.i2p.router.update.PluginUpdateRunner
- All Implemented Interfaces:
Runnable, UpdateTask, EepGet.StatusListener
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.
Nested Class Summary
Nested classes/interfaces inherited from class I2PThread
I2PThread.OOMEventListenerModifier and TypeClassDescriptionstatic interfaceListener for out-of-memory events.Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandlerField Summary
Modifier and TypeFieldDescriptionprivate final StringThe display name of the app.private StringThe name of the app being updated.private StringThe error message to display.private booleanTrue when the plugin was updated.private final URIThe URI of the update site.private final StringThe URL of the xpi2p file.static final StringDirectory plugins are installed into, relative to the router install.private static final StringConfig key allowing untrusted plugins.private static final StringFile name of the downloaded plugin.private static final StringFile name of the zipped plugin.Fields inherited from class UpdateRunner
_baos, _context, _currentURI, _get, _isPartial, _isRunning, _log, _method, _mgr, _newVersion, _type, _updateFile, _urls, CONNECT_TIMEOUT, done, INACTIVITY_TIMEOUT, NOPROXY_INACTIVITY_TIMEOUTModifier and TypeFieldDescriptionprotected final ByteArrayOutputStream56 byte header, only used for suds.protected final RouterContextRouter context.protected URICurrent URI being fetched.protected EepGetThe current EepGet instance.protected booleanTells the listeners what mode we are in - set to true in extending classes for checks.protected booleanWhether the runner is currently running.protected final LogClass logger.protected final UpdateMethodUpdate method.protected final ConsoleUpdateManagerUpdate manager.protected StringSet by the listeners on completion.protected final UpdateTypeUpdate type.protected final StringTemporary file for the update download.List of update URIs.protected static final longConnect timeout in ms.protected booleanWhether the update completed.protected static final longInactivity timeout with proxy in ms.protected static final longInactivity timeout without proxy in ms.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITYConstructor Summary
ConstructorsConstructorDescriptionPluginUpdateRunner(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.Method Summary
Modifier and TypeMethodDescriptionvoidbytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) Overridden to change the "Updating I2P" text in super.getID()The plugin's update id.private PropertiesgetPluginConfig(File f, File to, String url) Load the plugin's config for the update.getURI()The plugin's update URI.private static booleanWhether the file has a SU3 magic header.private voidprocessFinal(File to, File appDir, String url, Properties props, String sudVersion, String pubkey, String signer) Move the downloaded update into place.private voidprocessSU3(File f, File appDir, String url) Process a SU3 plugin file.private voidprocessSUD(File f, File appDir, String url) Install a .sud plugin update.private voidstatusDone(String msg) Marks the update done with a status message.voidtransferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) Handle completion of plugin download.voidtransferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) Give up on this attempt: delete the partial download and report the failure.protected voidupdate()Download and install the plugin from the single configured URI.Methods inherited from class UpdateRunner
_t, _t, attemptFailed, attempting, getMethod, getType, headerReceived, isRunning, linkify, run, shutdown, toString, updateStatusModifier and TypeMethodDescriptionprotected StringTranslate a string.protected StringTranslate a string with a parameter.voidattemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) An attempt failed.voidattempting(String url) A retry is starting.Returns how the update is fetched, such as HTTP or torrent.getType()Returns what kind of update this runner handles.voidheaderReceived(String url, int attemptNum, String key, String val) HTTP response headers are not used to determine the update version.booleanWhether running.protected static StringWrap a URL in an anchor tag for display.voidrun()Runs the update, reporting any failure to the update manager.voidshutdown()Clears the running flag and interrupts any update in progress.toString()Handler summary for log messages.protected voidReport progress to the user.Methods inherited from class I2PAppThread
addOOMEventThreadListener, fireOOM, removeOOMEventThreadListenerModifier and TypeMethodDescriptionvoidRegister a new component that wants notification of OOM events.protected voidfireOOM(OutOfMemoryError oom) Notify listeners that an OutOfMemoryError occurred.voidUnregister a component that wants notification of OOM events.Methods inherited from class I2PThread
addOOMEventListener, removeOOMEventListener, startModifier and TypeMethodDescriptionstatic voidRegister a new component that wants notification of OOM events.static voidUnregister a component that wants notification of OOM events.voidstart()Overridden to provide useful info to users on OOM, and to prevent shutting down the whole JVM for what is most likely not a heap issue.Methods inherited from class Thread
activeCount, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, startVirtualThread, threadId, yieldMethods inherited from interface UpdateTask
start
Field Details
_appName
The name of the app being updated._appDisplayName
The display name of the app._uri
The URI of the update site._xpi2pURL
The URL of the xpi2p file._updated
private boolean _updatedTrue when the plugin was updated._errMsg
The error message to display.XPI2P
ZIP
PLUGIN_DIR
Directory plugins are installed into, relative to the router install.- See Also:
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 contextmgr- the update manageruris- update source URIsappName- the plugin nameoldVersion- current installed version
Method Details
getURI
The plugin's update URI.- Specified by:
getURIin interfaceUpdateTask- Overrides:
getURIin classUpdateRunner- Returns:
- the u r i
getID
The plugin's update id.- Specified by:
getIDin interfaceUpdateTask- Overrides:
getIDin classUpdateRunner- Returns:
- the i d
update
protected void update()Download and install the plugin from the single configured URI.- Overrides:
updatein classUpdateRunner
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:
bytesTransferredin interfaceEepGet.StatusListener- Overrides:
bytesTransferredin classUpdateRunner- 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 listenerbytesTransferred- 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 lengthurl- 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:
transferCompletein interfaceEepGet.StatusListener- Overrides:
transferCompletein classUpdateRunner- Parameters:
alreadyTransferred- total bytes transferredbytesTransferred- total incl headersbytesRemaining- bytes still owed by the server, or -1 if chunked encoding or no Content-Length was returnedurl- the address the transfer was readingoutputFile- null if unknown (output stream constructor)notModified- whether 304- See Also:
isSU3File
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
processSU3
getPluginConfig
Load the plugin's config for the update.- Parameters:
f- the downloaded update file, deleted on errorto- the temporary zip extracted from the updateurl- 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 installappDir- the applications directory to install intourl- the source URL, used in status messagesprops- the plugin config read from the updatesudVersion- the version recorded in the update container, checked against the config versionpubkey- null OK for su3signer- 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:
transferFailedin interfaceEepGet.StatusListener- Overrides:
transferFailedin classUpdateRunner- Parameters:
url- the address whose transfer failedbytesTransferred- bytes received so far, counted across every attempt and including response headersbytesRemaining- bytes still owed, or -1 if unknowncurrentAttempt- zero-based index of the attempt that failed- See Also:
statusDone
Marks the update done with a status message.- Parameters:
msg- the message to display