1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
use jormungandr_lib::interfaces::{
    JRpc, LayersConfig, LogEntry, LogOutput, Mempool, Policy, Rest, TopicsOfInterest,
};
use multiaddr::Multiaddr;
use serde::{Deserialize, Serialize};
use std::{net::SocketAddr, path::PathBuf};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct P2p {
    /// The public address to which other peers may connect to
    pub public_address: Multiaddr,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub public_id: Option<String>,

    /// the rendezvous points for the peer to connect to in order to initiate
    /// the p2p discovery from.
    pub trusted_peers: Vec<TrustedPeer>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub listen: Option<SocketAddr>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_connections: Option<u32>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_inbound_connections: Option<u32>,

    pub allow_private_addresses: bool,

    pub whitelist: Option<Vec<Multiaddr>>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub topics_of_interest: Option<TopicsOfInterest>,

    pub policy: Option<Policy>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub layers: Option<LayersConfig>,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub dns_server_address: Option<SocketAddr>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TrustedPeer {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,
    pub address: Multiaddr,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Log(pub Vec<LogEntry>);

impl Log {
    pub fn file_path(&self) -> Option<&std::path::Path> {
        self.0.iter().find_map(|log_entry| match &log_entry.output {
            LogOutput::File(path) => Some(path.as_path()),
            _ => None,
        })
    }
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct LegacyNodeConfig {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub storage: Option<PathBuf>,
    pub rest: Rest,
    pub jrpc: JRpc,
    pub p2p: P2p,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub log: Option<Log>,
    #[serde(rename = "log", skip_serializing_if = "Option::is_none")]
    pub single_log: Option<jormungandr_lib::interfaces::Log>,
    pub mempool: Option<Mempool>,
    pub bootstrap_from_trusted_peers: Option<bool>,
    pub skip_bootstrap: Option<bool>,
}