MCPcopy Index your code
hub / github.com/al8n/memberlist

github.com/al8n/memberlist @v0.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.6 ↗ · + Follow
1,357 symbols 4,470 edges 241 files 262 documented · 19%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Memberlist

A highly customable, adaptable, runtime agnostic and WASM/WASI friendly Gossip protocol which helps manage cluster membership and member failure detection.

Port and improve HashiCorp's memberlist to Rust.

[github][Github-url] LoC [Build][CI-url] [codecov][codecov-url]

[docs.rs][doc-url] [crates.io][crates-url] [crates.io][crates-url] license

English | 简体中文

Introduction

memberlist is a rust crate that manages cluster membership and member failure detection using a gossip based protocol.

The use cases for such a library are far-reaching: all distributed systems require membership, and memberlist is a re-usable solution to managing cluster membership and node failure detection.

memberlist is eventually consistent but converges quickly on average. The speed at which it converges can be heavily tuned via various knobs on the protocol. Node failures are detected and network partitions are partially tolerated by attempting to communicate to potentially dead nodes through multiple routes.

memberlist is WASM/WASI friendly, all crates can be compiled to wasm-wasi and wasm-unknown-unknown (need to configure the crate features).

Design

Unlike the original Go implementation, Rust's memberlist use highly generic and layered architecture, users can easily implement a component by themselves and plug it to the memberlist. Users can even custom their own Id and Address.

Here are the layers:

  • Transport Layer

By default, Rust's memberlist provides two kinds of transport -- QuicTransport and NetTransport.

  • Runtime Layer

    Async runtime agnostic are provided by agnostic's Runtime trait, tokio, async-std and smol are supported by default. Users can implement their own Runtime and plug it into the memberlist.

  • Address Resolver Layer

    The address resolver layer is supported by nodecraft's AddressResolver trait.

  • Serialize/Deserilize Layer

    By default, Rust's memberlist is using length-prefix encoding (Lpe) to serialize/deserialize messages to bytes or visa-vise. The implemention of Lpe tries the best to avoid reallocating when doing the serialize/deserialize.

    But, users can use any other serialize/deserialize framework by implementing Wire trait.

  • NetTransport

    Builtin stream layers for NetTransport:

  • QuicTransport

    QUIC transport is an experimental transport implementation, it is well tested but still experimental.

    Builtin stream layers for QuicTransport: - Quinn: based on quinn

Users can still implement their own stream layer for different kinds of transport implementations.

  • Delegate Layer

This layer is used as a reactor for different kinds of messages.

  • Delegate

    Delegate is the trait that clients must implement if they want to hook into the gossip layer of Memberlist. All the methods must be thread-safe, as they can and generally will be called concurrently.

    Here are the sub delegate traits:

    • AliveDelegate

    Used to involve a client in processing a node "alive" message. When a node joins, either through a packet gossip or promised push/pull, we update the state of that node via an alive message. This can be used to filter a node out and prevent it from being considered a peer using application specific logic.

    • ConflictDelegate

    Used to inform a client that a node has attempted to join which would result in a name conflict. This happens if two clients are configured with the same name but different addresses.

    • EventDelegate

    A simpler delegate that is used only to receive notifications about members joining and leaving. The methods in this delegate may be called by multiple threads, but never concurrently. This allows you to reason about ordering.

    • MergeDelegate

    Used to involve a client in a potential cluster merge operation. Namely, when a node does a promised push/pull (as part of a join), the delegate is involved and allowed to cancel the join based on custom logic. The merge delegate is NOT invoked as part of the push-pull anti-entropy.

    • NodeDelegate

    Used to manage node related events. e.g. metadata

    • PingDelegate

    Used to notify an observer how long it took for a ping message to complete a round trip. It can a

Extension points exported contracts — how you extend this code

IsGlobalIp (Interface)
A trait for checking if an IP address is globally reachable. [6 implementers]
memberlist-core/src/util.rs
DataRef (Interface)
The reference type of the data. [28 implementers]
memberlist-proto/src/data.rs
Listener (Interface)
Represents a network listener. This trait defines the operations required for a network listener that can bind to an ad [2 …
memberlist-net/src/stream_layer.rs
QuicStream (Interface)
A trait for QUIC bidirectional streams. [1 implementers]
memberlist-quic/src/stream_layer.rs
Connection (Interface)
The connection [4 implementers]
memberlist-core/src/transport.rs
Data (Interface)
The memberlist data can be transmitted through the network. [27 implementers]
memberlist-proto/src/data.rs
PromisedStream (Interface)
Represents a network connection. This trait encapsulates functionality for a network connection that supports asynchron [2 …
memberlist-net/src/stream_layer.rs
StreamLayer (Interface)
A trait for QUIC stream layers. [1 implementers]
memberlist-quic/src/stream_layer.rs

Core symbols most depended-on inside this repo

clone
called by 135
memberlist-core/src/delegate/event.rs
cheap_clone
called by 122
memberlist-proto/src/alive.rs
clone
called by 116
memberlist-core/src/base.rs
next
called by 110
memberlist-core/src/lib.rs
with_label
called by 96
memberlist-proto/src/proto/decoder.rs
id
called by 87
memberlist-core/src/broadcast.rs
len
called by 87
memberlist-proto/src/meta.rs
alive_node
called by 68
memberlist-core/src/state.rs

Shape

Method 882
Function 280
Class 129
Enum 40
Interface 26

Languages

Rust100%

Modules by API surface

memberlist-proto/src/proto/encoder.rs55 symbols
memberlist-proto/src/encryption.rs53 symbols
memberlist-core/src/state/tests.rs47 symbols
memberlist-core/src/base/tests.rs39 symbols
memberlist-core/src/state.rs37 symbols
memberlist-proto/src/compression.rs36 symbols
memberlist-net/src/stream_layer/tls.rs36 symbols
memberlist-core/src/transport/unimplemented.rs34 symbols
memberlist-quic/src/stream_layer/quinn.rs30 symbols
memberlist-core/src/api.rs30 symbols
memberlist-core/src/delegate/composite.rs29 symbols
memberlist-quic/src/lib.rs27 symbols

For agents

$ claude mcp add memberlist \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact