org.klomp.snark
Class SnarkManager

java.lang.Object
  extended by org.klomp.snark.SnarkManager
All Implemented Interfaces:
Snark.CompleteListener

public class SnarkManager
extends java.lang.Object
implements Snark.CompleteListener

Manage multiple snarks


Nested Class Summary
 class SnarkManager.SnarkManagerShutdown
           
 
Field Summary
static java.lang.String DEFAULT_AUTO_START
           
static java.lang.String DEFAULT_LINK_PREFIX
           
static int DEFAULT_MAX_UP_BW
           
static int DEFAULT_STARTUP_DELAY
           
static int MIN_UP_BW
           
static java.lang.String PROP_AUTO_START
           
static java.lang.String PROP_DIR
           
static java.lang.String PROP_I2CP_HOST
           
static java.lang.String PROP_I2CP_OPTS
           
static java.lang.String PROP_I2CP_PORT
           
static java.lang.String PROP_LINK_PREFIX
           
static java.lang.String PROP_META_BITFIELD_SUFFIX
           
static java.lang.String PROP_META_PREFIX
           
static java.lang.String PROP_STARTUP_DELAY
           
static java.lang.String PROP_TRACKERS
          comma delimited list of name=announceURL=baseURL for the trackers to be displayed
static java.lang.String PROP_UPBW_MAX
           
static java.lang.String PROP_UPLOADERS_TOTAL
           
 
Method Summary
 void addMessage(java.lang.String message)
           
 void addTorrent(java.lang.String filename)
           
 void addTorrent(java.lang.String filename, boolean dontAutoStart)
           
 java.util.Properties getConfig()
           
 java.io.File getDataDir()
           
 java.util.List getMessages()
          newest last
 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
 Snark getTorrent(java.lang.String filename)
          Grab the torrent given the (canonical) filename of the .torrent file
 Snark getTorrentByBaseName(java.lang.String filename)
          Grab the torrent given the base name of the storage
 java.util.Map getTrackers()
          sorted map of name to announceURL=baseURL
static SnarkManager instance()
           
 java.lang.String linkPrefix()
           
 java.util.Set<java.lang.String> listTorrentFiles()
          set of canonical .torrent filenames that we are dealing with
 void loadConfig(java.lang.String filename)
          null to set initial defaults
 void removeTorrent(java.lang.String filename)
          Stop the torrent and delete the torrent file itself, but leaving the data behind.
 void removeTorrentStatus(MetaInfo metainfo)
          Remove the status of a torrent from the config file.
 void saveConfig()
           
 void saveTorrentStatus(MetaInfo metainfo, BitField bitfield)
          Save the completion status of a torrent and the current time in the config file in the form "i2psnark.zmeta.
 boolean shouldAutoStart()
           
 void start()
          Caller _must_ call loadConfig(file) before this if setting new values for i2cp host/port or i2psnark.dir
 void stop()
           
 Snark stopTorrent(java.lang.String filename, boolean shouldRemove)
          Stop the torrent, leaving it on the list of torrents unless told to remove it
 void torrentComplete(Snark snark)
          two listeners
 void updateConfig(java.lang.String dataDir, boolean autoStart, java.lang.String startDelay, java.lang.String seedPct, java.lang.String eepHost, java.lang.String eepPort, java.lang.String i2cpHost, java.lang.String i2cpPort, java.lang.String i2cpOpts, java.lang.String upLimit, java.lang.String upBW, boolean useOpenTrackers, java.lang.String openTrackers)
           
 void updateStatus(Snark snark)
           
 I2PSnarkUtil util()
          hook to I2PSnarkUtil for the servlet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_I2CP_HOST

public static final java.lang.String PROP_I2CP_HOST
See Also:
Constant Field Values

PROP_I2CP_PORT

public static final java.lang.String PROP_I2CP_PORT
See Also:
Constant Field Values

PROP_I2CP_OPTS

public static final java.lang.String PROP_I2CP_OPTS
See Also:
Constant Field Values

PROP_UPLOADERS_TOTAL

public static final java.lang.String PROP_UPLOADERS_TOTAL
See Also:
Constant Field Values

PROP_UPBW_MAX

public static final java.lang.String PROP_UPBW_MAX
See Also:
Constant Field Values

PROP_DIR

public static final java.lang.String PROP_DIR
See Also:
Constant Field Values

PROP_META_PREFIX

public static final java.lang.String PROP_META_PREFIX
See Also:
Constant Field Values

PROP_META_BITFIELD_SUFFIX

public static final java.lang.String PROP_META_BITFIELD_SUFFIX
See Also:
Constant Field Values

PROP_AUTO_START

public static final java.lang.String PROP_AUTO_START
See Also:
Constant Field Values

