java.lang.Object
java.lang.Thread
net.i2p.util.I2PThread
net.i2p.util.I2PAppThread
net.i2p.router.update.UpdateRunner
net.i2p.router.update.NewsFetcher
- All Implemented Interfaces:
Runnable, UpdateTask, EepGet.StatusListener
Task to fetch updates to the news.xml, and to keep track of whether that has an announcement for a new version.
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
FieldsModifier and TypeFieldDescriptionprivate StringMessage shown when the fetch fails.private booleanDid we get a new news entry.private booleanIs the news newer.private StringLast-Modified header of the news file on disk.private longLast-Modified time of the fetched news.private final FileThe local news file.private final booleanTrue to log the fetch progress.private booleanTrue when the fetch succeeded.private final FileTemp file for the news being fetched.private final longTime allowed for the fetch, in ms.private static final StringDocs subdirectory holding the blocklist.private static final StringName of the blocklist file.private static final StringFeed key of the clearnet HTTP SU3 source.private static final StringFeed key of the clearnet HTTPS SU3 source.private static final booleanDefault setting for torrent updates.private static final booleanDefault setting for vanilla updates.private static final longDefault fetch timeout, in ms.private static final StringSU3 key for I2P @since 0.9.52.private static final StringFeed key of the minimum Java version.private static final StringFeed key of the minimum version required.(package private) static final StringProperty: current blocklist version.private static final StringConfig key enabling torrent updates.private static final StringConfig key enabling vanilla updates.private static final StringFeed key of the SU3 torrent source.private static final StringName of the temp news file.private static final StringFeed key of the latest version.private static final StringStart of the release element in the feed.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
ConstructorsConstructorDescriptionNewsFetcher(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris) Fetches from the first source that succeeds, using the default timeout.NewsFetcher(RouterContext ctx, ConsoleUpdateManager mgr, List<URI> uris, long timeout) And we will log status to the sidebar.Method Summary
Modifier and TypeMethodDescriptionprivate URIAdd a query param for the local language to get translated news.private voidaddMethod(UpdateMethod method, String urls, Map<UpdateMethod, List<URI>> map) Parse URLs and add to the map.voidattemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) Override for status update.voidbytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) Override to prevent status update.(package private) voidParse the installed (not the temp) news file for the latest version.voidDownloads the news feed, optionally through the HTTP proxy.private static voidGunzip the file.voidheaderReceived(String url, int attemptNum, String key, String val) Overridden to get the last-modified header.private booleanWhether the UI language changed since the last fetch.private voidoutputOldNewsXML(NewsMetadata data, List<NewsEntry> entries, String sudVersion, String signingKeyName, File to) Output in the old format.Modified from LoadClientAppsJob and I2PTunnelHTTPClientBase All keys are mapped to lower case.private voidpersistCRLEntries(List<CRLEntry> entries) Output any updated CRL entries.private voidProcess blocklist entries.private FileProcess the fetched su3 news file _tempFile.voidrun()Runs one fetch, reporting failure and completion to the manager.Splits a space separated URL list.voidtransferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) Copies the file from temp dir to the news location, calls checkForUpdates().voidtransferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) Override for status update.private static voidWrite out key="foo,bar,baz".Methods inherited from class UpdateRunner
_t, _t, attempting, getID, getMethod, getType, getURI, isRunning, linkify, shutdown, toString, update, updateStatusModifier and TypeMethodDescriptionprotected StringTranslate a string.protected StringTranslate a string with a parameter.voidattempting(String url) A retry is starting.getID()I d.Returns how the update is fetched, such as HTTP or torrent.getType()Returns what kind of update this runner handles.getURI()U r i.booleanWhether running.protected static StringWrap a URL in an anchor tag for display.voidshutdown()Clears the running flag and interrupts any update in progress.toString()Handler summary for log messages.protected voidupdate()Loop through the entire list of update URLs.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
_lastModified
Last-Modified header of the news file on disk._newLastModified
private long _newLastModifiedLast-Modified time of the fetched news._newsFile
The local news file._tempFile
Temp file for the news being fetched._timeout
private final long _timeoutTime allowed for the fetch, in ms._showStatus
private final boolean _showStatusTrue to log the fetch progress._failMsg
Message shown when the fetch fails._isNewer
private boolean _isNewerIs the news newer._success
private boolean _successTrue when the fetch succeeded._gotNewEntry
private boolean _gotNewEntryDid we get a new news entry.TEMP_NEWS_FILE
PROP_BLOCKLIST_TIME
Property: current blocklist version.- See Also:
BLOCKLIST_DIR
Docs subdirectory holding the blocklist.- See Also:
BLOCKLIST_FILE
DEFAULT_TIMEOUT
private static final long DEFAULT_TIMEOUTDefault fetch timeout, in ms.- See Also:
VERSION_PREFIX
Start of the release element in the feed.- See Also:
VERSION_KEY
Feed key of the latest version.- See Also:
MIN_VERSION_KEY
Feed key of the minimum version required.- See Also:
MIN_JAVA_VERSION_KEY
Feed key of the minimum Java version.- See Also:
SU3_KEY
Feed key of the SU3 torrent source.- See Also:
CLEARNET_HTTP_SU3_KEY
Feed key of the clearnet HTTP SU3 source.- See Also:
CLEARNET_HTTPS_SU3_KEY
Feed key of the clearnet HTTPS SU3 source.- See Also:
PROP_ENABLE_TORRENT_UPDATES
Config key enabling torrent updates.- See Also:
DEFAULT_ENABLE_TORRENT_UPDATES
private static final boolean DEFAULT_ENABLE_TORRENT_UPDATESDefault setting for torrent updates.- See Also:
PROP_ENABLE_VANILLA_UPDATES
Config key enabling vanilla updates.- See Also:
DEFAULT_ENABLE_VANILLA_UPDATES
private static final boolean DEFAULT_ENABLE_VANILLA_UPDATESDefault setting for vanilla updates.- See Also:
I2P_SU3_KEY
Constructor Details
NewsFetcher
Fetches from the first source that succeeds, using the default timeout.- Parameters:
ctx- the router context, supplying the router and temp directoriesmgr- the manager notified of progress, failure and completionuris- the news source URIs, tried in turn until one succeeds
NewsFetcher
And we will log status to the sidebar.- Parameters:
ctx- the router context, supplying the router and temp directoriesmgr- the manager notified of progress, failure and completionuris- the news source URIs, tried in turn until one succeedstimeout- if less than 60 seconds, we assume this was manually initiated,
Method Details
run
public void run()Runs one fetch, reporting failure and completion to the manager.- Specified by:
runin interfaceRunnable- Overrides:
runin classUpdateRunner
fetchNews
public void fetchNews()Downloads the news feed, optionally through the HTTP proxy.addLang
Add a query param for the local language to get translated news. Unchanged if disabled by property, if language is english, or if URI already contains a language parameter.- Parameters:
uri- the news feed URI to modify- Returns:
- the same URI if unchanged, otherwise a copy with a lang query param
langChanged
private boolean langChanged()Whether the UI language changed since the last fetch.- Returns:
- true if the language has changed
checkForUpdates
void checkForUpdates()Parse the installed (not the temp) news file for the latest version. Only the first <i2p.releaseentry is examined, and only with the line-oriented fake XML parser described above, so an entry that is spread over several lines is not recognized.parseArgs
tokenize
addMethod
Parse URLs and add to the map.- Parameters:
method- the update method to associate the URLs withurls- may be nullmap- the map the shuffled URI list is stored in
bytesTransferred
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url) Override to prevent status update.- 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
headerReceived
Overridden to get the last-modified header.- Specified by:
headerReceivedin interfaceEepGet.StatusListener- Overrides:
headerReceivedin classUpdateRunner- Parameters:
url- the address the header arrived onattemptNum- zero-based index of the attempt the header arrived onkey- header keyval- header value
transferComplete
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified) Copies the file from temp dir to the news location, calls checkForUpdates().- 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:
attemptFailed
public void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) Override for status update.- Specified by:
attemptFailedin interfaceEepGet.StatusListener- Overrides:
attemptFailedin classUpdateRunner- Parameters:
url- the address whose fetch attempt 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 failednumRetries- total attempts this fetch is allowedcause- the exception that ended the attempt- See Also:
transferFailed
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) Override for status update.- 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:
processSU3
Process the fetched su3 news file _tempFile. Handles 3 types of contained files: xml.gz (preferred), xml, and html (old format fake xml).- Returns:
- the temp file containing the HTML-format news.xml
- Throws:
IOException- if the SU3 file fails verification or cannot be read or written
gunzip
Gunzip the file.- Parameters:
from- the gzipped file to readto- the output file the decompressed contents are written to, overwritten if it exists- Throws:
IOException- if the input cannot be read or the output cannot be written
persistCRLEntries
processBlocklistEntries
Process blocklist entries.- Parameters:
ble- the blocklist feed data, ignored if its update time is not newer than the stored one
outputOldNewsXML
private void outputOldNewsXML(NewsMetadata data, List<NewsEntry> entries, String sudVersion, String signingKeyName, File to) throws IOException Output in the old format.- Parameters:
data- the news metadata, its first release supplies the version attributesentries- the news entries to writesudVersion- the SU3 version string, written as the SUD versionsigningKeyName- the SU3 signer key name, written as the signing keyto- the output file to write, overwritten if it exists- Throws:
IOException- if the output file cannot be opened or written
writeList
Write out key="foo,bar,baz". Values cannot contain ','.- Parameters:
out- the writer the attribute is appended tokey- the attribute name to writevalues- if null or empty, does nothing- Throws:
IOException- if writing to the writer fails