use crate::actor::*;
use super::*;
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 struct HolochainP2pConfig {
pub get_db_peer_meta: GetDbPeerMeta,
pub get_db_op_store: GetDbOpStore,
pub target_arc_factor: u32,
pub network_config: Option<serde_json::Value>,
pub compat: NetworkCompatParams,
#[cfg(feature = "test_utils")]
pub k2_test_builder: bool,
#[cfg(feature = "test_utils")]
pub disable_bootstrap: bool,
#[cfg(feature = "test_utils")]
pub disable_publish: bool,
#[cfg(feature = "test_utils")]
pub disable_gossip: bool,
#[cfg(feature = "test_utils")]
pub mem_bootstrap: 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);
#[cfg(feature = "test_utils")]
{
dbg.field("k2_test_builder", &self.k2_test_builder)
.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!()),
get_db_op_store: Arc::new(|_| unimplemented!()),
target_arc_factor: 1,
network_config: None,
compat: Default::default(),
#[cfg(feature = "test_utils")]
k2_test_builder: false,
#[cfg(feature = "test_utils")]
disable_bootstrap: false,
#[cfg(feature = "test_utils")]
disable_publish: false,
#[cfg(feature = "test_utils")]
disable_gossip: false,
#[cfg(feature = "test_utils")]
mem_bootstrap: true,
}
}
}
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,
pub dpki_uuid: [u8; 32],
}
impl std::fmt::Debug for NetworkCompatParams {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let dna_hash = DnaHash::from_raw_32(self.dpki_uuid.to_vec());
f.debug_struct("NetworkCompatParams")
.field("proto_ver", &self.proto_ver)
.field("dpki_uuid", &dna_hash)
.finish()
}
}
impl Default for NetworkCompatParams {
fn default() -> Self {
Self {
proto_ver: HCP2P_PROTO_VER,
dpki_uuid: [0; 32],
}
}
}