Expand description
SWIM membership and failure detection with Lifeguard, for Rust and Python.
Cluster runs one node on the current tokio runtime: it binds UDP and TCP on one port,
joins the configured seeds and keeps the membership view current while the application reads
members and listens to events.
use kinship::{Cluster, Config, Event, Key};
use std::time::Duration;
let cfg = Config::lan()
.with_name("worker-17")
.with_keys([Key::from_base64(&std::env::var("KINSHIP_KEY")?)?])
.with_seeds(["10.0.0.5:7946".parse()?]);
let cluster = Cluster::start(cfg).await?; // binds, joins seeds
let mut events = cluster.events();
while let Some(event) = events.recv().await {
match event {
Event::MemberDead(m) | Event::MemberLeft(m) => println!("{} is gone", m.name),
Event::UserMessage { sender, data, .. } => println!("{}: {data:?}", sender.name),
Event::EventsLost(_) => println!("resync: {} members", cluster.members().len()),
_ => {}
}
}
cluster.leave(Duration::from_secs(5)).await?;
cluster.close().await;Modules§
- mem
- An in-memory
Transportfor tests: datagrams and streams between nodes in one process, with no sockets.
Structs§
- Cluster
- A running cluster member.
- Config
- Everything a
Clusterneeds, built from a preset withwith_*setters. - Config
Error - A
ConfigorIdentityfield holds an unusable value. - Core
Config - The protocol half of
Config, fromkinship-core. Everything the protocol needs to know that is not an input. - Events
- One subscription to a node’s events, from
Memberlist::events. - Key
- A 32-byte XChaCha20-Poly1305 key. Zeroized on drop and never printed.
- KeyId
- The public id of a
Key: safe to log, and printed as 8 hex characters. - Keyring
- Runtime key rotation for one node, from
Memberlist::keyring. - Member
- One member as this node sees it.
- Metrics
- Monotonic counters since the node started.
- Seed
Error - A seed that is not
host:portwith an IP address or a DNS name. - Stats
- Counters from the protocol core and this node’s Lifeguard local health score.
- Tokio
Transport - UDP and TCP sockets from tokio, sharing one port.
Enums§
- Error
- Why a call on a
Memberlistfailed. - Event
- Something the application should hear about. Member events never describe the local node;
NameConflictmay. - KeyError
- Text given as a key could not be turned into one.
- Seed
- A seed: an address, or a host name and port that is looked up at every join and rejoin.
- State
- Where a member stands in this node’s view.
Constants§
- DEFAULT_
PORT - Default port for UDP and TCP.
- WIRE_
VERSION - Wire format version spoken by this build.
Traits§
- Transport
- One node’s datagram endpoint and stream listener, both on the same address.
Functions§
- generate_
key - A new random key: 32 bytes from the operating system’s secure random source.