|
||||||||||
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 | |
---|---|
(package private) static long |
CHECK_PERIOD
|
(package private) int |
interestedAndChoking
External use by PeerCheckerTask only. |
(package private) static int |
MAX_UPLOADERS
|
(package private) MetaInfo |
metainfo
External use by PeerMonitorTask only. |
(package private) Queue<Peer> |
peers
synchronize on this when changing peers or downloaders. |
(package private) static int |
RATE_DEPTH
|
(package private) Storage |
storage
External use by PeerMonitorTask only. |
(package private) int |
uploaders
Approximation of the number of current uploaders. |
Constructor Summary | |
---|---|
PeerCoordinator(I2PSnarkUtil util,
byte[] id,
byte[] infohash,
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. |
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()
|
byte[] |
getInfoHash()
|
long |
getLeft()
Returns how many bytes are still needed to get the complete file. |
MetaInfo |
getMetaInfo()
|
String |
getName()
|
PartialPiece |
getPartialPiece(Peer peer,
BitField havePieces)
Return partial piece to the PeerState if it's still wanted and peer has it. |
int |
getPeerCount()
might be wrong |
int |
getPeers()
should be right |
(package private) Set<PeerID> |
getPEXPeers()
Called by TrackerClient |
(package private) static long |
getRate(long[] array)
|
Storage |
getStorage()
|
long |
getUploaded()
Returns the total number of uploaded bytes of all peers. |
int |
getUploaders()
|
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)
this does nothing but logging |
void |
gotExtension(Peer peer,
int id,
byte[] bs)
PeerListener callback |
boolean |
gotHave(Peer peer,
int piece)
Called when a have piece message is received. |
void |
gotInterest(Peer peer,
boolean interest)
Called when an interested message is received. |
void |
gotPeers(Peer peer,
List<PeerID> peers)
PeerListener callback |
boolean |
gotPiece(Peer peer,
int piece,
byte[] bs)
Returns false if the piece is no good (according to the hash). |
void |
gotPort(Peer peer,
int port)
PeerListener callback Tell the DHT to ping it, this will get back the node info |
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()
|
boolean |
needPeers()
|
boolean |
needPiece(Peer peer,
BitField havePieces)
Called when we are downloading from the peer and may need to ask for a new piece. |
boolean |
overUpBWLimit()
|
boolean |
overUpBWLimit(long total)
|
List<Peer> |
peerList()
|
void |
removePeerFromPieces(Peer peer)
Called when a peer is removed, to prevent it from being used in rarest-first calculations. |
void |
savePartialPieces(Peer peer,
List<PartialPiece> partials)
Save partial pieces on peer disconnection and hopefully restart it later. |
(package private) void |
sendPeers(Peer peer)
Send a PEX message to the peer, if he supports PEX. |
(package private) static void |
setRate(long val,
long[] array)
|
void |
setRateHistory(long up,
long down)
Push the total uploaded/downloaded onto a RATE_DEPTH deep stack |
void |
setStorage(Storage stg)
Sets the storage after transition out of magnet mode Snark calls this after we call gotMetaInfo() |
void |
setWantedPieces()
|
(package private) void |
unchokePeer()
|
void |
updatePiecePriorities()
Maps file priorities to piece priorities. |
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 |
---|
MetaInfo metainfo
Storage storage
static final long CHECK_PERIOD
static final int MAX_UPLOADERS
int uploaders
int interestedAndChoking
static final int RATE_DEPTH
final Queue<Peer> peers
Constructor Detail |
---|
public PeerCoordinator(I2PSnarkUtil util, byte[] id, byte[] infohash, MetaInfo metainfo, Storage storage, CoordinatorListener listener, Snark torrent)
metainfo
- null if in magnet modestorage
- null if in magnet modeMethod Detail |
---|
public void setWantedPieces()
public Storage getStorage()
public List<Peer> peerList()
public byte[] getID()
public String getName()
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)
static void setRate(long val, long[] array)
public long getDownloadRate()
public long getUploadRate()
public long getCurrentUploadRate()
static long getRate(long[] array)
public MetaInfo getMetaInfo()
public byte[] getInfoHash()
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 boolean gotHave(Peer peer, int piece)
PeerListener
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 void updatePiecePriorities()
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.
RuntimeException
- on IOE getting the datapublic 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.
RuntimeException
- on IOE saving the piecepublic void gotChoke(Peer peer, boolean choke)
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 savePartialPieces(Peer peer, List<PartialPiece> partials)
savePartialPieces
in interface PeerListener
peer
- partials, must include the zero-offset (empty) ones toopublic PartialPiece getPartialPiece(Peer peer, BitField havePieces)
getPartialPiece
in interface PeerListener
havePieces
- pieces the peer has, the rv will be one of these
public boolean needPiece(Peer peer, BitField havePieces)
needPiece
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 void gotExtension(Peer peer, int id, byte[] bs)
gotExtension
in interface PeerListener
peer
- the Peer that got the message.id
- the message IDbs
- the message payloadvoid sendPeers(Peer peer)
public void setStorage(Storage stg)
public void gotPort(Peer peer, int port)
gotPort
in interface PeerListener
peer
- the Peer that got the message.port
- the portpublic void gotPeers(Peer peer, List<PeerID> peers)
gotPeers
in interface PeerListener
peer
- the Peer that got the message.peers
- the peer IDs (dest hashes)Set<PeerID> getPEXPeers()
public int allowedUploaders()
public int getUploaders()
public boolean overUpBWLimit()
public boolean overUpBWLimit(long total)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |