feat(federation): add multi-node peer registration, cross-node envelope replication, and gossip broadcast

Open
#11 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust

Research direction

Start with src/p2p.rs (lines 51-98, add_peer and peer_count), src/udp_gossip.rs, and the routes in src/http_server.rs (lines 149-235), then read tests/milestone10_node_test.rs. Done means two nodes peer through POST /v1/p2p/peers, replicate the signed tree head and relay envelopes without loops, and reject conflicting roots with 409 EQUIVOCATION_DETECTED. This is multi-part design work, so agree on scope with the maintainer before writing code.

Written by the indexing model from the issue text.

Description

area::node effort::l impact::critical priority::critical source::auto status::review type::feature

Description

sonaraim-node/src/p2p.rs:51-98 and src/udp_gossip.rs:1-141 implement P2pMeshNode equivocation detection and POST /v1/p2p/gossip ingestion, but lack live HTTP/UDP multi-node federation so independent enterprise and community nodes can dynamically peer (POST /v1/p2p/peers, GET /v1/p2p/peers), automatically replicate SignedTreeHead Merkle roots on POST /v1/identity, and gossip/replicate store-and-forward envelopes across registered peer nodes for censorship resistance.

Affected Files

  • src/p2p.rs:51-98
  • src/udp_gossip.rs:93-141
  • src/http_server.rs:149-235

Evidence (Current Code Snippet)

// src/p2p.rs:71-81
    /// Registers or updates a peer's QUIC multiaddr.
    pub fn add_peer(&mut self, peer_id: &str, multiaddr: &str) {
        self.peers
            .insert(peer_id.to_string(), multiaddr.to_string());
    }

    /// Returns the number of connected peers.
    #[must_use]
    pub fn peer_count(&self) -> usize {
        self.peers.len()
    }

Impact & Historical Context

  • Impact: Without POST /v1/p2p/peers, GET /v1/p2p/peers, and cross-node replication of SignedTreeHead + relay envelopes (replicated: true flag to prevent infinite loops), multiple sonaraim-node instances cannot form a decentralized censorship-resistant mesh where enterprises and users connect to different nodes and still exchange messages and verify a unified Merkle identity log.
  • Historical Context: Parent Meta-Issue alfonsodg/sonaraim#14. Extends alfonsodg/sonaraim-node#2 and #7 (5354708).

Proposed Solution

  1. Expose POST /v1/p2p/peers ({"peer_id": "...", "rpc_url": "http://...", "multiaddr": "..."}) and GET /v1/p2p/peers on sonaraim-node.
  2. When POST /v1/identity appends a DID key leaf, broadcast the new SignedTreeHead (POST /v1/p2p/gossip) to all registered HTTP peer rpc_urls so every peer validates the Merkle root and immediately detects split-view equivocation.
  3. When POST /v1/relay/envelopes queues an envelope without "replicated": true, replicate it ("replicated": true) to registered peers so a recipient polling any node in the federation can retrieve their sealed envelopes even if the origin node is censored or offline.
  4. Add a multi-node integration test in tests/milestone10_node_test.rs spinning up Node A (Enterprise Node) and Node B (User/Community Node), peering them, posting an identity + envelope on Node A, and verifying both the SignedTreeHead and envelope are available on Node B (and that conflicting Merkle roots trigger 409 Conflict EQUIVOCATION_DETECTED).

Acceptance Criteria

  • Functional: Two or more sonaraim-node instances peer via POST /v1/p2p/peers, replicate SignedTreeHead roots on identity registration, and replicate relay envelopes across nodes without infinite loops.
  • Code Quality: All files in src/ strictly < 300 lines; cargo fmt --check and cargo clippy -- -D warnings pass.
  • Tests: Multi-node integration test in tests/milestone10_node_test.rs verifies Node A -> Node B envelope delivery and Merkle equivocation rejection.
  • Regression: All 13 existing tests and GHCR CI/CD builds pass.
Dominant language
Rust
Stars
0
Forks
0
Avg merge
4m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from alfonsodg/sonaraim-node

All issues in alfonsodg/sonaraim-node

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.