DEFAULT_AUTO_START

public static final java.lang.String DEFAULT_AUTO_START
See Also:
Constant Field Values

PROP_LINK_PREFIX

public static final java.lang.String PROP_LINK_PREFIX
See Also:
Constant Field Values

DEFAULT_LINK_PREFIX

public static final java.lang.String DEFAULT_LINK_PREFIX
See Also:
Constant Field Values

PROP_STARTUP_DELAY

public static final java.lang.String PROP_STARTUP_DELAY
See Also:
Constant Field Values

MIN_UP_BW

public static final int MIN_UP_BW
See Also:
Constant Field Values

DEFAULT_MAX_UP_BW

public static final int DEFAULT_MAX_UP_BW
See Also:
Constant Field Values

DEFAULT_STARTUP_DELAY

public static final int DEFAULT_STARTUP_DELAY
See Also:
Constant Field Values

PROP_TRACKERS

public static final java.lang.String PROP_TRACKERS
comma delimited list of name=announceURL=baseURL for the trackers to be displayed

See Also:
Constant Field Values
Method Detail

instance

public static SnarkManager instance()

start

public void start()
Caller _must_ call loadConfig(file) before this if setting new values for i2cp host/port or i2psnark.dir


stop

public void stop()

util

public I2PSnarkUtil util()
hook to I2PSnarkUtil for the servlet


addMessage

public void addMessage(java.lang.String message)

getMessages

public java.util.List getMessages()
newest last


shouldAutoStart

public boolean shouldAutoStart()

linkPrefix

public java.lang.String linkPrefix()

getDataDir

public java.io.File getDataDir()

loadConfig

public void loadConfig(java.lang.String filename)
null to set initial defaults


updateConfig

public void updateConfig(java.lang.String dataDir,
                         boolean autoStart,
                         java.lang.String startDelay,
                         java.lang.String seedPct,
                         java.lang.String eepHost,
                         java.lang.String eepPort,
                         java.lang.String i2cpHost,
                         java.lang.String i2cpPort,
                         java.lang.String i2cpOpts,
                         java.lang.String upLimit,
                         java.lang.String upBW,
                         boolean useOpenTrackers,
                         java.lang.String openTrackers)

saveConfig

public void saveConfig()

getConfig

public java.util.Properties getConfig()

listTorrentFiles

public java.util.Set<java.lang.String> listTorrentFiles()
set of canonical .torrent filenames that we are dealing with


getTorrent

public Snark getTorrent(java.lang.String filename)
Grab the torrent given the (canonical) filename of the .torrent file

Returns:
Snark or null

getTorrentByBaseName

public Snark getTorrentByBaseName(java.lang.String filename)
Grab the torrent given the base name of the storage

Returns:
Snark or null
Since:
0.7.14

addTorrent

public void addTorrent(java.lang.String filename)

addTorrent

public void addTorrent(java.lang.String filename,
                       boolean dontAutoStart)

getSavedTorrentTime

public long getSavedTorrentTime(Snark snark)
Get the timestamp for a torrent from the config file

Specified by:
getSavedTorrentTime in interface Snark.CompleteListener

getSavedTorrentBitField

public BitField getSavedTorrentBitField(Snark snark)
Get the saved bitfield for a torrent from the config file. Convert "." to a full bitfield.

Specified by:
getSavedTorrentBitField in interface Snark.CompleteListener

saveTorrentStatus

public void saveTorrentStatus(MetaInfo metainfo,
                              BitField bitfield)
Save the completion status of a torrent and the current time in the config file in the form "i2psnark.zmeta.$base64infohash=$time,$base64bitfield". The config file property key is appended with the Base64 of the infohash, with the '=' changed to '$' since a key can't contain '='. The time is a standard long converted to string. The status is either a bitfield converted to Base64 or "." for a completed torrent to save space in the config file and in memory.


removeTorrentStatus

public void removeTorrentStatus(MetaInfo metainfo)
Remove the status of a torrent from the config file. This may help the config file from growing too big.


stopTorrent

public Snark stopTorrent(java.lang.String filename,
                         boolean shouldRemove)
Stop the torrent, leaving it on the list of torrents unless told to remove it


removeTorrent

public void removeTorrent(java.lang.String filename)
Stop the torrent and delete the torrent file itself, but leaving the data behind.


torrentComplete

public void torrentComplete(Snark snark)
two listeners

Specified by:
torrentComplete in interface Snark.CompleteListener

updateStatus

public void updateStatus(Snark snark)
Specified by:
updateStatus in interface Snark.CompleteListener

getTrackers

public java.util.Map getTrackers()
sorted map of name to announceURL=baseURL