|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.klomp.snark.PeerCoordinator
public class PeerCoordinator
Coordinates what peer does what.
Field Summary | |
---|---|
I2PSnarkUtil |
_util
|
(package private) static long |
CHECK_PERIOD
|
(package private) int |
interestedAndChoking
|
(package private) static int |
MAX_UPLOADERS
|
(package private) MetaInfo |
metainfo
|
(package private) int |
peerCount
estimate of the peers, without requiring any synchronization |
(package private) java.util.List<Peer> |
peers
|
(package private) static int |
RATE_DEPTH
|
(package private) Snark |
snark
|
(package private) Storage |
storage
|
java.lang.String |
trackerProblems
|
int |
trackerSeenPeers
|
(package private) int |
uploaders
|
Constructor Summary | |
---|---|
PeerCoordinator(I2PSnarkUtil util,
byte[] id,
MetaInfo metainfo,
Storage storage,
CoordinatorListener listener,
Snark torrent)
|
Method Summary | |
---|---|
boolean |
addPeer(Peer peer)
|
int |
allowedUploaders()
Return number of allowed uploaders for this torrent. |
boolean |
completed()
|
void |
connected(Peer peer)
Called when the connection to the peer has started and the handshake was successfull. |
void |
disconnected(Peer peer)
Called when the connection to the peer was terminated or the connection handshake failed. |
void |
downloaded(Peer peer,
int size)
Called when a peer has downloaded some bytes of a piece. |
byte[] |
getBitMap()
|
long |
getCurrentUploadRate()
|
long |
getDownloaded()
Returns the total number of downloaded bytes of all peers. |
long |
getDownloadRate()
Returns the 4-minute-average rate in Bps |
byte[] |
getID()
|
long |
getLeft()
Returns how many bytes are still needed to get the complete file. |
CoordinatorListener |
getListener()
|
MetaInfo |
getMetaInfo()
|
int |
getPeerCount()
might be wrong |
Request |
getPeerPartial(BitField havePieces)
Return partial piece if it's still wanted and peer has it. |
int |
getPeers()
should be right |
Storage |
getStorage()
|
long |
getUploaded()
Returns the total number of uploaded bytes of all peers. |
long |
getUploadRate()
|
boolean |
gotBitField(Peer peer,
BitField bitfield)
Returns true if the given bitfield contains at least one piece we are interested in. |
void |
gotChoke(Peer peer,
boolean choke)
Called when a choke message is received. |
boolean |
gotHave(Peer peer,
int piece)
Returns true if we don't have the given piece yet. |
void |
gotInterest(Peer peer,
boolean interest)
Called when an interested message is received. |
boolean |
gotPiece(Peer peer,
int piece,
byte[] bs)
Returns false if the piece is no good (according to the hash). |
byte[] |
gotRequest(Peer peer,
int piece,
int off,
int len)
Returns a byte array containing the requested piece or null of the piece is unknown. |
void |
halt()
|
boolean |
halted()
|
void |
markUnrequested(Peer peer)
Mark a peer's requested pieces unrequested when it is disconnected Once for each piece This is enough trouble, maybe would be easier just to regenerate the requested list from scratch instead. |
boolean |
needPeers()
|
boolean |
overUpBWLimit()
|
boolean |
overUpBWLimit(long total)
|
java.util.List<Peer> |
peerList()
|
void |
removePeerFromPieces(Peer peer)
Called when a peer is removed, to prevent it from being used in rarest-first calculations. |
void |
savePeerPartial(PeerState state)
Called when the peer has disconnected and the peer task may have a partially downloaded piece that the PeerCoordinator can save |
void |
setRateHistory(long up,
long down)
Push the total uploaded/downloaded onto a RATE_DEPTH deep stack |
void |
setWantedPieces()
|
(package private) void |
unchokePeer()
|
void |
uploaded(Peer peer,
int size)
Called when a peer has uploaded some bytes of a piece. |
int |
wantPiece(Peer peer,
BitField havePieces)
Returns one of pieces in the given BitField that is still wanted or -1 if none of the given pieces are wanted. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
final MetaInfo metainfo
final Storage storage
final Snark snark
static final long CHECK_PERIOD
static final int MAX_UPLOADERS
int uploaders
int interestedAndChoking
static final int RATE_DEPTH
final java.util.List<Peer> peers
volatile int peerCount
public I2PSnarkUtil _util
public java.lang.String trackerProblems
public int trackerSeenPeers
Constructor Detail |
---|
public PeerCoordinator(I2PSnarkUtil util, byte[] id, MetaInfo metainfo, Storage storage, CoordinatorListener listener, Snark torrent)
Method Detail |
---|
public void setWantedPieces()
public Storage getStorage()
public CoordinatorListener getListener()
public java.util.List<Peer> peerList()
public byte[] getID()
public boolean completed()
public int getPeerCount()
public int getPeers()
public long getLeft()
public long getUploaded()
public long getDownloaded()
public void setRateHistory(long up, long down)
public long getDownloadRate()
public long getUploadRate()
public long getCurrentUploadRate()
public MetaInfo getMetaInfo()
public boolean needPeers()
public boolean halted()
public void halt()
public void connected(Peer peer)
PeerListener
connected
in interface PeerListener
peer
- the Peer that just got connected.public boolean addPeer(Peer peer)
void unchokePeer()
public byte[] getBitMap()
public boolean gotHave(Peer peer, int piece)
gotHave
in interface PeerListener
peer
- the Peer that got the message.piece
- the piece number that the per just got.
public boolean gotBitField(Peer peer, BitField bitfield)
gotBitField
in interface PeerListener
peer
- the Peer that got the message.bitfield
- a BitField containing the pieces that the other
side has.
public int wantPiece(Peer peer, BitField havePieces)
wantPiece
in interface PeerListener
peer
- the Peer that will be asked to provide the piece.havePieces
- a BitField containing the pieces that the other
side has.
public byte[] gotRequest(Peer peer, int piece, int off, int len)
gotRequest
in interface PeerListener
peer
- the Peer that wants the piece.piece
- the piece number requested.off
- byte offset into the piece.len
- length of the chunk requested.
public void uploaded(Peer peer, int size)
uploaded
in interface PeerListener
peer
- the Peer to which size bytes where uploaded.size
- the number of bytes that where uploaded.public void downloaded(Peer peer, int size)
downloaded
in interface PeerListener
peer
- the Peer from which size bytes where downloaded.size
- the number of bytes that where downloaded.public boolean gotPiece(Peer peer, int piece, byte[] bs)
gotPiece
in interface PeerListener
peer
- the Peer that got the piece.piece
- the piece number received.bs
- the byte array containing the piece.
public void gotChoke(Peer peer, boolean choke)
PeerListener
gotChoke
in interface PeerListener
peer
- the Peer that got the message.choke
- true when the peer got a choke message, false when
the peer got an unchoke message.public void gotInterest(Peer peer, boolean interest)
PeerListener
gotInterest
in interface PeerListener
peer
- the Peer that got the message.interest
- true when the peer got a interested message, false when
the peer got an uninterested message.public void disconnected(Peer peer)
PeerListener
disconnected
in interface PeerListener
peer
- the Peer that just got disconnected.public void removePeerFromPieces(Peer peer)
public void savePeerPartial(PeerState state)
PeerListener
savePeerPartial
in interface PeerListener
state
- the PeerState for the peerpublic Request getPeerPartial(BitField havePieces)
getPeerPartial
in interface PeerListener
havePieces
- the have-pieces bitmask for the peer
public void markUnrequested(Peer peer)
markUnrequested
in interface PeerListener
peer
- the peer that is disconnectingpublic int allowedUploaders()
public boolean overUpBWLimit()
public boolean overUpBWLimit(long total)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |