Expand description
no_std + alloc download-engine core: BitTorrent v1/v2 (peer wire,
DHT, PEX, LSD, uTP, web seeds, UDP/HTTP trackers, magnet, SOCKS5) — plus
provable download receipts, a utility scheduler and a disk cache.
links::parse_link also parses eD2k / Thunder / QQDL / FlashGet /
IPFS / Kad / Baidu / Xunlei-Netdisk links into typed links::DownloadLink
values (parsing only — no fetch adapters for those protocols yet, see the
README protocol matrix). Transport is injected via platform::Host;
crypto is in-tree under crypto.
Re-exports§
pub use engine::Engine;pub use engine::EngineConfig;pub use engine::EngineEvent;pub use error::Error;pub use error::Result;pub use metainfo::InfoHash;pub use platform::Host;pub use platform::LogLevel;pub use platform::NetAddr;
Modules§
- bencode
- Bencode codec (BEP-3) with strict resource limits, for
.torrentmetainfo, tracker announce/scrape and DHT KRPC. Exposes a raw-range walker to capture the exactinfodict for infohash computation. - bitfield
- Compact bitset for piece availability and block accounting.
- consts
- Protocol constants.
- crypto
- In-tree cryptography (the engine may only link the four ecosystem
crates). Implemented from scratch,
no_std,unsafe-free, pinned against standard test vectors: - dht
- Kademlia DHT (BEP-5/42): pure
no_stdKRPC engine — routing table, transactions, announce tokens, iterative lookups. BEP-5 token auth forannounce_peer; iterativeget_peers/find_nodewith K-closest pruning. - disk_
cache - Write-back disk cache: blocks are buffered and flushed in large, offset-ordered coalesced batches (fewer writes/seeks); a piece hits stable storage before it is verified. Read-through serves seeding reads.
- engine
- The top-level engine: owns the host, all torrent sessions, the shared
disk cache and the DHT, and drives the non-blocking event loop. The host
calls
Engine::tickon a fixed cadence and drainsEngine::take_events. - error
- Unified error type for the TypeBit core.
- ffi
ffi - C ABI for the TypeBit engine — the language bridge.
- geo
- Best-effort IPv4 → country (ISO-3166 alpha-2) lookup for peer rows.
- host_
std std - OS-backed
Hostfor desktop/server builds (featurestd). - leech
- Anti-leech engine: client fingerprinting, per-peer reputation, reciprocity-aware choke scoring (tit-for-tat), snub handling, corrupt accountability with bans, optimistic unchoke rotation, anti-flap.
- links
- Unified download-link parsing.
parse_linkturns every mainstream URL format into a typedDownloadLink(magnet, eD2k, Xunlei, QQDL, FlashGet, IPFS/IPNS, Kad, HTTP(S)/FTP, Baidu/Xunlei Netdisk — Netdisks need host credentials).ContentIdgives cross-format content addressing. - lsd
- Local Service Discovery (LSD, BEP-14): announce our presence in active swarms to LAN neighbours over UDP multicast, and answer their announces — no internet tracker or DHT needed.
- magnet
- Magnet URI parsing (BEP-9 / BEP-53).
- metainfo
- Torrent metainfo: v1 (BEP-3), v2 (BEP-52) and hybrid parsing.
- monitoring
- Swarm availability monitoring (“the downloader as a measurement probe”):
treats the torrent as a time-varying replication graph and estimates
content recoverability
A(t, B) = Pr[obtain and verify all required pieces within budget B], producing an evidence-backedSwarmReport(JSON vianextjson) as early-warning for drifting content. - peer_id
- Peer id generation and client identification.
- pex
- Peer exchange (BEP-11 / BEP-11.1) — facade over the wire codec
(
crate::wire::PexMsg): adds swarm-level helpers for compact peer list encoding with flags. - picker
- Piece/block picker.
- piece
- Per-torrent piece/block state tracking: pieces of
piece_lengthbytes (last possibly shorter), each split into 16 KiB blocks. Tracks verified, partially-received, and in-flight block state. - platform
- The platform abstraction seam: the engine is written against
Host; a concrete implementation (std, Android/Kotlin, iOS/Swift, embedded) only provides ~15 primitives. Transports are non-blocking (Host::tcp_recvreturnsError::WouldBlock,tcp_sendmay take a partial prefix), so one engine drives hundreds of peers from a single thread. - portmap
- Port mapping for the listen port: NAT-PMP (RFC 6886) with UPnP IGD
(SSDP discovery + SOAP control) fallback. Allocation-bounded codecs plus
a time-driven state machine pumped once per tick; transport via the
Hostseam. NAT-PMP needs no HTTP; UPnP needsHost::http_post/Host::local_ip(a platform may leave them unsupported → clear failure, not guessing). Replies arrive as unicast UDP on the engine socket, routed here byPortMapManager::handle_datagram. - ratelimit
- Token-bucket byte rate limiting. One bucket per throttle point: the
engine keeps global upload/download buckets, each
TorrentSessionkeeps per-task buckets.0= unlimited. Refill from wall time (now_ms) so buckets stay correct at any tick cadence. - receipt
- Provable download & availability receipts.
- scheduler
- Semantic, utility-driven piece scheduler:
- session
- Per-torrent session: owns peer connections, piece/block bookkeeping, the
utility scheduler, tracker/DHT/PEX discovery, metadata fetching (magnet
links), receipts and the swarm monitor; talks outward via
SessionCtx. - socks
- SOCKS5 (RFC 1928) + username/password auth (RFC 1929) transport — the
anonymity seam for Tor (SOCKS5h :9050) and I2P (SOCKS :4444).
no_std, depends only oncrate::platform+crate::error. - state
- Session persistence with the ecosystem codecs: binary via
rustbinary, human vianextjson, wall-clock viatzcraft::Ticks. The host stores the produced bytes (file, KV store, mobile keychain). - swarm
- Peer connection state and wire-level bookkeeping.
- tracker
- Tracker protocol codecs: HTTP (BEP-3) announce/scrape URL construction
and bencoded parsing (compact + dict peer lists); UDP (BEP-15)
connect/announce/scrape builders and parsers. Transport is delegated to
the
crate::platform::Hostseam (http_get/udp_send/udp_recv). - trackerlist
- Built-in public tracker list (qBittorrent/BitComet compatible fallback),
used when a torrent declares no announce URLs and
crate::session::SessionConfig::use_default_trackersis set. - utp
- BEP-29 uTP — Micro Transport Protocol over UDP, with LEDBAT congestion
control (RFC 6817 style): yields bandwidth when the network is busy,
fills the pipe when idle. All I/O goes through
Host::udp_send, so it runs on every platform. Pureno_std + alloc, zerounsafe. - verify
- Piece hash verification, optionally offloaded to a
stdworker pool so the engine loop keeps pumping I/O while SHA-1 / SHA-256 runs on other cores. Underno_std,VerifyPoolis a no-op handle (inline verification). Both paths share the pureverify_piecefunction, so pooled and inline results are guaranteed identical. - wire
- Peer wire protocol (BEP-3) with extensions: BEP-6 fast (
have_all/have_none/suggest/reject/allowed_fast), BEP-10 extended handshake, BEP-9 metadata (ut_metadata), BEP-11 PEX (ut_pex), BEP-52 v2 bit. All codecs are allocation-bounded and reject malformed frames.