hopr_transport_probe/
traits.rs

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