mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 05:50:31 +08:00
node: Handle refs update announcement
Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
@@ -4,7 +4,7 @@ use git_url::Url;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::crypto;
|
||||
use crate::identity::ProjId;
|
||||
use crate::identity::{ProjId, UserId};
|
||||
use crate::protocol::{Context, NodeId, Timestamp, PROTOCOL_VERSION};
|
||||
use crate::storage;
|
||||
|
||||
@@ -86,9 +86,7 @@ pub enum Message {
|
||||
announcement: NodeAnnouncement,
|
||||
},
|
||||
/// Get a peer's inventory.
|
||||
GetInventory {
|
||||
ids: Vec<ProjId>,
|
||||
},
|
||||
GetInventory { ids: Vec<ProjId> },
|
||||
/// Send our inventory to a peer. Sent in response to [`Message::GetInventory`].
|
||||
/// Nb. This should be the whole inventory, not a partial update.
|
||||
Inventory {
|
||||
@@ -98,8 +96,17 @@ pub enum Message {
|
||||
/// are the originator, only when relaying.
|
||||
origin: Option<NodeId>,
|
||||
},
|
||||
InventoryUpdate {
|
||||
inv: Vec<ProjId>,
|
||||
/// Project refs were updated. Includes the signature of the user who updated
|
||||
/// their view of the project.
|
||||
RefsUpdate {
|
||||
/// Project under which the refs were updated.
|
||||
proj: ProjId,
|
||||
/// User signing.
|
||||
user: UserId,
|
||||
/// Updated refs.
|
||||
refs: storage::Refs,
|
||||
/// Signature over the refs.
|
||||
signature: crypto::Signature,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -194,9 +194,28 @@ impl Peer {
|
||||
}));
|
||||
}
|
||||
}
|
||||
(PeerState::Negotiated { id, git, .. }, Message::InventoryUpdate { inv }) => {
|
||||
// TODO: Buffer/throttle fetches.
|
||||
ctx.process_inventory_update(&inv, *id, git);
|
||||
(
|
||||
PeerState::Negotiated { git, .. },
|
||||
Message::RefsUpdate {
|
||||
proj,
|
||||
user,
|
||||
refs,
|
||||
signature,
|
||||
},
|
||||
) => {
|
||||
let bytes = serde_json::to_vec(&refs).unwrap();
|
||||
|
||||
if user.verify(&signature, &bytes).is_ok() {
|
||||
// TODO: Buffer/throttle fetches.
|
||||
// TODO: Also pass the updated refs so that we can check whether
|
||||
// we need to fetch or not.
|
||||
// TODO: Check that the refs are valid.
|
||||
if ctx.process_refs_update(&proj, &user, git) {
|
||||
// TODO: If refs were updated, propagate message to peers.
|
||||
}
|
||||
} else {
|
||||
return Err(PeerError::Misbehavior);
|
||||
}
|
||||
}
|
||||
(
|
||||
PeerState::Negotiated { .. },
|
||||
|
||||
Reference in New Issue
Block a user