The ensemble registry is a DNS packet on the mainline DHT, fetched with nothing but the ensemble public key -- which syn ensemble info prints and the pkdns bootstrap link embeds. Every entry carried name_len || name_bytes in the clear, so a device label, and through it its owner, was world-readable to anyone who had ever seen that key, a removed node included. Sealing it there was the wrong trade. publish_membership runs only during ensemble init/register, while the ensemble secret is briefly in memory, and no code path ever rewrites the record -- so the name in it was a snapshot from join time that no later rename reached. It cost privacy to publish a value that was already drifting, and it cost packet budget: variable-length entries meant how many members fit in pkarr's 1000 bytes depended on how long people's laptops were called. Entries are now fixed-size at 105 bytes, and six still fit. The roster loses nothing gossip does not replace: names arrive sealed over the topic and persist in peer_nodes, so a member reads as (unnamed) only until it first announces itself. The version byte stays at 1 and the decoder takes a fixed-length prefix, ignoring whatever follows, so a record published by an older build still bootstraps -- its trailing name simply never read. A test covers exactly that, since losing it would cost existing ensembles their bootstrap. syn ensemble dht-peers and ensemble info list registry entries without names rather than borrowing one gossip happened to supply: those listings are what is *published*, and a placeholder is the honest answer. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gkup9bGFrnEaBVG8TQTJrS
6.5 KiB
Document and Artifact Design
Current Design (as of March 2026)
A Document has a DocumentType (PDF, Podcast, MusicTrack, etc.) and contains
a list of Artifacts. Each Artifact has an ArtifactType which is a tagged
union that carries both the semantic meaning and the actual data inline:
enum ArtifactType {
PDFFile { data: Vec<u8>, page_count: Option<u32> },
AudioFile { data: Vec<u8>, format: AudioFormat, duration_seconds: Option<f64> },
TextContent { text: String, format: TextFormat },
ListeningProgress { current_position_seconds: f64, ... },
Tags { tags: Vec<String> },
// etc.
}
This works for sync (the bytes are self-contained in the artifact), but creates problems for local storage on a node.
Problem: Same Artifact, Different Physical Representations
When node A syncs a PDF document to node B, the bytes need to travel over the wire. But once node B (e.g. an Android phone) receives them, it should materialize those bytes to a local file and store a reference to that file, rather than keeping raw bytes in the database or in memory.
The current design conflates two concerns in ArtifactType:
- What the artifact is (semantically: a PDF, an audio file, etc.)
- Where the bytes live (inline Vec, local file path, etc.)
This conflation means every node must store binary content the same way, and there's no clean way to represent "this PDF exists as a file at /data/.../foo.pdf" vs. "this PDF is a blob of bytes in transit."
Proposed Design: Separate Type from Content Storage
Split ArtifactType into semantic type information and a separate
ArtifactContent for binary data storage:
// Semantic: what is this artifact?
enum ArtifactType {
// Binary content types - large data stored via ArtifactContent
PDF { page_count: Option<u32> },
Audio { format: AudioFormat, duration_seconds: Option<f64> },
// Inline data types - small/structured, data lives here directly
TextContent { text: String, format: TextFormat },
ListeningProgress { current_position_seconds: f64, total_duration_seconds: f64, completed: bool },
ReadingProgress { current_page: u32, total_pages: u32, completed: bool },
PodcastMetadata { title: String, description: String, author: String, ... },
AudioMetadata { title: String, artist: String, ... },
Tags { tags: Vec<String> },
UserNotes { notes: String },
PodcastReference { podcast_id: String, episode_url: String, title: String },
ExternalReference { url: String, ... },
}
// Storage: where are the bytes for binary artifact types?
enum ArtifactContent {
Inline(Vec<u8>), // bytes stored directly (wire transfer, small content)
LocalFile(PathBuf), // materialized to local filesystem
}
struct Artifact {
id: ArtifactID,
artifact_type: ArtifactType,
content: Option<ArtifactContent>, // Some for binary types, None for inline-data types
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
}
How this works in practice
- On the wire (node A -> node B): binary artifacts ship with
content: Some(Inline(bytes)) - After receiving on Android: the node materializes bytes to a cache/storage
file, stores
content: Some(LocalFile(path)). The exact filename is a local implementation detail, not shared between nodes. - For metadata artifacts (Tags, Progress, UserNotes):
content: None, all data lives in theArtifactTypeenum itself. - Adding new binary types (e.g. video): just add a new
ArtifactTypevariant; the storage strategy is already handled byArtifactContent.
Open question: where does ArtifactContent live?
ArtifactContent is fundamentally a local node concern. The LocalFile
variant should never leave the node — when serializing for sync, content is
always resolved to Inline. Two options:
-
Part of the Artifact struct: simpler, but means serialization must handle the local-only variant carefully. Need
#[serde(skip)]or a custom serialization strategy forLocalFile. -
Store-level side table:
ArtifactContentis not part ofArtifactat all. Instead, the localDocumentStoremaintains a mapping ofArtifactID -> local file pathfor materialized binary artifacts. TheArtifactstruct stays clean and always serializable. The store handles materialization and lookup transparently.
Option 2 is cleaner architecturally (Artifact is always wire-safe), but adds complexity to the store layer. Option 1 is simpler to implement initially.
Node Provenance and Location Tracking
Each Document should track:
created_by_node: [u8; 32]— the public key of the node that originally created the document. Immutable for the lifetime of the document.known_nodes: Vec<[u8; 32]>— the set of nodes that the current node believes hold a copy of this document. This changes over time as documents are synced, moved, or deleted from individual nodes.
Human-readable node identifiers
Node public keys are 32-byte Ed25519 keys. The current hex encoding produces a 64-character string, which is too long for casual display.
Preferred display strategy:
- Show the node's human-readable name (from local settings for this node, or
the
peer_nodesrow a gossip announcement wrote for another) when available. Not from the pkarr registry, which carries no names — see ADR 0044. - Fall back to a short identifier derived from the public key.
Encoding considerations:
- For a full-length encoding shorter than hex, Base58 (as used by Bitcoin and
IPFS) is the leading candidate. It encodes 32 bytes into ~44 characters, avoids
ambiguous characters (0/O, I/l), and has good ecosystem support (
bs58crate). - For display in most UI contexts, a truncated prefix (8–16 hex characters or the equivalent in base58) is sufficient to disambiguate among a small number of nodes. This mirrors git's short-hash convention.
- Combined display example:
Greg's Phone (a3f7c021)or justa3f7c021when no name is set.
Impact on Android PDF Rendering
The current Android PDF viewer accepts a Uri from the system file picker and
copies it to a temp file for MuPDF. With the new design, there would be two
entry points:
- Local file pick (current): URI ->
MuPdfDocument.openFromUri - Document store (new):
DocumentID-> query store -> get local file path or bytes ->MuPdfDocument.openFromPathoropenFromBytes
The rendering layer (MuPdfDocument, PdfPageCache, PdfViewer) does not need
to change. Only the code that obtains the PDF content needs to know about
the document store.