### Install memberlist with default features (tokio + tcp) Source: https://github.com/al8n/memberlist/blob/main/README.md Add the memberlist crate with its default features, which include the tokio runtime and TCP transport. This is the basic installation for a dependency entry. ```toml [dependencies] memberlist = "0.9" # tokio runtime + tcp transport by default ``` -------------------------------- ### Enable tracing with tracing_subscriber::fmt().init() Source: https://github.com/al8n/memberlist/blob/main/README.md Install a tracing subscriber in the main function before starting the node. The driver task and memberlist-proto emit tracing events during probing, suspicion, gossip dissemination, push/pull anti-entropy, and join/leave. ```rust fn main() { tracing_subscriber::fmt().init(); // … start your node … } ``` -------------------------------- ### Install memberlist with smol runtime Source: https://github.com/al8n/memberlist/blob/main/README.md Enable the smol runtime instead of tokio by disabling default features and selecting the smol and tcp features. ```toml [dependencies] memberlist = { version = "0.9", default-features = false, features = ["smol", "tcp"] } ``` -------------------------------- ### Install memberlist with compio runtime Source: https://github.com/al8n/memberlist/blob/main/README.md Enable the compio runtime, which is completion-based and thread-per-core, by disabling default features and selecting compio and tcp. ```toml [dependencies] memberlist = { version = "0.9", default-features = false, features = ["compio", "tcp"] } ``` -------------------------------- ### Install memberlist-smoltcp with alloc feature Source: https://github.com/al8n/memberlist/blob/main/memberlist-smoltcp/README.md Adds the memberlist-smoltcp crate with default features disabled and the alloc feature enabled, suitable for no_std + alloc environments. ```toml [dependencies] memberlist-smoltcp = { version = "0.1", default-features = false, features = ["alloc"] } ``` -------------------------------- ### Run memberlist-compio example inside compio runtime Source: https://github.com/al8n/memberlist/blob/main/memberlist-compio/README.md Shows how to create a memberlist node with a TCP transport, join a cluster, and leave. The driver is !Send and thread-per-core, so it must run inside a compio runtime. The join method returns Ok(reached_set) on success and Err((reached_so_far, error)) on failure. ```rust use core::net::SocketAddr; use memberlist_compio::{ FirstAddrResolver, MaybeResolved, Memberlist, Options, SocketAddrResolver, TcpTransport, TcpTransportOptions, VoidDelegate, }; use smol_str::SmolStr; async fn run() -> Result<(), Box> { let advertise: SocketAddr = "127.0.0.1:7946".parse()?; let opts = Options::>::new( TcpTransportOptions::::new() .with_local_id(SmolStr::new("node-a")) .with_advertise_addr(MaybeResolved::Resolved(advertise)), ); let node = Memberlist::new( opts, VoidDelegate::default(), &SocketAddrResolver, &FirstAddrResolver, ) .await?; let seed: SocketAddr = "127.0.0.1:7947".parse()?; // join returns Ok(reached_set) on success, Err((reached_so_far, error)) on failure. let reached = node .join(&SocketAddrResolver, &[MaybeResolved::Resolved(seed)]) .await .map_err(|(_, e)| e)?; println!("{} members online (reached {})", node.num_online_members(), reached.len()); node.leave().await?; Ok(()) } ``` -------------------------------- ### Run fuzz targets with cargo +nightly fuzz run Source: https://github.com/al8n/memberlist/blob/main/memberlist-proto/fuzz/README.md Runs the parse_messages fuzz target with the nightly toolchain. Requires cargo-fuzz installed via `cargo install cargo-fuzz`; the crate is its own workspace and must be built through cargo fuzz, never the host --workspace build. ```sh cargo +nightly fuzz run parse_messages cargo +nightly fuzz run unwrap_transforms -- -max_total_time=300 ``` -------------------------------- ### Install memberlist with embassy (no_std) runtime Source: https://github.com/al8n/memberlist/blob/main/README.md Enable the embassy runtime for no_std targets. This feature does not pull in std, making it suitable for bare-metal embedded use. ```toml [dependencies] memberlist = { version = "0.9", default-features = false, features = ["embassy", "tcp"] } ``` -------------------------------- ### Create and poll a Memberlist node over smoltcp Source: https://github.com/al8n/memberlist/blob/main/memberlist-smoltcp/README.md Shows how to construct a Memberlist node with smoltcp and pump it from your own poll loop. The poll method advances the protocol and interface, returning the next instant to poll or None. The example is marked ignore in the source and assumes a device and now are available. ```rust use core::net::SocketAddr; use memberlist_smoltcp::{ EndpointOptions, InterfaceOptions, Memberlist, Options, TransformOptions, }; use smol_str::SmolStr; // `device` is your smoltcp `Device` (an Ethernet/IP driver); `now` is a portable // `Instant` your firmware advances. let advertise: SocketAddr = "10.0.0.2:7946".parse().unwrap(); let mut node = Memberlist::::new( Options::new(), InterfaceOptions::new(hardware_addr), // + IP addresses, routes, RNG seed TransformOptions::default(), EndpointOptions::new(SmolStr::new("node-a"), advertise), &mut device, now, ); // Pump from your own loop; `poll` advances the protocol + the smoltcp interface and // returns the next instant the driver wants to be polled (or `None`). loop { let next = node.poll(now, &mut device); while let Some(event) = node.poll_event() { // react to membership events (joined / updated / left, ping completed, …) } // ...sleep until `next` or until the device is RX-ready, then advance `now`... } ``` -------------------------------- ### Use memberlist::tokio tcp constructor to create a node and join a cluster Source: https://github.com/al8n/memberlist/blob/main/README.md Showcases the tokio-pinned API from memberlist::tokio for a TCP reliable plane with UDP gossip. Uses the free tcp constructor, SocketAddrResolver, MaybeResolved addresses, Options::new(), VoidDelegate, and Methods join(), num_online_members(), and leave(). Delete expects join to return Ok(reached_set) or Err((reached_so_far, error)); error and leave are mapped before returning Ok(()). This example is the primary usage for the tokio runtime. ```rust use core::net::SocketAddr; use memberlist::tokio::{tcp, MaybeResolved, Options, SocketAddrResolver, VoidDelegate}; use smol_str::SmolStr; #[tokio::main] async fn main() -> Result<(), Box> { let advertise: SocketAddr = "127.0.0.1:7946".parse()?; // Start a node pinned to the tokio runtime (TCP reliable plane + UDP gossip). let node = tcp( &SocketAddrResolver, SmolStr::new("node-a"), MaybeResolved::Resolved(advertise), Options::new(), VoidDelegate::::new(), ) .await?; // Join an existing cluster through one or more seed addresses. // join returns Ok(reached_set) on success, Err((reached_so_far, error)) on failure. let seed: SocketAddr = "127.0.0.1:7947".parse()?; let reached = node .join(&SocketAddrResolver, &[MaybeResolved::Resolved(seed)]) .await .map_err(|(_, e)| e)?; println!("{} members online (reached {})", node.num_online_members(), reached.len()); // Gracefully leave: broadcast a leave, then drain. node.leave().await?; Ok(()) } ``` -------------------------------- ### Build and run the QEMU proof binary Source: https://github.com/al8n/memberlist/blob/main/tests/memberlist-embassy-qemu/README.md Run from the crate directory to build and execute the proof binary on the emulated Cortex-M. The crate is excluded from the host workspace and must be built on its own. ```sh cd tests/memberlist-embassy-qemu && cargo run ``` -------------------------------- ### Create and join a memberlist node with Tokio Source: https://github.com/al8n/memberlist/blob/main/memberlist-reactor/README.md Shows how to create a TCP memberlist node using the Tokio runtime, join a seed node, and leave. The runtime is a type parameter; pick TokioRuntime or SmolRuntime. join returns Ok(reached_set) on success, Err((reached_so_far, error)) on failure. ```rust use core::net::SocketAddr; use agnostic::tokio::TokioRuntime; use memberlist_reactor::{MaybeResolved, Memberlist, Options, SocketAddrResolver, VoidDelegate}; use smol_str::SmolStr; #[tokio::main] async fn main() -> Result<(), Box> { let advertise: SocketAddr = "127.0.0.1:7946".parse()?; // The runtime is a type parameter; pick `TokioRuntime` or `SmolRuntime`. let node = Memberlist::::tcp::( &SocketAddrResolver, SmolStr::new("node-a"), MaybeResolved::Resolved(advertise), Options::new(), VoidDelegate::::new(), ) .await?; let seed: SocketAddr = "127.0.0.1:7947".parse()?; // join returns Ok(reached_set) on success, Err((reached_so_far, error)) on failure. let reached = node .join(&SocketAddrResolver, &[MaybeResolved::Resolved(seed)]) .await .map_err(|(_, e)| e)?; println!("{} members online (reached {})", node.num_online_members(), reached.len()); node.leave().await?; Ok(()) } ``` -------------------------------- ### Run memberlist-embassy on embassy executor Source: https://github.com/al8n/memberlist/blob/main/memberlist-embassy/README.md Shows how to build a Memberlist node and its Runner, spawn the Runner as an embassy task, and use the Memberlist handle to join and interact with the cluster. ```rust use memberlist_embassy::{Memberlist, Runner}; #[embassy_executor::task] async fn memberlist_driver(runner: Runner) { runner.run().await; // owns the embassy-net sockets; pumps the engine forever } // In your network setup task, after embassy-net's `Stack` is up: let (node, runner) = Memberlist::new(/* options, endpoint options, embassy-net stack */); spawner.must_spawn(memberlist_driver(runner)); node.join(/* seeds */).await?; // … node.members(), node.send(...), node.leave().await, … ``` -------------------------------- ### Add memberlist-proto dependency with feature flags Source: https://github.com/al8n/memberlist/blob/main/memberlist-proto/README.md Shows three Cargo.toml dependency configurations for memberlist-proto 0.4: the default std build, a no_std build with alloc and the plain-tcp coordinator, and a bare no_std build without an allocator. ```toml [dependencies] memberlist-proto = "0.4" # std (default) # no_std + alloc, with the plain-tcp coordinator: memberlist-proto = { version = "0.4", default-features = false, features = ["alloc", "tcp"] } # bare no_std, no allocator: memberlist-proto = { version = "0.4", default-features = false } ``` -------------------------------- ### Build bare-metal with --no-default-features --features alloc Source: https://github.com/al8n/memberlist/blob/main/memberlist-embedded/README.md Builds the crate for a bare-metal environment without the default std feature, enabling the alloc feature for a global allocator. The protocol state lives in slab-backed pools, so there is no per-packet heap traffic on the hot path. ```text --no-default-features --features alloc ``` -------------------------------- ### Add memberlist-driver dependency Source: https://github.com/al8n/memberlist/blob/main/memberlist-driver/README.md Add the memberlist-driver crate as a dependency. The crate is std-only and has no feature flags. ```toml [dependencies] memberlist-driver = "0.1" ``` -------------------------------- ### Add memberlist-embassy dependency with alloc feature Source: https://github.com/al8n/memberlist/blob/main/memberlist-embassy/README.md Adds the memberlist-embassy crate as a dependency with default features disabled and the alloc feature enabled for no_std bare-metal builds. ```toml [dependencies] memberlist-embassy = { version = "0.1", default-features = false, features = ["alloc"] } ``` -------------------------------- ### Initialize tracing subscriber for memberlist-proto Source: https://github.com/al8n/memberlist/blob/main/memberlist-proto/README.md Initializes a tracing subscriber to collect structured tracing events emitted by the state machine when the "tracing" feature is enabled. Place this in your application after enabling features = ["tracing"]. ```rust tracing_subscriber::fmt().init(); ``` -------------------------------- ### Add memberlist-compio dependency to Cargo.toml Source: https://github.com/al8n/memberlist/blob/main/memberlist-compio/README.md Adds the memberlist-compio crate version 0.1 to the project's dependencies. ```toml [dependencies] memberlist-compio = "0.1" ``` -------------------------------- ### Add memberlist-reactor dependency Source: https://github.com/al8n/memberlist/blob/main/memberlist-reactor/README.md Adds the memberlist-reactor crate to a Cargo.toml file. The version is 0.1. ```toml [dependencies] memberlist-reactor = "0.1" ```