1mod addr;
2mod chan;
3mod error;
4mod frame;
5mod id;
6mod net;
7mod time;
8mod x25519;
9
10#[cfg(feature = "metrics")]
11mod metrics;
12
13pub mod retry;
14
15use std::sync::Arc;
16
17pub use addr::{Address, InvalidAddress};
18use bon::Builder;
19pub use error::NetworkError;
20#[cfg(feature = "metrics")]
21use hotshot_types::traits::metrics::Metrics;
22pub use id::Id;
23pub use net::Network;
24pub use retry::Retry;
25use tokio::sync::Semaphore;
26pub use x25519::{
27 InvalidKeypair, InvalidPublicKey, InvalidSecretKey, Keypair, PublicKey, SecretKey,
28};
29
30pub const MAX_MESSAGE_SIZE: usize = 8 * 1024 * 1024;
32
33const NUM_DELAYS: usize = 5;
34const LAST_DELAY: usize = NUM_DELAYS - 1;
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
38pub enum Role {
39 Active,
41 Passive,
46}
47
48impl Role {
49 pub fn is_active(self) -> bool {
50 matches!(self, Self::Active)
51 }
52}
53
54#[derive(Debug, Builder)]
55pub struct NetConf<K> {
56 name: &'static str,
58
59 label: K,
61
62 keypair: Keypair,
64
65 bind: Address,
67
68 #[builder(with = <_>::from_iter)]
70 parties: Vec<(K, PublicKey, Address)>,
71
72 #[builder(default = 64 * parties.len())]
74 total_capacity_egress: usize,
75
76 #[builder(default = 32 * parties.len())]
78 total_capacity_ingress: usize,
79
80 #[builder(default = 64)]
82 peer_capacity_egress: usize,
83
84 #[builder(default = 32)]
86 peer_capacity_ingress: usize,
87
88 #[builder(default = MAX_MESSAGE_SIZE)]
90 max_message_size: usize,
91
92 #[builder(default = [1, 3, 5, 15, 30])]
94 retry_delays: [u8; NUM_DELAYS],
95
96 #[cfg(feature = "metrics")]
97 metrics: Box<dyn Metrics>,
98}
99
100impl<K> NetConf<K> {
101 fn new_budget(&self) -> Arc<Semaphore> {
102 Arc::new(Semaphore::new(self.peer_capacity_ingress))
103 }
104}