Skip to main content

Module peer

Module peer 

Source
Expand description

Re-export framework services (HTTP, URI, etc.) from the dedicated services crate. Local-network peer streaming for Cranpose apps.

One app instance serves byte ranges of content it can read (files, content:// documents, …) over plain HTTP on the LAN; another instance fetches them. This is the transport for peer-to-peer media sharing — e.g. one player streaming another player’s library on the same network, with no server, no cloud, and no account.

The transport is deliberately the portable half: PeerServer and fetch_range are pure std::net and work the same on desktop, Android, and iOS. The non-portable pieces — LAN discovery (mDNS/NSD/Bonjour) and the Android keep-alive foreground service — live elsewhere; this module only moves bytes once you know an address.

§Model

The app supplies a SourceResolver: given an opaque handle (a string the app chose when it shared something), return a ByteSource or None. The server only ever serves handles the resolver recognizes, so it is not an open file server — an app exposes exactly what it decided to share. Every request must carry the shared Bearer token established out-of-band (e.g. by a pairing step), so a stray device on the LAN cannot read anything.

GET /track/{handle} with an optional Range: bytes=START-END header returns 200/206 with the bytes; 401 without the token; 404 for an unknown handle.

Structs§

BytesSource
In-memory ByteSource backed by a byte buffer. Handy for small payloads and tests.
FetchResult
Result of a fetch_range call.
PeerServer
A running peer server. Dropping it stops accepting new connections.

Enums§

PeerError
Errors from peer serving or fetching.

Traits§

ByteSource
Random-access source of bytes the app is willing to serve.

Functions§

content_length
Returns the total length of a shared handle, via a one-byte range probe.
fetch_range
Fetches a byte range of a shared handle from a peer at base (e.g. "192.168.1.20:54123") into memory. len = None fetches to the end.
fetch_to_writer
Streams a byte range of a shared handle from a peer into writer, in chunks, without buffering the whole range in memory — use this to spool a track to disk. Returns the total source length (from Content-Range) when known.

Type Aliases§

SourceResolver
Resolves a shared handle to its ByteSource, or None if not shared.