hopr_api/network/traits.rs
1use std::collections::HashSet;
2
3use super::{Health, Observable};
4use crate::{Multiaddr, PeerId};
5
6/// Trait representing a read-only view of the network state.
7pub trait NetworkView {
8 /// Multiaddresses used for listening by the local node.
9 fn listening_as(&self) -> HashSet<Multiaddr>;
10
11 /// Translation of the peer into its known multiaddresses.
12 fn multiaddress_of(&self, peer: &PeerId) -> Option<HashSet<Multiaddr>>;
13
14 /// Peers collected by the network discovery mechanism.
15 fn discovered_peers(&self) -> HashSet<PeerId>;
16
17 /// Peers currently connected and tracked by the network.
18 fn connected_peers(&self) -> HashSet<PeerId>;
19
20 /// Observables related to a specific peer in the network.
21 ///
22 /// Returns `None` if no observations have been recorded for the peer.
23 fn observations_for<'a>(&'a self, peer: &'a PeerId) -> Option<impl Observable + 'static>;
24
25 /// Represents perceived health of the network.
26 fn health(&self) -> Health;
27}
28
29/// Trait representing a reporter of network immediate peer testing observations.
30pub trait NetworkObservations {
31 fn update(&self, peer: &PeerId, result: std::result::Result<std::time::Duration, ()>);
32}