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_UPLOADERSMaximum peers we upload to across all torrents. |
(package private) static int | MIN_TOTAL_UPLOADERSMaintain a configurable total uploader cap CoordinatorListener |
static String | PROP_MAX_CONNECTIONSMaximum 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)Create the torrent in multitorrent or magnet mode, for the snark-rpc plugin. |
| Snark(I2PSnarkUtil util,
String torrent,
byte[] ih,
String trackerURL,
CompleteListener complistener,
PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor,
String rootDir)Create the torrent in multitorrent or magnet mode. |
| Snark(I2PSnarkUtil util,
String torrent,
String ip,
int user_port,
StorageListener slistener,
CoordinatorListener clistener,
CompleteListener complistener,
PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor,
String rootDir)Create the torrent in multitorrent mode. |
| Snark(I2PSnarkUtil util,
String torrent,
String ip,
int user_port,
StorageListener slistener,
CoordinatorListener clistener,
CompleteListener complistener,
PeerCoordinatorSet peerCoordinatorSet,
ConnectionAcceptor connectionAcceptor,
String rootDir,
File baseFile)Create the torrent in multitorrent mode. |
| 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 |
(package private) void | awaitUnannounces(long ms)Wait, capped at ms, for this torrent's unannounces to dispatch. |
void | ban(Hash h)Ban the given hash. |
String | getBaseName()The base name of the torrent. |
double | getCheckingProgress()The progress of file checking as a percentage. |
CommentSet | getComments()The current comment set for this torrent. |
long | getDataLength()The total length of all non-padding torrent files; equals getTotalLength() for
torrents without BEP 47 padding files. |
TorrentDest | getDest()The transient multi-dest destination, or null when multi-dest is
disabled or the torrent is stopped. |
long | getDownloaded()The total number of bytes downloaded. |
long | getDownloadRate()The current download rate in bytes per second. |
byte[] | getID()The peer ID. |
byte[] | getInfoHash()The info hash. |
long | getLastTrackerResponse()The wall-clock time of the last valid tracker announce or scrape
response, or 0 if none was ever received. |
MetaInfo | getMetaInfo()The metainfo. |
String | getName()The file name of the .torrent file. |
long | getNeeded()Does not account (i.e. |
long | getNeededLength()Bytes still wanted. |
int | getPeerCount()The peer count. |
List<Peer> | getPeerList()The peer list. |
int | getPieceLength(int p)The piece length. |
int | getPieces()The number of pieces. |
long | getRemainingLength()Bytes not yet in storage. |
int | getRPCID()A unique ID for this torrent, useful for RPC |
int | getScrapeLeechers()The best-known leech count from tracker scrapes. |
int | getScrapePartialSeeds()The best-known partial seed count from tracker scrapes. |
int | getScrapeSeeders()The best-known seed count from tracker scrapes. |
long | getSkippedLength()Bytes not received and set to skipped. |
long | getStartedTime()When did we start this torrent For RPC |
Storage | getStorage()The storage. |
int | getSwarmPeerCount()Distinct swarm peers seen recently (via announce, PEX or DHT) or
currently connected, for the torrent view peer count. |
long | getTotalLength()The total length of all torrent files. |
String | getTrackerProblems()Not HTML escaped. |
int | getTrackerSeenPeers()The tracker seen peers count. |
String | getTrackerURL()The tracker URL. |
long | getUploaded()The total number of bytes uploaded. |
long | getUploadRate()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 | isBanned(Hash h)Is the given hash banned? |
boolean | isChecking()Check if file checking is in progress. |
boolean | isNotificationSent()Whether a completion notification has already been sent for this torrent. |
boolean | isStarting()Check if startup is in progress. |
boolean | isStopped()Check if the torrent is stopped. |
boolean | isStorageCompleted()Whether the torrent storage has completed. |
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)Store whether the torrent is auto-stoppable. |
void | setLastTrackerResponse(long t)Record a valid tracker announce or scrape response. |
void | setNotificationSent(boolean sent)Mark that a completion notification has been sent. |
void | setStarting()Mark startup in progress. |
void | setTrackerProblems(String p)Store the tracker problems string. |
void | setTrackerSeenPeers(int p)Store 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 |
(package private) void | stopTorrent(boolean fast,
boolean deferTeardown)Stop contacting the tracker and talking with peers, optionally leaving the
I2P session open so the caller can dispatch unannounces before teardown. |
void | storageAllChecked(Storage storage)StorageListener callback called when all pieces have been checked. |
void | storageAllocated(Storage storage,
long length)No-op; deliberately empty. |
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 |
(package private) void | teardownSession()Destroy the I2P session for this stopped torrent. |
void | updatePiecePriorities()Recalculate piece priorities |
void | updateScrape(int seeders,
int leechers)Update the best-known swarm composition from a tracker scrape (BEP 15/48). |
void | updateScrape(int seeders,
int leechers,
int partials)Update the best-known swarm composition from a tracker scrape (BEP 15/48/21). |
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 displayvoid awaitUnannounces(long ms)
public void ban(Hash h)
ban in interface CoordinatorListenerh - the hashpublic String getBaseName()
public double getCheckingProgress()
public CommentSet getComments()
public long getDataLength()
getTotalLength() for
torrents without BEP 47 padding files. The projected downloaded size.public TorrentDest getDest()
public long getDownloaded()
public long getDownloadRate()
public byte[] getID()
public byte[] getInfoHash()
public long getLastTrackerResponse()
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 int getScrapeLeechers()
public int getScrapePartialSeeds()
Partial seeds have some files but download nothing more (BEP 21).
public int getScrapeSeeders()
public long getSkippedLength()
public long getStartedTime()
public Storage getStorage()
public int getSwarmPeerCount()
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 isBanned(Hash h)
isBanned in interface CoordinatorListenerh - the hashpublic 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 setLastTrackerResponse(long t)
t - milliseconds since epochpublic 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 threadsvoid stopTorrent(boolean fast,
boolean deferTeardown)fast - if true, limit the life of the unannounce threadsdeferTeardown - if true, keep the session for teardownSession()public 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 lengthvoid teardownSession()
public void updatePiecePriorities()
public void updateScrape(int seeders,
int leechers)Keeps the maximum of each count, and raises the aggregate tracker seen peers to the sum when larger.
seeders - the seed countleechers - the leech countpublic void updateScrape(int seeders,
int leechers,
int partials)Keeps the maximum of each count, and raises the aggregate tracker seen peers to the sum when larger.
seeders - the seed countleechers - the leech countpartials - the partial seed count, 0 if unknown