UdpSocket

class UdpSocket(socket: BoundDatagramSocket, socks5: Socks5UdpAssociation? = null) : DatagramTransport

A real UDP socket, for UDP trackers, the DHT, and uTP.

When socks5 is set, this socket is proxied: outbound datagrams are SOCKS5-wrapped (RFC 1928 §7) and physically sent to the proxy's UDP relay, and inbound datagrams are unwrapped so the caller sees the true origin (host, port). The destination IP never leaves the host in clear. This is the seam that routes the engine's shared uTP/DHT/UDP-tracker socket through the proxy without touching UtpSocketManager/UtpStream (they keep sending/receiving on a UdpSocket). Mirrors libtorrent's udp_socket, which wraps/unwraps via its embedded socks5 helper on the exact same datagrams when a SOCKS5 proxy with an open UDP association is configured.

When socks5 is null the behaviour is byte-identical to a plain unproxied socket.

Constructors

Link copied to clipboard
constructor(socket: BoundDatagramSocket, socks5: Socks5UdpAssociation? = null)

Properties

Link copied to clipboard
open override val localPort: Int

The actually-bound local port (useful when bound to port 0).

Functions

Link copied to clipboard
open override fun close()

Close the socket. For a proxied socket this also tears down the SOCKS5 association (its kept- alive control connection, since the proxy drops the relay when it closes anyway), so an ephemeral proxied socket leaks nothing. The association's close() re-closes this same underlying socket, which is harmless. A direct socket just closes the socket.

Link copied to clipboard
open suspend override fun receive(): UdpPacket

Suspend until a datagram arrives; return its bytes and sender host/port.

Link copied to clipboard
open suspend override fun send(data: ByteArray, host: String, port: Int)

Send data to host:port.