PeerAddress

A parsed IP address: the pure-Kotlin stand-in for libtorrent's libtorrent::address (Boost.Asio) inside the peer-list port.

KiteTorrent v0 deliberately keeps a peer's address as a host string (see TorrentPeer.host); there are no socket types in commonMain. But several faithful behaviours genuinely need the address in its numeric, network-byte-order form: BEP 40 peer priority (peerPriority), local-address preference (isLocal), IPv6 link-local rejection, and the canonical address ordering that keeps the peer list sorted. PeerAddress provides exactly that: it parses a dotted-quad / colon-hex literal into its raw bytes and exposes the predicates those behaviours require, and nothing more.

This class understands only numeric literals (it never resolves DNS, which is a platform concern). parseOrNull returns null for anything it cannot parse as a literal IPv4 or IPv6 address, and callers treat such hosts as opaque.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

the address in network byte order: 4 bytes for IPv4, 16 for IPv6. The array is owned by this instance and must not be mutated.

Link copied to clipboard

True if this address is "local" in the sense of aux::is_local(address const&) (src/ip_helpers.cpp). Local peers are always tried first in comparePeer.

Link copied to clipboard

True for the "unspecified" / any address (0.0.0.0 or ::). This is the analogue of comparing against a default-constructed address. libtorrent's add_peer ignores such endpoints.

Link copied to clipboard

True if this is an IPv4 (4-byte) address.

Link copied to clipboard

True if this is an IPv6 (16-byte) address.

Link copied to clipboard

True for an IPv6 link-local address (fe80::/10): the port of address_v6::is_link_local. libtorrent refuses to add such peers in peer_list::add_peer because they require a scope/interface to be usable. Always false for IPv4.

Functions

Link copied to clipboard
open operator override fun compareTo(other: PeerAddress): Int

Total ordering over addresses matching address::operator<: IPv4 sorts before IPv6 (fewer bytes first), and within a family the comparison is the unsigned lexicographic order of the network-byte-order bytes. This is the ordering PeerList keeps its peer vector in.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int