public class SnarkManager extends Object implements CompleteListener, ClientApp, I2PSocketManager.DisconnectListener
This class is the core controller that manages:
As a ClientApp, it integrates with the I2P router application framework and can be started, stopped, and monitored through the standard I2P interfaces.
| Constructor and Description |
|---|
SnarkManager(I2PAppContext ctx)
For embedded.
|
SnarkManager(I2PAppContext ctx,
String ctxPath,
String ctxName)
For webapp.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDownloader(Snark torrent)
Add and start a FetchAndAdd task.
|
void |
addMagnet(String name,
byte[] ih,
String trackerURL,
boolean updateStatus)
Add a torrent with the info hash alone (magnet / maggot)
|
Snark |
addMagnet(String name,
byte[] ih,
String trackerURL,
boolean updateStatus,
boolean autoStart,
File dataDir,
CompleteListener listener)
Add a torrent with the info hash alone (magnet / maggot) External use is for UpdateRunner.
|
void |
addMagnet(String name,
byte[] ih,
String trackerURL,
boolean updateStatus,
File dataDir)
Add a torrent with the info hash alone (magnet / maggot)
|
void |
addMessage(Snark snark,
String message)
A Snark.CompleteListener method.
|
void |
addMessage(String message)
Use if it does not include a link.
|
void |
addMessageNoEscape(String message)
Use if it includes a link.
|
boolean |
addTorrent(MetaInfo metainfo,
BitField bitfield,
String filename,
File baseFile,
boolean dontAutoStart)
Add a torrent from a MetaInfo.
|
boolean |
areFilesPublic() |
void |
clearMessages() |
void |
clearMessages(int id)
Clear through this id
|
boolean |
copyAndAddTorrent(File fromfile,
String filename,
File dataDir)
Add a torrent from a file not in the torrent directory.
|
void |
deleteMagnet(Snark snark)
Stop and delete a torrent running in magnet mode
|
void |
fatal(Snark snark,
String error)
A Snark.CompleteListener method.
|
BandwidthListener |
getBandwidthListener()
The BandwidthManager.
|
File |
getConfigDir()
For RPC
|
int |
getCreateFilterCount()
Returns the current number of configured file filters
|
File |
getDataDir() |
String |
getDiskUsage() |
String |
getDisplayName()
ClientApp method.
|
int |
getMaxFilesPerTorrent() |
int |
getMaxLogMessages() |
List<UIMessages.Message> |
getMessages()
newest last
|
String |
getName()
ClientApp method.
|
int |
getPageSize()
For GUI
|
List<String> |
getPrivateTrackers() |
int |
getRefreshDelaySeconds() |
long[] |
getSavedAddedAndCompleted(Snark snark)
Get setting for a torrent from the config file.
|
CommentSet |
getSavedComments(Snark snark)
The comments for a torrent
|
boolean |
getSavedCommentsEnabled(Snark snark)
Get setting for comments enabled from the config file.
|
boolean |
getSavedPreserveNamesSetting(Snark snark)
Get setting for a torrent from the config file.
|
BitField |
getSavedTorrentBitField(Snark snark)
Get the saved bitfield for a torrent from the config file.
|
long |
getSavedTorrentTime(Snark snark)
Get the timestamp for a torrent from the config file.
|
long |
getSavedUploaded(Snark snark)
Get setting for a torrent from the config file.
|
List<TorrentCreateFilter> |
getSortedTorrentCreateFilterStrings()
Sorted copy
|
List<Tracker> |
getSortedTrackers()
Sorted copy
|
ClientAppState |
getState()
ClientApp method.
|
String |
getTheme()
Get current theme.
|
String[] |
getThemes()
Get all themes
|
String |
getTime() |
Snark |
getTorrent(String filename)
Grab the torrent given the (canonical) filename of the .torrent file
|
Snark |
getTorrentByBaseName(String filename)
Grab the torrent given the base name of the storage
|
Snark |
getTorrentByInfoHash(byte[] infohash)
Grab the torrent given the info hash
|
Map<String,TorrentCreateFilter> |
getTorrentCreateFilterMap()
Unsorted map of name to TorrentCreateFilter object Modifiable, not a copy
|
Collection<TorrentCreateFilter> |
getTorrentCreateFilterStrings()
Unsorted, do not modify
|
Collection<Snark> |
getTorrents()
Unmodifiable
|
Map<String,Tracker> |
getTrackerMap()
Unsorted map of name to Tracker object Modifiable, not a copy
|
Collection<Tracker> |
getTrackers()
Unsorted, do not modify
|
boolean |
getUniversalTheming() |
String |
gotMetaInfo(Snark snark)
We transitioned from magnet mode, we have now initialized our metainfo and storage.
|
void |
gotPiece(Snark snark)
A Snark.CompleteListener method.
|
boolean |
hasModifiedTrackers()
Has the default tracker list been modified?
|
boolean |
isCollapsePanelsEnabled() |
boolean |
isEnableLightbox() |
boolean |
isShowStatusFilter() |
boolean |
isSmartSortEnabled() |
boolean |
isStopping() |
boolean |
isVaryInboundHops() |
boolean |
isVaryOutboundHops() |
Set<String> |
listTorrentFiles()
Set of canonical .torrent filenames that we are dealing with.
|
void |
loadConfig(String filename) |
void |
loadSavedFilePriorities(Snark snark)
Get the saved priorities for a torrent from the config file.
|
void |
locked_saveComments(Snark snark,
CommentSet comments)
Save the comments for a torrent Caller must synchronize on comments.
|
void |
recheckTorrent(Snark snark)
Threaded.
|
void |
removeMagnetStatus(byte[] ih)
Remove the magnet marker from the config file.
|
void |
removeTorrent(String filename)
Stop the torrent and delete the torrent file itself, but leaving the data behind.
|
void |
saveConfig() |
void |
saveMagnetStatus(byte[] ih,
String dir,
String trackerURL,
String dn)
Just remember we have it.
|
void |
saveOpenTrackers(List<String> ot) |
void |
savePrivateTrackers(List<String> pt) |
void |
saveTorrentCreateFilterMap() |
void |
saveTorrentStatus(Snark snark)
Save the completion status of a torrent and other data in the config file for that torrent.
|
void |
saveTrackerMap() |
void |
sessionDisconnected()
DisconnectListener interface
|
void |
setDefaultTorrentCreateFilterMap() |
void |
setDefaultTrackerMap() |
void |
setSavedCommentsEnabled(Snark snark,
boolean yes)
Set setting for comments enabled in the config file.
|
boolean |
shouldAutoStart() |
boolean |
shouldPreallocateFiles() |
void |
shutdown(String[] args)
ClientApp method.
|
void |
start()
Caller _must_ call loadConfig(file) before this if setting new values for i2cp host/port or
i2psnark.dir
|
void |
startAllTorrents()
Always thread it
|
void |
startTorrent(byte[] infoHash)
If not connected, thread it, otherwise inline
|
void |
startTorrent(Snark snark)
If not connected, thread it, otherwise inline
|
void |
startup()
ClientApp method.
|
void |
stop() |
void |
stopAllTorrents(boolean finalShutdown)
Stop all running torrents, and close the tunnel after a delay to allow for announces.
|
void |
stopTorrent(Snark torrent)
Stop the torrent only, leaving it on the list of torrents.
|
void |
stopTorrent(Snark torrent,
boolean shouldRemove)
Stop the torrent, leaving it on the list of torrents unless told to remove it.
|
Snark |
stopTorrent(String filename,
boolean shouldRemove)
Stop the torrent, leaving it on the list of torrents unless told to remove it.
|
void |
torrentComplete(Snark snark)
A Snark.CompleteListener method.
|
void |
updateConfig(String dataDir,
boolean filesPublic,
boolean autoStart,
String refreshDelay,
String startDelay,
String pageSize,
String seedPct,
String eepHost,
String eepPort,
String i2cpHost,
String i2cpPort,
String i2cpOpts,
String upLimit,
String upBW,
String downBW,
boolean useOpenTrackers,
boolean useDHT,
String theme,
String lang,
boolean enableRatings,
boolean enableComments,
String commentName,
boolean collapsePanels,
boolean showStatusFilter,
boolean enableLightbox,
boolean enableAddCreate,
boolean enableVaryInboundHops,
boolean enableVaryOutboundHops,
String apiTarget,
String apiKey)
all params may be null or need trimming
|
void |
updateStatus(Snark snark)
A Snark.CompleteListener method.
|
I2PSnarkUtil |
util()
hook to I2PSnarkUtil for the servlet
|
public static final String CONFIG_DIR_SUFFIX
public static final String CONFIG_FILE
public static final String DEFAULT_BACKUP_TRACKER
public static final String DEFAULT_ENABLE_ADDCREATE
public static final String DEFAULT_ENABLE_LIGHTBOX
public static final int DEFAULT_MAX_FILES_PER_TORRENT
public static final int DEFAULT_MAX_UP_BW
public static final String DEFAULT_PREALLOCATE_FILES
public static final int DEFAULT_REFRESH_DELAY_SECS
public static final String DEFAULT_SHOW_STATUSFILTER
public static final int DEFAULT_STARTUP_DELAY
public static final String DEFAULT_THEME
public static final int DEFAULT_TUNNEL_QUANTITY
public static final int MIN_DOWN_BW
public static final int MIN_UP_BW
public static final String PROP_AUTO_START
public static final String PROP_COLLAPSE_PANELS
public static final String PROP_DIR
public static final String PROP_DOWNBW_MAX
public static final String PROP_ENABLE_ADDCREATE
public static final String PROP_ENABLE_LIGHTBOX
public static final String PROP_FILES_PUBLIC
public static final String PROP_I2CP_HOST
public static final String PROP_I2CP_OPTS
public static final String PROP_I2CP_PORT
public static final String PROP_MAX_FILES_PER_TORRENT
public static final String PROP_MAX_MESSAGES
public static final String PROP_OLD_AUTO_START
public static final String PROP_OPENTRACKERS
public static final String PROP_PAGE_SIZE
public static final String PROP_PREALLOCATE_FILES
public static final String PROP_PRIVATETRACKERS
public static final String PROP_REFRESH_DELAY
public static final String PROP_SHOW_STATUSFILTER
public static final String PROP_STARTUP_DELAY
public static final String PROP_THEME
public static final String PROP_TORRENT_CREATE_FILTERS
public static final String PROP_TORRENT_FILTERS_CONFIG
public static final String PROP_TRACKERS
public static final String PROP_UPBW_MAX
public static final String PROP_UPLOADERS_TOTAL
public static final String PROP_VARY_INBOUND_HOPS
public static final String PROP_VARY_OUTBOUND_HOPS
public static final String RC_PROP_THEME
public static final String RC_PROP_UNIVERSAL_THEMING
public SnarkManager(I2PAppContext ctx)
public SnarkManager(I2PAppContext ctx, String ctxPath, String ctxName)
ctxPath - generally "/i2psnark"ctxName - generally "i2psnark"public void addDownloader(Snark torrent)
torrent - must be instanceof FetchAndAddRuntimeException - via Snark.fatal()?public void addMagnet(String name, byte[] ih, String trackerURL, boolean updateStatus)
name - hex or b32 name from the magnet linkih - 20 byte info hashtrackerURL - may be nullupdateStatus - should we add this magnet to the config file, to save it across restarts,
in case we don't get the metadata before shutdown?RuntimeException - via Snark.fatal()public Snark addMagnet(String name, byte[] ih, String trackerURL, boolean updateStatus, boolean autoStart, File dataDir, CompleteListener listener)
name - hex or b32 name from the magnet linkih - 20 byte info hashtrackerURL - may be nullupdateStatus - should we add this magnet to the config file, to save it across restarts,
in case we don't get the metadata before shutdown?dataDir - must exist, or null to default to snark data directorylistener - to intercept callbacks, should pass through to thisRuntimeException - via Snark.fatal()public void addMagnet(String name, byte[] ih, String trackerURL, boolean updateStatus, File dataDir)
name - hex or b32 name from the magnet linkih - 20 byte info hashtrackerURL - may be nullupdateStatus - should we add this magnet to the config file, to save it across restarts,
in case we don't get the metadata before shutdown?dataDir - must exist, or null to default to snark data directoryRuntimeException - via Snark.fatal()public void addMessage(Snark snark, String message)
addMessage in interface CompleteListenerpublic void addMessage(String message)
public void addMessageNoEscape(String message)
public boolean addTorrent(MetaInfo metainfo, BitField bitfield, String filename, File baseFile, boolean dontAutoStart) throws IOException
Called from servlet. This is only for the 'create torrent' form.
metainfo - the metainfo for the torrentbitfield - the current completion status of the torrent, or nullfilename - the absolute path to save the metainfo to, generally ending in ".torrent",
which is also the name of the torrent Must be a filesystem-safe name. If null, will
generate a name from the metainfo.baseFile - may be null, if so look in rootDataDirRuntimeException - via Snark.fatal()IOExceptionpublic boolean areFilesPublic()
public void clearMessages()
public void clearMessages(int id)
public boolean copyAndAddTorrent(File fromfile, String filename, File dataDir) throws IOException
fromfile - where the file is now, presumably in a temp directory somewherefilename - the absolute path to save the metainfo to, generally ending in ".torrent",
which is also the name of the torrent Must be a filesystem-safe name.dataDir - must exist, or null to default to snark data directoryRuntimeException - via Snark.fatal()IOExceptionpublic void deleteMagnet(Snark snark)
snark - a torrent with a fake file name ("Magnet xxxx")public void fatal(Snark snark, String error)
fatal in interface CompleteListenerpublic BandwidthListener getBandwidthListener()
getBandwidthListener in interface CompleteListenerpublic File getConfigDir()
public int getCreateFilterCount()
public File getDataDir()
public String getDiskUsage()
public String getDisplayName()
getDisplayName in interface ClientApppublic int getMaxFilesPerTorrent()
public int getMaxLogMessages()
public List<UIMessages.Message> getMessages()
public String getName()
public int getPageSize()
public List<String> getPrivateTrackers()
public int getRefreshDelaySeconds()
public long[] getSavedAddedAndCompleted(Snark snark)
public CommentSet getSavedComments(Snark snark)
getSavedComments in interface CompleteListenerpublic boolean getSavedCommentsEnabled(Snark snark)
public boolean getSavedPreserveNamesSetting(Snark snark)
getSavedPreserveNamesSetting in interface CompleteListenerpublic BitField getSavedTorrentBitField(Snark snark)
getSavedTorrentBitField in interface CompleteListenerpublic long getSavedTorrentTime(Snark snark)
getSavedTorrentTime in interface CompleteListenerpublic long getSavedUploaded(Snark snark)
getSavedUploaded in interface CompleteListenerpublic List<TorrentCreateFilter> getSortedTorrentCreateFilterStrings()
public ClientAppState getState()
public String getTheme()
public String[] getThemes()
public String getTime()
public Snark getTorrent(String filename)
public Snark getTorrentByBaseName(String filename)
filename - must be the filtered name, which may be different than the metainfo's namepublic Snark getTorrentByInfoHash(byte[] infohash)
public Map<String,TorrentCreateFilter> getTorrentCreateFilterMap()
public Collection<TorrentCreateFilter> getTorrentCreateFilterStrings()
public Collection<Snark> getTorrents()
public Map<String,Tracker> getTrackerMap()
public Collection<Tracker> getTrackers()
public boolean getUniversalTheming()
public String gotMetaInfo(Snark snark)
gotMetaInfo in interface CompleteListenerpublic void gotPiece(Snark snark)
gotPiece in interface CompleteListenerpublic boolean hasModifiedTrackers()
public boolean isCollapsePanelsEnabled()
public boolean isEnableLightbox()
public boolean isShowStatusFilter()
public boolean isSmartSortEnabled()
public boolean isStopping()
public boolean isVaryInboundHops()
public boolean isVaryOutboundHops()
public Set<String> listTorrentFiles()
public void loadConfig(String filename)
filename - null to set initial defaultspublic void loadSavedFilePriorities(Snark snark)
public void locked_saveComments(Snark snark, CommentSet comments)
locked_saveComments in interface CompleteListenercomments - non-nullpublic void recheckTorrent(Snark snark)
public void removeMagnetStatus(byte[] ih)
public void removeTorrent(String filename)
public void saveConfig()
public void saveMagnetStatus(byte[] ih,
String dir,
String trackerURL,
String dn)
dir - may be nulltrackerURL - may be nulldn - may be nullpublic void saveOpenTrackers(List<String> ot)
ot - null to restore defaultpublic void savePrivateTrackers(List<String> pt)
pt - null ok, default is nonepublic void saveTorrentCreateFilterMap()
public void saveTorrentStatus(Snark snark)
public void saveTrackerMap()
public void sessionDisconnected()
sessionDisconnected in interface I2PSocketManager.DisconnectListenerpublic void setDefaultTorrentCreateFilterMap()
public void setDefaultTrackerMap()
public void setSavedCommentsEnabled(Snark snark, boolean yes)
public boolean shouldAutoStart()
shouldAutoStart in interface CompleteListenerpublic boolean shouldPreallocateFiles()
public void shutdown(String[] args)
public void start()
public void startAllTorrents()
public void startTorrent(byte[] infoHash)
RuntimeException - via Snark.fatal()public void startTorrent(Snark snark)
RuntimeException - via Snark.fatal()public void startup()
public void stop()
public void stopAllTorrents(boolean finalShutdown)
finalShutdown - if true, sleep at the end if any torrents were runningpublic void stopTorrent(Snark torrent)
public void stopTorrent(Snark torrent, boolean shouldRemove)
public Snark stopTorrent(String filename, boolean shouldRemove)
public void torrentComplete(Snark snark)
torrentComplete in interface CompleteListenerpublic void updateConfig(String dataDir, boolean filesPublic, boolean autoStart, String refreshDelay, String startDelay, String pageSize, String seedPct, String eepHost, String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts, String upLimit, String upBW, String downBW, boolean useOpenTrackers, boolean useDHT, String theme, String lang, boolean enableRatings, boolean enableComments, String commentName, boolean collapsePanels, boolean showStatusFilter, boolean enableLightbox, boolean enableAddCreate, boolean enableVaryInboundHops, boolean enableVaryOutboundHops, String apiTarget, String apiKey)
public void updateStatus(Snark snark)
updateStatus in interface CompleteListenerpublic I2PSnarkUtil util()