hopr_transport_probe/
traits.rs

1use async_trait::async_trait;
2use libp2p_identity::PeerId;
3
4#[cfg_attr(test, mockall::automock)]
5#[async_trait]
6pub trait PeerDiscoveryFetch {
7    /// Get untested peers not observed since a specific timestamp.
8    async fn get_peers(&self, from_timestamp: std::time::SystemTime) -> Vec<PeerId>;
9}
10
11#[async_trait]
12pub trait ProbeStatusUpdate {
13    /// Update the peer status after probing
14    async fn on_finished(&self, peer: &PeerId, result: &crate::errors::Result<std::time::Duration>);
15}
16
17/// A common interface for wrapping caching operations needed by the probing mechanism.
18///
19/// This trait should eventually disappear as parts of this functionality move closer
20/// to the network layer.
21#[async_trait]
22pub trait DbOperations {
23    /// Attempts to find SURB and its ID given the [`SurbMatcher`].
24    async fn find_surb(
25        &self,
26        matcher: hopr_network_types::types::SurbMatcher,
27    ) -> hopr_db_api::errors::Result<(hopr_db_api::protocol::HoprSenderId, hopr_db_api::protocol::HoprSurb)>;
28
29    /// Tries to resolve on-chain public key given the off-chain public key
30    async fn resolve_chain_key(
31        &self,
32        offchain_key: &hopr_crypto_types::types::OffchainPublicKey,
33    ) -> hopr_db_api::errors::Result<Option<hopr_primitive_types::prelude::Address>>;
34}