aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/simtest/holding.rs44
-rw-r--r--src/swarm/peer/members.rs38
2 files changed, 76 insertions, 6 deletions
diff --git a/src/simtest/holding.rs b/src/simtest/holding.rs
index 3ab8582..ed6a9a5 100644
--- a/src/simtest/holding.rs
+++ b/src/simtest/holding.rs
@@ -23,9 +23,11 @@ use crate::federation::version::Version;
use crate::federation::vote::Rules;
use crate::files::Files;
use crate::node::NodeConfig;
-use crate::state::AppState;
+use crate::state::{AppState, HelloState};
use crate::swarm::bootstrap::{Origin, Start};
use crate::swarm::topology;
+use crate::transport::MessageKind;
+use crate::transport::sim::LinkParams;
/// How long a test waits for what takes a few rounds of syncs, writes and reads.
const LONG: Duration = Duration::from_secs(30);
@@ -300,6 +302,46 @@ async fn the_events_put_on_a_member_reach_every_member_alone() {
assert!(events::ids(&d.doc.read().await.doc).is_empty());
}
+/// b's HELLO reaches a, a's reply doesn't: a takes b's handshake and syncs with it, and b,
+/// which hasn't taken a's, reads none of it, but says HELLO again; once a's replies come
+/// through, they sync.
+#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
+async fn a_member_whose_reply_was_lost_is_asked_for_its_handshake() {
+ let sim = Sim::with_identity(91);
+ let (tv, lass, _) = three();
+ let (_, root, id) = federation(&[(&tv, &["a"]), (&lass, &["b"])]);
+ sim.net.set_link(
+ "a",
+ "b",
+ LinkParams {
+ drop: vec![MessageKind::HelloReply],
+ ..LinkParams::default()
+ },
+ );
+ let a = sim.start_with("a", &[], Start::FromDocument(Origin::Root), |config| {
+ of_the_store(config, id, Some(&root), holding("tv"))
+ });
+ let b = sim.start_with("b", &["a"], Start::FromDocument(Origin::Root), |config| {
+ of_the_store(config, id, Some(&root), holding("lass"))
+ });
+ sim.wait_ready(&[&a, &b], SOON).await;
+ let (on_a, b_id) = (&a, b.local_id().to_owned());
+ sim.wait_until("a took b's handshake", SOON, move || {
+ let b_id = b_id.clone();
+ async move {
+ match on_a.get_peer_state(&b_id).await {
+ Some(peer) => peer.lock().await.hello_state == HelloState::Established,
+ None => false,
+ }
+ }
+ })
+ .await;
+ // What a sends meanwhile, b doesn't read.
+ tokio::time::sleep(Duration::from_secs(2)).await;
+ sim.net.set_link("a", "b", LinkParams::default());
+ sim.wait_converged(&[&a, &b], LONG).await;
+}
+
/// Different events to different peers: tv, lass and makefu, a node each, apart while
/// each is given its own: two writes of tv's at one place, a write of lass's, and a
/// proposal and the votes that pass it, each on another node. Together, they read the
diff --git a/src/swarm/peer/members.rs b/src/swarm/peer/members.rs
index ddbd4a7..3df7674 100644
--- a/src/swarm/peer/members.rs
+++ b/src/swarm/peer/members.rs
@@ -3,13 +3,30 @@
//! any other goes unanswered, and what we had with it ends, as with a banned node; and so
//! does what we had with a member at its next message, once the store names it no more.
//! While the node holds no store yet, joining, it can't tell, and takes everyone of its
-//! swarm: its seeds, which take it only where its party lists it.
+//! swarm: its seeds, which take it only where its party lists it. From a peer whose
+//! handshake it hasn't taken (its reply was lost, say), it reads nothing, and says HELLO
+//! to it, as to any peer whose reply it waits for: the party its reply names tells.
+use tokio::time::Instant;
use tracing::{debug, warn};
use crate::state::{AppState, HelloState, Standing};
use crate::transport::ParsedMessage;
+/// A message from `peer`, whose handshake this node hasn't taken: where it knows the peer,
+/// its HELLO goes now, the first, or again where it waits for a reply.
+async fn handshake_first(state: &AppState, peer: &str) {
+ let Some(peer_state) = state.get_peer_state(peer).await else {
+ debug!(peer = %peer, "A message of a node it doesn't know, before any handshake: unread");
+ return;
+ };
+ debug!(peer = %peer, "A message before its handshake was taken: unread; saying HELLO");
+ if peer_state.lock().await.hello_again_now(Instant::now()) {
+ state.peers_due.now();
+ }
+ super::handshake::ensure_handshake(state, peer).await;
+}
+
/// Whether `message` from `peer` is a member's, by the party its handshakes name, which a
/// handshake records; where it isn't, what we had with it ends.
pub(super) async fn member(state: &AppState, peer: &str, message: &ParsedMessage) -> bool {
@@ -22,10 +39,17 @@ pub(super) async fn member(state: &AppState, peer: &str, message: &ParsedMessage
Some(party) => party.clone(),
// Holding no store, it can't tell.
None if !state.holding.tells_members() => return true,
- None => match state.get_peer_state(peer).await {
- Some(peer_state) => peer_state.lock().await.party.clone(),
- None => None,
- },
+ None => {
+ let known = match state.get_peer_state(peer).await {
+ Some(peer_state) => peer_state.lock().await.party.clone(),
+ None => None,
+ };
+ if known.is_none() {
+ handshake_first(state, peer).await;
+ return false;
+ }
+ known
+ }
};
// A member, or it can't tell yet: the party a handshake names is kept.
if state.holding.member(peer, party.as_deref()) != Some(false) {
@@ -41,6 +65,10 @@ pub(super) async fn member(state: &AppState, peer: &str, message: &ParsedMessage
}
if let Some(peer_state) = state.get_peer_state(peer).await {
let mut peer_state = peer_state.lock().await;
+ // Kept, so that what it sends next is known to be a non-member's.
+ if named.is_some() {
+ peer_state.party = party.clone();
+ }
if peer_state.standing.is_admitted() {
warn!(peer = %peer, party = party.as_deref(), "Not a member of the store, as it reads now: no longer synced with");
}