diff --git a/src/config.rs b/src/config.rs index a16c272..29ff8b9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -188,9 +188,22 @@ pub fn load_config() -> Result { let mut networks: Vec = vec![]; for toml_network in toml_config.networks.iter() { let mut nodes: Vec = vec![]; + let mut node_ids: Vec = vec![]; for toml_node in toml_network.nodes.iter() { match parse_toml_node(toml_node) { - Ok(node) => nodes.push(node), + Ok(node) => { + if !node_ids.contains(&node.info().id) { + node_ids.push(node.info().id); + nodes.push(node); + } else { + error!( + "Duplicate node id {}: The node {} could not be loaded.", + node.info().id, + node.info() + ); + return Err(ConfigError::DuplicateNodeId); + } + } Err(e) => { error!("Error while parsing a node configuration: {}", toml_node); return Err(e); diff --git a/src/error.rs b/src/error.rs index 3da75e4..5abf5f2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -111,6 +111,7 @@ pub enum ConfigError { NoBtcdRpcAuth, NoNetworks, UnknownImplementation, + DuplicateNodeId, TomlError(toml::de::Error), ReadError(io::Error), AddrError(AddrParseError), @@ -124,6 +125,7 @@ impl fmt::Display for ConfigError { ConfigError::NoBtcdRpcAuth => write!(f, "no values for rpc_user and rpc_password"), ConfigError::NoNetworks => write!(f, "no networks defined in the configuration"), ConfigError::UnknownImplementation => write!(f, "the node implementation defined in the config is not supported"), + ConfigError::DuplicateNodeId => write!(f, "a node id has been used multiple times in the same network"), ConfigError::TomlError(e) => write!(f, "the TOML in the configuration file could not be parsed: {}", e), ConfigError::ReadError(e) => write!(f, "the configuration file could not be read: {}", e), ConfigError::AddrError(e) => write!(f, "the address could not be parsed: {}", e), @@ -142,6 +144,7 @@ impl error::Error for ConfigError { ConfigError::TomlError(ref e) => Some(e), ConfigError::ReadError(ref e) => Some(e), ConfigError::AddrError(ref e) => Some(e), + ConfigError::DuplicateNodeId => None, } } }