diff --git a/Cargo.lock b/Cargo.lock index 4e63698..b9dbf52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -431,55 +431,84 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-executor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "futures-channel" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "futures-core" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures-executor" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures-io" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures-macro" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "futures-sink" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures-task" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures-util" -version = "0.3.1" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-macro 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -507,9 +536,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -594,9 +623,9 @@ version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "h2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -737,6 +766,7 @@ dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "fern 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonwebtoken 7.0.0-alpha.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1101,6 +1131,21 @@ name = "ppv-lite86" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro-hack" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro-nested" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "proc-macro2" version = "1.0.6" @@ -1663,7 +1708,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1694,8 +1739,8 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "pin-project-lite 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1869,7 +1914,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "headers 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2113,13 +2158,15 @@ dependencies = [ "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6f16056ecbb57525ff698bb955162d0cd03bee84e6241c27ff75c08d8ca5987" -"checksum futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86" -"checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866" -"checksum futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff" -"checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16" -"checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9" -"checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" +"checksum futures 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5c329ae8753502fb44ae4fc2b622fa2a94652c41e795143765ba0927f92ab780" +"checksum futures-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c77d04ce8edd9cb903932b608268b3fffec4163dc053b3b402bf47eac1f1a8" +"checksum futures-core 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f25592f769825e89b92358db00d26f965761e094951ac44d3663ef25b7ac464a" +"checksum futures-executor 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f674f3e1bcb15b37284a90cedf55afdba482ab061c407a9c0ebbd0f3109741ba" +"checksum futures-io 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a638959aa96152c7a4cddf50fcb1e3fede0583b27157c26e67d6f99904090dc6" +"checksum futures-macro 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9a5081aa3de1f7542a794a397cde100ed903b0630152d0973479018fd85423a7" +"checksum futures-sink 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3466821b4bc114d95b087b850a724c6f83115e929bc88f1fa98a3304a944c8a6" +"checksum futures-task 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0a34e53cf6cdcd0178aa573aed466b646eb3db769570841fda0c7ede375a27" +"checksum futures-util 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "22766cf25d64306bedf0384da004d05c9974ab104fcc4528f1236181c18004c5" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" "checksum h2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7938e6aa2a31df4e21f224dc84704bd31c089a6d1355c535b03667371cccc843" @@ -2188,6 +2235,8 @@ dependencies = [ "checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" "checksum plotters 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)" = "4e3bb8da247d27ae212529352020f3e5ee16e83c0c258061d27b08ab92675eeb" "checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +"checksum proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ecd45702f76d6d3c75a80564378ae228a85f0b59d2f3ed43c91b4a69eb2ebfc5" +"checksum proc-macro-nested 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "369a6ed065f249a159e06c45752c780bda2fb53c995718f9e484d08daa9eb42e" "checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" diff --git a/Cargo.toml b/Cargo.toml index 6062c91..7ea097d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,11 +37,12 @@ tree_magic = "0.2.1" snafu = "0.6.2" bytes = "0.5.3" hex = "0.3.1" +futures = "0.3.4" fern = { version = "0.5.9", features = ["colored", "syslog-4"] } clap = { version = "2.33.0", features = ["yaml"] } warp = { version = "0.2.0", features = ["tls"] } log = { version = "0.4.8", features = ["serde"] } -tokio = { version = "0.2.9", features = ["full"] } +tokio = { version = "0.2.9", features = ["full", "sync"] } serpent = { git = "https://github.com/RustCrypto/block-ciphers" } block-modes = "0.3.3" hyper = "0.13.4" diff --git a/src/build.rs b/src/build.rs index eb9873f..80d1308 100644 --- a/src/build.rs +++ b/src/build.rs @@ -6,9 +6,10 @@ fn main() { if std::env::var("PROFILE").unwrap() == "release" { let mut res = winres::WindowsResource::new(); res.set_icon("assets/favicon.ico"); - res.compile().expect("Unable to setup windows resources informations."); + res.compile() + .expect("Unable to setup windows resources informations."); } } #[cfg(not(target_os = "windows"))] -fn main() {} \ No newline at end of file +fn main() {} diff --git a/src/configuration.rs b/src/configuration.rs index ca73182..ed14199 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -18,6 +18,7 @@ pub struct Configuration { pub authentication: Authentication, pub persistence: Persistence, pub encryption: Encryption, + pub sse: ServerSentEvent, pub webui: WebUI, pub store: Store, pub http: Http, @@ -58,6 +59,7 @@ impl Default for Configuration { private_key: hex::encode(rand::thread_rng().gen::<[u8; 24]>()), iv: hex::encode(rand::thread_rng().gen::<[u8; 16]>()), }, + sse: ServerSentEvent { enabled: false }, webui: WebUI { enabled: false }, store: Store { max_limit: 7340032 }, http: Http { @@ -107,6 +109,11 @@ pub struct WebUI { pub enabled: bool, } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServerSentEvent { + pub enabled: bool, +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Store { pub max_limit: u64, diff --git a/src/server.rs b/src/server.rs index 008a96f..aca811d 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,7 +1,4 @@ -use std::{ - net::SocketAddr, - sync::{Arc, RwLock}, -}; +use std::{net::SocketAddr, sync::RwLock}; use bytes::{Buf, Bytes}; use jsonwebtoken::Validation; @@ -9,11 +6,25 @@ use snafu::Snafu; use warp::{ self, filters, fs, http::{Response, StatusCode}, - path, reject, Filter, Rejection, Reply, + path, reject, Rejection, Reply, }; use crate::configuration::{Claims, Configuration}; use crate::kvstore::KvStore; +use futures::{Stream, StreamExt}; +use std::collections::HashMap; +use std::sync::{ + atomic::{AtomicUsize, Ordering}, + Arc, Mutex, +}; +use tokio::sync::mpsc; +use warp::{sse::ServerSentEvent, Filter}; + +#[derive(Debug)] +pub struct SseMessage { + key: String, + value: String +} #[derive(Serialize, Deserialize)] struct JsonMessage { @@ -24,6 +35,10 @@ pub struct Server { configuration: Arc>, } +type Events = Arc>>>; + +static NEXT_EVENT_ID: AtomicUsize = AtomicUsize::new(1); + impl Server { pub fn new(configuration: Arc>) -> Server { Server { configuration } @@ -46,8 +61,9 @@ impl Server { } } let store = Arc::new(KvStore::new(encryption_key)); + let events = Arc::new(Mutex::new(HashMap::new())); - let instance = warp::serve(routes_filter(store, self.configuration.clone())); + let instance = warp::serve(routes_filter(store, events, self.configuration.clone())); if configuration.general.use_ssl { let bind_endpoint = SocketAddr::from(( configuration.general.bind_address, @@ -101,11 +117,13 @@ impl Server { pub fn routes_filter( store: Arc, + events: Events, config: Arc>, ) -> impl Filter + Clone + Send + Sync + 'static { let configuration = config.read().unwrap(); let store = warp::any().map(move || store.clone()); + let events = warp::any().map(move || events.clone()); let config = config.clone(); let config = warp::any().map(move || config.clone()); @@ -117,14 +135,17 @@ pub fn routes_filter( let webui_enabled = config.clone().and_then(check_webui).untuple_one(); + let sse_enabled = config.clone().and_then(check_sse).untuple_one(); + let api_kv_key_path = path!("api" / "kv" / String).and(path::end()); - let api_kv_key = auth.and( + let api_kv_key = auth.clone().and( warp::get() .and(store.clone()) .and(api_kv_key_path) .and_then(get_key) .or(warp::put() .and(store.clone()) + .and(events.clone()) .and(config.clone()) .and(api_kv_key_path) .and(filters::body::content_length_limit( @@ -169,8 +190,20 @@ pub fn routes_filter( .allow_methods(vec!["HEAD", "GET", "PUT", "POST", "PATCH", "DELETE"]) .allow_any_origin(); + let sse = warp::path("notifications") + .and(warp::get()) + .and(events) + .and(auth) + .and(sse_enabled) + .map(|events| { + let stream = sse_event_stream(events); + warp::sse::reply(warp::sse::keep_alive().stream(stream)) + }) + .with(warp::log("lucid::server::sse")); + api_kv_key .or(webui) + .or(sse) .or(robots) .recover(process_error) .with(warp::reply::with::header( @@ -193,6 +226,7 @@ async fn get_key(store: Arc, key: String) -> Result, + events: Events, config: Arc>, key: String, body: Bytes, @@ -204,6 +238,13 @@ async fn put_key( max_limit: config.read().unwrap().store.max_limit, })) } else { + // TODO: handle non-ascii data + if let Ok(byte_to_string) = String::from_utf8((&body).bytes().to_vec()) { + events + .lock() + .unwrap() + .retain(|_, tx| tx.send(SseMessage { key: key.clone(), value: byte_to_string.clone() }).is_ok()); + } if let Some(_) = store.set(key, body.to_vec()) { Ok(warp::reply::json(&JsonMessage { message: "The specified key was successfully updated.".to_string(), @@ -314,6 +355,29 @@ async fn check_webui(config: Arc>) -> Result<(), Rejection } } +async fn check_sse(config: Arc>) -> Result<(), Rejection> { + let config = config.read().unwrap(); + if config.sse.enabled { + Ok(()) + } else { + Err(reject::not_found()) + } +} + +fn sse_event_stream( + events: Events, +) -> impl Stream> + Send + 'static +{ + let my_id = NEXT_EVENT_ID.fetch_add(1, Ordering::Relaxed); + + let (tx, rx) = mpsc::unbounded_channel(); + + tx.send(SseMessage { key: String::from("lol"), value: String::from("lol") }).unwrap(); + events.lock().unwrap().insert(0, tx); + + rx.map(move |msg: SseMessage| Ok((warp::sse::id(my_id), warp::sse::event(msg.key), warp::sse::data(msg.value)))) +} + async fn process_error(err: Rejection) -> Result { if let Some(err) = err.find::() { let code = match err { diff --git a/tests/api_test.rs b/tests/api_test.rs index 0774d27..f4e61d5 100644 --- a/tests/api_test.rs +++ b/tests/api_test.rs @@ -1,4 +1,4 @@ -use std::sync::{Arc, RwLock}; +use std::{collections::HashMap, sync::{Arc, RwLock, Mutex}}; use hyper::StatusCode; use serde_json::Value; @@ -8,8 +8,9 @@ use lucid::{configuration::Configuration, kvstore::KvStore, server::routes_filte fn create_routes_filter() -> impl Filter + Clone + Send + Sync + 'static { let store = Arc::new(KvStore::new(None)); + let events = Arc::new(Mutex::new(HashMap::new())); let config = Arc::new(RwLock::new(Configuration::default())); - routes_filter(store.clone(), config.clone()) + routes_filter(store, events, config) } #[cfg(test)]