brainwires_network/discovery/traits.rs
1use anyhow::Result;
2use async_trait::async_trait;
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6use crate::identity::AgentIdentity;
7
8/// Identifies which discovery protocol is in use.
9#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10pub enum DiscoveryProtocol {
11 /// Explicit manual peer list.
12 Manual,
13 /// HTTP-backed central registry.
14 Registry,
15 /// mDNS zero-config LAN discovery.
16 Mdns,
17 /// Gossip-based decentralized peer exchange.
18 Gossip,
19 /// Custom protocol with a user-defined identifier.
20 Custom(String),
21}
22
23/// The core discovery trait.
24///
25/// Implementations provide a way for agents to register their presence,
26/// discover peers, and look up specific agents by UUID.
27#[async_trait]
28pub trait Discovery: Send + Sync {
29 /// Register this agent's identity with the discovery service.
30 async fn register(&self, identity: &AgentIdentity) -> Result<()>;
31
32 /// Deregister this agent from the discovery service.
33 async fn deregister(&self, id: &Uuid) -> Result<()>;
34
35 /// Discover all currently known/reachable peers.
36 async fn discover(&self) -> Result<Vec<AgentIdentity>>;
37
38 /// Look up a specific agent by UUID.
39 async fn lookup(&self, id: &Uuid) -> Result<Option<AgentIdentity>>;
40
41 /// The discovery protocol this implementation uses.
42 fn protocol(&self) -> DiscoveryProtocol;
43}