diff options
Diffstat (limited to 'src/config/mod.rs')
-rw-r--r-- | src/config/mod.rs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index f05578b..772e1ee 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -34,8 +34,11 @@ pub use self::file::FileConfig; mod environment; pub use self::environment::EnvironmentConfig; -use Error; +mod memory; +pub use self::memory::MemoryConfig; + use key::KeyProtection; +use Error; /// Maximum number of requests to process in one batch and include the the Merkle tree. pub const DEFAULT_BATCH_SIZE: u8 = 64; @@ -89,7 +92,13 @@ pub trait ServerConfig { fn key_protection(&self) -> &KeyProtection; /// Convenience function to create a `SocketAddr` from the provided `interface` and `port` - fn socket_addr(&self) -> Result<SocketAddr, Error>; + fn socket_addr(&self) -> Result<SocketAddr, Error> { + let addr = format!("{}:{}", self.interface(), self.port()); + match addr.parse() { + Ok(v) => Ok(v), + Err(_) => Err(Error::InvalidConfiguration(addr)), + } + } } /// Factory function to create a `ServerConfig` _trait object_ based on the value @@ -135,14 +144,22 @@ pub fn is_valid_config(cfg: &Box<ServerConfig>) -> bool { is_valid = false; } if cfg.batch_size() < 1 || cfg.batch_size() > 64 { - error!("batch_size {} is invalid; valid range 1-64", cfg.batch_size()); + error!( + "batch_size {} is invalid; valid range 1-64", + cfg.batch_size() + ); is_valid = false; } if is_valid { match cfg.socket_addr() { Err(e) => { - error!("failed to create socket {}:{} {:?}", cfg.interface(), cfg.port(), e); + error!( + "failed to create socket {}:{} {:?}", + cfg.interface(), + cfg.port(), + e + ); is_valid = false; } _ => (), |