Skip to main content

Crate typebit

Crate typebit 

Source
Expand description

no_std + alloc universal download engine: BitTorrent (v1/v2, DHT, PEX, web seeds), eD2k, Xunlei, IPFS, Kad, direct HTTP(S) — plus provable download receipts, a utility scheduler and a disk cache. 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 .torrent metainfo, tracker announce/scrape and DHT KRPC. Exposes a raw-range walker to capture the exact info dict for infohash computation.
bitfield
Compact bitset for piece availability and block accounting.
consts
Protocol constants.
crypto
In-tree cryptography for the TypeBit core.
dht
Kademlia DHT (BEP-5/42): pure no_std KRPC engine — routing table, transactions, announce tokens, iterative lookups. BEP-5 token auth for announce_peer; iterative get_peers/find_node with 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::tick on a fixed cadence and drains Engine::take_events.
error
Unified error type for the TypeBit core.
leech
Anti-leech engine: peer-client fingerprinting, per-peer reputation, reciprocity-aware choke scoring (tit-for-tat), snub handling, corrupt-block accountability with escalating bans, the optimistic unchoke rotation, and an anti-flap (hysteresis) rule.
links
Unified download-link parsing. parse_link turns every mainstream URL format into a typed DownloadLink (magnet, eD2k, Xunlei, QQDL, FlashGet, IPFS/IPNS, Kad, HTTP(S)/FTP, Baidu/Xunlei Netdisk — Netdisks need host credentials). ContentId gives cross-format content addressing.
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-backed SwarmReport (JSON via nextjson) 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_length bytes (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_recv returns Error::WouldBlock, tcp_send may take a partial prefix), so one engine drives hundreds of peers from a single thread.
portmap
Port mapping (firewall / NAT traversal) for the engine’s listen port: NAT-PMP (RFC 6886) with UPnP IGD (SSDP discovery + SOAP control) fallback.
ratelimit
Token-bucket byte rate limiting.
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 layer.
state
Session persistence with the ecosystem codecs: binary via rustbinary, human via nextjson, wall-clock via tzcraft::Ticks. The host stores the produced bytes (file, KV store, mobile keychain).
swarm
Peer connection state and wire-level bookkeeping.
tracker
Tracker protocol codecs.
trackerlist
Built-in public tracker list (qBittorrent/BitComet compatible fallback), used when a torrent declares no announce URLs and crate::session::SessionConfig::use_default_trackers is set.
verify
Piece hash verification, optionally offloaded to a std worker pool so the engine event loop keeps pumping peer I/O while SHA-1 / SHA-256 runs on other cores.
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.