UtpHeader

data class UtpHeader(val type: UtpType, val version: Int = UTP_VERSION, val extension: Int = UtpExtension.NONE, val connectionId: Int, val timestampMicros: Long, val timestampDiffMicros: Long, val wndSize: Long, val seqNr: Int, val ackNr: Int)

A parsed/parseable uTP header: the faithful Kotlin analogue of libtorrent's struct utp_header (include/libtorrent/aux_/utp_stream.hpp).

libtorrent stores each field in a big_endian_int, which casts a raw network buffer in place; here we hold host-order values and (de)serialise explicitly in encode/decode. All wrap-around-counter fields (seqNr, ackNr, connectionId) are kept as 16-bit unsigned values in an Int; the 32-bit fields (timestampMicros, timestampDiffMicros, wndSize) likewise use a Long so the unsigned range survives. Producing the on-wire bytes only ever uses the low 16/32 bits, so over-large values truncate exactly as the C++ does.

Constructors

Link copied to clipboard
constructor(type: UtpType, version: Int = UTP_VERSION, extension: Int = UtpExtension.NONE, connectionId: Int, timestampMicros: Long, timestampDiffMicros: Long, wndSize: Long, seqNr: Int, ackNr: Int)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val ackNr: Int

16-bit sequence number the sender has received in order (cumulative ack).

Link copied to clipboard

16-bit connection id (send_id for non-SYN, recv_id for ST_SYN).

Link copied to clipboard

First extension chain id (0 == none). See UtpExtension.

Link copied to clipboard
val seqNr: Int

16-bit sequence number of this packet.

Link copied to clipboard

Difference between our recv time and their send time; 0 == no sample yet.

Link copied to clipboard

Sender's clock in microseconds (32-bit, may be a synthetic counter).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Bytes of receive-window space the sender currently has free.

Functions

Link copied to clipboard

Serialise just the 20-byte header (no extension body, no payload). The type_ver byte packs (type.code << 4) | version, exactly like h->type_ver = (ST_SYN << 4) | 1 in send_syn().