mm1_node/runtime/
config.rs

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
use std::collections::{HashMap, HashSet};

use mm1_address::subnet::NetAddress;
use tokio::runtime::Runtime;

use crate::runtime::actor_key::ActorKey;

mod actor_config;
mod rt_config;

pub(crate) use actor_config::EffectiveActorConfig;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct Mm1Config {
    #[serde(default = "defaults::subnet_address")]
    pub subnet_address: NetAddress,

    #[serde(default)]
    actor: actor_config::ActorConfigNode,

    #[serde(default)]
    runtime: rt_config::RtConfigs,
}

impl Mm1Config {
    pub(crate) fn actor_config(&self, actor_key: &ActorKey) -> impl EffectiveActorConfig + '_ {
        self.actor.select(actor_key)
    }

    pub(crate) fn build_runtimes(&self) -> std::io::Result<(Runtime, HashMap<String, Runtime>)> {
        self.runtime.build_runtimes()
    }

    pub(crate) fn validate(&self) -> Result<(), String> {
        let runtime_keys: HashSet<_> = self.runtime.runtime_keys().collect();
        self.actor.ensure_runtime_keys_are_valid(&runtime_keys)?;

        Ok(())
    }
}

impl Default for Mm1Config {
    fn default() -> Self {
        Self {
            subnet_address: consts::DEFAULT_SUBNET_ADDRESS,
            actor:          Default::default(),
            runtime:        Default::default(),
        }
    }
}

pub mod consts {
    use mm1_address::address::Address;
    use mm1_address::subnet::{NetAddress, NetMask};

    pub const DEFAULT_SUBNET_ADDRESS: NetAddress = NetAddress {
        address: Address::from_u64(0xFFFFFFFF_00000000),
        mask:    NetMask::M_32,
    };

    pub const DEFAULT_ACTOR_NETMASK: NetMask = NetMask::M_56;
    pub const DEFAULT_ACTOR_INBOX_SIZE: usize = 1024;
}

mod defaults {
    use mm1_address::subnet::NetAddress;

    use super::consts;
    pub(super) const fn subnet_address() -> NetAddress {
        consts::DEFAULT_SUBNET_ADDRESS
    }
}