diff --git a/src/db.rs b/src/db.rs index 1cea93b..e5d13d6 100644 --- a/src/db.rs +++ b/src/db.rs @@ -20,9 +20,9 @@ use rusqlite::params; use rusqlite::types::ToSql; use rusqlite::Connection; use rusqlite::OpenFlags; +use std::fmt::Write as _; use std::path::Path; use std::thread; -use std::fmt::Write as _; use std::time::Duration; use std::time::Instant; use tokio::task; @@ -342,7 +342,7 @@ pub fn write_event(conn: &mut PooledConnection, e: &Event) -> Result { // if this event is a deletion, hide the referenced events from the same author. if e.kind == 5 { let event_candidates = e.tag_values_by_name("e"); - // first parameter will be author + // first parameter will be author let mut params: Vec> = vec![Box::new(hex::decode(&e.pubkey)?)]; event_candidates .iter() @@ -516,7 +516,7 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec>) { // Apply per-filter limit to this subquery. // The use of a LIMIT implies a DESC order, to capture only the most recent events. if let Some(lim) = f.limit { - let _ = write!(query, " ORDER BY e.created_at DESC LIMIT {}", lim); + let _ = write!(query, " ORDER BY e.created_at DESC LIMIT {}", lim); } else { query.push_str(" ORDER BY e.created_at ASC") } diff --git a/src/event.rs b/src/event.rs index 58dfb5b..eb464a0 100644 --- a/src/event.rs +++ b/src/event.rs @@ -129,7 +129,7 @@ impl Event { let tagnamechar = tagnamechar_opt.unwrap(); let tagval = t.get(1).unwrap(); // ensure a vector exists for this tag - idx.entry(tagnamechar).or_insert_with(HashSet::new); + idx.entry(tagnamechar).or_insert_with(HashSet::new); // get the tag vec and insert entry let tidx = idx.get_mut(&tagnamechar).expect("could not get tag vector"); tidx.insert(tagval.clone()); diff --git a/src/main.rs b/src/main.rs index 6a47dc1..aa7cc51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -229,21 +229,21 @@ fn main() -> Result<(), Error> { .unwrap(); // start tokio rt.block_on(async { - let broadcast_buffer_limit; - let persist_buffer_limit; - let verified_users_active; - let db_min_conn; + let broadcast_buffer_limit; + let persist_buffer_limit; + let verified_users_active; + let db_min_conn; let db_max_conn; - // hack to prove we drop the mutexguard prior to any await points - // (https://github.com/rust-lang/rust-clippy/issues/6446) - { + // hack to prove we drop the mutexguard prior to any await points + // (https://github.com/rust-lang/rust-clippy/issues/6446) + { let settings = config::SETTINGS.read().unwrap(); - broadcast_buffer_limit = settings.limits.broadcast_buffer; - persist_buffer_limit = settings.limits.event_persist_buffer; - verified_users_active = settings.verified_users.is_active(); - db_min_conn = settings.database.min_conn; + broadcast_buffer_limit = settings.limits.broadcast_buffer; + persist_buffer_limit = settings.limits.event_persist_buffer; + verified_users_active = settings.verified_users.is_active(); + db_min_conn = settings.database.min_conn; db_max_conn = settings.database.max_conn; - } + } info!("listening on: {}", socket_addr); // all client-submitted valid events are broadcast to every // other client on this channel. This should be large enough @@ -252,8 +252,7 @@ fn main() -> Result<(), Error> { let (bcast_tx, _) = broadcast::channel::(broadcast_buffer_limit); // validated events that need to be persisted are sent to the // database on via this channel. - let (event_tx, event_rx) = - mpsc::channel::(persist_buffer_limit); + let (event_tx, event_rx) = mpsc::channel::(persist_buffer_limit); // establish a channel for letting all threads now about a // requested server shutdown. let (invoke_shutdown, shutdown_listen) = broadcast::channel::<()>(1); @@ -301,7 +300,7 @@ fn main() -> Result<(), Error> { rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY | rusqlite::OpenFlags::SQLITE_OPEN_SHARED_CACHE, db_min_conn, - db_max_conn, + db_max_conn, true, ); // A `Service` is needed for every connection, so this @@ -482,9 +481,9 @@ async fn nostr_server( Some(Ok(Message::Text(m))) => { convert_to_msg(m) }, - Some(Ok(Message::Binary(_))) => { - ws_stream.send( - make_notice_message("binary messages are not accepted")).await.ok(); + Some(Ok(Message::Binary(_))) => { + ws_stream.send( + make_notice_message("binary messages are not accepted")).await.ok(); continue; }, Some(Ok(Message::Ping(_))) | Some(Ok(Message::Pong(_))) => { @@ -492,12 +491,12 @@ async fn nostr_server( // send responses automatically. continue; }, - Some(Err(WsError::Capacity(MessageTooLong{size, max_size}))) => { - ws_stream.send( - make_notice_message( - &format!("message too large ({} > {})",size, max_size))).await.ok(); + Some(Err(WsError::Capacity(MessageTooLong{size, max_size}))) => { + ws_stream.send( + make_notice_message( + &format!("message too large ({} > {})",size, max_size))).await.ok(); continue; - }, + }, None | Some(Ok(Message::Close(_))) | Some(Err(WsError::AlreadyClosed)) |