diff --git a/src/conn.rs b/src/conn.rs index 6973ae4..6584c08 100644 --- 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 index cbcb077..72e5ca0 100644 --- 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 index 87e6d5e..f512e68 100644 --- 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 index f2defa3..b53f712 100644 --- 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");