Skip to main content

Crate rift_torrent

Crate rift_torrent 

Source
Expand description

rift-torrent: SRT-based torrent peer discovery for zero-infrastructure P2P.

This crate provides BitTorrent-compatible metadata parsing with Predictive Rendezvous (SRT) extensions for zero-infrastructure peer discovery.

§Key Features

  • Zero-Infrastructure Discovery: Use SRTs derived from infohash instead of trackers or DHT bootstrap nodes
  • BitTorrent Compatible: Parse and create standard .torrent files with optional SRT extensions
  • Magnet URI Support: Parse magnet URIs with xs=riftd-srt:// parameter
  • Deterministic Rendezvous: Peers independently derive identical schedules from the infohash alone

§How It Works

Instead of announcing to a tracker or bootstrapping DHT nodes, peers derive a Semantic Rendezvous Token (SRT) from the torrent infohash:

infohash → BLAKE3 → space_id (namespace isolation)
infohash + t0 → BLAKE3 → seed (schedule derivation)

Both peers compute identical rendezvous schedules and can discover each other without any central infrastructure.

§Example

use rift_torrent::{MagnetUri, SwarmSrt, SwarmDiscovery, DiscoveryConfig, InfoHash};
use rift_rndzv::PeerId;

// Parse a magnet URI with SRT extension
let magnet = MagnetUri::parse(
    "magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567&xs=riftd-srt://v1..."
).unwrap();

// Or derive SRT from just an infohash
let srt = SwarmSrt::from_infohash(*magnet.primary_hash());

// Create a discovery instance
let local_peer = PeerId([0u8; 32]); // Your peer ID
let discovery = SwarmDiscovery::new(srt, local_peer, DiscoveryConfig::default());

// Get the SRT URI for sharing
let uri = discovery.srt_uri().unwrap();
println!("Share this SRT: {}", uri);

§Magnet URI Extension

Standard magnet URIs can include an SRT in the xs (exact source) parameter:

magnet:?xt=urn:btih:HASH&dn=NAME&xs=riftd-srt://v1?space=...&seed=...

§Fallback Strategy

When SRT discovery fails or times out, the crate supports fallback to traditional methods:

  1. SRT Rendezvous (primary) - Zero-infrastructure
  2. DHT Hints (hybrid) - Use DHT for candidate addresses
  3. DHT Bootstrap (fallback) - Standard Kademlia lookup
  4. Tracker Announce (fallback) - HTTP/UDP trackers

Re-exports§

pub use error::TorrentError;
pub use magnet::MagnetUri;
pub use meta::FileInfo;
pub use meta::InfoHash;
pub use meta::PieceHash;
pub use meta::SrtExtension;
pub use meta::TorrentMeta;
pub use peer::DiscoveryConfig;
pub use peer::DiscoveryMode;
pub use peer::PeerExchange;
pub use peer::PexPeer;
pub use peer::SwarmDiscovery;
pub use peer::SwarmPeer;
pub use srt::derive_seed;
pub use srt::derive_space_id;
pub use srt::SwarmSrt;
pub use bencode::decode as decode_bencode;
pub use bencode::encode as encode_bencode;
pub use bencode::parse_torrent;
pub use bencode::BValue;

Modules§

bencode
Bencode encoding and decoding (BEP-3 compatible).
error
Error types for rift-torrent.
magnet
Magnet URI parsing with SRT extension support.
meta
Torrent metadata types: TorrentMeta, InfoHash, PieceHash, FileInfo.
peer
Peer discovery using SRT and fallback mechanisms.
srt
SwarmSrt: SRT derivation from infohash for torrent swarms.

Structs§

PeerId
Stable identifier for a peer in the rndzv layer.
RendezvousSpaceId
Logical coordination namespace for a rendezvous session.
TimeModel
Time model governing rendezvous slotting and search windows.