From 2f8ecd482077d82f2d1a937c7f979eaaa87a27b2 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 3 Dec 2025 08:54:00 +0000 Subject: feat: implement LMDB database backend - Add nostr-lmdb dependency (v0.44) for persistent storage - Create SharedDatabase type alias for database abstraction - Update all database-related functions to use trait object - Support runtime selection via NGIT_DATABASE_BACKEND env var Database backends: - memory: In-memory (default, fastest, no persistence) - lmdb: LMDB backend (persistent, general purpose) All 34 tests pass with the new implementation. --- src/http/mod.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/http') diff --git a/src/http/mod.rs b/src/http/mod.rs index 5cf8dbe..4665281 100644 --- a/src/http/mod.rs +++ b/src/http/mod.rs @@ -7,7 +7,6 @@ pub mod nip11; use std::future::Future; use std::net::SocketAddr; use std::pin::Pin; -use std::sync::Arc; use base64::Engine; use http_body_util::{BodyExt, Full}; @@ -17,7 +16,6 @@ use hyper::server::conn::http1; use hyper::service::Service; use hyper::{Method, Request, Response}; use hyper_util::rt::TokioIo; -use nostr_relay_builder::prelude::MemoryDatabase; use nostr_relay_builder::LocalRelay; use nostr_sdk::hashes::sha1::Hash as Sha1Hash; use nostr_sdk::hashes::{Hash, HashEngine}; @@ -26,6 +24,7 @@ use tokio::net::TcpListener; use crate::config::Config; use crate::git; +use crate::nostr::builder::SharedDatabase; /// CORS headers required by GRASP-01 specification (lines 40-47) const CORS_ALLOW_ORIGIN: &str = "*"; @@ -90,7 +89,7 @@ struct HttpService { config: Config, remote: SocketAddr, /// Database reference for direct queries (e.g., push authorization) - database: Arc, + database: SharedDatabase, } impl HttpService { @@ -98,7 +97,7 @@ impl HttpService { relay: LocalRelay, config: Config, remote: SocketAddr, - database: Arc, + database: SharedDatabase, ) -> Self { Self { relay, @@ -423,7 +422,7 @@ fn derive_accept_key(request_key: &[u8]) -> String { pub async fn run_server( config: Config, relay: LocalRelay, - database: Arc, + database: SharedDatabase, ) -> anyhow::Result<()> { let bind_addr: SocketAddr = config.bind_address.parse()?; -- cgit v1.2.3