Package-level declarations

Types

Link copied to clipboard
class Bitfield

A bitfield of arbitrary length. This is a pure-Kotlin port of libtorrent's bitfield (bitfield.hpp). It tracks which pieces a peer has, and which we have.

Link copied to clipboard

Holds an N-bit digest (or any fixed-size bit sequence). This is the pure-Kotlin port of libtorrent's digest32<N> (sha1_hash.hpp). In libtorrent this is used for info-hashes, piece hashes, peer IDs, DHT node IDs, etc.

Link copied to clipboard
object Hex

Hexadecimal encode/decode. Pure Kotlin (no platform codecs), so it works in commonMain across every target. Port of libtorrent's aux::to_hex / aux::from_hex (hex.cpp).

Link copied to clipboard
typealias PeerId = Sha1Hash

A 20-byte BitTorrent peer id. This is the pure-Kotlin port of libtorrent's using peer_id = sha1_hash; (peer_id.hpp). Structurally it is just a 20-byte digest, so it aliases Sha1Hash exactly as upstream aliases sha1_hash.

Link copied to clipboard
typealias Sha1Hash = Digest32

A 160-bit digest: info-hash v1, piece hash, peer ID, DHT node ID.

Link copied to clipboard
typealias Sha256Hash = Digest32

A 256-bit digest: info-hash v2 and BitTorrent v2 merkle nodes.

Link copied to clipboard
object Version

KiteTorrent version info, tracking the libtorrent release it is ported from (version.hpp). The protocol-level peer-id prefix follows libtorrent's convention of "-LT-" style fingerprints.

Properties

Link copied to clipboard

KiteTorrent's two-character client tag, stamped into generated peer-ids.

Link copied to clipboard
const val PEER_ID_SIZE: Int

The length of a peer id in bytes (== SHA-1 width).

Functions

Link copied to clipboard

KiteTorrent's default fingerprint, "-KT0010-": tag "KT" at version Version.MAJOR.Version.MINOR.Version.TINY (0.0.1) with tag 0.

Link copied to clipboard
fun generateFingerprint(clientTag: String, major: Int, minor: Int = 0, tiny: Int = 0, tag: Int = 0): String

Build an 8-character client fingerprint string in libtorrent's Azureus style, porting generate_fingerprint(std::string name, int major, int minor, int revision, int tag).

Link copied to clipboard
fun generatePeerId(fingerprint: String, randomTail: ByteArray): PeerId

Deterministic peer-id construction: place the fingerprint at the front and use the caller-supplied randomTail for the remaining bytes verbatim. This is the testable counterpart of generatePeerId. It consults no random number generator.

fun generatePeerId(fingerprint: String = defaultFingerprint(), random: Random = Random.Default): PeerId

Generate a 20-byte peer id whose leading bytes are the client fingerprint and whose remaining bytes are URL-safe random characters. This is the port of aux::generate_peer_id(session_settings const&) (src/generate_peer_id.cpp).

Link copied to clipboard

Encode a single version component as one fingerprint character. This is the port of the anonymous version_to_char(int v) in src/fingerprint.cpp.