Skip to main content

Crate nectar_mantaray

Crate nectar_mantaray 

Source
Expand description

Mantaray manifest trie for Ethereum Swarm.

Dedicated to the memory of ldeffenb, whose guidance on manifest generation made this implementation possible.

Mantaray is a trie-based manifest structure that maps human-readable paths (e.g. index.html, img/logo.png) to content-addressed chunk references. It supports XOR obfuscation, versioned binary serialisation (v0.1 and v0.2), and metadata per path.

§Efficient Partial Updates

The trie uses lazy loading and dirty-reference tracking so that updating a single path in a million-entry manifest only re-serialises O(depth) nodes:

  1. Manifest::add lazily loads only the affected path branch.
  2. Modified nodes have their reference cleared (dirty flag).
  3. Manifest::save skips nodes with non-empty references (unmodified).
  4. After save, child forks are dropped from memory.
  5. The next operation lazily reloads from the new state.

§Unified Store

Manifest operations use the typed chunk store traits from nectar_primitives: SyncChunkGet for loading and SyncChunkPut for saving. This means a single MemoryStore can hold both file chunks and manifest trie nodes.

let store = DefaultMemoryStore::new();
let mut manifest: PlainManifest<_> = PlainManifest::new(store);

§Website Manifests

Configure index and error documents for Swarm-hosted websites:

manifest.set_index_document("index.html").unwrap();
manifest.set_error_document("404.html").unwrap();

§Metadata Constants

Well-known metadata keys are available in the metadata module:

use nectar_mantaray::metadata;
assert_eq!(metadata::CONTENT_TYPE, "Content-Type");

§Upstream-bug workarounds

Code that exists solely to tolerate a defect in an upstream reference implementation is tagged with a grep-able BEE-WORKAROUND(bee#NNNN) comment. When the upstream fix lands and downstream consumers have upgraded past the buggy releases, every site tagged with that issue number should be removed. Run git grep -n BEE-WORKAROUND to enumerate them.

Re-exports§

pub use entry::Entry;
pub use error::MantarayError;
pub use error::Result;
pub use manifest::Manifest;
pub use manifest::ManifestIter;
pub use manifest_ref::ManifestRef;
pub use mode::NodeEntry;
pub use node::Fork;
pub use node::Node;
pub use node::NodeType;
pub use node::Prefix;
pub use obfuscation::ObfuscationKey;

Modules§

codec
Binary encoding for mantaray nodes (v0.1 and v0.2).
entry
Manifest entry type: path, reference, and metadata.
error
Error types for mantaray operations.
manifest
High-level mantaray manifest and lazy iterator.
manifest_ref
Encrypted manifest reference (root address + obfuscation key).
metadata
Well-known metadata keys for manifest entries.
mode
Node entry types for plain and encrypted manifests.
node
Node and Fork types for the mantaray trie.
obfuscation
XOR obfuscation key for mantaray node serialisation.

Structs§

MemoryStore
In-memory chunk storage using a RwLock<HashMap>.

Traits§

SyncChunkHas
Checks chunk existence (synchronous).

Type Aliases§

DefaultManifest
Default manifest type using DEFAULT_BODY_SIZE and plain mode.
DefaultMemoryStore
Default in-memory chunk store.
EncryptedManifest
Encrypted manifest: 64-byte refs, random obfuscation key.
PlainManifest
Plain manifest: 32-byte refs, no obfuscation.