radicle_node/service/
gossip.rs1pub mod store;
2
3use std::str::FromStr;
4
5use super::*;
6use crate::{PROTOCOL_VERSION, VERSION};
7use once_cell::sync::Lazy;
8use radicle::node::UserAgent;
9
10pub use store::{AnnouncementId, Error, RelayStatus, Store};
11
12pub static USER_AGENT: Lazy<UserAgent> = Lazy::new(|| {
14 FromStr::from_str(format!("/radicle:{}/", VERSION.version).as_str())
15 .expect("user agent is valid")
16});
17
18pub fn node(config: &Config, timestamp: Timestamp) -> NodeAnnouncement {
19 let features = config.features();
20 let alias = config.alias.clone();
21 let addresses: BoundedVec<_, ADDRESS_LIMIT> = config
22 .external_addresses
23 .clone()
24 .try_into()
25 .expect("external addresses are within the limit");
26 let agent = USER_AGENT.clone();
27 let version = PROTOCOL_VERSION;
28
29 NodeAnnouncement {
30 features,
31 version,
32 timestamp,
33 alias,
34 addresses,
35 nonce: 0,
36 agent,
37 }
38}
39
40pub fn inventory(
41 timestamp: Timestamp,
42 inventory: impl IntoIterator<Item = RepoId>,
43) -> InventoryAnnouncement {
44 let inventory = inventory.into_iter().collect::<Vec<_>>();
45 if inventory.len() > INVENTORY_LIMIT {
46 error!(
47 target: "service",
48 "inventory announcement limit ({}) exceeded, other nodes will see only some of your projects",
49 inventory.len()
50 );
51 }
52
53 InventoryAnnouncement {
54 inventory: BoundedVec::truncate(inventory),
55 timestamp,
56 }
57}