Skip to main content

hashiverse_lib/transport/bootstrap_provider/
manual_bootstrap_provider.rs

1//! # Hand-configured bootstrap provider
2//!
3//! Trivial implementation of
4//! [`crate::transport::bootstrap_provider::bootstrap_provider::BootstrapProvider`] that
5//! just hands back a `Vec<String>` provided at construction time. Used by tests
6//! (the integration-test harness feeds every client the addresses of the in-memory
7//! servers it spawned) and by private deployments that prefer to pin seed nodes in
8//! config rather than rely on public DNSSEC.
9
10use crate::transport::bootstrap_provider::bootstrap_provider::BootstrapProvider;
11use std::sync::Arc;
12
13pub struct ManualBootstrapProvider {
14    addresses: Vec<String>,
15}
16
17impl ManualBootstrapProvider {
18    pub fn default() -> Arc<Self> {
19        Self::new(vec![])
20    }
21    pub fn new(addresses: Vec<String>) -> Arc<Self> {
22        Arc::new(Self { addresses })
23    }
24    pub fn new_tcp_localhost() -> Arc<Self> {
25        Arc::new(Self { addresses: vec!["127.0.0.1:443".to_string()] })
26    }
27    pub fn new_mem_multiple() -> Arc<Self> {
28        Arc::new(Self {
29            addresses: vec![
30                "443".to_string(),
31                "10000".to_string(),
32                "20000".to_string(),
33                "20001".to_string(),
34                "20002".to_string(),
35                "20003".to_string(),
36                "20004".to_string(),
37                "20005".to_string(),
38                "20006".to_string(),
39                "20007".to_string(),
40                "20008".to_string(),
41                "20009".to_string(),
42                "20010".to_string(),
43                "20011".to_string(),
44                "20012".to_string(),
45                "20013".to_string(),
46                "20014".to_string(),
47                "20015".to_string(),
48                "20016".to_string(),
49                "20017".to_string(),
50                "20018".to_string(),
51                "20019".to_string(),
52            ],
53        })
54    }
55}
56
57#[async_trait::async_trait]
58impl BootstrapProvider for ManualBootstrapProvider {
59    async fn get_bootstrap_addresses(&self) -> Vec<String> {
60        self.addresses.clone()
61    }
62}