gossip.rs

Overview

The gossip.rs file implements a networked gossip protocol node using the chitchat library. It sets up a node capable of joining a cluster, exchanging state information with peers, and exposing a REST API to inspect and modify the local node state. The node periodically gossips with other nodes to maintain a consistent cluster state. This file provides the entry point of the application, configuration parsing, initialization of the gossip node, and a minimal HTTP API for interacting with the node's key-value state.


Components

Structs and Types

Api

Opt


Functions and Methods

Api::index

async fn index(&self) -> Json<serde_json::Value>
curl http://<node_address>/

Api::set_kv

async fn set_kv(&self, key: Query<String>, value: Query<String>) -> Json<serde_json::Value>
curl "http://<node_address>/set_kv/?key=mykey&value=myvalue"

generate_server_id

fn generate_server_id(public_addr: SocketAddr) -> String

main

#[tokio::main]
async fn main() -> anyhow::Result<()>

Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram

classDiagram
class Api {
+chitchat: ChitchatRef
+index()
+set_kv()
}
class Opt {
+listen_addr: SocketAddr
+public_addr: Option<SocketAddr>
+node_id: Option<String>
+seeds: Vec<String>
+interval: u64
}
Api --> ChitchatRef : uses
main --> Opt : parses CLI args
main --> Api : instantiates API
main --> ChitchatConfig : configures gossip node
main --> spawn_chitchat : spawns gossip node
main --> OpenApiService : creates HTTP API
main --> Server : runs HTTP server

This diagram represents the high-level structure showing the main structs (Api, Opt) and the main function interactions with configuration, gossip node spawning, API creation, and HTTP server execution. The Api struct depends on ChitchatRef for accessing gossip state.