aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/model.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 01:48:57 +0000
committertv <tv@krebsco.de>2026-11-19 03:18:34 +0100
commitf24063e90d02ef76d87401d6e74cf8c9f489ff7d (patch)
tree313fa30d2610a248f5132dfe1c2d3a37ce73f624 /src/federation/model.rs
parentc0bb757df50fe4aa025ba2e6ac021e179291c78b (diff)
fold: of a party's lists, those written under the latest version first
A key a version names, stolen, could write its party's node list at a history from before the version that named the party's keys anew: written under the version before, it counted, as naming keys anew leaves a list's `since` alone, and beside the list the party wrote under the new version the lower ID won. The thief signed a few, kept the lowest, and did so again after every list the party wrote. Of a party's key sets, and of its node lists, those written under the latest version now come first, then what no other has in its history, then the lowest ID; the model alike. A list the party writes under the version that replaced the key stays, as `federation.md` says. Key sets were safe already, by their `since`; one rule serves both. This changes what counts where two of a party's lists, written under different versions, are beside each other: nodes read them alike only once all run it. Row 69 is tested (`federation_attack_69`).
Diffstat (limited to 'src/federation/model.rs')
-rw-r--r--src/federation/model.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/federation/model.rs b/src/federation/model.rs
index 2107d9f..8cd189b 100644
--- a/src/federation/model.rs
+++ b/src/federation/model.rs
@@ -205,7 +205,8 @@ impl Model {
})
}
- /// The key set, or node list, of `party` that counts in a history by `version`.
+ /// The key set, or node list, of `party` that counts in a history by `version`: of
+ /// those written under the latest version, the latest.
fn list(
&self,
history: &BTreeSet<Id>,
@@ -219,17 +220,23 @@ impl Model {
} else {
given.nodes_since
};
- let ids: Vec<Id> = self
+ let ids: Vec<(Id, u64)> = self
.signed(history)
- .filter(|(id, signed)| {
+ .filter(|(_, signed)| {
signed.party == party
&& match signed.does {
Does::Keys(_) => keys,
Does::Nodes(_) => !keys,
_ => false,
}
- && self.under(id).is_some_and(|under| under.number >= since)
})
+ .filter_map(|(id, _)| Some((id, self.under(&id)?.number)))
+ .filter(|(_, number)| *number >= since)
+ .collect();
+ let latest = ids.iter().map(|(_, number)| *number).max()?;
+ let ids: Vec<Id> = ids
+ .into_iter()
+ .filter(|(_, number)| *number == latest)
.map(|(id, _)| id)
.collect();
self.latest(&ids)