mirror of
https://github.com/mikedilger/chorus.git
synced 2026-01-03 06:15:33 +00:00
Improve negentropy error handling by using NEG-ERR when we can
This commit is contained in:
parent
4f8fcb7c65
commit
e9fd738213
@ -227,6 +227,7 @@ async fn websocket_thread(peer: HashedPeer, websocket: HyperWebsocket, origin: S
|
||||
user: None,
|
||||
error_punishment: 0.0,
|
||||
replied: false,
|
||||
negentropy_sub: None,
|
||||
};
|
||||
|
||||
// Increment connection count
|
||||
@ -362,6 +363,7 @@ struct WebSocketService {
|
||||
pub user: Option<Pubkey>,
|
||||
pub error_punishment: f32,
|
||||
pub replied: bool,
|
||||
pub negentropy_sub: Option<String>,
|
||||
}
|
||||
|
||||
impl WebSocketService {
|
||||
@ -544,9 +546,14 @@ impl WebSocketService {
|
||||
}
|
||||
}
|
||||
if !self.replied {
|
||||
if let Some(subid) = &self.negentropy_sub {
|
||||
let reply = NostrReply::NegErr(subid, format!("error: {e}"));
|
||||
self.send(Message::text(reply.as_json())).await?;
|
||||
} else {
|
||||
let reply = NostrReply::Notice(format!("error: {}", e.inner));
|
||||
self.send(Message::text(reply.as_json())).await?;
|
||||
}
|
||||
}
|
||||
if self.error_punishment >= 1.0 {
|
||||
let reply = NostrReply::Notice("Closing due to error(s)".into());
|
||||
self.send(Message::text(reply.as_json())).await?;
|
||||
|
||||
12
src/nostr.rs
12
src/nostr.rs
@ -468,8 +468,11 @@ impl WebSocketService {
|
||||
subid
|
||||
};
|
||||
|
||||
self.negentropy_sub = Some(subid.clone());
|
||||
|
||||
if !GLOBALS.config.read().enable_negentropy {
|
||||
let reply = NostrReply::NegErr(&subid, "blocked: Negentropy sync is disabled".to_owned());
|
||||
let reply =
|
||||
NostrReply::NegErr(&subid, "blocked: Negentropy sync is disabled".to_owned());
|
||||
self.send(Message::text(reply.as_json())).await?;
|
||||
return Ok(());
|
||||
}
|
||||
@ -600,8 +603,11 @@ impl WebSocketService {
|
||||
subid
|
||||
};
|
||||
|
||||
self.negentropy_sub = Some(subid.clone());
|
||||
|
||||
if !GLOBALS.config.read().enable_negentropy {
|
||||
let reply = NostrReply::NegErr(&subid, "blocked: Negentropy sync is disabled".to_owned());
|
||||
let reply =
|
||||
NostrReply::NegErr(&subid, "blocked: Negentropy sync is disabled".to_owned());
|
||||
self.send(Message::text(reply.as_json())).await?;
|
||||
return Ok(());
|
||||
}
|
||||
@ -677,6 +683,8 @@ impl WebSocketService {
|
||||
subid
|
||||
};
|
||||
|
||||
self.negentropy_sub = Some(subid.clone());
|
||||
|
||||
// Close the subscription
|
||||
self.neg_subscriptions.remove(&subid);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user