Expand description
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§
- Bytes
Source - In-memory
ByteSourcebacked by a byte buffer. Handy for small payloads and tests. - Fetch
Result - Result of a
fetch_rangecall. - Peer
Server - A running peer server. Dropping it stops accepting new connections.
Enums§
- Peer
Error - Errors from peer serving or fetching.
Traits§
- Byte
Source - 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 = Nonefetches 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 (fromContent-Range) when known.
Type Aliases§
- Source
Resolver - Resolves a shared handle to its
ByteSource, orNoneif not shared.