aboutsummaryrefslogtreecommitdiffstats
path: root/src/transport/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/mod.rs')
-rw-r--r--src/transport/mod.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/transport/mod.rs b/src/transport/mod.rs
index 52b544a..8cbf412 100644
--- a/src/transport/mod.rs
+++ b/src/transport/mod.rs
@@ -251,6 +251,12 @@ pub(crate) enum ParsedMessage {
Prune(TreeLink),
/// Asks the recipient to send a writer's changes at once (`swarm::plumtree`).
Graft(TreeLink),
+ /// Asks the recipient to be neighbours (`swarm::hyparview`).
+ Neighbour(NeighbourRequest),
+ /// Answers a NEIGHBOUR.
+ NeighbourReply(NeighbourAnswer),
+ /// Tells the recipient we are neighbours no more (`swarm::hyparview`).
+ Disconnect(NeighbourAnswer),
}
/// A node's proof that it holds the key of its node ID (`identity`), sending from its
@@ -397,6 +403,9 @@ pub(crate) enum MessageKind {
ProbeReply,
Prune,
Graft,
+ Neighbour,
+ NeighbourReply,
+ Disconnect,
}
impl ParsedMessage {
@@ -418,6 +427,9 @@ impl ParsedMessage {
ParsedMessage::ProbeReply(_) => MessageKind::ProbeReply,
ParsedMessage::Prune(_) => MessageKind::Prune,
ParsedMessage::Graft(_) => MessageKind::Graft,
+ ParsedMessage::Neighbour(_) => MessageKind::Neighbour,
+ ParsedMessage::NeighbourReply(_) => MessageKind::NeighbourReply,
+ ParsedMessage::Disconnect(_) => MessageKind::Disconnect,
}
}
@@ -441,6 +453,10 @@ impl ParsedMessage {
ParsedMessage::Prune(link) | ParsedMessage::Graft(link) => {
Some((link.epoch, link.epoch_seq))
}
+ ParsedMessage::Neighbour(request) => Some((request.epoch, request.epoch_seq)),
+ ParsedMessage::NeighbourReply(answer) | ParsedMessage::Disconnect(answer) => {
+ Some((answer.epoch, answer.epoch_seq))
+ }
ParsedMessage::Who(_)
| ParsedMessage::Me(_)
| ParsedMessage::Ping(_)
@@ -461,6 +477,29 @@ pub(crate) struct TreeLink {
pub(crate) writer: u64,
}
+/// NEIGHBOUR: the sender asks the recipient to be neighbours (`swarm::hyparview`), as
+/// HyParView's NEIGHBOR; `high` when the sender has none (then the recipient makes room
+/// if it must).
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub(crate) struct NeighbourRequest {
+ #[serde(with = "crate::transport::wire::codec::epoch")]
+ pub(crate) epoch: Epoch,
+ /// See `SyncEnvelope::epoch_seq`.
+ pub(crate) epoch_seq: u32,
+ pub(crate) high: bool,
+}
+
+/// NEIGHBOUR_REPLY (whether the recipient of a NEIGHBOUR agreed) and DISCONNECT (never
+/// agreed: neighbours no more) (`swarm::hyparview`).
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub(crate) struct NeighbourAnswer {
+ #[serde(with = "crate::transport::wire::codec::epoch")]
+ pub(crate) epoch: Epoch,
+ /// See `SyncEnvelope::epoch_seq`.
+ pub(crate) epoch_seq: u32,
+ pub(crate) agreed: bool,
+}
+
/// PROBE: whether the recipient reaches `member` (`swarm::working_links`), as SWIM
/// asks others before it suspects a member. Answered from what the recipient knows,
/// without contacting the member.