use super::*;
use crate::actor::*;
use std::time::Duration;
mod actor;
pub use actor::WrapEvtSender;
pub async fn spawn_holochain_p2p(
config: HolochainP2pConfig,
lair_client: holochain_keystore::MetaLairClient,
) -> HolochainP2pResult<DynHcP2p> {
tracing::info!(?config, "Launching HolochainP2p");
actor::HolochainP2pActor::create(config, lair_client).await
}
pub type GetDbPeerMeta = Arc<
dyn Fn(DnaHash) -> BoxFut<'static, HolochainP2pResult<DbWrite<DbKindPeerMetaStore>>>
+ 'static
+ Send
+ Sync,
>;
pub type GetDbOpStore = Arc<
dyn Fn(DnaHash) -> BoxFut<'static, HolochainP2pResult<DbWrite<DbKindDht>>>
+ 'static
+ Send
+ Sync,
>;
pub type GetDbConductor =
Arc<dyn Fn() -> BoxFut<'static, DbWrite<DbKindConductor>> + 'static + Send + Sync>;
#[derive(Default)]
pub enum ReportConfig {
#[default]
None,
JsonLines(hc_report::HcReportConfig),
}
pub struct HolochainP2pConfig {
pub get_db_peer_meta: GetDbPeerMeta,
pub peer_meta_pruning_interval_ms: u64,
pub get_db_op_store: GetDbOpStore,
pub get_conductor_db: GetDbConductor,
pub target_arc_factor: u32,
pub auth_material: Option<Vec<u8>>,
pub network_config: Option<serde_json::Value>,
pub compat: NetworkCompatParams,
pub request_timeout: Duration,
pub report: ReportConfig,
pub incoming_request_concurrency_limit: u16,
#[cfg(feature = "test_utils")]
pub disable_bootstrap: bool,
#[cfg(feature = "test_utils")]
pub disable_publish: bool,
#[cfg(feature = "test_utils")]
pub disable_gossip: bool,
}
impl std::fmt::Debug for HolochainP2pConfig {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut dbg = f.debug_struct("HolochainP2pConfig");
dbg.field("compat", &self.compat);
dbg.field("auth_material", &self.auth_material);
dbg.field("request_timeout", &self.request_timeout);
dbg.field("target_arc_factor", &self.target_arc_factor);
dbg.field("network_config", &self.network_config);
#[cfg(feature = "test_utils")]
{
dbg.field("disable_bootstrap", &self.disable_bootstrap)
.field("disable_publish", &self.disable_publish)
.field("disable_gossip", &self.disable_gossip);
}
dbg.finish()
}
}
impl Default for HolochainP2pConfig {
fn default() -> Self {
Self {
get_db_peer_meta: Arc::new(|_| unimplemented!()),
peer_meta_pruning_interval_ms: 10_000,
get_db_op_store: Arc::new(|_| unimplemented!()),
get_conductor_db: Arc::new(|| unimplemented!()),
target_arc_factor: 1,
auth_material: None,
network_config: None,
compat: Default::default(),
request_timeout: Duration::from_secs(60),
report: ReportConfig::default(),
incoming_request_concurrency_limit: 4,
#[cfg(feature = "test_utils")]
disable_bootstrap: false,
#[cfg(feature = "test_utils")]
disable_publish: false,
#[cfg(feature = "test_utils")]
disable_gossip: false,
}
}
}
pub const HCP2P_PROTO_VER: u32 = 2;
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize)]
pub struct NetworkCompatParams {
pub proto_ver: u32,
}
impl std::fmt::Debug for NetworkCompatParams {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("NetworkCompatParams")
.field("proto_ver", &self.proto_ver)
.finish()
}
}
impl Default for NetworkCompatParams {
fn default() -> Self {
Self {
proto_ver: HCP2P_PROTO_VER,
}
}
}