use std::time::Duration;
use std::string::String;
use std::str::FromStr;
use std::sync::Arc;
use iron::request::Request;
use crypto::sha2::Sha256;
use crypto::digest::Digest;
use rand::Rng;
use rand::os::OsRng;
pub struct Config {
pub ping_timeout: Duration,
pub ping_interval: Duration,
pub cookie: Option<String>,
pub cookie_path: Option<String>,
pub generate_id: Arc<Box<Fn(&Request) -> String>>,
}
pub fn generate_id(r: &Request) -> String {
let mut hasher = Sha256::new();
hasher.input_str(format!("{}{}", r.remote_addr, OsRng::new().unwrap().next_u32()).as_str());
hasher.result_str()
}
impl Default for Config {
fn default() -> Config {
Config {
ping_timeout: Duration::from_millis(60000),
ping_interval: Duration::from_millis(25000),
cookie: Some(String::from_str("io").unwrap()),
cookie_path: None,
generate_id: Arc::new(Box::new(generate_id)),
}
}
}