UtpSocketManager

class UtpSocketManager(socket: UdpSocket, scope: CoroutineScope)

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.

libtorrent runs uTP, the DHT and UDP trackers over the same listen socket; session_impl::on_udp_packet sniffs each datagram and hands uTP-shaped ones (incoming_packet) to the manager, which routes by connection id, turning ST_SYNs with no matching stream into new incoming connections. This class does the same:

Connection-id arithmetic (see UtpStream): an active open with id I sends on I and receives on I-1; its SYN advertises I-1. The passive side derives send C/receive C+1 from the SYN's id C. Inbound routing therefore keys on the receiver's id: I-1 for streams we opened, C+1 for accepted ones.

Constructors

Link copied to clipboard
constructor(socket: UdpSocket, scope: CoroutineScope)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The local UDP port (== the engine's listen port when bound there).

Link copied to clipboard

The manager calls this (in a fresh coroutine) for each accepted inbound uTP connection, once its SYN is processed. The engine then reads the BitTorrent handshake off the stream and routes by info-hash, exactly like a TCP accept.

Functions

Link copied to clipboard
fun close()

Close the underlying socket; the receive loop then winds down.

Link copied to clipboard
suspend fun connect(host: String, port: Int): UtpStream

Actively open a uTP connection to host:port (suspends until connected).

Link copied to clipboard

A virtual DatagramTransport carrying every non-uTP datagram, for the DHT. close() is a no-op, because the manager owns the real socket.

Link copied to clipboard
suspend fun disconnect(stream: UtpStream)

Close stream and drop its routing entry.

Link copied to clipboard
suspend fun numStreams(): Int

Live stream count (for tests/observability).

Link copied to clipboard
fun start(): Job

Start the receive/dispatch loop.