summaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/peer/keepalive.rs7
-rw-r--r--src/swarm/topology.rs32
2 files changed, 38 insertions, 1 deletions
diff --git a/src/swarm/peer/keepalive.rs b/src/swarm/peer/keepalive.rs
index ea7ade2..afc2b3d 100644
--- a/src/swarm/peer/keepalive.rs
+++ b/src/swarm/peer/keepalive.rs
@@ -171,9 +171,14 @@ pub(super) async fn note_status(state: &AppState, peer: &str, remote: &transport
let mut peer_state = peer_state.lock().await;
let became_ready = remote.ready && peer_state.reports_ready != Some(true);
peer_state.reports_ready = Some(remote.ready);
- peer_state.syncs_with_us = Some(remote.syncs_with_you);
+ let changed =
+ peer_state.syncs_with_us.replace(remote.syncs_with_you) != Some(remote.syncs_with_you);
peer_state.reported_heads = remote.heads.heads().map(<[_]>::len);
drop(peer_state);
+ if changed {
+ // A neighbour that only connects out stays one as long as it says so.
+ state.topology_changed.notify_one();
+ }
// Off the consumer: telling which heads we lack takes the document's lock.
{
let (state, peer, remote) = (state.clone(), peer.to_owned(), remote.clone());
diff --git a/src/swarm/topology.rs b/src/swarm/topology.rs
index 1d98637..3731036 100644
--- a/src/swarm/topology.rs
+++ b/src/swarm/topology.rs
@@ -47,6 +47,10 @@ pub(crate) struct NeighbourView {
/// Peers that proved they are of our swarm but aren't in our member list (yet): their
/// registration hasn't reached us. They are neighbours too (`refresh`).
unlisted: BTreeSet<String>,
+ /// Members the member list gives no address for on our transports, that reach us
+ /// anyway: they only connect out (no listen address). They are neighbours too while
+ /// they say they sync with us (`refresh`).
+ outbound: BTreeSet<String>,
neighbours: BTreeSet<String>,
/// Every reachable member is a neighbour.
full_mesh: bool,
@@ -227,11 +231,36 @@ pub(crate) async fn refresh(state: &AppState) -> Option<NeighbourChange> {
unlisted.insert(peer);
}
}
+ // A member that lists no address on our transports, but reached us anyway, only
+ // connects out: it isn't in the graph on our side (it's on none of our transports, as
+ // far as the list goes), while on its side we are, so it would sync with us while we
+ // never sent it our changes (only answers to its). It picks its neighbours; those it
+ // picked keep it, as it says (STATUS).
+ let mut outbound = BTreeSet::new();
+ for member in &current {
+ if member == state.local_id()
+ || unreachable.contains(member)
+ || transports
+ .get(member)
+ .is_some_and(|on| !on.is_disjoint(&local_transports))
+ {
+ continue;
+ }
+ if let Some(peer_state) = state.get_peer_state(member).await {
+ let peer_state = peer_state.lock().await;
+ if matches!(peer_state.standing, crate::state::Standing::Member { .. })
+ && peer_state.syncs_with_us != Some(false)
+ {
+ outbound.insert(member.clone());
+ }
+ }
+ }
let previous = {
let view = state.neighbours.read_or_recover();
if view.as_ref().is_some_and(|view| {
view.members == current
&& view.unlisted == unlisted
+ && view.outbound == outbound
&& view.k == k
&& view.unreachable == unreachable
&& view.stable == stable
@@ -256,6 +285,7 @@ pub(crate) async fn refresh(state: &AppState) -> Option<NeighbourChange> {
&|m| unreachable.contains(m),
&|m| stable.contains(m),
);
+ computed.extend(outbound.iter().cloned());
let listed_neighbours = computed.len();
computed.extend(unlisted.iter().cloned());
let change = NeighbourChange {
@@ -277,6 +307,7 @@ pub(crate) async fn refresh(state: &AppState) -> Option<NeighbourChange> {
k,
neighbours = computed.len(),
unlisted = unlisted.len(),
+ outbound = outbound.len(),
added = change.added.len(),
removed = change.removed.len(),
"Neighbours computed from the member list"
@@ -294,6 +325,7 @@ pub(crate) async fn refresh(state: &AppState) -> Option<NeighbourChange> {
transports,
local_transports,
unlisted,
+ outbound,
neighbours: computed,
});
Some(change)