Skip to main content

Module node

Module node 

Source
Expand description

Node API — the single public entry point for all truffle functionality.

The Node struct wires together Layers 3-6 and exposes a clean ~12-method API that Layer 7 applications consume. Applications should never import from lower layers directly; everything they need is accessible through Node.

§Quick start

use truffle_core::Node;

let node = Node::builder()
    .name("my-app")
    .sidecar_path("/usr/local/bin/truffle-sidecar")
    .build()
    .await?;

// Discover peers (Layer 3 — no transport needed)
let peers = node.peers().await;

// Send a namespaced message (Layer 6 envelope over Layer 4 WS)
node.send(&peers[0].id, "chat", b"hello!").await?;

// Subscribe to a namespace
let mut rx = node.subscribe("chat");
let msg = rx.recv().await?;

// Open a raw TCP stream (Layer 4 direct)
let stream = node.open_tcp(&peers[0].id, 8080).await?;

Structs§

NamespacedMessage
A message received on a specific namespace.
Node
The main truffle node — single public entry point for all functionality.
NodeBuilder
Builder for constructing a Node<TailscaleProvider>.
Peer
A peer as seen by application code.

Enums§

NodeError
Errors from the Node API.