Skip to content

Commit

Permalink
Add limit to reduce backpressure risk
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Mar 29, 2024
1 parent b878777 commit 0487ea0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/actors/relay_event_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,15 @@ impl<T: Subscribe> Actor for RelayEventDispatcher<T> {
message: Self::Msg,
state: &mut Self::State,
) -> Result<(), ActorProcessingErr> {
debug!("Handling message: {:?}", message);
match message {
// TODO: Connect and Reconnect should probably be instead Fetch with
// a limit, which would be sent initially from main and then from
// the event enqueuer actor when it's done with the previous batch.
// This would reduce risk of backpressure because ractor has a
// hardcoded broadcast buffer size of 10 items. For the moment, we
// avoid this risk by just having a since filter for the Nostr
// request. DMs are not so common but we should fix this to avoid
// DOS
RelayEventDispatcherMessage::Connect => {
if let Err(e) = self.handle_connection(myself, state, "Connecting").await {
error!("Failed to connect: {}", e);
Expand Down
6 changes: 5 additions & 1 deletion src/bin/giftwrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ async fn main() -> Result<()> {

if args.len() < 2 {
eprintln!("Usage: {} <receiver_public_key>", args[0]);
eprintln!("Example:");
eprintln!(
r#"echo "I'm a boring comment, someone may report it because it's too boring" | ./target/debug/giftwrapper add5190be4673768546c18b565da3a699241f0e06a75e2dbc03f18663d1b7b27 | nak event ws://localhost"#
);

std::process::exit(1);
}

let receiver_pubkey = PublicKey::from_str(&args[1]).expect("Failed to parse the public key");
println!("Receiver public key: {}", receiver_pubkey.to_string());

let stdin = io::stdin();
let mut iterator = stdin.lock().lines();
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async fn main() -> Result<()> {
//TODO: We should probably also filter through `since`
let gift_wrap_filter = vec![Filter::new()
.pubkey(reportinator_public_key)
.limit(10)
.kind(Kind::GiftWrap)];

let relays = get_relays()?;
Expand Down

0 comments on commit 0487ea0

Please sign in to comment.