holochain_p2p/types/
event.rs

1#![allow(clippy::too_many_arguments)]
2//! Module containing incoming events from HolochainP2p.
3
4use crate::*;
5use holochain_zome_types::signature::Signature;
6
7/// The data required for a get request.
8#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
9pub enum GetRequest {
10    /// Get all the integrated data.
11    #[default]
12    All,
13    /// Get only the integrated content.
14    Content,
15    /// Get only the metadata.
16    /// If you already have the content this is all you need.
17    Metadata,
18    /// Get the content even if it's still pending.
19    Pending,
20}
21
22/// Get options help control how the get is processed at various levels.
23#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
24pub struct GetOptions {
25    /// Whether the remote-end should follow redirects or just return the
26    /// requested entry.
27    pub follow_redirects: bool,
28    /// Return all live actions even if there is deletes.
29    /// Useful for metadata calls.
30    pub all_live_actions_with_metadata: bool,
31    /// The type of data this get request requires.
32    pub request_type: GetRequest,
33}
34
35impl From<&actor::GetOptions> for GetOptions {
36    fn from(a: &actor::GetOptions) -> Self {
37        Self {
38            follow_redirects: a.follow_redirects,
39            all_live_actions_with_metadata: a.all_live_actions_with_metadata,
40            request_type: a.request_type.clone(),
41        }
42    }
43}
44
45/// GetMeta options help control how the get is processed at various levels.
46#[derive(Debug, serde::Serialize, serde::Deserialize)]
47pub struct GetMetaOptions {}
48
49impl From<&actor::GetMetaOptions> for GetMetaOptions {
50    fn from(_a: &actor::GetMetaOptions) -> Self {
51        Self {}
52    }
53}
54
55/// GetLinks options help control how the get is processed at various levels.
56#[derive(Debug, serde::Serialize, serde::Deserialize)]
57pub struct GetLinksOptions {}
58
59impl From<&actor::GetLinksOptions> for GetLinksOptions {
60    fn from(_a: &actor::GetLinksOptions) -> Self {
61        Self {}
62    }
63}
64
65/// Get agent activity options help control how the get is processed at various levels.
66#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
67pub struct GetActivityOptions {
68    /// Include the activity actions in the response
69    pub include_valid_activity: bool,
70    /// Include any rejected actions in the response.
71    pub include_rejected_activity: bool,
72    /// Include warrants in the response.
73    pub include_warrants: bool,
74    /// Include the full records, instead of just the hashes.
75    pub include_full_records: bool,
76}
77
78impl Default for GetActivityOptions {
79    fn default() -> Self {
80        Self {
81            include_valid_activity: true,
82            include_warrants: true,
83            include_rejected_activity: false,
84            include_full_records: false,
85        }
86    }
87}
88
89impl From<&actor::GetActivityOptions> for GetActivityOptions {
90    fn from(a: &actor::GetActivityOptions) -> Self {
91        Self {
92            include_valid_activity: a.include_valid_activity,
93            include_warrants: a.include_warrants,
94            include_rejected_activity: a.include_rejected_activity,
95            include_full_records: a.include_full_records,
96        }
97    }
98}
99
100/// Message between agents actively driving/negotiating a countersigning session.
101#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
102pub enum CountersigningSessionNegotiationMessage {
103    /// An authority has a complete set of signed actions and is responding with
104    /// them back to the counterparties.
105    AuthorityResponse(Vec<SignedAction>),
106    /// Counterparties are sending their signed action to an enzyme instead of
107    /// authorities as part of an enzymatic session.
108    EnzymePush(Box<ChainOp>),
109}
110
111/// Handle requests made by remote peers.
112pub trait HcP2pHandler: 'static + Send + Sync + std::fmt::Debug {
113    /// A remote node is attempting to make a remote call on us.
114    fn handle_call_remote(
115        &self,
116        dna_hash: DnaHash,
117        to_agent: AgentPubKey,
118        zome_call_params_serialized: ExternIO,
119        signature: Signature,
120    ) -> BoxFut<'_, HolochainP2pResult<SerializedBytes>>;
121
122    /// A remote node is publishing data in a range we claim to be holding.
123    fn handle_publish(
124        &self,
125        dna_hash: DnaHash,
126        request_validation_receipt: bool,
127        ops: Vec<holochain_types::dht_op::DhtOp>,
128    ) -> BoxFut<'_, HolochainP2pResult<()>>;
129
130    /// A remote node is requesting entry data from us.
131    fn handle_get(
132        &self,
133        dna_hash: DnaHash,
134        to_agent: AgentPubKey,
135        dht_hash: holo_hash::AnyDhtHash,
136        options: GetOptions,
137    ) -> BoxFut<'_, HolochainP2pResult<WireOps>>;
138
139    /// A remote node is requesting metadata from us.
140    fn handle_get_meta(
141        &self,
142        dna_hash: DnaHash,
143        to_agent: AgentPubKey,
144        dht_hash: holo_hash::AnyDhtHash,
145        options: GetMetaOptions,
146    ) -> BoxFut<'_, HolochainP2pResult<MetadataSet>>;
147
148    /// A remote node is requesting link data from us.
149    fn handle_get_links(
150        &self,
151        dna_hash: DnaHash,
152        to_agent: AgentPubKey,
153        link_key: WireLinkKey,
154        options: GetLinksOptions,
155    ) -> BoxFut<'_, HolochainP2pResult<WireLinkOps>>;
156
157    /// A remote node is requesting a link count from us.
158    fn handle_count_links(
159        &self,
160        dna_hash: DnaHash,
161        to_agent: AgentPubKey,
162        query: WireLinkQuery,
163    ) -> BoxFut<'_, HolochainP2pResult<CountLinksResponse>>;
164
165    /// A remote node is requesting agent activity from us.
166    fn handle_get_agent_activity(
167        &self,
168        dna_hash: DnaHash,
169        to_agent: AgentPubKey,
170        agent: AgentPubKey,
171        query: ChainQueryFilter,
172        options: GetActivityOptions,
173    ) -> BoxFut<'_, HolochainP2pResult<AgentActivityResponse>>;
174
175    /// A remote node is requesting agent activity from us.
176    fn handle_must_get_agent_activity(
177        &self,
178        dna_hash: DnaHash,
179        to_agent: AgentPubKey,
180        author: AgentPubKey,
181        filter: holochain_zome_types::chain::ChainFilter,
182    ) -> BoxFut<'_, HolochainP2pResult<MustGetAgentActivityResponse>>;
183
184    /// A remote node has sent us a validation receipt.
185    fn handle_validation_receipts_received(
186        &self,
187        dna_hash: DnaHash,
188        to_agent: AgentPubKey,
189        receipts: ValidationReceiptBundle,
190    ) -> BoxFut<'_, HolochainP2pResult<()>>;
191
192    /// A remote node is publishing countersigning data to us.
193    fn handle_publish_countersign(
194        &self,
195        dna_hash: DnaHash,
196        op: holochain_types::dht_op::ChainOp,
197    ) -> BoxFut<'_, HolochainP2pResult<()>>;
198
199    /// Messages between agents that drive a countersigning session.
200    fn handle_countersigning_session_negotiation(
201        &self,
202        dna_hash: DnaHash,
203        to_agent: AgentPubKey,
204        message: CountersigningSessionNegotiationMessage,
205    ) -> BoxFut<'_, HolochainP2pResult<()>>;
206}
207
208/// Trait-object HcP2pHandler.
209pub type DynHcP2pHandler = Arc<dyn HcP2pHandler>;