public abstract class ProtocolP2PPacket<T extends Payload>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected Payload |
payload |
private static byte |
PROTOCOL_VERSION |
protected byte |
version |
protected static int |
VERSION_POSITION |
Modifier | Constructor and Description |
---|---|
protected |
ProtocolP2PPacket(byte[] packet)
Construct a packet from byte[], subclasses must overwrite this constructor.
|
protected |
ProtocolP2PPacket(java.lang.Object socket)
Receive a request, subclasses must overwrite this constructor.
|
|
ProtocolP2PPacket(T payload)
Constructor with payload parameter (typically used when sending Packet).
|
Modifier and Type | Method and Description |
---|---|
protected void |
checkProtocolVersion()
Used to check protocol version when a Packet is constructed from bytes[].
|
abstract HostItem |
getHostItem()
Get hostItem of the sender
|
Payload |
getPayload()
Returns Payload associated with the Packet.
|
abstract ProtocolP2PPacket<?> |
receiveResponse()
Receive a response
|
abstract void |
sendRequest(java.lang.Object socket)
Send a request
|
abstract <U extends ProtocolP2PPacket<?>> |
sendResponse(U response)
Send a response
|
private static final byte PROTOCOL_VERSION
protected static final int VERSION_POSITION
protected byte version
protected Payload payload
public ProtocolP2PPacket(T payload)
payload
- the payload associated with the Packet to sendprotected ProtocolP2PPacket(java.lang.Object socket) throws TransmissionError, ProtocolError, VersionError, InternalError, SizeError, java.io.IOException, SocketClosed
socket
- socket used to get the requestTransmissionError
ProtocolError
VersionError
InternalError
SizeError
java.io.IOException
SocketClosed
protected ProtocolP2PPacket(byte[] packet) throws TransmissionError, ProtocolError, VersionError, InternalError, SizeError
packet
- Packet receivedTransmissionError
ProtocolError
VersionError
InternalError
SizeError
public abstract void sendRequest(java.lang.Object socket) throws InternalError, java.io.IOException, SocketClosed
socket
- Socket used to send packet.InternalError
java.io.IOException
SocketClosed
public abstract <U extends ProtocolP2PPacket<?>> void sendResponse(U response) throws InternalError, java.io.IOException, SocketClosed
response
- Response to send.InternalError
java.io.IOException
SocketClosed
public abstract HostItem getHostItem() throws InternalError
InternalError
public abstract ProtocolP2PPacket<?> receiveResponse() throws EmptyFile, NotFound, NotATracker, EmptyDirectory, InternalRemoteError, VersionRemoteError, ProtocolRemoteError, TransmissionError, ProtocolError, VersionError, InternalError, SizeError, java.io.IOException, SocketClosed, UnknownHost
public Payload getPayload()
protected void checkProtocolVersion() throws VersionError
VersionError