Skip to main content

Crate truffle

Crate truffle 

Source
Expand description

§truffle

P2P mesh networking for your devices, built on Tailscale.

This is the convenience crate that bundles truffle-core (the Rust library) and truffle-sidecar (auto-downloaded Go binary). For most users, this is the only dependency you need.

§Quick start

[dependencies]
truffle = "0.3"
use truffle::{Node, sidecar_path};
use truffle::network::tailscale::TailscaleProvider;

let node = Node::<TailscaleProvider>::builder()
    .name("my-app")
    .sidecar_path(sidecar_path())
    .build()
    .await?;

// Send a message to all peers
node.broadcast("chat", b"hello!").await;

// Subscribe to messages
let mut rx = node.subscribe("chat");

§Advanced: BYO sidecar

If you want to manage the sidecar binary yourself, depend on truffle-core directly:

[dependencies]
truffle-core = "0.3"

Modules§

envelope
Layer 6: Envelope — Namespace-routed message framing.
file_transfer
File transfer subsystem for truffle-core.
identity
Identity and namespacing primitives (RFC 017).
network
Layer 3: Network — Peer discovery, addressing, encrypted tunnels.
node
Node API — the single public entry point for all truffle functionality.
request_reply
Request/reply utility for correlated message exchange.
session
Layer 5: Session — Peer identity, connection lifecycle, message routing.
synced_store
SyncedStore — device-owned state synchronization across the mesh.
transport
Layer 4: Transport — Protocol-specific connection management.

Structs§

AppId
An application identifier that defines the namespace two nodes must share in order to see each other as peers.
DeviceId
A stable per-device identifier, formatted as a 26-character Crockford base32 ULID.
DeviceName
A human-readable device name supplied by the user.
Envelope
A namespace-routed message. All application messages use this format over WebSocket connections. truffle-core NEVER inspects the payload.
FileBackend
File-backed persistence. Each device slice is stored as a JSON file at {base_dir}/{store_id}/{device_id}.json.
FileOffer
An incoming file offer from a remote peer.
FileTransfer
File transfer handle — the public API for file transfers.
MemoryBackend
In-memory backend (no persistence). Default.
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>.
OfferResponder
One-shot responder for an incoming file offer.
Peer
A peer as seen by application code.
Slice
A versioned slice of data owned by a single device.
SyncedStore
A synchronized key-value store with device-owned slices.
TransferProgress
Progress update for an in-flight file transfer.
TransferResult
Result of a completed file transfer.

Enums§

FileTransferEvent
Events emitted by the file transfer subsystem.
FtMessage
File transfer signaling message types (sent via WS namespace “ft”).
IdentityError
Errors produced when parsing identifier inputs.
NodeError
Errors from the Node API.
OfferDecision
The application’s decision on a file offer.
RequestError
Errors returned by send_and_wait.
StoreEvent
Events emitted by a SyncedStore.
SyncMessage
Wire protocol messages sent on namespace "ss:{store_id}".
TransferDirection
Direction of a file transfer.
TransferError
Errors during file transfer.

Traits§

StoreBackend
Backend for persisting store data across restarts.

Functions§

send_and_wait
Send a namespaced message and wait for a reply that matches a predicate.
sidecar_path
Returns the path to the truffle sidecar binary.
sidecar_version
Returns the version of the bundled sidecar.
slug
Produce a Tailscale-safe slug from a raw device-name string, fitting within budget ASCII characters.
tailscale_hostname
Compose the final Tailscale hostname truffle-{app_id}-{slug}.