public class SnarkManager extends Object implements CompleteListener
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 |
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.
|
File |
getDataDir() |
List<String> |
getMessages()
newest last
|
int |
getPageSize()
For GUI
|
List<String> |
getPrivateTrackers() |
int |
getRefreshDelaySeconds() |
long[] |
getSavedAddedAndCompleted(Snark snark)
Get setting for a torrent 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<Tracker> |
getSortedTrackers()
Sorted copy
|
String |
getTheme()
Get current theme.
|
String[] |
getThemes()
Get all themes
|
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
|
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
|
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 |
isSmartSortEnabled() |
boolean |
isStopping() |
Set<String> |
listTorrentFiles()
Set of canonical .torrent filenames that we are dealing with.
|
void |
loadConfig(String filename)
null to set initial defaults
|
void |
loadSavedFilePriorities(Snark snark)
Get the saved priorities for a torrent from the config file.
|
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 |
saveTorrentStatus(Snark snark)
Save the completion status of a torrent and other data in the config file
for that torrent.
|
void |
saveTrackerMap() |
void |
setDefaultTrackerMap() |
boolean |
shouldAutoStart() |
void |
start()
Caller _must_ call loadConfig(file) before this if setting new values
for i2cp host/port or i2psnark.dir
|
void |
startAllTorrents()
If not connected, thread it, otherwise inline
|
void |
startTorrent(byte[] infoHash)
If not connected, thread it, otherwise inline
|
void |
startTorrent(Snark snark)
If not connected, thread it, otherwise inline
|
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,
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,
boolean smartSort,
String refreshDelay,
String startDelay,
String pageSize,
String seedPct,
String eepHost,
String eepPort,
String i2cpHost,
String i2cpPort,
String i2cpOpts,
String upLimit,
String upBW,
boolean useOpenTrackers,
boolean useDHT,
String theme,
String lang)
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 PROP_I2CP_HOST
public static final String PROP_I2CP_PORT
public static final String PROP_I2CP_OPTS
public static final String PROP_UPLOADERS_TOTAL
public static final String PROP_UPBW_MAX
public static final String PROP_DIR
public static final String PROP_FILES_PUBLIC
public static final String PROP_OLD_AUTO_START
public static final String PROP_AUTO_START
public static final String DEFAULT_AUTO_START
public static final String PROP_STARTUP_DELAY
public static final String PROP_REFRESH_DELAY
public static final String PROP_PAGE_SIZE
public static final String RC_PROP_THEME
public static final String RC_PROP_UNIVERSAL_THEMING
public static final String PROP_THEME
public static final String DEFAULT_THEME
public static final String PROP_OPENTRACKERS
public static final String PROP_PRIVATETRACKERS
public static final int MIN_UP_BW
public static final int DEFAULT_MAX_UP_BW
public static final int DEFAULT_STARTUP_DELAY
public static final int DEFAULT_REFRESH_DELAY_SECS
public static final int DEFAULT_TUNNEL_QUANTITY
public static final String CONFIG_DIR_SUFFIX
public static final String DEFAULT_BACKUP_TRACKER
public static final String PROP_TRACKERS
public static final int MAX_FILES_PER_TORRENT
public SnarkManager(I2PAppContext ctx)
public SnarkManager(I2PAppContext ctx, String ctxPath, String ctxName)
ctxPath
- generally "/i2psnark"ctxName
- generally "i2psnark"public void start()
public void stop()
public boolean isStopping()
public I2PSnarkUtil util()
public void addMessage(String message)
public void addMessageNoEscape(String message)
public void clearMessages()
public boolean areFilesPublic()
public boolean shouldAutoStart()
public boolean isSmartSortEnabled()
public int getRefreshDelaySeconds()
public int getPageSize()
public File getDataDir()
public void loadConfig(String filename)
public String getTheme()
public String[] getThemes()
public void updateConfig(String dataDir, boolean filesPublic, boolean autoStart, boolean smartSort, String refreshDelay, String startDelay, String pageSize, String seedPct, String eepHost, String eepPort, String i2cpHost, String i2cpPort, String i2cpOpts, String upLimit, String upBW, boolean useOpenTrackers, boolean useDHT, String theme, String lang)
public List<String> getPrivateTrackers()
public void saveOpenTrackers(List<String> ot)
ot
- null to restore defaultpublic void savePrivateTrackers(List<String> pt)
pt
- null ok, default is nonepublic void saveConfig()
public Set<String> listTorrentFiles()
public Snark getTorrent(String filename)
public Collection<Snark> getTorrents()
public Snark getTorrentByBaseName(String filename)
public Snark getTorrentByInfoHash(byte[] infohash)
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 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 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 deleteMagnet(Snark snark)
snark
- a torrent with a fake file name ("Magnet xxxx")public void addDownloader(Snark torrent)
torrent
- must be instanceof FetchAndAddRuntimeException
- via Snark.fatal()?public boolean addTorrent(MetaInfo metainfo, BitField bitfield, String filename, File baseFile, boolean dontAutoStart) throws IOException
metainfo
- the metainfo for the torrentbitfield
- the current completion status of the torrentfilename
- 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.baseFile
- may be null, if so look in rootDataDirRuntimeException
- via Snark.fatal()IOException
public void 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()IOException
public long getSavedTorrentTime(Snark snark)
getSavedTorrentTime
in interface CompleteListener
public BitField getSavedTorrentBitField(Snark snark)
getSavedTorrentBitField
in interface CompleteListener
public void loadSavedFilePriorities(Snark snark)
public boolean getSavedPreserveNamesSetting(Snark snark)
getSavedPreserveNamesSetting
in interface CompleteListener
public long getSavedUploaded(Snark snark)
getSavedUploaded
in interface CompleteListener
public long[] getSavedAddedAndCompleted(Snark snark)
public void saveTorrentStatus(Snark snark)
public void saveMagnetStatus(byte[] ih, String dir, String trackerURL, String dn)
dir
- may be nulltrackerURL
- may be nulldn
- may be nullpublic void removeMagnetStatus(byte[] ih)
public Snark stopTorrent(String filename, boolean shouldRemove)
public void stopTorrent(Snark torrent, boolean shouldRemove)
public void removeTorrent(String filename)
public void torrentComplete(Snark snark)
torrentComplete
in interface CompleteListener
public void updateStatus(Snark snark)
updateStatus
in interface CompleteListener
public String gotMetaInfo(Snark snark)
gotMetaInfo
in interface CompleteListener
public void fatal(Snark snark, String error)
fatal
in interface CompleteListener
public void addMessage(Snark snark, String message)
addMessage
in interface CompleteListener
public void gotPiece(Snark snark)
gotPiece
in interface CompleteListener
public Map<String,Tracker> getTrackerMap()
public Collection<Tracker> getTrackers()
public void setDefaultTrackerMap()
public void saveTrackerMap()
public void startTorrent(byte[] infoHash)
public void startTorrent(Snark snark)
public void startAllTorrents()
public void stopAllTorrents(boolean finalShutdown)
finalShutdown
- if true, sleep at the end if any torrents were runningpublic void recheckTorrent(Snark snark)