nostr-rs-relay

My dev fork of nostr-rs-relay
git clone git://jb55.com/nostr-rs-relay
Log | Files | Refs | README | LICENSE

commit 1b9f364e15a539127cf2939fa9f0023bc9370d95
parent 4d983dd1e001b2f66a59f8ecce062b4bc21c7e79
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Fri,  2 Sep 2022 12:38:31 -0500

chore: rustfmt

Diffstat:
Msrc/db.rs | 6+++---
Msrc/event.rs | 2+-
Msrc/main.rs | 45++++++++++++++++++++++-----------------------
3 files changed, 26 insertions(+), 27 deletions(-)

diff --git 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<usize> { // 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<Box<dyn ToSql>> = vec![Box::new(hex::decode(&e.pubkey)?)]; event_candidates .iter() @@ -516,7 +516,7 @@ fn query_from_filter(f: &ReqFilter) -> (String, Vec<Box<dyn ToSql>>) { // 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 @@ -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 @@ -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::<Event>(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::<SubmittedEvent>(persist_buffer_limit); + let (event_tx, event_rx) = mpsc::channel::<SubmittedEvent>(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)) |