summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2018-10-14 20:23:45 -0400
committerAaron Hill <aa1ronham@gmail.com>2018-10-17 21:19:10 -0400
commit1f09d2797c4061e2f15146af061a24a71c1e10af (patch)
tree97371be709998131261839a0cce46e1304f467d3 /src
parent204cb428b38c119922ed596f27b3f36a6b33366f (diff)
downloadroughenough-1f09d2797c4061e2f15146af061a24a71c1e10af.zip
Add MemoryConfig
Diffstat (limited to 'src')
-rw-r--r--src/config/environment.rs9
-rw-r--r--src/config/file.rs8
-rw-r--r--src/config/memory.rs58
-rw-r--r--src/config/mod.rs27
4 files changed, 69 insertions, 33 deletions
diff --git a/src/config/environment.rs b/src/config/environment.rs
index 2385b28..533f5c0 100644
--- a/src/config/environment.rs
+++ b/src/config/environment.rs
@@ -15,7 +15,6 @@
extern crate hex;
use std::env;
-use std::net::SocketAddr;
use std::time::Duration;
use config::ServerConfig;
@@ -123,14 +122,6 @@ impl ServerConfig for EnvironmentConfig {
self.status_interval
}
- 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)),
- }
- }
-
fn key_protection(&self) -> &KeyProtection {
&self.key_protection
}
diff --git a/src/config/file.rs b/src/config/file.rs
index 440c78c..bef0f1e 100644
--- a/src/config/file.rs
+++ b/src/config/file.rs
@@ -16,7 +16,6 @@ extern crate hex;
use std::fs::File;
use std::io::Read;
-use std::net::SocketAddr;
use std::time::Duration;
use yaml_rust::YamlLoader;
@@ -126,13 +125,6 @@ impl ServerConfig for FileConfig {
self.status_interval
}
- 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)),
- }
- }
fn key_protection(&self) -> &KeyProtection {
&self.key_protection
diff --git a/src/config/memory.rs b/src/config/memory.rs
new file mode 100644
index 0000000..6f35532
--- /dev/null
+++ b/src/config/memory.rs
@@ -0,0 +1,58 @@
+use std::time::Duration;
+use config::ServerConfig;
+use config::{DEFAULT_BATCH_SIZE, DEFAULT_STATUS_INTERVAL};
+use key::KeyProtection;
+
+use hex;
+
+
+/// A purely in-memory Roughenough config
+/// This is useful for fuzzing a server without the need
+/// to create additioanl files.
+pub struct MemoryConfig {
+ pub port: u16,
+ pub interface: String,
+ pub seed: Vec<u8>,
+ pub batch_size: u8,
+ pub status_interval: Duration,
+ pub key_protection: KeyProtection
+}
+
+impl MemoryConfig {
+ pub fn new(port: u16) -> MemoryConfig {
+ MemoryConfig {
+ port,
+ interface: "127.0.0.1".to_string(),
+ seed: hex::decode("a32049da0ffde0ded92ce10a0230d35fe615ec8461c14986baa63fe3b3bac3db").unwrap(),
+ batch_size: DEFAULT_BATCH_SIZE,
+ status_interval: DEFAULT_STATUS_INTERVAL,
+ key_protection: KeyProtection::Plaintext
+ }
+ }
+}
+
+impl ServerConfig for MemoryConfig {
+ fn interface(&self) -> &str {
+ self.interface.as_ref()
+ }
+
+ fn port(&self) -> u16 {
+ self.port
+ }
+
+ fn seed(&self) -> Vec<u8> {
+ self.seed.clone()
+ }
+
+ fn batch_size(&self) -> u8 {
+ self.batch_size
+ }
+
+ fn status_interval(&self) -> Duration {
+ self.status_interval
+ }
+
+ fn key_protection(&self) -> &KeyProtection {
+ &self.key_protection
+ }
+}
diff --git a/src/config/mod.rs b/src/config/mod.rs
index b70bbd5..658669a 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -34,6 +34,9 @@ pub use self::file::FileConfig;
mod environment;
pub use self::environment::EnvironmentConfig;
+mod memory;
+pub use self::memory::MemoryConfig;
+
use Error;
use key::KeyProtection;
@@ -89,7 +92,14 @@ 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
@@ -112,21 +122,6 @@ pub fn make_config(arg: &str) -> Result<Box<ServerConfig>, Error> {
}
}
-/// Creates a config suitable for fuzzing a server instance
-/// This is intended to create a minimal useable config
-/// that allows a server to respond to requests.
-#[cfg(fuzzing)]
-pub fn make_fuzzing_config(port: u16) -> Box<ServerConfig> {
- return Box(EnvironmentConfig {
- port,
- interface: "127.0.0.1".to_string(),
- seed: hex::decode("a32049da0ffde0ded92ce10a0230d35fe615ec8461c14986baa63fe3b3bac3db").unwrap(),
- batch_size: DEFAULT_BATCH_SIZE,
- status_interval: DEFAULT_STATUS_INTERVAL,
- key_protection: KeyProtection::Plaintext
- })
-}
-
///
/// Validate configuration settings. Returns `true` if the config is valid, `false` otherwise.
///