upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/http/mod.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-03 08:54:00 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-03 08:54:00 +0000
commit2f8ecd482077d82f2d1a937c7f979eaaa87a27b2 (patch)
treecd892cde6ef6fd7ff654377946cab5b95339276f /src/http/mod.rs
parent62a3855cb96616caf704a0f112fb2ade99fb8b45 (diff)
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.
Diffstat (limited to 'src/http/mod.rs')
-rw-r--r--src/http/mod.rs9
1 files changed, 4 insertions, 5 deletions
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;
7use std::future::Future; 7use std::future::Future;
8use std::net::SocketAddr; 8use std::net::SocketAddr;
9use std::pin::Pin; 9use std::pin::Pin;
10use std::sync::Arc;
11 10
12use base64::Engine; 11use base64::Engine;
13use http_body_util::{BodyExt, Full}; 12use http_body_util::{BodyExt, Full};
@@ -17,7 +16,6 @@ use hyper::server::conn::http1;
17use hyper::service::Service; 16use hyper::service::Service;
18use hyper::{Method, Request, Response}; 17use hyper::{Method, Request, Response};
19use hyper_util::rt::TokioIo; 18use hyper_util::rt::TokioIo;
20use nostr_relay_builder::prelude::MemoryDatabase;
21use nostr_relay_builder::LocalRelay; 19use nostr_relay_builder::LocalRelay;
22use nostr_sdk::hashes::sha1::Hash as Sha1Hash; 20use nostr_sdk::hashes::sha1::Hash as Sha1Hash;
23use nostr_sdk::hashes::{Hash, HashEngine}; 21use nostr_sdk::hashes::{Hash, HashEngine};
@@ -26,6 +24,7 @@ use tokio::net::TcpListener;
26 24
27use crate::config::Config; 25use crate::config::Config;
28use crate::git; 26use crate::git;
27use crate::nostr::builder::SharedDatabase;
29 28
30/// CORS headers required by GRASP-01 specification (lines 40-47) 29/// CORS headers required by GRASP-01 specification (lines 40-47)
31const CORS_ALLOW_ORIGIN: &str = "*"; 30const CORS_ALLOW_ORIGIN: &str = "*";
@@ -90,7 +89,7 @@ struct HttpService {
90 config: Config, 89 config: Config,
91 remote: SocketAddr, 90 remote: SocketAddr,
92 /// Database reference for direct queries (e.g., push authorization) 91 /// Database reference for direct queries (e.g., push authorization)
93 database: Arc<MemoryDatabase>, 92 database: SharedDatabase,
94} 93}
95 94
96impl HttpService { 95impl HttpService {
@@ -98,7 +97,7 @@ impl HttpService {
98 relay: LocalRelay, 97 relay: LocalRelay,
99 config: Config, 98 config: Config,
100 remote: SocketAddr, 99 remote: SocketAddr,
101 database: Arc<MemoryDatabase>, 100 database: SharedDatabase,
102 ) -> Self { 101 ) -> Self {
103 Self { 102 Self {
104 relay, 103 relay,
@@ -423,7 +422,7 @@ fn derive_accept_key(request_key: &[u8]) -> String {
423pub async fn run_server( 422pub async fn run_server(
424 config: Config, 423 config: Config,
425 relay: LocalRelay, 424 relay: LocalRelay,
426 database: Arc<MemoryDatabase>, 425 database: SharedDatabase,
427) -> anyhow::Result<()> { 426) -> anyhow::Result<()> {
428 let bind_addr: SocketAddr = config.bind_address.parse()?; 427 let bind_addr: SocketAddr = config.bind_address.parse()?;
429 428