p2p_chat/sync/engine/
events.rs

1//! This module defines the events that can be sent to the `SyncEngine`.
2use libp2p::{kad, PeerId};
3use std::collections::HashSet;
4
5/// Events that can be sent to the `SyncEngine` to trigger synchronization logic.
6#[derive(Debug)]
7pub enum SyncEvent {
8    /// A peer has successfully connected to the local node.
9    PeerConnected(PeerId),
10    /// A connection attempt to a peer has failed.
11    PeerConnectionFailed(PeerId),
12    /// The result of a Kademlia DHT query.
13    DhtQueryResult {
14        /// The ID of the query.
15        query_id: kad::QueryId,
16        /// The result of the query.
17        result: DhtQueryResult,
18    },
19}
20
21/// The result of a Kademlia DHT query.
22#[derive(Debug)]
23pub enum DhtQueryResult {
24    /// Providers for a key were found.
25    ProvidersFound {
26        /// The set of found providers.
27        providers: HashSet<PeerId>,
28        /// Whether this is the final result for the query.
29        finished: bool,
30    },
31    /// The DHT query failed.
32    QueryFailed {
33        /// A description of the error.
34        error: String,
35    },
36}