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