WeaveDocs
Weave Core

Network Runtime

Network runtime facade in Weave Core — unified access to DHT, swarm, and adapter-mediated transports.

Purpose

Facade over filesystem, network, storage, identity, crypto, and model crates.

This page follows the real source shape for Weave Core and explains the workflow a developer is likely to use first.

Network contract

Document peer identity, topic selection, message framing, session lifetime, retry behavior, metrics, and what must be stable between releases. Any change here can strand peers, so examples should be exercised with at least two real processes.

Primary types to know

  • AgentFs — libs/weave-core/src/filesystem/agentfs.rs
  • AgentFsConfig — libs/weave-core/src/filesystem/agentfs.rs
  • AgentFsEntry — libs/weave-core/src/filesystem/agentfs.rs
  • ContentAnnouncement — libs/weave-core/src/network/dht.rs
  • Dht — libs/weave-core/src/network/dht.rs
  • DhtBehaviour — libs/weave-core/src/network/dht.rs
  • DhtConfig — libs/weave-core/src/network/dht.rs
  • DhtStats — libs/weave-core/src/network/dht.rs
  • Did — libs/weave-core/src/identity/mod.rs
  • Diff — libs/weave-core/src/filesystem/diff.rs
  • DiffEntry — libs/weave-core/src/filesystem/diff.rs
  • DiffSummary — libs/weave-core/src/filesystem/diff.rs

Example shape

use weave_core::{Dht, Did, Swarm};
use weave_core::network::dht::DhtConfig;
use weave_core::network::swarm::SwarmConfig;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let owner = Did::new("did:l1fe:agent:net-runtime")?;

    // The DHT subsystem owns kademlia state per owner DID. DhtConfig defaults
    // are appropriate for a small private deployment.
    let dht_cfg = DhtConfig {
        bootstrap_peers: vec![],
        ..DhtConfig::default()
    };
    let dht = Dht::new(dht_cfg, owner.clone())?;
    let dht_stats = dht.stats();

    // The Swarm wraps libp2p with a custom WeaveSwarmBehaviour. peers() returns
    // the typed Peer rows currently in the routing table.
    let swarm_cfg = SwarmConfig::default();
    let swarm = Swarm::new(swarm_cfg, owner)?;
    let peers = swarm.peers();

    println!(
        "dht_peer_id={} dht_records={} swarm_peers={}",
        dht.local_peer_id(),
        dht_stats.total_records,
        peers.len(),
    );
    Ok(())
}