java.lang.Object
java.lang.Thread
net.i2p.util.I2PThread
net.i2p.util.I2PAppThread
net.i2p.router.update.UpdateRunner
net.i2p.router.update.PluginUpdateChecker
- 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.
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
FieldsFields 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
ConstructorsConstructorDescriptionPluginUpdateChecker(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris, String appName, String oldVersion) Prepare a plugin update check.Method Summary
Public MethodsModifier and TypeMethodDescriptionvoidbytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) Progress callback during the header fetch; the version bytes are not inspected here, only their arrival is reported.getID()Identify this task in the update manager's status lists and logs.voidtransferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) Subclasses should override.voidtransferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) The header fetch failed: drop the partial download and report the check as unsuccessful rather than as merely up to date.protected voidupdate()Start the check: fetch only the plugin's version header over the HTTP proxy and let the manager report whether anything newer appeared.Methods inherited from class UpdateRunner
_t, _t, attemptFailed, attempting, getMethod, getType, getURI, 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.getURI()U r i.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
Name of the plugin being checked._oldVersion
Version currently installed.
Constructor Details
PluginUpdateChecker
public PluginUpdateChecker(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris, String appName, String oldVersion) Prepare a plugin update check. The first of the update URIs is the one actually fetched; the rest are kept only for display, andupdate()fetches just the leadingTrustedUpdate.HEADER_BYTESto compare versions rather than the whole plugin.- Parameters:
ctx- the router contextmgr- the update manageruris- update source URIsappName- the plugin nameoldVersion- current installed version
Method Details
getID
Identify this task in the update manager's status lists and logs.- Specified by:
getIDin interfaceUpdateTask- Overrides:
getIDin classUpdateRunner- Returns:
- the i d
update
protected void update()Start the check: fetch only the plugin's version header over the HTTP proxy and let the manager report whether anything newer appeared.- Overrides:
updatein classUpdateRunner
bytesTransferred
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) Progress callback during the header fetch; the version bytes are not inspected here, only their arrival is reported.- 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) Description copied from class:UpdateRunnerSubclasses should override.- 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:
transferFailed
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) The header fetch failed: drop the partial download and report the check as unsuccessful rather than as merely up to date.- 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: