node: Handle announcement commands

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-09-13 10:16:05 +02:00
parent 400ba8d935
commit ff2bd185e7
3 changed files with 43 additions and 21 deletions
+7 -2
View File
@@ -86,7 +86,9 @@ 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 {
@@ -96,6 +98,9 @@ pub enum Message {
/// are the originator, only when relaying.
origin: Option<NodeId>,
},
InventoryUpdate {
inv: Vec<ProjId>,
},
}
impl Message {
@@ -119,7 +124,7 @@ impl Message {
}
}
pub fn inventory<S, T, G>(ctx: &mut Context<S, T, G>) -> Result<Self, storage::Error>
pub fn inventory<S, T, G>(ctx: &Context<S, T, G>) -> Result<Self, storage::Error>
where
T: storage::ReadStorage,
{
+4
View File
@@ -194,6 +194,10 @@ impl Peer {
}));
}
}
(PeerState::Negotiated { id, git, .. }, Message::InventoryUpdate { inv }) => {
// TODO: Buffer/throttle fetches.
ctx.process_inventory_update(&inv, *id, git);
}
(
PeerState::Negotiated { .. },
Message::Node {