Package org.klomp.snark
Class Snark
- java.lang.Object
- 
- org.klomp.snark.Snark
 
- 
- All Implemented Interfaces:
- CoordinatorListener,- ShutdownListener,- StorageListener
 - Direct Known Subclasses:
- FetchAndAdd
 
 public class Snark extends Object implements StorageListener, CoordinatorListener, ShutdownListener Main Snark program startup class.- Author:
- Mark Wielaard (mark@klomp.org)
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description (package private) static classSnark.RouterExceptionA unique exception class to blame the router that can be caught by SnarkManager
 - 
Field SummaryFields Modifier and Type Field Description protected I2PSnarkUtil_util(package private) static intMAX_TOTAL_UPLOADERS(package private) static intMIN_TOTAL_UPLOADERSMaintain a configurable total uploader cap coordinatorListenerstatic StringPROP_MAX_CONNECTIONSmax connections
 - 
Constructor SummaryConstructors Modifier Constructor Description protectedSnark(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 SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddComments(List<Comment> comments)Add to the current comment set for this torrent, creating it if it didn't previously exist.voidaddMessage(String message)StorageListener and CoordinatorListener callbackStringgetBaseName()doublegetCheckingProgress()If checking is in progress, return completion 0.0 ...CommentSetgetComments()The current comment set for this torrent.longgetDownloaded()longgetDownloadRate()byte[]getID()byte[]getInfoHash()MetaInfogetMetaInfo()StringgetName()longgetNeeded()Does not account (i.e.longgetNeededLength()Bytes still wanted.intgetPeerCount()List<Peer>getPeerList()intgetPieceLength(int p)intgetPieces()longgetRemainingLength()Bytes not yet in storage.intgetRPCID()A unique ID for this torrent, useful for RPClonggetSkippedLength()Bytes not received and set to skipped.longgetStartedTime()When did we start this torrent For RPCStoragegetStorage()longgetTotalLength()StringgetTrackerProblems()Not HTML escaped.intgetTrackerSeenPeers()StringgetTrackerURL()longgetUploaded()longgetUploadRate()voidgotMetaInfo(PeerCoordinator coordinator, MetaInfo metainfo)Called when the PeerCoordinator got the MetaInfo via magnet.booleanisAllocating()Disk allocation (ballooning) in progress.booleanisAutoStoppable()booleanisChecking()File checking in progress.booleanisStarting()Startup in progress.booleanisStopped()booleanoverUpBWLimit()Is i2psnark as a whole over its limit?booleanoverUpBWLimit(long total)Is a particular peer who has this recent download rate (in Bps) over our upstream bandwidth limit?booleanoverUploadLimit(int uploaders)Is this number of uploaders over the per-torrent limit?voidpeerChange(PeerCoordinator coordinator, Peer peer)CoordinatorListener - this does nothingbooleanrestartAcceptor()voidsetAutoStoppable(boolean yes)voidsetStarting()Set startup in progress.voidsetTrackerProblems(String p)voidsetTrackerSeenPeers(int p)voidsetWantedPieces(Storage storage)Reset the peer's wanted pieces table Call after the storage double-check failsvoidshutdown()SnarkSnutdown callback unusedvoidstartTorrent()Start up contacting peers and querying the tracker.voidstopTorrent()Stop contacting the tracker and talking with peersvoidstopTorrent(boolean fast)Stop contacting the tracker and talking with peersvoidstorageAllChecked(Storage storage)Called when all pieces in the storage have been checked.voidstorageAllocated(Storage storage, long length)does nothingvoidstorageChecked(Storage storage, int num, boolean checked)Called when storage is being checked and the num piece of that total pieces has been checked.voidstorageCompleted(Storage storage)Called the one time when the data is completely received and checked.voidstorageCreateFile(Storage storage, String name, long length)does nothingvoidupdatePiecePriorities()
 
- 
- 
- 
Field Detail- 
PROP_MAX_CONNECTIONSpublic static final String PROP_MAX_CONNECTIONS max connections- See Also:
- Constant Field Values
 
 - 
_utilprotected final I2PSnarkUtil _util 
 - 
MIN_TOTAL_UPLOADERSstatic final int MIN_TOTAL_UPLOADERS Maintain a configurable total uploader cap coordinatorListener- See Also:
- Constant Field Values
 
 - 
MAX_TOTAL_UPLOADERSstatic final int MAX_TOTAL_UPLOADERS - See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
Snarkpublic 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()
 
 - 
Snarkpublic 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
 
 - 
Snarkprotected 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
 
 - 
Snarkpublic 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 hash
- trackerURL- may be null
- Throws:
- RuntimeException- via fatal()
- Snark.RouterException- via fatalRouter()
- Since:
- 0.8.4
 
 
- 
 - 
Method Detail- 
startTorrentpublic 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()
 
 - 
stopTorrentpublic void stopTorrent() Stop contacting the tracker and talking with peers
 - 
stopTorrentpublic 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
 
 - 
getNamepublic String getName() - Returns:
- file name of .torrent file (should be full absolute path), or a fake name if in magnet mode.
- Since:
- 0.8.4
 
 - 
getBaseNamepublic String getBaseName() - Returns:
- base name of torrent [filtered version of getMetaInfo.getName()], or a fake name if in magnet mode
- Since:
- 0.8.4
 
 - 
getIDpublic byte[] getID() - Returns:
- always will be valid even in magnet mode
- Since:
- 0.8.4
 
 - 
getInfoHashpublic byte[] getInfoHash() - Returns:
- always will be valid even in magnet mode
- Since:
- 0.8.4
 
 - 
getMetaInfopublic MetaInfo getMetaInfo() - Returns:
- may be null if in magnet mode
- Since:
- 0.8.4
 
 - 
getStoragepublic Storage getStorage() - Returns:
- may be null if in magnet mode
- Since:
- 0.8.4
 
 - 
isStoppedpublic boolean isStopped() - Since:
- 0.8.4
 
 - 
isStartingpublic boolean isStarting() Startup in progress.- Since:
- 0.9.1
 
 - 
setStartingpublic void setStarting() Set startup in progress.- Since:
- 0.9.1
 
 - 
isCheckingpublic boolean isChecking() File checking in progress.- Since:
- 0.9.3
 
 - 
getCheckingProgresspublic double getCheckingProgress() If checking is in progress, return completion 0.0 ... 1.0, else return 1.0.- Since:
- 0.9.23
 
 - 
isAllocatingpublic boolean isAllocating() Disk allocation (ballooning) in progress.- Since:
- 0.9.3
 
 - 
getDownloadRatepublic long getDownloadRate() - Since:
- 0.8.4
 
 - 
getUploadRatepublic long getUploadRate() - Since:
- 0.8.4
 
 - 
getDownloadedpublic long getDownloaded() - Since:
- 0.8.4
 
 - 
getUploadedpublic long getUploaded() - Since:
- 0.8.4
 
 - 
getPeerCountpublic int getPeerCount() - Since:
- 0.8.4
 
 - 
getTrackerProblemspublic String getTrackerProblems() Not HTML escaped.- Returns:
- String returned from tracker, or null if no error
- Since:
- 0.8.4
 
 - 
setTrackerProblemspublic void setTrackerProblems(String p) - Parameters:
- p- tracker error string or null
- Since:
- 0.8.4
 
 - 
getTrackerSeenPeerspublic int getTrackerSeenPeers() - Returns:
- count returned from tracker
- Since:
- 0.8.4
 
 - 
setTrackerSeenPeerspublic void setTrackerSeenPeers(int p) - Since:
- 0.8.4
 
 - 
updatePiecePrioritiespublic void updatePiecePriorities() - Since:
- 0.8.4
 
 - 
getTotalLengthpublic long getTotalLength() - Returns:
- total of all torrent files, or total of metainfo file if fetching magnet, or -1
- Since:
- 0.8.4
 
 - 
getRemainingLengthpublic 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
 
 - 
getNeededLengthpublic 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
 
 - 
getSkippedLengthpublic 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
 
 - 
getNeededpublic 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
 
 - 
getPieceLengthpublic int getPieceLength(int p) - Parameters:
- p- the piece number
- Returns:
- metainfo piece length or 16K if fetching magnet
- Since:
- 0.8.4
 
 - 
getPiecespublic int getPieces() - Returns:
- number of pieces
- Since:
- 0.8.4
 
 - 
restartAcceptorpublic boolean restartAcceptor() - Returns:
- true if restarted
- Since:
- 0.8.4
 
 - 
getTrackerURLpublic String getTrackerURL() - Returns:
- trackerURL string from magnet-mode constructor, may be null
- Since:
- 0.8.4
 
 - 
isAutoStoppablepublic boolean isAutoStoppable() - Since:
- 0.9.9
 
 - 
setAutoStoppablepublic void setAutoStoppable(boolean yes) - Since:
- 0.9.9
 
 - 
peerChangepublic void peerChange(PeerCoordinator coordinator, Peer peer) CoordinatorListener - this does nothing- Specified by:
- peerChangein interface- CoordinatorListener
 
 - 
gotMetaInfopublic void gotMetaInfo(PeerCoordinator coordinator, MetaInfo metainfo) 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:
- gotMetaInfoin interface- CoordinatorListener
- Throws:
- RuntimeException- via fatal()
- Since:
- 0.8.4
 
 - 
storageCreateFilepublic void storageCreateFile(Storage storage, String name, long length) does nothing- Specified by:
- storageCreateFilein interface- StorageListener
 
 - 
storageAllocatedpublic void storageAllocated(Storage storage, long length) does nothing- Specified by:
- storageAllocatedin interface- StorageListener
 
 - 
storageCheckedpublic void storageChecked(Storage storage, int num, boolean checked) Description copied from interface:StorageListenerCalled 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:
- storageCheckedin interface- StorageListener
 
 - 
storageAllCheckedpublic void storageAllChecked(Storage storage) Description copied from interface:StorageListenerCalled 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:
- storageAllCheckedin interface- StorageListener
 
 - 
storageCompletedpublic void storageCompleted(Storage storage) Description copied from interface:StorageListenerCalled the one time when the data is completely received and checked.- Specified by:
- storageCompletedin interface- StorageListener
 
 - 
setWantedPiecespublic void setWantedPieces(Storage storage) Description copied from interface:StorageListenerReset the peer's wanted pieces table Call after the storage double-check fails- Specified by:
- setWantedPiecesin interface- StorageListener
 
 - 
shutdownpublic void shutdown() SnarkSnutdown callback unused- Specified by:
- shutdownin interface- ShutdownListener
 
 - 
addMessagepublic void addMessage(String message) StorageListener and CoordinatorListener callback- Specified by:
- addMessagein interface- CoordinatorListener
- Specified by:
- addMessagein interface- StorageListener
- Since:
- 0.9.2
 
 - 
overUploadLimitpublic boolean overUploadLimit(int uploaders) Description copied from interface:CoordinatorListenerIs this number of uploaders over the per-torrent limit?- Specified by:
- overUploadLimitin interface- CoordinatorListener
 
 - 
overUpBWLimitpublic boolean overUpBWLimit() Is i2psnark as a whole over its limit?- Specified by:
- overUpBWLimitin interface- CoordinatorListener
 
 - 
overUpBWLimitpublic boolean overUpBWLimit(long total) Is a particular peer who has this recent download rate (in Bps) over our upstream bandwidth limit?- Specified by:
- overUpBWLimitin interface- CoordinatorListener
 
 - 
getRPCIDpublic int getRPCID() A unique ID for this torrent, useful for RPC- Returns:
- positive value unless you wrap around
- Since:
- 0.9.30
 
 - 
getStartedTimepublic long getStartedTime() When did we start this torrent For RPC- Returns:
- 0 if not started before. Not cleared when stopped.
- Since:
- 0.9.30
 
 - 
getCommentspublic CommentSet 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
 
 
- 
 
-