Skip to main content

urma_node/daemon/
options.rs

1use crate::{
2    cache, config,
3    platform::{CommitRpc, ServiceSettings},
4};
5use libp2p::Multiaddr;
6use std::{net::SocketAddr, path::PathBuf, time::Duration};
7
8/// Everything `serve` runs with, whether it came from flags or service.json.
9#[derive(Clone, Debug)]
10pub struct ServeOptions {
11    pub data: PathBuf,
12    pub config: PathBuf,
13    pub listen: SocketAddr,
14    pub token_file: PathBuf,
15    pub p2p: bool,
16    pub header_bootstrap: Option<PathBuf>,
17    pub chain_peers: Vec<SocketAddr>,
18    pub commit_rpc: Option<CommitRpc>,
19    pub commit_public: bool,
20    pub overlay: OverlayOptions,
21    pub cache_bytes: u64,
22    pub object_timeout: Duration,
23}
24
25/// The URMA overlay; without a key it is off and does no key or book I/O.
26#[derive(Clone, Debug)]
27pub struct OverlayOptions {
28    pub key: Option<PathBuf>,
29    pub listen: Option<SocketAddr>,
30    pub manual: Vec<Multiaddr>,
31    pub seeds: Vec<Multiaddr>,
32    pub builtin_seeds: bool,
33    pub announce: Vec<Multiaddr>,
34}
35
36impl ServeOptions {
37    /// The installed service: chain sync, overlay with built-in seeds and the
38    /// public commit providers unless service.json turns them off.
39    pub fn from_settings(settings: ServiceSettings) -> Self {
40        Self {
41            data: settings.data,
42            config: settings.config,
43            listen: settings.listen,
44            token_file: settings.token,
45            p2p: true,
46            header_bootstrap: None,
47            chain_peers: settings.chain_peers,
48            commit_rpc: settings.commit_rpc,
49            commit_public: settings.commit_public,
50            overlay: OverlayOptions {
51                key: Some(settings.peer_key),
52                listen: settings.urma_listen,
53                manual: Vec::new(),
54                seeds: Vec::new(),
55                builtin_seeds: true,
56                announce: settings.urma_announce,
57            },
58            cache_bytes: cache::DEFAULT_CACHE_BYTES,
59            object_timeout: config::SERVICE_OBJECT_TIMEOUT,
60        }
61    }
62}