#![allow(clippy::too_many_arguments)]
use crate::*;
use holochain_zome_types::signature::Signature;
use kitsune_p2p::{agent_store::AgentInfoSigned, dht::region::RegionBounds, event::*};
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
#[derive(Default)]
pub enum GetRequest {
#[default]
All,
Content,
Metadata,
Pending,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct GetOptions {
pub follow_redirects: bool,
pub all_live_actions_with_metadata: bool,
pub request_type: GetRequest,
}
impl From<&actor::GetOptions> for GetOptions {
fn from(a: &actor::GetOptions) -> Self {
Self {
follow_redirects: a.follow_redirects,
all_live_actions_with_metadata: a.all_live_actions_with_metadata,
request_type: a.request_type.clone(),
}
}
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct GetMetaOptions {}
impl From<&actor::GetMetaOptions> for GetMetaOptions {
fn from(_a: &actor::GetMetaOptions) -> Self {
Self {}
}
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct GetLinksOptions {}
impl From<&actor::GetLinksOptions> for GetLinksOptions {
fn from(_a: &actor::GetLinksOptions) -> Self {
Self {}
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct GetActivityOptions {
pub include_valid_activity: bool,
pub include_rejected_activity: bool,
pub include_full_actions: bool,
}
impl Default for GetActivityOptions {
fn default() -> Self {
Self {
include_valid_activity: true,
include_rejected_activity: false,
include_full_actions: false,
}
}
}
impl From<&actor::GetActivityOptions> for GetActivityOptions {
fn from(a: &actor::GetActivityOptions) -> Self {
Self {
include_valid_activity: a.include_valid_activity,
include_rejected_activity: a.include_rejected_activity,
include_full_actions: a.include_full_actions,
}
}
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub enum CountersigningSessionNegotiationMessage {
AuthorityResponse(Vec<SignedAction>),
EnzymePush(Box<DhtOp>),
}
#[derive(Debug, derive_more::From)]
pub enum FetchOpDataQuery {
Hashes {
op_hash_list: Vec<holo_hash::DhtOpHash>,
include_limbo: bool,
},
Regions(Vec<RegionBounds>),
}
impl FetchOpDataQuery {
pub fn from_kitsune(kit: FetchOpDataEvtQuery) -> Self {
match kit {
FetchOpDataEvtQuery::Hashes {
op_hash_list,
include_limbo,
} => Self::Hashes {
op_hash_list: op_hash_list
.into_iter()
.map(|h| DhtOpHash::from_kitsune(&h))
.collect::<Vec<_>>(),
include_limbo,
},
FetchOpDataEvtQuery::Regions(coords) => Self::Regions(coords),
}
}
}
ghost_actor::ghost_chan! {
pub chan HolochainP2pEvent<super::HolochainP2pError> {
fn put_agent_info_signed(dna_hash: DnaHash, peer_data: Vec<AgentInfoSigned>) -> Vec<kitsune_p2p_types::bootstrap::AgentInfoPut>;
fn query_agent_info_signed(dna_hash: DnaHash, agents: Option<std::collections::HashSet<Arc<kitsune_p2p::KitsuneAgent>>>, kitsune_space: Arc<kitsune_p2p::KitsuneSpace>) -> Vec<AgentInfoSigned>;
fn query_gossip_agents(
dna_hash: DnaHash,
agents: Option<Vec<AgentPubKey>>,
kitsune_space: Arc<kitsune_p2p::KitsuneSpace>,
since_ms: u64,
until_ms: u64,
arc_set: Arc<kitsune_p2p_types::dht_arc::DhtArcSet>,
) -> Vec<AgentInfoSigned>;
fn query_agent_info_signed_near_basis(dna_hash: DnaHash, kitsune_space: Arc<kitsune_p2p::KitsuneSpace>, basis_loc: u32, limit: u32) -> Vec<AgentInfoSigned>;
fn query_peer_density(dna_hash: DnaHash, kitsune_space: Arc<kitsune_p2p::KitsuneSpace>, dht_arc: kitsune_p2p_types::dht_arc::DhtArc) -> kitsune_p2p_types::dht::PeerView;
fn call_remote(
dna_hash: DnaHash,
from_agent: AgentPubKey,
signature: Signature,
to_agent: AgentPubKey,
zome_name: ZomeName,
fn_name: FunctionName,
cap_secret: Option<CapSecret>,
payload: ExternIO,
nonce: Nonce256Bits,
expires_at: Timestamp,
) -> SerializedBytes;
fn publish(
dna_hash: DnaHash,
request_validation_receipt: bool,
countersigning_session: bool,
ops: Vec<holochain_types::dht_op::DhtOp>,
) -> ();
fn get(
dna_hash: DnaHash,
to_agent: AgentPubKey,
dht_hash: holo_hash::AnyDhtHash,
options: GetOptions,
) -> WireOps;
fn get_meta(
dna_hash: DnaHash,
to_agent: AgentPubKey,
dht_hash: holo_hash::AnyDhtHash,
options: GetMetaOptions,
) -> MetadataSet;
fn get_links(
dna_hash: DnaHash,
to_agent: AgentPubKey,
link_key: WireLinkKey,
options: GetLinksOptions,
) -> WireLinkOps;
fn count_links(
dna_hash: DnaHash,
to_agent: AgentPubKey,
query: WireLinkQuery,
) -> CountLinksResponse;
fn get_agent_activity(
dna_hash: DnaHash,
to_agent: AgentPubKey,
agent: AgentPubKey,
query: ChainQueryFilter,
options: GetActivityOptions,
) -> AgentActivityResponse<ActionHash>;
fn must_get_agent_activity(
dna_hash: DnaHash,
to_agent: AgentPubKey,
author: AgentPubKey,
filter: holochain_zome_types::chain::ChainFilter,
) -> MustGetAgentActivityResponse;
fn validation_receipts_received(
dna_hash: DnaHash,
to_agent: AgentPubKey,
receipts: ValidationReceiptBundle,
) -> ();
fn query_op_hashes(
dna_hash: DnaHash,
arc_set: kitsune_p2p::dht_arc::DhtArcSet,
window: TimeWindow,
max_ops: usize,
include_limbo: bool,
) -> Option<(Vec<holo_hash::DhtOpHash>, TimeWindowInclusive)>;
fn fetch_op_data(
dna_hash: DnaHash,
query: FetchOpDataQuery,
) -> Vec<(holo_hash::DhtOpHash, holochain_types::dht_op::DhtOp)>;
fn sign_network_data(
dna_hash: DnaHash,
to_agent: AgentPubKey,
data: Vec<u8>,
) -> Signature;
fn countersigning_session_negotiation(
dna_hash: DnaHash,
to_agent: AgentPubKey,
message: CountersigningSessionNegotiationMessage,
) -> ();
}
}
macro_rules! match_p2p_evt {
($h:ident => |$i:ident| { $($t:tt)* }, { $($t2:tt)* }) => {
match $h {
HolochainP2pEvent::CallRemote { $i, .. } => { $($t)* }
HolochainP2pEvent::Get { $i, .. } => { $($t)* }
HolochainP2pEvent::GetMeta { $i, .. } => { $($t)* }
HolochainP2pEvent::GetLinks { $i, .. } => { $($t)* }
HolochainP2pEvent::CountLinks { $i, .. } => { $($t)* }
HolochainP2pEvent::GetAgentActivity { $i, .. } => { $($t)* }
HolochainP2pEvent::MustGetAgentActivity { $i, .. } => { $($t)* }
HolochainP2pEvent::ValidationReceiptsReceived { $i, .. } => { $($t)* }
HolochainP2pEvent::SignNetworkData { $i, .. } => { $($t)* }
HolochainP2pEvent::CountersigningSessionNegotiation { $i, .. } => { $($t)* }
$($t2)*
}
};
}
impl HolochainP2pEvent {
pub fn dna_hash(&self) -> &DnaHash {
match_p2p_evt!(self => |dna_hash| { dna_hash }, {
HolochainP2pEvent::Publish { dna_hash, .. } => { dna_hash }
HolochainP2pEvent::FetchOpData { dna_hash, .. } => { dna_hash }
HolochainP2pEvent::QueryOpHashes { dna_hash, .. } => { dna_hash }
HolochainP2pEvent::QueryAgentInfoSigned { dna_hash, .. } => { dna_hash }
HolochainP2pEvent::QueryAgentInfoSignedNearBasis { dna_hash, .. } => { dna_hash }
HolochainP2pEvent::QueryGossipAgents { dna_hash, .. } => { dna_hash }
HolochainP2pEvent::PutAgentInfoSigned { dna_hash, .. } => { dna_hash }
HolochainP2pEvent::QueryPeerDensity { dna_hash, .. } => { dna_hash }
})
}
pub fn target_agents(&self) -> &AgentPubKey {
match_p2p_evt!(self => |to_agent| { to_agent }, {
HolochainP2pEvent::Publish { .. } => { unimplemented!("There is no single agent target for Publish") }
HolochainP2pEvent::FetchOpData { .. } => { unimplemented!("There is no single agent target for FetchOpData") }
HolochainP2pEvent::QueryOpHashes { .. } => { unimplemented!("There is no single agent target for QueryOpHashes") }
HolochainP2pEvent::QueryAgentInfoSigned { .. } => { unimplemented!("There is no single agent target for QueryAgentInfoSigned") },
HolochainP2pEvent::QueryAgentInfoSignedNearBasis { .. } => { unimplemented!("There is no single agent target for QueryAgentInfoSignedNearBasis") },
HolochainP2pEvent::QueryGossipAgents { .. } => { unimplemented!("There is no single agent target for QueryGossipAgents") },
HolochainP2pEvent::PutAgentInfoSigned { .. } => { unimplemented!("There is no single agent target for PutAgentInfoSigned") },
HolochainP2pEvent::QueryPeerDensity { .. } => { unimplemented!() },
})
}
}
pub type HolochainP2pEventReceiver = futures::channel::mpsc::Receiver<HolochainP2pEvent>;