Skip to content

Commit bf17baf

Browse files
committed
pool: change log levels for relay filtering check
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 99f8d7d commit bf17baf

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

crates/nostr-relay-pool/src/relay/error.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::time::Duration;
88
use async_utility::thread;
99
use nostr::message::relay::NegentropyErrorCode;
1010
use nostr::message::MessageHandleError;
11-
use nostr::{event, EventId, Kind, PublicKey};
11+
use nostr::{event, EventId, Kind};
1212
use nostr_database::DatabaseError;
1313
use thiserror::Error;
1414

@@ -131,15 +131,6 @@ pub enum Error {
131131
/// Min. difficulty
132132
min: u8,
133133
},
134-
/// Event ID blacklisted
135-
#[error("Received event with blacklisted ID: {0}")]
136-
EventIdBlacklisted(EventId),
137-
/// Public key whitelist
138-
#[error("Received event authored by non-whitelisted public key: {0}")]
139-
PublicKeyNotInWhitelist(PublicKey),
140-
/// Public key blacklisted
141-
#[error("Received event authored by blacklisted public key: {0}")]
142-
PublicKeyBlacklisted(PublicKey),
143134
/// Unexpected kind
144135
#[error("Unexpected kind: expected={expected}, found={found}")]
145136
UnexpectedKind {

crates/nostr-relay-pool/src/relay/filtering.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ use std::sync::Arc;
1111
use nostr::{EventId, PartialEvent, PublicKey};
1212
use tokio::sync::RwLock;
1313

14-
use super::error::Error;
14+
pub(crate) enum CheckFiltering {
15+
Allow,
16+
EventIdBlacklisted(EventId),
17+
PublicKeyBlacklisted(PublicKey),
18+
PublicKeyNotInWhitelist(PublicKey),
19+
}
1520

1621
/// Filtering mode
1722
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -181,28 +186,25 @@ impl RelayFiltering {
181186
public_keys.contains(public_key)
182187
}
183188

184-
pub(crate) async fn check_partial_event(
185-
&self,
186-
partial_event: &PartialEvent,
187-
) -> Result<(), Error> {
189+
pub(crate) async fn check_partial_event(&self, partial_event: &PartialEvent) -> CheckFiltering {
188190
match self.mode.load() {
189191
RelayFilteringMode::Whitelist => {
190192
if !self.has_public_key(&partial_event.pubkey).await {
191-
return Err(Error::PublicKeyNotInWhitelist(partial_event.pubkey));
193+
return CheckFiltering::PublicKeyNotInWhitelist(partial_event.pubkey);
192194
}
193195
}
194196
RelayFilteringMode::Blacklist => {
195197
if self.has_id(&partial_event.id).await {
196-
return Err(Error::EventIdBlacklisted(partial_event.id));
198+
return CheckFiltering::EventIdBlacklisted(partial_event.id);
197199
}
198200

199201
if self.has_public_key(&partial_event.pubkey).await {
200-
return Err(Error::PublicKeyBlacklisted(partial_event.pubkey));
202+
return CheckFiltering::PublicKeyBlacklisted(partial_event.pubkey);
201203
}
202204
}
203205
};
204206

205-
Ok(())
207+
CheckFiltering::Allow
206208
}
207209

208210
/// Remove everything

crates/nostr-relay-pool/src/relay/internal.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tokio::sync::mpsc::{self, Receiver, Sender};
3030
use tokio::sync::{broadcast, oneshot, watch, Mutex, MutexGuard, RwLock};
3131

3232
use super::constants::{MIN_ATTEMPTS, MIN_UPTIME, PING_INTERVAL, WEBSOCKET_TX_TIMEOUT};
33-
use super::filtering::RelayFiltering;
33+
use super::filtering::{CheckFiltering, RelayFiltering};
3434
use super::flags::AtomicRelayServiceFlags;
3535
use super::options::{
3636
FilterOptions, NegentropyOptions, RelayOptions, RelaySendOptions, SubscribeAutoCloseOptions,
@@ -930,7 +930,27 @@ impl InternalRelay {
930930
let partial_event: PartialEvent = PartialEvent::from_raw(&event)?;
931931

932932
// Check filtering
933-
self.filtering.check_partial_event(&partial_event).await?;
933+
match self.filtering.check_partial_event(&partial_event).await {
934+
CheckFiltering::Allow => {
935+
// Nothing to do
936+
}
937+
CheckFiltering::EventIdBlacklisted(id) => {
938+
tracing::debug!("Received event with blacklisted ID: {id}");
939+
return Ok(None);
940+
}
941+
CheckFiltering::PublicKeyBlacklisted(pubkey) => {
942+
tracing::debug!(
943+
"Received event authored by blacklisted public key: {pubkey}"
944+
);
945+
return Ok(None);
946+
}
947+
CheckFiltering::PublicKeyNotInWhitelist(pubkey) => {
948+
tracing::debug!(
949+
"Received event authored by non-whitelisted public key: {pubkey}"
950+
);
951+
return Ok(None);
952+
}
953+
}
934954

935955
// Check min POW
936956
let difficulty: u8 = self.opts.get_pow_difficulty();

0 commit comments

Comments
 (0)