public class Snark extends Object implements StorageListener, CoordinatorListener, ShutdownListener
| Modifier and Type | Class and Description |
|---|---|
(package private) static class | Snark.RouterExceptionA unique exception class to blame the router that can be caught by SnarkManager |
| Modifier and Type | Field and Description |
|---|---|
protected I2PSnarkUtil | _utilThe util |
(package private) static int | MAX_TOTAL_UPLOADERSM a x t o t a l u p l o a d e r s |
(package private) static int | MIN_TOTAL_UPLOADERSMaintain a configurable total uploader cap CoordinatorListener |
static String | PROP_MAX_CONNECTIONSmax connections |
boolean | storageCompletedWhether the torrent storage has reported completion. |
| Modifier | Constructor and Description |
|---|---|
protected | Snark(I2PSnarkUtil util,
String torrent,
byte[] ih,
String trackerURL,
CompleteListener complistener,
PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor,
boolean ignored,
String rootDir)multitorrent, magnet, Used by snark-rpc plugin |
| Snark(I2PSnarkUtil util,
String torrent,
byte[] ih,
String trackerURL,
CompleteListener complistener,
PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor,
String rootDir)multitorrent, magnet |
| Snark(I2PSnarkUtil util,
String torrent,
String ip,
int user_port,
StorageListener slistener,
CoordinatorListener clistener,
CompleteListener complistener,
PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor,
String rootDir)multitorrent |
| Snark(I2PSnarkUtil util,
String torrent,
String ip,
int user_port,
StorageListener slistener,
CoordinatorListener clistener,
CompleteListener complistener,
PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor,
String rootDir,
File baseFile)multitorrent |
| Modifier and Type | Method and Description |
|---|---|
boolean | addComments(List<Comment> comments)Add to the current comment set for this torrent, creating it if it didn't previously exist. |
void | addMessage(String message)StorageListener and CoordinatorListener callback |
String | getBaseName()Get the base name of the torrent. |
double | getCheckingProgress()Get the progress of file checking as a percentage. |
CommentSet | getComments()The current comment set for this torrent. |
long | getDownloaded()Get the total number of bytes downloaded. |
long | getDownloadRate()Get the current download rate in bytes per second. |
byte[] | getID()Get the peer ID. |
byte[] | getInfoHash()Get the info hash. |
MetaInfo | getMetaInfo()Get the metainfo. |
String | getName()Get the file name of the .torrent file. |
long | getNeeded()Does not account (i.e. |
long | getNeededLength()Bytes still wanted. |
int | getPeerCount()Get the peer count. |
List<Peer> | getPeerList()Get the peer list. |
int | getPieceLength(int p)Get the piece length. |
int | getPieces()Get the number of pieces. |
long | getRemainingLength()Bytes not yet in storage. |
int | getRPCID()A unique ID for this torrent, useful for RPC |
long | getSkippedLength()Bytes not received and set to skipped. |
long | getStartedTime()When did we start this torrent For RPC |
Storage | getStorage()Get the storage. |
long | getTotalLength()Get the total length of all torrent files. |
String | getTrackerProblems()Not HTML escaped. |
int | getTrackerSeenPeers()Get the tracker seen peers count. |
String | getTrackerURL()Get the tracker URL. |
long | getUploaded()Get the total number of bytes uploaded. |
long | getUploadRate()Get the current upload rate in bytes per second. |
void | gotMetaInfo(PeerCoordinator coordinator,
MetaInfo metainfo)Called when the PeerCoordinator got the MetaInfo via magnet. |
boolean | isAllocating()Check if disk allocation (ballooning) is in progress. |
boolean | isAutoStoppable()Check if the torrent is auto-stoppable. |
boolean | isChecking()Check if file checking is in progress. |
boolean | isNotificationSent() |
boolean | isStarting()Check if startup is in progress. |
boolean | isStopped()Check if the torrent is stopped. |
boolean | isStorageCompleted() |
boolean | overUploadLimit(int uploaders)CoordinatorListener callback to check if the total uploaders across all torrents exceeds the
configured limit. |
void | peerChange(PeerCoordinator coordinator,
Peer peer)CoordinatorListener no-op |
void | replaceMetaInfo(MetaInfo metainfo)Call after editing torrent. |
boolean | restartAcceptor()Restart the connection acceptor. |
void | setAutoStoppable(boolean yes)Set whether the torrent is auto-stoppable. |
void | setNotificationSent(boolean sent)Mark that a completion notification has been sent. |
void | setStarting()Set startup in progress. |
void | setTrackerProblems(String p)Set the tracker problems string. |
void | setTrackerSeenPeers(int p)Set the tracker seen peers count. |
void | setWantedPieces(Storage storage)StorageListener callback to update the coordinator's wanted piece set. |
void | shutdown()SnarkShutdown callback unused |
void | startTorrent()Start up contacting peers and querying the tracker. |
void | stopTorrent()Stop contacting the tracker and talking with peers |
void | stopTorrent(boolean fast)Stop contacting the tracker and talking with peers |
void | storageAllChecked(Storage storage)StorageListener callback called when all pieces have been checked. |
void | storageAllocated(Storage storage,
long length)does nothing |
void | storageChecked(Storage storage,
int num,
boolean checked)StorageListener callback called when a piece check completes. |
void | storageCompleted(Storage storage)StorageListener callback called when the torrent has completed. |
void | storageCreateFile(Storage storage,
String name,
long length)StorageListener no-op |
void | updatePiecePriorities()Recalculate piece priorities |
protected final I2PSnarkUtil _util
static final int MAX_TOTAL_UPLOADERS
static final int MIN_TOTAL_UPLOADERS
public static final String PROP_MAX_CONNECTIONS
public boolean storageCompleted
protected Snark(I2PSnarkUtil util, String torrent, byte[] ih, String trackerURL, CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet, ConnectionAcceptor connectionAcceptor, boolean ignored, String rootDir)
Will not start itself. Caller must call startTorrent() if desired.
util - the I2PSnarkUtiltorrent - the torrentih - the info hashtrackerURL - the tracker URLcomplistener - the complete listenerpeerCoordinatorSet - the peer coordinator setconnectionAcceptor - the connection acceptorignored - used to be autostartrootDir - the root data directoryRuntimeException - via fatal()Snark.RouterException - via fatalRouter()public Snark(I2PSnarkUtil util, String torrent, byte[] ih, String trackerURL, CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet, ConnectionAcceptor connectionAcceptor, String rootDir)
Will not start itself. Caller must call startTorrent() if desired.
util - the I2PSnarkUtiltorrent - a fake name for now (not a file name)ih - 20-byte info hashtrackerURL - may be nullcomplistener - the complete listenerpeerCoordinatorSet - the peer coordinator setconnectionAcceptor - the connection acceptorrootDir - the root data directoryRuntimeException - via fatal()Snark.RouterException - via fatalRouter()public Snark(I2PSnarkUtil util, String torrent, String ip, int user_port, StorageListener slistener, CoordinatorListener clistener, CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet, ConnectionAcceptor connectionAcceptor, String rootDir)
Will not start itself. Caller must call startTorrent() if desired.
util - the I2PSnarkUtiltorrent - the torrentip - the IP addressuser_port - the user portslistener - the storage listenerclistener - the coordinator listenercomplistener - the complete listenerpeerCoordinatorSet - the peer coordinator setconnectionAcceptor - the connection acceptorrootDir - the root data directoryRuntimeException - via fatal()Snark.RouterException - via fatalRouter()public Snark(I2PSnarkUtil util, String torrent, String ip, int user_port, StorageListener slistener, CoordinatorListener clistener, CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet, ConnectionAcceptor connectionAcceptor, String rootDir, File baseFile)
Will not start itself. Caller must call startTorrent() if desired.
util - the I2PSnarkUtiltorrent - the torrentip - the IP addressuser_port - the user portslistener - the storage listenerclistener - the coordinator listenercomplistener - the complete listenerpeerCoordinatorSet - the peer coordinator setconnectionAcceptor - the connection acceptorrootDir - the root data directorybaseFile - if null, use rootDir/torrentName; if non-null, use it insteadRuntimeException - via fatal()Snark.RouterException - via fatalRouter()public boolean addComments(List<Comment> comments)
public void addMessage(String message)
addMessage in interface CoordinatorListeneraddMessage in interface StorageListenermessage - the message to displaypublic String getBaseName()
public double getCheckingProgress()
public CommentSet getComments()
public long getDownloaded()
public long getDownloadRate()
public byte[] getID()
public byte[] getInfoHash()
public MetaInfo getMetaInfo()
public String getName()
public long getNeeded()
public long getNeededLength()
public int getPeerCount()
public int getPieceLength(int p)
p - the piece numberpublic int getPieces()
public long getRemainingLength()
public int getRPCID()
public long getSkippedLength()
public long getStartedTime()
public Storage getStorage()
public long getTotalLength()
public String getTrackerProblems()
public int getTrackerSeenPeers()
public String getTrackerURL()
public long getUploaded()
public long getUploadRate()
public void gotMetaInfo(PeerCoordinator coordinator, MetaInfo metainfo)
gotMetaInfo in interface CoordinatorListenerRuntimeException - via fatal()public boolean isAllocating()
public boolean isAutoStoppable()
public boolean isChecking()
public boolean isNotificationSent()
public boolean isStarting()
public boolean isStopped()
public boolean isStorageCompleted()
public boolean overUploadLimit(int uploaders)
overUploadLimit in interface CoordinatorListeneruploaders - the number of interested uploaders on this coordinatorpublic void peerChange(PeerCoordinator coordinator, Peer peer)
peerChange in interface CoordinatorListenercoordinator - the PeerCoordinator reporting the changepeer - the peer whose state changedpublic void replaceMetaInfo(MetaInfo metainfo)
public boolean restartAcceptor()
public void setAutoStoppable(boolean yes)
yes - true if auto-stoppablepublic void setNotificationSent(boolean sent)
sent - true if the notification was sentpublic void setStarting()
public void setTrackerProblems(String p)
p - tracker error string or nullpublic void setTrackerSeenPeers(int p)
p - peer count from trackerpublic void setWantedPieces(Storage storage)
setWantedPieces in interface StorageListenerstorage - the storagepublic void shutdown()
shutdown in interface ShutdownListenerpublic void startTorrent()
RuntimeException - via fatal()Snark.RouterException - via fatalRouter()public void stopTorrent()
public void stopTorrent(boolean fast)
fast - if true, limit the life of the unannounce threadspublic void storageAllChecked(Storage storage)
storageAllChecked in interface StorageListenerstorage - the storagepublic void storageAllocated(Storage storage, long length)
storageAllocated in interface StorageListenerstorage - the storage instancelength - the number of bytes allocatedpublic void storageChecked(Storage storage, int num, boolean checked)
storageChecked in interface StorageListenerstorage - the storagenum - the piece numberchecked - true if the piece hash was correctpublic void storageCompleted(Storage storage)
storageCompleted in interface StorageListenerstorage - the storagepublic void storageCreateFile(Storage storage, String name, long length)
storageCreateFile in interface StorageListenerstorage - the storage instancename - the file namelength - the file lengthpublic void updatePiecePriorities()