MagnetLink

class MagnetLink(val infoHashV1: Sha1Hash?, val infoHashV2: Sha256Hash?, val displayName: String?, val trackers: List<String>, val trackerTiers: List<Int>, val webSeeds: List<String>, val peers: List<String>, val dhtNodes: List<Pair<String, Int>>, val selectOnly: Set<Int>?)

The information extracted from a magnet: URI: the pure-Kotlin counterpart of the subset of libtorrent's add_torrent_params that parseMagnetUri fills in (src/magnet_uri.cpp, parse_magnet_uri).

libtorrent parses a magnet link straight into an add_torrent_params; KiteTorrent has no session/add_torrent_params yet, so the parsed fields are collected into this dedicated, immutable struct. Every field maps 1:1 onto an add_torrent_params member:

  • infoHashV1 / infoHashV2info_hashes.v1 / info_hashes.v2

  • displayNamename (from the dn parameter)

  • trackers / trackerTierstrackers / tracker_tiers (from tr)

  • webSeedsurl_seeds (from ws)

  • peerspeers (from x.pe); kept as the raw host:port text since KiteTorrent has no endpoint type in commonMain

  • dhtNodesdht_nodes (from dht)

  • selectOnly ← the indices the so parameter marks for download (see below)

The on-the-wire forms of the BitTorrent URN schemes (BEP 9 / BEP 53):

  • xt=urn:btih:<hash> where <hash> is either the 40-character lowercase/upper hex of the 20-byte SHA-1 info-hash, or its 32-character RFC 4648 base32 encoding.

  • xt=urn:btmh:1220<hash> (BEP 52) where 1220 is the multihash prefix for "sha2-256, 32 bytes" and <hash> is the 64-character hex of the v2 info-hash.

Constructors

Link copied to clipboard
constructor(infoHashV1: Sha1Hash?, infoHashV2: Sha256Hash?, displayName: String?, trackers: List<String>, trackerTiers: List<Int>, webSeeds: List<String>, peers: List<String>, dhtNodes: List<Pair<String, Int>>, selectOnly: Set<Int>?)

Properties

Link copied to clipboard

DHT bootstrap nodes from dht parameters, as host to port pairs.

Link copied to clipboard

Display name from the (URL-decoded) dn parameter, or null if absent.

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

v1 info-hash (SHA-1) from xt=urn:btih:, or null if the link had no v1 URN.

Link copied to clipboard

v2 info-hash (SHA-256) from xt=urn:btmh:1220…, or null if no v2 URN.

Link copied to clipboard

Peers from x.pe parameters, as their raw host:port text (e.g. 1.2.3.4:6881 or [::1]:6881). libtorrent parses these into tcp::endpoints; with no endpoint type available in commonMain the textual form is preserved verbatim.

Link copied to clipboard

The set of file indices selected for download by the so (select-only) parameter, or null when no valid so parameter was present. When non-null, every file not in this set is to be skipped (libtorrent expresses this by setting default_dont_download and giving the listed indices default_priority).

Link copied to clipboard

Tracker URLs from the tr parameters, URL-decoded and validated, in link order.

Link copied to clipboard

Tier index assigned to each tracker, aligned with trackers. libtorrent assigns a strictly increasing tier to every accepted tr (each tracker in its own tier).

Link copied to clipboard

Web seed URLs from the ws parameters (BEP 19), URL-decoded.

Functions

Link copied to clipboard

The canonical info-hash hex for display/lookups: the v2 hash when present (it is the stronger identity), otherwise the v1 hash, or "" if somehow neither is set.

Link copied to clipboard
open override fun toString(): String