Package-level declarations
Types
A datagram (host, port) source and sink. This is the seam consumers (DHT, UDP trackers, uTP) program against. UdpSocket is the real implementation; a demultiplexer (see UtpSocketManager) hands out virtual transports over one shared socket, the way libtorrent's session_impl routes one listen socket to uTP, DHT and trackers.
A resolved IGD control endpoint: the absolute SOAP control URL and the service type (WANIPConnection/WANPPPConnection) to use as the SOAP namespace and SOAPAction prefix. The engine caches this after Upnp.discoverIgd / Upnp.describe.
One local network interface address. This is the slice of libtorrent's ip_interface (enum_net.hpp) a client actually uses: pick a bind address, learn the LAN address for UPnP, skip loopback.
A deterministic microsecond source for tests. Each call returns the previous value plus one. It is not a wall clock and it is not a monotonic clock.
A real monotonic microsecond clock. Use this for every production UtpStream.
A NAT-PMP client: the live half of libtorrent's natpmp (src/natpmp.cpp), speaking the NAT-PMP (RFC 6886) wire format over the proven UdpSocket. The fixed-layout packet build/parse lives in NatPmpCodec; this class owns the UDP round-trip to the gateway (always port 5351, the NAT-PMP server port udp::endpoint(*route, 5351) in natpmp::start) and the retransmission loop.
The socket runtime. One SelectorManager drives all non-blocking I/O, the way a single Boost.Asio io_context does in libtorrent. ktor-network's selector is coroutine-native, so there are no callbacks: a read simply suspends.
A proxy connectTcp tunnels outbound dials through. See Socks5Config, HttpProxyConfig.
Raised when a proxy negotiation fails.
The decoded origin and payload of an inbound SOCKS5-wrapped UDP datagram (see Socks5UdpAssociation.unwrap).
A TCP connection to a peer (or HTTP tracker). Thin coroutine wrapper over a ktor Socket exposing the two operations the wire protocol needs: read exactly N bytes, and write a frame. Replaces the bespoke async read/write buffers in libtorrent's peer_connection.
A real UDP socket, for UDP trackers, the DHT, and uTP.
The handle returned by Upnp.mapTcpAndUdp: enough state for the engine to refresh the lease (re-call mapTcpAndUdp before leaseSeconds elapses) and to tear the mapping down (Upnp.removeMapping) on shutdown.
Raised by UtpStream.readExactly when the peer closes the stream early.
uTP extension-header kinds. From libtorrent's utp_extensions_t:
A parsed/parseable uTP header: the faithful Kotlin analogue of libtorrent's struct utp_header (include/libtorrent/aux_/utp_stream.hpp).
Raised when the peer sends ST_RESET.
Demultiplexes one UDP socket across many UtpStreams: the port of libtorrent's utp_socket_manager (src/utp_socket_manager.cpp) plus the session-level routing that shares the listen socket between uTP and the DHT.
uTP (Micro Transport Protocol, BEP-29) connection over a single UdpSocket to one remote (host, port). This is a faithful core port of libtorrent's utp_socket_impl (src/utp_stream.cpp), with enough state machine to actually move bytes. It implements ByteStream so a PeerConnection runs over uTP with no changes (the same seam TcpConnection.asByteStream satisfies).
Properties
Functions
Build a full uTP packet: header (its UtpHeader.extension is overridden to advertise a SACK iff sack is non-null), then, if present, the SACK extension TLV (next_ext=0, len, bitmask), then payload.
Open a TCP connection to host:port, tunnelling through NetworkRuntime.proxy if set.
Android interface enumeration via NetworkInterface (same as JVM).
Enumerate local interface addresses: a port of enum_net() (enum_net.cpp). This is an expect/actual declaration because listing interfaces is a per-OS syscall with no portable KMP API (NetworkInterface on JVM/Android, getifaddrs on Apple).
Apple interface enumeration.
JVM/desktop interface enumeration via NetworkInterface.
Parse a datagram into a UtpPacket, walking the extension chain to find a SACK bitmask and to locate the payload. Returns null on any malformed framing (short header, unknown type, truncated extension). These are the same rejects libtorrent applies in incoming_packet().
The non-loopback IPv4 addresses: the usual candidates to advertise/bind.