holochain_p2p/
spawn.rs

1use crate::actor::*;
2use crate::event::*;
3
4mod actor;
5use actor::*;
6
7/// Spawn a new HolochainP2p actor.
8/// Conductor will call this on initialization.
9pub async fn spawn_holochain_p2p(
10    config: kitsune_p2p::dependencies::kitsune_p2p_types::config::KitsuneP2pConfig,
11    tls_config: kitsune_p2p::dependencies::kitsune_p2p_types::tls::TlsConfig,
12    host: kitsune_p2p::HostApi,
13    compat: NetworkCompatParams,
14) -> HolochainP2pResult<(
15    ghost_actor::GhostSender<HolochainP2p>,
16    HolochainP2pEventReceiver,
17)> {
18    let (evt_send, evt_recv) = futures::channel::mpsc::channel(10);
19
20    let builder = ghost_actor::actor_builder::GhostActorBuilder::new();
21
22    let channel_factory = builder.channel_factory().clone();
23
24    let sender = channel_factory.create_channel::<HolochainP2p>().await?;
25
26    tokio::task::spawn(builder.spawn(
27        HolochainP2pActor::new(config, tls_config, channel_factory, evt_send, host, compat).await?,
28    ));
29
30    Ok((sender, evt_recv))
31}
32
33/// Some parameters used as part of a protocol compability check during tx5 preflight
34#[derive(Debug, Default, serde::Serialize, serde::Deserialize)]
35pub struct NetworkCompatParams {
36    /// The UUID of the installed DPKI service.
37    /// If the service is backed by a Dna, this is the core 32 bytes of the DnaHash.
38    pub dpki_uuid: Option<[u8; 32]>,
39}