class PeerState extends Object implements DataLoader
Modifier and Type | Field and Description |
---|---|
(package private) BitField |
bitfield
the pieces the peer has.
|
(package private) boolean |
choked |
(package private) boolean |
choking |
(package private) PeerConnectionIn |
in |
(package private) boolean |
interested |
(package private) boolean |
interesting |
(package private) PeerListener |
listener
Fixme, used by Peer.disconnect() to get to the coordinator
|
(package private) PeerConnectionOut |
out |
static int |
PARTSIZE |
Constructor and Description |
---|
PeerState(Peer peer,
PeerListener listener,
MetaInfo metainfo,
PeerConnectionIn in,
PeerConnectionOut out) |
Modifier and Type | Method and Description |
---|---|
(package private) void |
addRequest()
Adds a new request to the outstanding requests list.
|
(package private) void |
allowedFastMessage(int piece)
BEP 6
Ignored for now
|
(package private) void |
bitfieldMessage(byte[] bitmap) |
(package private) void |
cancelMessage(int piece,
int begin,
int length) |
(package private) void |
cancelPiece(int piece)
Tell the other side that we are no longer interested in any of
the outstanding requests (if any) for this piece.
|
(package private) void |
chokeMessage(boolean choke) |
(package private) void |
extensionMessage(int id,
byte[] bs) |
(package private) Request |
getOutstandingRequest(int piece,
int begin,
int length)
Called when a piece message is being processed by the incoming
connection.
|
(package private) String |
getRequests()
debug
|
(package private) void |
haveMessage(boolean isAll)
BEP 6
|
(package private) void |
haveMessage(int piece) |
(package private) void |
havePiece(int piece)
We now have this piece.
|
(package private) void |
interestedMessage(boolean interest) |
(package private) boolean |
isRequesting(int piece)
Deprecated.
deadlocks
|
(package private) void |
keepAlive() |
(package private) void |
keepAliveMessage() |
ByteArray |
loadData(int piece,
int begin,
int length)
This is the callback that PeerConnectionOut calls
|
(package private) void |
pieceMessage(Request req)
Called when a full chunk (i.e.
|
(package private) void |
portMessage(int port)
Unused
|
(package private) void |
rejectMessage(int piece,
int begin,
int length)
BEP 6
If the peer rejects lower chunks but not higher ones, thus creating holes,
we won't figure it out and the piece will fail, since we don't currently
keep a chunk bitmap in PartialPiece.
|
(package private) void |
requestMessage(int piece,
int begin,
int length) |
(package private) void |
retransmitRequests() |
(package private) List<Request> |
returnPartialPieces()
Get partial pieces, give them back to PeerCoordinator.
|
(package private) void |
setChoking(boolean choke) |
(package private) void |
setInteresting(boolean interest) |
void |
setMetaInfo(MetaInfo meta)
Switch from magnet mode to normal mode.
|
(package private) void |
suggestMessage(int piece)
BEP 6
Treated as "have" for now
|
(package private) void |
unknownMessage(int type,
byte[] bs) |
(package private) void |
uploaded(int size)
Called when some bytes have left the outgoing connection.
|
final PeerListener listener
volatile boolean interesting
volatile boolean choking
volatile boolean interested
volatile boolean choked
BitField bitfield
final PeerConnectionIn in
final PeerConnectionOut out
public static final int PARTSIZE
PeerState(Peer peer, PeerListener listener, MetaInfo metainfo, PeerConnectionIn in, PeerConnectionOut out)
metainfo
- null if in magnet modevoid keepAliveMessage()
void chokeMessage(boolean choke)
void interestedMessage(boolean interest)
void haveMessage(int piece)
void bitfieldMessage(byte[] bitmap)
void requestMessage(int piece, int begin, int length)
public ByteArray loadData(int piece, int begin, int length)
loadData
in interface DataLoader
RuntimeException
- on IOE getting the datavoid uploaded(int size)
void pieceMessage(Request req)
Request getOutstandingRequest(int piece, int begin, int length)
List<Request> returnPartialPieces()
void cancelMessage(int piece, int begin, int length)
void extensionMessage(int id, byte[] bs)
public void setMetaInfo(MetaInfo meta)
meta
- non-nullvoid portMessage(int port)
void suggestMessage(int piece)
void haveMessage(boolean isAll)
isAll
- true for have_all, false for have_nonevoid rejectMessage(int piece, int begin, int length)
void allowedFastMessage(int piece)
void unknownMessage(int type, byte[] bs)
void havePiece(int piece)
void cancelPiece(int piece)
@Deprecated boolean isRequesting(int piece)
void addRequest()
By getOustandingRequest() when the first part of a chunk comes in By havePiece() when somebody got a new piece completed By chokeMessage() when we receive an unchoke By setInteresting() when we are now interested By PeerCoordinator.updatePiecePriorities()
void setInteresting(boolean interest)
void setChoking(boolean choke)
void keepAlive()
void retransmitRequests()
String getRequests()