1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/// Represents different types of requests that can be made within the swarm.
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum SwarmRequest {
/// Represents a request to ask a peer for some data or action.
///
/// This variant includes information about the actor, the message, payload, and timeout settings.
Ask {
/// Identifier of the actor initiating the request.
actor_id: WireActorId,
/// Remote identifier of the actor.
actor_remote_id: String,
/// Remote identifier of the message.
message_remote_id: String,
/// The payload data to be sent with the request.
payload: Vec<u8>,
/// Optional timeout duration for the mailbox to receive the request.
mailbox_timeout: Option<Duration>,
/// Optional timeout duration to wait for a reply to the request.
reply_timeout: Option<Duration>,
/// Indicates whether the request should be sent immediately.
immediate: bool,
},
/// Represents a request to tell a peer some information without expecting a response.
///
/// This variant includes information about the actor, the message, payload, and timeout settings.
Tell {
/// Identifier of the actor initiating the message.
actor_id: WireActorId,
/// Remote identifier of the actor.
actor_remote_id: String,
/// Remote identifier of the message.
message_remote_id: String,
/// The payload data to be sent with the message.
payload: Vec<u8>,
/// Optional timeout duration for the mailbox to receive the message.
mailbox_timeout: Option<Duration>,
/// Indicates whether the message should be sent immediately.
immediate: bool,
},
/// A request to link two actors together.
Link {
/// Actor ID.
actor_id: WireActorId,
/// Actor remote ID.
actor_remote_id: String,
/// Sibling ID.
sibling_id: WireActorId,
/// Sibling remote ID.
sibling_remote_id: String,
},
/// A request to unlink two actors.
Unlink {
/// Actor ID.
actor_id: WireActorId,
/// Actor remote ID.
actor_remote_id: String,
/// Sibling ID.
sibling_id: WireActorId,
},
/// A signal notifying a linked actor has died.
SignalLinkDied {
/// The actor which died.
dead_actor_id: WireActorId,
/// The actor to notify.
notified_actor_id: WireActorId,
/// The actor to notify.
notified_actor_remote_id: String,
/// The reason the actor died.
stop_reason: WireActorStopReason,
},
}
impl SwarmRequest {
/// Compact diagnostic summary that never includes payload bytes.
pub fn summary(&self) -> String {
match self {
SwarmRequest::Ask {
actor_remote_id,
message_remote_id,
payload,
..
} => format!(
"Ask {actor_remote_id}::{message_remote_id} payload={}B",
payload.len()
),
SwarmRequest::Tell {
actor_remote_id,
message_remote_id,
payload,
..
} => format!(
"Tell {actor_remote_id}::{message_remote_id} payload={}B",
payload.len()
),
SwarmRequest::Link {
actor_remote_id,
sibling_remote_id,
..
} => format!("Link {actor_remote_id}<->{sibling_remote_id}"),
SwarmRequest::Unlink {
actor_remote_id, ..
} => format!("Unlink {actor_remote_id}"),
SwarmRequest::SignalLinkDied {
notified_actor_remote_id,
..
} => format!("SignalLinkDied {notified_actor_remote_id}"),
}
}
}
/// Represents different types of responses that can be sent within the swarm.
#[derive(Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "rkyv",
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)
)]
pub enum SwarmResponse {
/// Represents the response to an `Ask` request.
///
/// Contains either the successful payload data or an error indicating why the send failed.
Ask(Result<Vec<u8>, WireRemoteSendError>),
/// Represents the response to a `Tell` request.
///
/// Contains either a successful acknowledgment or an error indicating why the send failed.
Tell(Result<(), WireRemoteSendError>),
/// Represents the response to a link request.
Link(Result<(), WireRemoteSendError>),
/// Represents the response to an unlink request.
Unlink(Result<(), WireRemoteSendError>),
/// Represents the response to a link died signal.
SignalLinkDied(Result<(), WireRemoteSendError>),
/// Represents a failure that occurred while attempting to send an outbound request.
///
/// Contains the error that caused the outbound request to fail.
OutboundFailure(WireRemoteSendError),
}
impl SwarmResponse {
/// Compact diagnostic summary that never includes payload bytes.
pub fn summary(&self) -> String {
match self {
SwarmResponse::Ask(Ok(payload)) => format!("Ask ok payload={}B", payload.len()),
SwarmResponse::Ask(Err(err)) => format!("Ask err {err:?}"),
SwarmResponse::Tell(Ok(())) => "Tell ok".to_string(),
SwarmResponse::Tell(Err(err)) => format!("Tell err {err:?}"),
SwarmResponse::Link(Ok(())) => "Link ok".to_string(),
SwarmResponse::Link(Err(err)) => format!("Link err {err:?}"),
SwarmResponse::Unlink(Ok(())) => "Unlink ok".to_string(),
SwarmResponse::Unlink(Err(err)) => format!("Unlink err {err:?}"),
SwarmResponse::SignalLinkDied(Ok(())) => "SignalLinkDied ok".to_string(),
SwarmResponse::SignalLinkDied(Err(err)) => {
format!("SignalLinkDied err {err:?}")
}
SwarmResponse::OutboundFailure(err) => format!("OutboundFailure {err:?}"),
}
}
}