|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.i2p.client.streaming.Packet
public class Packet
Contain a single packet transferred as part of a streaming connection. The data format is as follows:
sendStreamId
[4 byte value]receiveStreamId
[4 byte value]sequenceNum
[4 byte unsigned integer]ackThrough
[4 byte unsigned integer]NACKs
resendDelay
[1 byte integer]The flags field above specifies some metadata about the packet, and in turn may require certain additional data to be included. The flags are as follows (with any data structures specified added to the options area in the given order):
FLAG_SYNCHRONIZE
: no option dataFLAG_CLOSE
: no option dataFLAG_RESET
: no option dataFLAG_SIGNATURE_INCLUDED
: Signature
FLAG_SIGNATURE_REQUESTED
: no option dataFLAG_FROM_INCLUDED
: Destination
FLAG_DELAY_REQUESTED
: 1 byte integerFLAG_MAX_PACKET_SIZE_INCLUDED
: 2 byte integerFLAG_PROFILE_INTERACTIVE
: no option dataIf the signature is included, it uses the Destination's DSA key to sign the entire header and payload with the space in the options for the signature being set to all zeroes.
If the sequenceNum is 0 and the SYN is not set, this is a plain ACK packet that should not be ACKed
Field Summary | |
---|---|
static int |
DEFAULT_MAX_SIZE
|
static int |
FLAG_CLOSE
The sender of this packet will not be sending any more payload data. |
static int |
FLAG_DELAY_REQUESTED
This packet includes an explicit request for the recipient to delay sending any packets with data for a given amount of time. |
static int |
FLAG_ECHO
If set, this packet is a ping (if sendStreamId is set) or a ping reply (if receiveStreamId is set). |
static int |
FLAG_FROM_INCLUDED
This packet includes the full I2P destination of the packet's sender. |
static int |
FLAG_MAX_PACKET_SIZE_INCLUDED
This packet includes a request that the recipient not send any subsequent packets with payloads greater than a specific size. |
static int |
FLAG_NO_ACK
If set, this packet doesn't really want to ack anything |
static int |
FLAG_PROFILE_INTERACTIVE
If set, this packet is travelling as part of an interactive flow, meaning it is more lag sensitive than throughput sensitive. |
static int |
FLAG_RESET
This packet is being sent to signify that the socket does not exist (or, if in response to an initial synchronize packet, that the connection was refused). |
static int |
FLAG_SIGNATURE_INCLUDED
This packet contains a DSA signature from the packet's sender. |
static int |
FLAG_SIGNATURE_REQUESTED
This packet wants the recipient to include signatures on subsequent packets sent to the creator of this packet. |
static int |
FLAG_SYNCHRONIZE
This packet is creating a new socket connection (if the receiveStreamId is STREAM_ID_UNKNOWN) or it is acknowledging a request to create a connection and in turn is accepting the socket. |
static int |
MAX_PAYLOAD_SIZE
|
static long |
MAX_STREAM_ID
|
static long |
STREAM_ID_UNKNOWN
The receiveStreamId will be set to this when the packet doesn't know what ID will be assigned by the remote peer (aka this is the initial synchronize packet) |
Constructor Summary | |
---|---|
Packet()
|
Method Summary | |
---|---|
ByteArray |
acquirePayload()
|
protected java.lang.StringBuffer |
formatAsString()
|
long |
getAckThrough()
The highest packet sequence number that received on the receiveStreamId. |
long[] |
getNacks()
List of packet sequence numbers below the getAckThrough() value have not been received. |
int |
getOptionalDelay()
How many milliseconds the sender of this packet wants the recipient to wait before sending any more data (only valid if the flag for it is set) |
Destination |
getOptionalFrom()
the sender of the packet (only included if the flag for it is set) |
int |
getOptionalMaxSize()
What is the largest payload the sender of this packet wants to receive? |
Signature |
getOptionalSignature()
the signature on the packet (only included if the flag for it is set) |
ByteArray |
getPayload()
get the actual payload of the message. |
int |
getPayloadSize()
|
long |
getReceiveStreamId()
stream the replies should be sent on. |
int |
getResendDelay()
How long is the creator of this packet going to wait before resending this packet (if it hasn't yet been ACKed). |
long |
getSendStreamId()
what stream do we send data to the peer on? |
long |
getSequenceNum()
0-indexed sequence number for this Packet in the sendStream |
boolean |
isFlagSet(int flag)
is a particular flag set on this packet? |
void |
readPacket(byte[] buffer,
int offset,
int length)
Read the packet from the buffer (starting at the offset) and return the number of bytes read. |
void |
releasePayload()
|
void |
setAckThrough(long id)
|
void |
setFlag(int flag)
|
void |
setFlag(int flag,
boolean set)
|
void |
setFlags(int flags)
|
void |
setNacks(long[] nacks)
|
void |
setOptionalDelay(int delayMs)
|
void |
setOptionalFrom(Destination from)
|
void |
setOptionalMaxSize(int numBytes)
|
void |
setOptionalSignature(Signature sig)
|
void |
setPayload(ByteArray payload)
|
void |
setReceiveStreamId(long id)
|
void |
setResendDelay(int numSeconds)
|
void |
setSendStreamId(long id)
|
void |
setSequenceNum(long num)
|
(package private) static java.lang.String |
toId(long id)
|
java.lang.String |
toString()
|
boolean |
verifySignature(I2PAppContext ctx,
Destination from,
byte[] buffer)
Determine whether the signature on the data is valid. |
int |
writePacket(byte[] buffer,
int offset)
Write the packet to the buffer (starting at the offset) and return the number of bytes written. |
int |
writeSignedPacket(byte[] buffer,
int offset,
I2PAppContext ctx,
SigningPrivateKey key)
Sign and write the packet to the buffer (starting at the offset) and return the number of bytes written. |
int |
writtenSize()
how large would this packet be if we wrote it |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final long STREAM_ID_UNKNOWN
public static final long MAX_STREAM_ID
public static final int FLAG_SYNCHRONIZE
public static final int FLAG_CLOSE
public static final int FLAG_RESET
public static final int FLAG_SIGNATURE_INCLUDED
public static final int FLAG_SIGNATURE_REQUESTED
public static final int FLAG_FROM_INCLUDED
public static final int FLAG_DELAY_REQUESTED
public static final int FLAG_MAX_PACKET_SIZE_INCLUDED
public static final int FLAG_PROFILE_INTERACTIVE
public static final int FLAG_ECHO
public static final int FLAG_NO_ACK
public static final int DEFAULT_MAX_SIZE
public static final int MAX_PAYLOAD_SIZE
Constructor Detail |
---|
public Packet()
Method Detail |
---|
public long getSendStreamId()
public void setSendStreamId(long id)
public long getReceiveStreamId()
public void setReceiveStreamId(long id)
public long getSequenceNum()
public void setSequenceNum(long num)
public long getAckThrough()
public void setAckThrough(long id)
public long[] getNacks()
public void setNacks(long[] nacks)
public int getResendDelay()
public void setResendDelay(int numSeconds)
public ByteArray getPayload()
public void setPayload(ByteArray payload)
public int getPayloadSize()
public void releasePayload()
public ByteArray acquirePayload()
public boolean isFlagSet(int flag)
public void setFlag(int flag)
public void setFlag(int flag, boolean set)
public void setFlags(int flags)
public Signature getOptionalSignature()
public void setOptionalSignature(Signature sig)
public Destination getOptionalFrom()
public void setOptionalFrom(Destination from)
public int getOptionalDelay()
public void setOptionalDelay(int delayMs)
public int getOptionalMaxSize()
public void setOptionalMaxSize(int numBytes)
public int writePacket(byte[] buffer, int offset) throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if there is data missing or otherwise b0rkedpublic int writtenSize() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public void readPacket(byte[] buffer, int offset, int length) throws java.lang.IllegalArgumentException
buffer
- packet buffer containing the dataoffset
- index into the buffer to start readignlength
- how many bytes within the buffer past the offset are
part of the packet?
java.lang.IllegalArgumentException
- if the data is b0rkedpublic boolean verifySignature(I2PAppContext ctx, Destination from, byte[] buffer)
public int writeSignedPacket(byte[] buffer, int offset, I2PAppContext ctx, SigningPrivateKey key) throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if there is data missing or otherwise b0rkedpublic java.lang.String toString()
toString
in class java.lang.Object
protected java.lang.StringBuffer formatAsString()
static final java.lang.String toId(long id)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |