mirror of
https://github.com/mikedilger/chorus.git
synced 2026-03-04 06:36:27 +00:00
max_subscriptions, default is 32
This commit is contained in:
parent
461c2d3e33
commit
ca0dee2285
@ -18,4 +18,5 @@ FriendlyConfig(
|
||||
// This is a bad idea in production, but useful for testing or for dumping
|
||||
// your entire relay
|
||||
allow_scraping: true,
|
||||
max_subscriptions: 32,
|
||||
)
|
||||
@ -19,6 +19,7 @@ pub struct FriendlyConfig {
|
||||
pub user_hex_keys: Vec<String>,
|
||||
pub verify_events: bool,
|
||||
pub allow_scraping: bool,
|
||||
pub max_subscriptions: usize,
|
||||
}
|
||||
|
||||
impl Default for FriendlyConfig {
|
||||
@ -38,6 +39,7 @@ impl Default for FriendlyConfig {
|
||||
user_hex_keys: vec![],
|
||||
verify_events: true,
|
||||
allow_scraping: false,
|
||||
max_subscriptions: 32,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -59,6 +61,7 @@ impl FriendlyConfig {
|
||||
user_hex_keys,
|
||||
verify_events,
|
||||
allow_scraping,
|
||||
max_subscriptions,
|
||||
} = self;
|
||||
|
||||
let mut public_key: Option<Pubkey> = None;
|
||||
@ -89,6 +92,7 @@ impl FriendlyConfig {
|
||||
user_hex_keys,
|
||||
verify_events,
|
||||
allow_scraping,
|
||||
max_subscriptions,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -110,4 +114,5 @@ pub struct Config {
|
||||
pub user_hex_keys: Vec<String>,
|
||||
pub verify_events: bool,
|
||||
pub allow_scraping: bool,
|
||||
pub max_subscriptions: usize,
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ async fn handle_http_request(
|
||||
}
|
||||
}
|
||||
|
||||
// DecrementIncrement count of active websockets
|
||||
// Decrement count of active websockets
|
||||
let old_num_websockets = GLOBALS.num_clients.fetch_sub(1, Ordering::SeqCst);
|
||||
|
||||
log::info!(
|
||||
|
||||
13
src/nostr.rs
13
src/nostr.rs
@ -62,6 +62,19 @@ impl WebSocketService {
|
||||
|
||||
log::info!("SUBID={}", subid);
|
||||
|
||||
let max_subscriptions = GLOBALS.config.read().await.max_subscriptions;
|
||||
if self.subscriptions.len() >= max_subscriptions {
|
||||
let reply = NostrReply::Closed(
|
||||
&subid,
|
||||
NostrReplyPrefix::RateLimited,
|
||||
format!(
|
||||
"No more than {max_subscriptions} subscriptions are allowed at any one time"
|
||||
),
|
||||
);
|
||||
self.websocket.send(Message::text(reply.as_json())).await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Read the filter into the session buffer
|
||||
let mut filters: Vec<OwnedFilter> = Vec::new();
|
||||
loop {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user