java.lang.Object
org.klomp.snark.UpdateRunner
- All Implemented Interfaces:
UpdateTask, CompleteListener
The downloader for router signed updates.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classTimeout timer for metainfo and complete deadlines.private classPeriodic watcher for torrent completion.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PAppContextThe app context.private URIThe URL being fetched now.private booleanTrue once the metainfo has been fetched.private booleanTrue once the download is complete.private booleanTrue while the runner is running.private final LogLogger for the plugin update.private final StringThe new version string being fetched.private final SnarkManagerThe snark manager being updated.private SnarkThe download doing the work.private final UpdateTypeThe type of update being run.private final UpdateManagerThe update manager that started us.The URLs to download from.private static final longInterval between progress checks.private static final longTime allowed for the download to complete.private static final longLargest update download accepted, in bytes.private static final longTime allowed to fetch the metainfo.Constructor Summary
ConstructorsConstructorDescriptionUpdateRunner(I2PAppContext ctx, UpdateManager umgr, SnarkManager smgr, UpdateType type, List<URI> uris, String newVersion) Update runner.Method Summary
Modifier and TypeMethodDescriptionvoidaddMessage(Snark snark, String message) Add a message to the console.private voidMarks the update as failed.voidHandle a fatal error.The bandwidth listener.getID()The ID.The method.getSavedComments(Snark snark) Add a message from the torrent to the console.getSavedTorrentBitField(Snark snark) The saved torrent bit field.longgetSavedTorrentTime(Snark snark) The saved torrent time.longgetSavedUploaded(Snark snark) The saved uploaded bytes.getType()The type.getURI()The URI.gotMetaInfo(Snark snark) Handle received metainfo.voidHandle a received piece.booleanWhether the runner is running.private static StringConvert a URL to an HTML link.voidlocked_saveComments(Snark snark, CommentSet comments) Save comments for the torrent.private voidReports the download progress to the manager.private voidprocessComplete(Snark snark) Handles a completed update download.booleanWhether to auto-start.voidshutdown()Shut down the runner.voidstart()Start the runner.voidtorrentComplete(Snark snark) Handle torrent completion.toString()String form of the runner.private voidupdate()Loop through the entire list of update URLs.private voidUpdates the status message shown in the console.voidupdateStatus(Snark snark) This is called by stopTorrent() among others.
Field Details
_context
The app context._log
Logger for the plugin update._umgr
The update manager that started us._smgr
The snark manager being updated._type
The type of update being run._urls
_isRunning
private volatile boolean _isRunningTrue while the runner is running._hasMetaInfo
private volatile boolean _hasMetaInfoTrue once the metainfo has been fetched._isComplete
private volatile boolean _isCompleteTrue once the download is complete._newVersion
The new version string being fetched._currentURI
The URL being fetched now._snark
The download doing the work.MAX_LENGTH
private static final long MAX_LENGTHLargest update download accepted, in bytes.- See Also:
METAINFO_TIMEOUT
private static final long METAINFO_TIMEOUTTime allowed to fetch the metainfo.- See Also:
COMPLETE_TIMEOUT
private static final long COMPLETE_TIMEOUTTime allowed for the download to complete.- See Also:
CHECK_INTERVAL
private static final long CHECK_INTERVALInterval 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 logumgr- the update manager, told when the download completes or failssmgr- the SnarkManager, which installs and starts the downloaded torrentstype- the update category to fetch, e.g. NEWS or PLUGINuris- the mirrors to try in turn when none are configurednewVersion- the version string the downloaded file must report
Method Details
isRunning
public boolean isRunning()Whether the runner is running.- Specified by:
isRunningin interfaceUpdateTask- Returns:
- true while the update task is in progress, false once it has finished or been shut down
shutdown
getType
The type.- Specified by:
getTypein interfaceUpdateTask- Returns:
- the
UpdateTypethis runner was created for, telling the manager which kind of update the torrent delivers
getMethod
The method.- Specified by:
getMethodin interfaceUpdateTask- Returns:
UpdateMethod.TORRENT, the only method this runner uses
getURI
getID
start
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
Marks the update as failed.- Parameters:
error- the error message to show
processComplete
Handles a completed update download.- Parameters:
snark- the finished download
notifyProgress
private void notifyProgress()Reports the download progress to the manager.torrentComplete
Handle torrent completion.- Specified by:
torrentCompletein interfaceCompleteListener- Parameters:
snark- the Snark instance that completed
updateStatus
This is called by stopTorrent() among others.- Specified by:
updateStatusin interfaceCompleteListener- Parameters:
snark- the Snark instance to update status for
gotMetaInfo
Handle received metainfo.- Specified by:
gotMetaInfoin interfaceCompleteListener- Parameters:
snark- the Snark instance that just initialized its metainfo and storage- Returns:
- the new name for the torrent or null on error
fatal
Handle a fatal error.- Specified by:
fatalin interfaceCompleteListener- Parameters:
snark- the Snark instance that stoppederror- the description of the failure, already localized for display
addMessage
Add a message to the console.- Specified by:
addMessagein interfaceCompleteListener- Parameters:
snark- the Snark instance raising the messagemessage- the text to show in the torrent UI, already localized
gotPiece
Handle a received piece.- Specified by:
gotPiecein interfaceCompleteListener- Parameters:
snark- the Snark instance that downloaded the piece
getSavedTorrentTime
The saved torrent time.- Specified by:
getSavedTorrentTimein interfaceCompleteListener- Parameters:
snark- the Snark instance holding the stored timestamp- Returns:
- the last saved torrent time, ms since epoch
getSavedTorrentBitField
The saved torrent bit field.- Specified by:
getSavedTorrentBitFieldin interfaceCompleteListener- Parameters:
snark- the Snark instance holding the stored bitfield- Returns:
- the saved completion state, or null if none
getSavedUploaded
The saved uploaded bytes.- Specified by:
getSavedUploadedin interfaceCompleteListener- Parameters:
snark- the Snark instance to read the uploaded byte count from- Returns:
- the saved uploaded
getSavedComments
Add a message from the torrent to the console.- Specified by:
getSavedCommentsin interfaceCompleteListener- Parameters:
snark- the Snark instance whose saved comments are returned- Returns:
- the comment text as saved, or null
locked_saveComments
Save comments for the torrent.- Specified by:
locked_saveCommentsin interfaceCompleteListener- Parameters:
snark- the Snark instance whose torrent lock is heldcomments- the comment set to write out while the lock is held
shouldAutoStart
public boolean shouldAutoStart()Whether to auto-start.- Specified by:
shouldAutoStartin interfaceCompleteListener- Returns:
- whether auto start
getBandwidthListener
The bandwidth listener.- Specified by:
getBandwidthListenerin interfaceCompleteListener- Returns:
- the bandwidth listener
linkify
updateStatus
Updates the status message shown in the console.- Parameters:
s- the status text
toString