Packet

class Packet(    val payload: ByteArray,     var sequenceNumber: UShort,     var acknowledgeSequenceNumber: UShort? = null,     var expirationTime: Instant = Instant.now())

Represents a data packet that carries the specified payload. It has the specified sequenceNumber and optionally acknowledges the specified acknowledgeSequenceNumber to the remote peer. The specified expirationTime indicates when the packet is due for (re)transmission.

The sequenceNumber is the number of bytes send prior to this packet and wraps around the 16bit unsigned integer boundary. It is used to let the remote know in which order to put incoming packets together and to know if there are any holes between the received packets.

When a packet is received the other side should acknowledge all packets received in sequence by sending back a packet with the highest sequenceNumber received in order, without holes, plus the size of the payload of that packet.

Initially the expirationTime will be the current time, indicating that the packet should be send immediately. After sending it is typically incremented by the send timeout.

Constructors

Link copied to clipboard
fun Packet(    payload: ByteArray,     sequenceNumber: UShort,     acknowledgeSequenceNumber: UShort? = null,     expirationTime: Instant = Instant.now())

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
var acknowledgeSequenceNumber: UShort? = null
Link copied to clipboard
var expirationTime: Instant
Link copied to clipboard
val payload: ByteArray
Link copied to clipboard
var sequenceNumber: UShort

Functions

Link copied to clipboard
fun getSequenceForAcknowledgement(): UShort

Returns the sequence number that should be used to acknowledge this packet.

Link copied to clipboard
fun isAcknowledgedBy(acknowledgementSequenceNumber: UShort): Boolean

Returns true if this packet is acknowledged by the specified acknowledgeSequenceNumber. Note that wrap around of the sequence numbers is taken into account. It is assumed that the transfer window is small enough that much less than half the sequence number space if ever in use at any point in time.

Link copied to clipboard
fun toByteArray(): ByteArray

Encodes the packet to a ByteArray.