Weave Dht
Stores
Stores in the Weave DHT. Peer discovery, mutable records, DID envelopes, local relay sessions, adapter registry, record stores, and handles.
Purpose
Peer discovery, mutable records, DID envelopes, local relay sessions, adapter registry, record stores, and handles.
This page follows the real source shape for Weave Dht and explains the workflow a developer is likely to use first.
Storage contract
Document persistence format, integrity checks, read/write ordering, idempotency, compaction or repair behavior, and how callers recover from partial failures. This section should answer what data is durable and what can be reconstructed.
Primary types to know
AdapterRegistry— network/weave-dht/src/methods.rsAnnouncementState— network/weave-dht/src/weave.rsAnnounceOpts— network/weave-dht/src/weave.rsDhtClient— network/weave-dht/src/lib.rsDhtConfig— network/weave-dht/src/lib.rsDhtHandle— network/weave-dht/src/lib.rsDhtMethodAdapter— network/weave-dht/src/methods.rsDhtNode— network/weave-dht/src/lib.rsDhtNodeBuilder— network/weave-dht/src/lib.rsDidEnvelope— network/weave-dht/src/envelope.rsEnhancedDhtNode— network/weave-dht/src/enhanced.rsMarsAdapter— network/weave-dht/src/methods.rs
Example shape
use weave_dht::DhtNode;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// The builder picks between in-memory and persistent stores.
// store_path enables the RocksDB backend; max_disk_bytes / record_ttl_secs
// cap usage and enforce expiry on stored records.
let dir = tempfile::tempdir()?;
let node = DhtNode::builder()
.store_path(dir.path().to_string_lossy().into_owned())
.max_disk_bytes(512 * 1024 * 1024)
.record_ttl_secs(60 * 60)
.provider_ttl_secs(15 * 60)
.listen_port(0)
.start()
.await?;
// store_stats returns (disk_bytes, record_count, get_hits, put_count).
let stats = node.handle().store_stats().await?;
println!(
"disk_bytes={:?} record_count={:?} get_hits={} put_count={}",
stats.0, stats.1, stats.2, stats.3,
);
Ok(())
}