node: fetch refs announcements

Ref announcements contain the namespace (NID) and the SHA of the new
`rad/sigrefs`. This information can be used by the fetch protocol to
fetch only those `Oid`s for those namespaces.

Add a new stage `SigrefsAnnouncement` that captures this behaviour by
only asking for the advertised `Oid`s and updating the corresponding
`rad/sigrefs` for each namespace. Note that this is a special case of
the `SpecialRefs` stage and so the protocol chooses between these two
by checking if there was announcement passed through. The following
stage, `DataRefs`, stays the same.

Note that this stage can only be activated via a `pull`, and `clone`
stays the same.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny
2023-11-09 17:47:10 +01:00
committed by cloudhead
parent d27cd0db0c
commit dd16356e4e
7 changed files with 204 additions and 40 deletions
+4 -11
View File
@@ -1,8 +1,7 @@
use std::collections::{HashMap, VecDeque};
use std::collections::VecDeque;
use std::time;
use log::*;
use radicle::git;
use radicle::storage::refs::RefsAt;
use crate::prelude::*;
@@ -29,8 +28,8 @@ pub enum Io {
remote: NodeId,
/// Namespaces being fetched.
namespaces: Namespaces,
/// If a refs announcements was made.
refs_at: Option<HashMap<NodeId, git::Oid>>,
/// If the node is fetching specific `rad/sigrefs`.
refs_at: Option<Vec<RefsAt>>,
/// Fetch timeout.
timeout: time::Duration,
},
@@ -92,13 +91,7 @@ impl Outbox {
refs_at: Vec<RefsAt>,
timeout: time::Duration,
) {
let refs_at = {
let refs = refs_at
.into_iter()
.map(|RefsAt { remote, at }| (remote, at))
.collect::<HashMap<_, _>>();
(!refs.is_empty()).then_some(refs)
};
let refs_at = (!refs_at.is_empty()).then_some(refs_at);
self.io.push_back(Io::Fetch {
rid,
namespaces,