Implement chrs-election: Stateful weighted leader election following original CHORUS specs

This commit is contained in:
anthonyrawlins
2026-03-04 04:49:03 +11:00
parent 83ef40d3e2
commit 6bc78f4854
908 changed files with 739 additions and 32 deletions

View File

@@ -25,6 +25,7 @@ pub struct BusMessage {
}
/// A handle to interact with the P2P bus from the agent.
#[derive(Clone)]
pub struct BusHandle {
pub outgoing_tx: mpsc::UnboundedSender<(String, Vec<u8>)>, // (topic, data)
pub local_peer_id: PeerId,
@@ -79,8 +80,13 @@ impl SwarmManager {
// Subscribe to default topics
let global_topic = gossipsub::IdentTopic::new("chorus-global");
let heartbeat_topic = gossipsub::IdentTopic::new("chorus-heartbeat");
let election_topic = gossipsub::IdentTopic::new("CHORUS/election/v1");
let admin_heartbeat_topic = gossipsub::IdentTopic::new("CHORUS/admin/heartbeat/v1");
swarm.behaviour_mut().gossipsub.subscribe(&global_topic)?;
swarm.behaviour_mut().gossipsub.subscribe(&heartbeat_topic)?;
swarm.behaviour_mut().gossipsub.subscribe(&election_topic)?;
swarm.behaviour_mut().gossipsub.subscribe(&admin_heartbeat_topic)?;
swarm.listen_on("/ip4/0.0.0.0/tcp/0".parse()?)?;