Package org.klomp.snark
Class Snark
java.lang.Object
org.klomp.snark.Snark
- All Implemented Interfaces:
CoordinatorListener
,ShutdownListener
,StorageListener
- Direct Known Subclasses:
FetchAndAdd
Main Snark program startup class.
- Author:
- Mark Wielaard (mark@klomp.org)
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
A unique exception class to blame the router that can be caught by SnarkManager -
Field Summary
Modifier and TypeFieldDescriptionprotected final I2PSnarkUtil
(package private) static final int
(package private) static final int
Maintain a configurable total uploader cap coordinatorListenerstatic final String
max connections -
Constructor Summary
ModifierConstructorDescriptionprotected
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 Will not start itself.Snark
(I2PSnarkUtil util, String torrent, byte[] ih, String trackerURL, CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet, ConnectionAcceptor connectionAcceptor, String rootDir) multitorrent, magnet Will not start itself.Snark
(I2PSnarkUtil util, String torrent, String ip, int user_port, StorageListener slistener, CoordinatorListener clistener, CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet, ConnectionAcceptor connectionAcceptor, String rootDir) Deprecated.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 Will not start itself. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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 callbackdouble
If checking is in progress, return completion 0.0 ...The current comment set for this torrent.long
long
byte[]
getID()
byte[]
getName()
long
Does not account (i.e.long
Bytes still wanted.int
int
getPieceLength
(int p) int
long
Bytes not yet in storage.int
getRPCID()
A unique ID for this torrent, useful for RPClong
Bytes not received and set to skipped.long
When did we start this torrent For RPClong
Not HTML escaped.int
long
long
void
gotMetaInfo
(PeerCoordinator coordinator, MetaInfo metainfo) Called when the PeerCoordinator got the MetaInfo via magnet.boolean
Disk allocation (ballooning) in progress.boolean
boolean
File checking in progress.boolean
Startup in progress.boolean
boolean
Is i2psnark as a whole over its limit?boolean
overUpBWLimit
(long total) Is a particular peer who has this recent download rate (in Bps) over our upstream bandwidth limit?boolean
overUploadLimit
(int uploaders) Is this number of uploaders over the per-torrent limit?void
peerChange
(PeerCoordinator coordinator, Peer peer) CoordinatorListener - this does nothingvoid
replaceMetaInfo
(MetaInfo metainfo) Call after editing torrent.boolean
void
setAutoStoppable
(boolean yes) void
Set startup in progress.void
void
setTrackerSeenPeers
(int p) void
setWantedPieces
(Storage storage) Reset the peer's wanted pieces table Call after the storage double-check failsvoid
shutdown()
SnarkSnutdown callback unusedvoid
Start up contacting peers and querying the tracker.void
Stop contacting the tracker and talking with peersvoid
stopTorrent
(boolean fast) Stop contacting the tracker and talking with peersvoid
storageAllChecked
(Storage storage) Called when all pieces in the storage have been checked.void
storageAllocated
(Storage storage, long length) does nothingvoid
storageChecked
(Storage storage, int num, boolean checked) Called when storage is being checked and the num piece of that total pieces has been checked.void
storageCompleted
(Storage storage) Called the one time when the data is completely received and checked.void
storageCreateFile
(Storage storage, String name, long length) does nothingvoid
-
Field Details
-
PROP_MAX_CONNECTIONS
max connections- See Also:
-
_util
-
MIN_TOTAL_UPLOADERS
static final int MIN_TOTAL_UPLOADERSMaintain a configurable total uploader cap coordinatorListener- See Also:
-
MAX_TOTAL_UPLOADERS
static final int MAX_TOTAL_UPLOADERS- See Also:
-
-
Constructor Details
-
Snark
public Snark(I2PSnarkUtil util, String torrent, String ip, int user_port, StorageListener slistener, CoordinatorListener clistener, CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet, ConnectionAcceptor connectionAcceptor, String rootDir) Deprecated.multitorrent Will not start itself. Caller must call startTorrent() if desired.- Throws:
RuntimeException
- via fatal()Snark.RouterException
- via fatalRouter()
-
Snark
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) multitorrent Will not start itself. Caller must call startTorrent() if desired.- Parameters:
baseFile
- if null, use rootDir/torrentName; if non-null, use it instead- Throws:
RuntimeException
- via fatal()Snark.RouterException
- via fatalRouter()- Since:
- 0.9.11
-
Snark
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 Will not start itself. Caller must call startTorrent() if desired.- Parameters:
ignored
- used to be autostart- Throws:
RuntimeException
- via fatal()Snark.RouterException
- via fatalRouter()- Since:
- 0.8.4, removed in 0.9.36, restored in 0.9.45 with boolean param now ignored
-
Snark
public Snark(I2PSnarkUtil util, String torrent, byte[] ih, String trackerURL, CompleteListener complistener, PeerCoordinatorSet peerCoordinatorSet, ConnectionAcceptor connectionAcceptor, String rootDir) multitorrent, magnet Will not start itself. Caller must call startTorrent() if desired.- Parameters:
torrent
- a fake name for now (not a file name)ih
- 20-byte info hashtrackerURL
- may be null- Throws:
RuntimeException
- via fatal()Snark.RouterException
- via fatalRouter()- Since:
- 0.8.4
-
-
Method Details
-
startTorrent
public void startTorrent()Start up contacting peers and querying the tracker. Blocks if tunnel is not yet open.- Throws:
RuntimeException
- via fatal()Snark.RouterException
- via fatalRouter()
-
stopTorrent
public void stopTorrent()Stop contacting the tracker and talking with peers -
stopTorrent
public void stopTorrent(boolean fast) Stop contacting the tracker and talking with peers- Parameters:
fast
- if true, limit the life of the unannounce threads- Since:
- 0.9.1
-
getName
- Returns:
- file name of .torrent file (should be full absolute path), or a fake name if in magnet mode.
- Since:
- 0.8.4
-
getBaseName
- Returns:
- base name of torrent [filtered version of getMetaInfo.getName()], or a fake name if in magnet mode
- Since:
- 0.8.4
-
getID
public byte[] getID()- Returns:
- always will be valid even in magnet mode
- Since:
- 0.8.4
-
getInfoHash
public byte[] getInfoHash()- Returns:
- always will be valid even in magnet mode
- Since:
- 0.8.4
-
getMetaInfo
- Returns:
- may be null if in magnet mode
- Since:
- 0.8.4
-
getStorage
- Returns:
- may be null if in magnet mode
- Since:
- 0.8.4
-
isStopped
public boolean isStopped()- Since:
- 0.8.4
-
isStarting
public boolean isStarting()Startup in progress.- Since:
- 0.9.1
-
setStarting
public void setStarting()Set startup in progress.- Since:
- 0.9.1
-
isChecking
public boolean isChecking()File checking in progress.- Since:
- 0.9.3
-
getCheckingProgress
public double getCheckingProgress()If checking is in progress, return completion 0.0 ... 1.0, else return 1.0.- Since:
- 0.9.23
-
isAllocating
public boolean isAllocating()Disk allocation (ballooning) in progress.- Since:
- 0.9.3
-
getDownloadRate
public long getDownloadRate()- Since:
- 0.8.4
-
getUploadRate
public long getUploadRate()- Since:
- 0.8.4
-
getDownloaded
public long getDownloaded()- Since:
- 0.8.4
-
getUploaded
public long getUploaded()- Since:
- 0.8.4
-
getPeerCount
public int getPeerCount()- Since:
- 0.8.4
-
getPeerList
- Since:
- 0.8.4
-
getTrackerProblems
Not HTML escaped.- Returns:
- String returned from tracker, or null if no error
- Since:
- 0.8.4
-
setTrackerProblems
- Parameters:
p
- tracker error string or null- Since:
- 0.8.4
-
getTrackerSeenPeers
public int getTrackerSeenPeers()- Returns:
- count returned from tracker
- Since:
- 0.8.4
-
setTrackerSeenPeers
public void setTrackerSeenPeers(int p) - Since:
- 0.8.4
-
updatePiecePriorities
public void updatePiecePriorities()- Since:
- 0.8.4
-
getTotalLength
public long getTotalLength()- Returns:
- total of all torrent files, or total of metainfo file if fetching magnet, or -1
- Since:
- 0.8.4
-
getRemainingLength
public long getRemainingLength()Bytes not yet in storage. Does NOT account for skipped files.- Returns:
- exact value. or -1 if no storage yet. getNeeded() * pieceLength(0) isn't accurate if last piece is still needed.
- Since:
- 0.8.9
-
getNeededLength
public long getNeededLength()Bytes still wanted. DOES account for (i.e. does not include) skipped files. FIXME -1 when not running.- Returns:
- exact value. or -1 if no storage yet or when not running.
- Since:
- 0.9.1
-
getSkippedLength
public long getSkippedLength()Bytes not received and set to skipped. This is not the same as the total of all skipped files, since pieces may span multiple files.- Returns:
- exact value. or 0 if no storage yet.
- Since:
- 0.9.24
-
getNeeded
public long getNeeded()Does not account (i.e. includes) for skipped files.- Returns:
- number of pieces still needed (magnet mode or not), or -1 if unknown
- Since:
- 0.8.4
-
getPieceLength
public int getPieceLength(int p) - Parameters:
p
- the piece number- Returns:
- metainfo piece length or 16K if fetching magnet
- Since:
- 0.8.4
-
getPieces
public int getPieces()- Returns:
- number of pieces
- Since:
- 0.8.4
-
restartAcceptor
public boolean restartAcceptor()- Returns:
- true if restarted
- Since:
- 0.8.4
-
getTrackerURL
- Returns:
- trackerURL string from magnet-mode constructor, may be null
- Since:
- 0.8.4
-
isAutoStoppable
public boolean isAutoStoppable()- Since:
- 0.9.9
-
setAutoStoppable
public void setAutoStoppable(boolean yes) - Since:
- 0.9.9
-
peerChange
CoordinatorListener - this does nothing- Specified by:
peerChange
in interfaceCoordinatorListener
-
gotMetaInfo
Called when the PeerCoordinator got the MetaInfo via magnet. CoordinatorListener. Create the storage, tell SnarkManager, and give the storage back to the coordinator.- Specified by:
gotMetaInfo
in interfaceCoordinatorListener
- Throws:
RuntimeException
- via fatal()- Since:
- 0.8.4
-
replaceMetaInfo
Call after editing torrent. Caller must ensure infohash, files, etc. did not change.- Since:
- 0.9.53
-
storageCreateFile
does nothing- Specified by:
storageCreateFile
in interfaceStorageListener
-
storageAllocated
does nothing- Specified by:
storageAllocated
in interfaceStorageListener
-
storageChecked
Description copied from interface:StorageListener
Called when storage is being checked and the num piece of that total pieces has been checked. When the piece hash matches the expected piece hash checked will be true, otherwise it will be false.- Specified by:
storageChecked
in interfaceStorageListener
-
storageAllChecked
Description copied from interface:StorageListener
Called when all pieces in the storage have been checked. Does not mean that the storage is complete, just that the state of the storage is known.- Specified by:
storageAllChecked
in interfaceStorageListener
-
storageCompleted
Description copied from interface:StorageListener
Called the one time when the data is completely received and checked.- Specified by:
storageCompleted
in interfaceStorageListener
-
setWantedPieces
Description copied from interface:StorageListener
Reset the peer's wanted pieces table Call after the storage double-check fails- Specified by:
setWantedPieces
in interfaceStorageListener
-
shutdown
public void shutdown()SnarkSnutdown callback unused- Specified by:
shutdown
in interfaceShutdownListener
-
addMessage
StorageListener and CoordinatorListener callback- Specified by:
addMessage
in interfaceCoordinatorListener
- Specified by:
addMessage
in interfaceStorageListener
- Since:
- 0.9.2
-
overUploadLimit
public boolean overUploadLimit(int uploaders) Description copied from interface:CoordinatorListener
Is this number of uploaders over the per-torrent limit?- Specified by:
overUploadLimit
in interfaceCoordinatorListener
-
overUpBWLimit
public boolean overUpBWLimit()Is i2psnark as a whole over its limit?- Specified by:
overUpBWLimit
in interfaceCoordinatorListener
-
overUpBWLimit
public boolean overUpBWLimit(long total) Is a particular peer who has this recent download rate (in Bps) over our upstream bandwidth limit?- Specified by:
overUpBWLimit
in interfaceCoordinatorListener
-
getRPCID
public int getRPCID()A unique ID for this torrent, useful for RPC- Returns:
- positive value unless you wrap around
- Since:
- 0.9.30
-
getStartedTime
public long getStartedTime()When did we start this torrent For RPC- Returns:
- 0 if not started before. Not cleared when stopped.
- Since:
- 0.9.30
-
getComments
The current comment set for this torrent. Not a copy. Caller MUST synch on the returned object for all operations.- Returns:
- may be null if none
- Since:
- 0.9.31
-
addComments
Add to the current comment set for this torrent, creating it if it didn't previously exist.- Returns:
- true if the set changed
- Since:
- 0.9.31
-