mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 01:24:21 +01:00
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:
@@ -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),
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user