feat: integrate nostrdb relay indexing

- Upgrade `nostrdb` to v0.6.1 with relay metadata support
- Switch to `nostr::RelayUrl` for typed relay URLs
- Use `process_event_with()` to pass relay info during ingestion
- Update `Relay`, `RelayPool`, and unknown ID logic accordingly

This enables richer indexing with relay provenance in events.

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-03-21 16:17:32 -07:00
parent a7f34a9dc7
commit 26b58683b8
12 changed files with 52 additions and 25 deletions

View File

@@ -25,6 +25,9 @@ pub enum Error {
#[error("invalid public key")]
InvalidPublicKey,
#[error("invalid relay url")]
InvalidRelayUrl,
// Secp(secp256k1::Error),
#[error("json error: {0}")]
Json(#[from] serde_json::Error),

View File

@@ -149,7 +149,7 @@ pub fn setup_multicast_relay(
}
pub struct Relay {
pub url: String,
pub url: nostr::RelayUrl,
pub status: RelayStatus,
pub sender: WsSender,
pub receiver: WsReceiver,
@@ -180,9 +180,10 @@ impl PartialEq for Relay {
impl Eq for Relay {}
impl Relay {
pub fn new(url: String, wakeup: impl Fn() + Send + Sync + 'static) -> Result<Self> {
pub fn new(url: nostr::RelayUrl, wakeup: impl Fn() + Send + Sync + 'static) -> Result<Self> {
let status = RelayStatus::Connecting;
let (sender, receiver) = ewebsock::connect_with_wakeup(&url, Options::default(), wakeup)?;
let (sender, receiver) =
ewebsock::connect_with_wakeup(url.as_str(), Options::default(), wakeup)?;
Ok(Self {
url,
@@ -210,7 +211,7 @@ impl Relay {
pub fn connect(&mut self, wakeup: impl Fn() + Send + Sync + 'static) -> Result<()> {
let (sender, receiver) =
ewebsock::connect_with_wakeup(&self.url, Options::default(), wakeup)?;
ewebsock::connect_with_wakeup(self.url.as_str(), Options::default(), wakeup)?;
self.status = RelayStatus::Connecting;
self.sender = sender;
self.receiver = receiver;

View File

@@ -1,5 +1,5 @@
use crate::relay::{setup_multicast_relay, MulticastRelay, Relay, RelayStatus};
use crate::{ClientMessage, Result};
use crate::{ClientMessage, Error, Result};
use nostrdb::Filter;
use std::collections::BTreeSet;
@@ -50,7 +50,7 @@ pub struct WebsocketRelay {
impl PoolRelay {
pub fn url(&self) -> &str {
match self {
Self::Websocket(wsr) => &wsr.relay.url,
Self::Websocket(wsr) => wsr.relay.url.as_str(),
Self::Multicast(_wsr) => "multicast",
}
}
@@ -315,7 +315,10 @@ impl RelayPool {
if self.has(&url) {
return Ok(());
}
let relay = Relay::new(url, wakeup)?;
let relay = Relay::new(
nostr::RelayUrl::parse(url).map_err(|_| Error::InvalidRelayUrl)?,
wakeup,
)?;
let pool_relay = PoolRelay::websocket(relay);
self.relays.push(pool_relay);

View File

@@ -229,6 +229,7 @@ fn calculate_error_size(error: &Error) -> usize {
| Error::InvalidBech32
| Error::InvalidByteSize
| Error::InvalidSignature
| Error::InvalidRelayUrl
| Error::Io(_)
| Error::InvalidPublicKey => mem::size_of_val(error), // No heap usage