use crate::dht::prelude::ArqSet;
use kitsune_p2p_fetch::{OpHashSized, RoughSized, TransferMethod};
use kitsune_p2p_timestamp::Timestamp;
use must_future::MustBoxFuture;
use std::sync::Arc;
use kitsune_p2p_types::{
bin_types::KitsuneSpace,
dependencies::lair_keystore_api,
dht::{
region::{Region, RegionCoords},
region_set::RegionSetLtcs,
spacetime::Topology,
},
dht_arc::DhtArcSet,
KOpData, KOpHash,
};
use crate::event::GetAgentInfoSignedEvt;
pub type KitsuneHostResult<'a, T> =
MustBoxFuture<'a, Result<T, Box<dyn Send + Sync + std::error::Error>>>;
pub trait KitsuneHost: 'static + Send + Sync + std::fmt::Debug {
fn block(&self, input: kitsune_p2p_block::Block) -> KitsuneHostResult<()>;
fn unblock(&self, input: kitsune_p2p_block::Block) -> KitsuneHostResult<()>;
fn is_blocked(
&self,
input: kitsune_p2p_block::BlockTargetId,
timestamp: Timestamp,
) -> KitsuneHostResult<bool>;
fn get_agent_info_signed(
&self,
input: GetAgentInfoSignedEvt,
) -> KitsuneHostResult<Option<crate::types::agent_store::AgentInfoSigned>>;
fn remove_agent_info_signed(&self, input: GetAgentInfoSignedEvt) -> KitsuneHostResult<bool>;
fn peer_extrapolated_coverage(
&self,
space: Arc<KitsuneSpace>,
dht_arc_set: DhtArcSet,
) -> KitsuneHostResult<Vec<f64>>;
fn query_region_set(
&self,
space: Arc<KitsuneSpace>,
arq_set: ArqSet,
) -> KitsuneHostResult<RegionSetLtcs>;
fn query_size_limited_regions(
&self,
space: Arc<KitsuneSpace>,
size_limit: u32,
regions: Vec<Region>,
) -> KitsuneHostResult<Vec<Region>>;
fn query_op_hashes_by_region(
&self,
space: Arc<KitsuneSpace>,
region: RegionCoords,
) -> KitsuneHostResult<Vec<OpHashSized>>;
fn record_metrics(
&self,
space: Arc<KitsuneSpace>,
records: Vec<MetricRecord>,
) -> KitsuneHostResult<()>;
fn get_topology(&self, space: Arc<KitsuneSpace>) -> KitsuneHostResult<Topology>;
fn op_hash(&self, op_data: KOpData) -> KitsuneHostResult<KOpHash>;
fn check_op_data(
&self,
space: Arc<KitsuneSpace>,
op_hash_list: Vec<KOpHash>,
_context: Option<kitsune_p2p_fetch::FetchContext>,
) -> KitsuneHostResult<Vec<bool>> {
let _space = space;
futures::FutureExt::boxed(
async move { Ok(op_hash_list.into_iter().map(|_| false).collect()) },
)
.into()
}
fn handle_op_hash_received(
&self,
_space: &KitsuneSpace,
_op_hash: &RoughSized<KOpHash>,
_transfer_method: TransferMethod,
) {
}
fn handle_op_hash_transmitted(
&self,
_space: &KitsuneSpace,
_op_hash: &RoughSized<KOpHash>,
_transfer_method: TransferMethod,
) {
}
fn lair_tag(&self) -> Option<Arc<str>> {
None
}
fn lair_client(&self) -> Option<lair_keystore_api::LairClient> {
None
}
}
pub type HostApi = std::sync::Arc<dyn KitsuneHost>;
#[derive(Clone, Debug, derive_more::Constructor, derive_more::Deref, derive_more::Into)]
pub struct HostApiLegacy {
#[deref]
pub api: HostApi,
pub legacy: futures::channel::mpsc::Sender<crate::event::KitsuneP2pEvent>,
}
#[cfg(any(test, feature = "test_utils"))]
mod host_stub;
#[cfg(any(test, feature = "test_utils"))]
pub use host_stub::*;
#[cfg(any(test, feature = "test_utils"))]
mod host_default_error;
#[cfg(any(test, feature = "test_utils"))]
pub use host_default_error::*;
use kitsune_p2p_types::metrics::MetricRecord;