nostr-rs-relay

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

commit bef7ca7e27a2e83ec9df576d0f539e27354ebdec
parent a98708ba4754a7c413fa63da72776e470ce7741f
Author: Greg Heartsfield <scsibug@imap.cc>
Date:   Sat, 24 Sep 2022 09:19:16 -0500

refactor: misc clippy suggestions

Diffstat:
Msrc/conn.rs | 6+++++-
Msrc/db.rs | 10+++++++---
Msrc/nip05.rs | 4++--
Msrc/server.rs | 4++--
4 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/conn.rs b/src/conn.rs @@ -60,6 +60,10 @@ impl ClientConn { } /// Add a new subscription for this connection. + /// # Errors + /// + /// Will return `Err` if the client has too many subscriptions, or + /// if the provided name is excessively long. pub fn subscribe(&mut self, s: Subscription) -> Result<()> { let k = s.get_id(); let sub_id_len = k.len(); @@ -94,7 +98,7 @@ impl ClientConn { } /// Remove the subscription for this connection. - pub fn unsubscribe(&mut self, c: Close) { + pub fn unsubscribe(&mut self, c: &Close) { // TODO: return notice if subscription did not exist. self.subscriptions.remove(&c.id); debug!( diff --git a/src/db.rs b/src/db.rs @@ -13,7 +13,7 @@ use crate::utils::{is_hex, is_lower_hex}; use governor::clock::Clock; use governor::{Quota, RateLimiter}; use hex; -use log::*; +use log::{debug, info, trace, warn}; use r2d2; use r2d2_sqlite::SqliteConnectionManager; use rusqlite::params; @@ -39,9 +39,13 @@ pub struct SubmittedEvent { pub const DB_FILE: &str = "nostr.db"; /// Build a database connection pool. +/// # Panics +/// +/// Will panic if the pool could not be created. +#[must_use] pub fn build_pool( name: &str, - settings: Settings, + settings: &Settings, flags: OpenFlags, min_size: u32, max_size: u32, @@ -98,7 +102,7 @@ pub async fn db_writer( // create a connection pool let pool = build_pool( "event writer", - settings.clone(), + &settings, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE, 1, 4, diff --git a/src/nip05.rs b/src/nip05.rs @@ -146,7 +146,7 @@ impl Verifier { // build a database connection for reading and writing. let write_pool = db::build_pool( "nip05 writer", - settings.clone(), + &settings, rusqlite::OpenFlags::SQLITE_OPEN_READ_WRITE, 1, // min conns 4, // max conns @@ -154,7 +154,7 @@ impl Verifier { ); let read_pool = db::build_pool( "nip05 reader", - settings.clone(), + &settings, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY, 1, // min conns 8, // max conns diff --git a/src/server.rs b/src/server.rs @@ -293,7 +293,7 @@ pub fn start_server(settings: Settings, shutdown_rx: MpscReceiver<()>) -> Result // build a connection pool for sqlite connections let pool = db::build_pool( "client query", - settings.clone(), + &settings, rusqlite::OpenFlags::SQLITE_OPEN_READ_ONLY | rusqlite::OpenFlags::SQLITE_OPEN_SHARED_CACHE, db_min_conn, @@ -579,7 +579,7 @@ async fn nostr_server( } // stop checking new events against // the subscription - conn.unsubscribe(c); + conn.unsubscribe(&c); }, Err(_) => { info!("invalid command ignored");