refactor: remove dead code, consolidate files (#52)
Remove the unused TCP transport and dead CLI/simulation scaffolding and collapse scattered single-purpose modules into consolidated files across the dashboard, process, and simulation crates.
- crates/transport: drop the TCP transport (src/tcp.rs and its tcp feature), leaving only ed25519 identity and encoding utilities behind the iroh transport
- crates/dashboard: collapse actor_detail_html/actors_html/dashboard_html/topology_html into a single html.rs, drop command/parse.rs, and inline the trace types into lib.rs
- crates/process: fold driver, pipeline_types, queue, subscriber, waker, and local pipes/signal/wait into local/mod.rs, pipeline.rs, and a unified types.rs, consolidating the public re-exports
- crates/simulation: remove the ci subdirectory (local_sim, sim) and dead node/config/trace modules, and flatten the distribution subdirectory into top-level files
- crates/datastore: remove the unused store_cli, cli, and in-memory storage, and deduplicate crypto.rs across datastore and distribution (about 190 lines of shared code removed)
- crates/distribution: drop dead codec code and trim the messages module
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-25 14:33:04 +00:00
|
|
|
//! Protocol messages for SWIM membership and Kademlia directory, plus JSON codec.
|
2026-02-12 09:13:50 +00:00
|
|
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use swactor::actor::ActorAddress;
|
refactor: remove dead code, consolidate files (#52)
Remove the unused TCP transport and dead CLI/simulation scaffolding and collapse scattered single-purpose modules into consolidated files across the dashboard, process, and simulation crates.
- crates/transport: drop the TCP transport (src/tcp.rs and its tcp feature), leaving only ed25519 identity and encoding utilities behind the iroh transport
- crates/dashboard: collapse actor_detail_html/actors_html/dashboard_html/topology_html into a single html.rs, drop command/parse.rs, and inline the trace types into lib.rs
- crates/process: fold driver, pipeline_types, queue, subscriber, waker, and local pipes/signal/wait into local/mod.rs, pipeline.rs, and a unified types.rs, consolidating the public re-exports
- crates/simulation: remove the ci subdirectory (local_sim, sim) and dead node/config/trace modules, and flatten the distribution subdirectory into top-level files
- crates/datastore: remove the unused store_cli, cli, and in-memory storage, and deduplicate crypto.rs across datastore and distribution (about 190 lines of shared code removed)
- crates/distribution: drop dead codec code and trim the messages module
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-25 14:33:04 +00:00
|
|
|
use swactor::transport::{Codec, CodecRegistry, NetworkMessage};
|
|
|
|
|
use swactor::Error;
|
2026-02-12 09:13:50 +00:00
|
|
|
|
|
|
|
|
use crate::types::{DirectoryEntry, MemberState, NodeId, NodeRecord};
|
|
|
|
|
|
|
|
|
|
// ─── SWIM Protocol Messages ────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
/// SWIM ping — "are you alive?"
|
2026-02-13 07:55:12 +00:00
|
|
|
///
|
|
|
|
|
/// Carries piggybacked membership gossip so that SWIM dissemination
|
|
|
|
|
/// propagates cluster state changes on every protocol message.
|
2026-02-12 09:13:50 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct Ping {
|
|
|
|
|
pub from: NodeId,
|
|
|
|
|
pub sequence: u64,
|
2026-02-13 07:55:12 +00:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub piggyback: Vec<u8>,
|
2026-02-12 09:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for Ping {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::Ping"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// SWIM ack — "yes, I'm alive"
|
2026-02-13 07:55:12 +00:00
|
|
|
///
|
|
|
|
|
/// Carries piggybacked membership gossip (same as Ping).
|
2026-02-12 09:13:50 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct Ack {
|
|
|
|
|
pub from: NodeId,
|
|
|
|
|
pub sequence: u64,
|
2026-02-13 07:55:12 +00:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub piggyback: Vec<u8>,
|
2026-02-12 09:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for Ack {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::Ack"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// SWIM indirect ping request — "please ping target on my behalf"
|
2026-02-13 07:55:12 +00:00
|
|
|
///
|
|
|
|
|
/// Carries piggybacked membership gossip (same as Ping).
|
2026-02-12 09:13:50 +00:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct PingReq {
|
|
|
|
|
pub from: NodeId,
|
|
|
|
|
pub target: NodeId,
|
|
|
|
|
pub sequence: u64,
|
2026-02-13 07:55:12 +00:00
|
|
|
#[serde(default)]
|
|
|
|
|
pub piggyback: Vec<u8>,
|
2026-02-12 09:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for PingReq {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::PingReq"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-19 14:39:33 +00:00
|
|
|
/// SWIM indirect ack — "the target you asked me to ping is alive"
|
|
|
|
|
///
|
|
|
|
|
/// Sent by a relay node back to the original prober after the relay
|
|
|
|
|
/// receives an ack from the indirect-ping target.
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct IndirectAck {
|
|
|
|
|
pub target: NodeId,
|
|
|
|
|
pub sequence: u64,
|
|
|
|
|
#[serde(default)]
|
|
|
|
|
pub piggyback: Vec<u8>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for IndirectAck {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::IndirectAck"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 09:13:50 +00:00
|
|
|
/// SWIM join request — "I want to join the cluster"
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct JoinRequest {
|
|
|
|
|
pub from: NodeId,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for JoinRequest {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::JoinRequest"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// SWIM join response — "here's the current member list"
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct JoinResponse {
|
|
|
|
|
pub members: Vec<NodeRecord>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for JoinResponse {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::JoinResponse"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Membership Dissemination ───────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
/// A single membership update, piggybacked on protocol messages.
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct MembershipUpdate {
|
|
|
|
|
pub node_id: NodeId,
|
|
|
|
|
pub state: MemberState,
|
|
|
|
|
pub incarnation: u64,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ─── Kademlia Protocol Messages ─────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
/// Kademlia FIND_NODE request — "who are the k closest nodes to this target?"
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct FindNodeRequest {
|
|
|
|
|
pub from: NodeId,
|
|
|
|
|
pub target: NodeId,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for FindNodeRequest {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::FindNodeRequest"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Kademlia FIND_NODE response — closest known nodes.
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct FindNodeResponse {
|
2026-02-15 09:47:05 +00:00
|
|
|
pub closest: Vec<NodeId>,
|
2026-02-12 09:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for FindNodeResponse {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::FindNodeResponse"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Kademlia STORE — "store this directory entry"
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct StoreRequest {
|
|
|
|
|
pub entry: DirectoryEntry,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for StoreRequest {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::StoreRequest"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Kademlia FIND_VALUE request — "where is this actor?"
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct FindValueRequest {
|
|
|
|
|
pub from: NodeId,
|
|
|
|
|
pub actor_addr: ActorAddress,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for FindValueRequest {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::FindValueRequest"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Kademlia FIND_VALUE response — either the entry or closer nodes.
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub enum FindValueResponse {
|
|
|
|
|
/// Found the actor — here's the directory entry.
|
|
|
|
|
Found(DirectoryEntry),
|
|
|
|
|
/// Don't have it — here are closer nodes to ask.
|
2026-02-15 09:47:05 +00:00
|
|
|
Closer(Vec<NodeId>),
|
2026-02-12 09:13:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl NetworkMessage for FindValueResponse {
|
|
|
|
|
fn type_tag() -> &'static str {
|
|
|
|
|
"swactor_dist::FindValueResponse"
|
|
|
|
|
}
|
|
|
|
|
}
|
refactor: remove dead code, consolidate files (#52)
Remove the unused TCP transport and dead CLI/simulation scaffolding and collapse scattered single-purpose modules into consolidated files across the dashboard, process, and simulation crates.
- crates/transport: drop the TCP transport (src/tcp.rs and its tcp feature), leaving only ed25519 identity and encoding utilities behind the iroh transport
- crates/dashboard: collapse actor_detail_html/actors_html/dashboard_html/topology_html into a single html.rs, drop command/parse.rs, and inline the trace types into lib.rs
- crates/process: fold driver, pipeline_types, queue, subscriber, waker, and local pipes/signal/wait into local/mod.rs, pipeline.rs, and a unified types.rs, consolidating the public re-exports
- crates/simulation: remove the ci subdirectory (local_sim, sim) and dead node/config/trace modules, and flatten the distribution subdirectory into top-level files
- crates/datastore: remove the unused store_cli, cli, and in-memory storage, and deduplicate crypto.rs across datastore and distribution (about 190 lines of shared code removed)
- crates/distribution: drop dead codec code and trim the messages module
Signed-off-by: Zachery Aaron Shores-Chmielewski <zacheryasc@gmail.com>
2026-02-25 14:33:04 +00:00
|
|
|
|
|
|
|
|
// ─── JSON Codec ─────────────────────────────────────────────────────────────
|
|
|
|
|
|
|
|
|
|
/// JSON codec for distribution protocol messages.
|
|
|
|
|
///
|
|
|
|
|
/// Using JSON for simplicity and debuggability. Can be swapped for
|
|
|
|
|
/// bincode/msgpack in production via the Codec trait.
|
|
|
|
|
pub struct JsonCodec;
|
|
|
|
|
|
|
|
|
|
macro_rules! impl_json_codec {
|
|
|
|
|
($ty:ty) => {
|
|
|
|
|
impl Codec<$ty> for JsonCodec {
|
|
|
|
|
fn encode(&self, msg: &$ty) -> Result<Vec<u8>, Error> {
|
|
|
|
|
serde_json::to_vec(msg).map_err(|e| Error::from(format!("encode: {e}")))
|
|
|
|
|
}
|
|
|
|
|
fn decode(&self, bytes: &[u8]) -> Result<$ty, Error> {
|
|
|
|
|
serde_json::from_slice(bytes).map_err(|e| Error::from(format!("decode: {e}")))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl_json_codec!(Ping);
|
|
|
|
|
impl_json_codec!(Ack);
|
|
|
|
|
impl_json_codec!(PingReq);
|
|
|
|
|
impl_json_codec!(JoinRequest);
|
|
|
|
|
impl_json_codec!(JoinResponse);
|
|
|
|
|
impl_json_codec!(FindNodeRequest);
|
|
|
|
|
impl_json_codec!(FindNodeResponse);
|
|
|
|
|
impl_json_codec!(StoreRequest);
|
|
|
|
|
impl_json_codec!(FindValueRequest);
|
|
|
|
|
impl_json_codec!(FindValueResponse);
|
|
|
|
|
|
|
|
|
|
/// Build a `CodecRegistry` with all distribution protocol messages registered.
|
|
|
|
|
pub fn distribution_codec_registry() -> CodecRegistry {
|
|
|
|
|
let mut cr = CodecRegistry::new();
|
|
|
|
|
cr.register::<Ping, _>(JsonCodec);
|
|
|
|
|
cr.register::<Ack, _>(JsonCodec);
|
|
|
|
|
cr.register::<PingReq, _>(JsonCodec);
|
|
|
|
|
cr.register::<JoinRequest, _>(JsonCodec);
|
|
|
|
|
cr.register::<JoinResponse, _>(JsonCodec);
|
|
|
|
|
cr.register::<FindNodeRequest, _>(JsonCodec);
|
|
|
|
|
cr.register::<FindNodeResponse, _>(JsonCodec);
|
|
|
|
|
cr.register::<StoreRequest, _>(JsonCodec);
|
|
|
|
|
cr.register::<FindValueRequest, _>(JsonCodec);
|
|
|
|
|
cr.register::<FindValueResponse, _>(JsonCodec);
|
|
|
|
|
cr
|
|
|
|
|
}
|