mirror of
https://github.com/mikedilger/chorus.git
synced 2026-08-01 07:21:39 +00:00
config: enable_negentropy
This commit is contained in:
parent
2e1ca26d3e
commit
4f8fcb7c65
@ -319,3 +319,14 @@ throttling_burst = 16777216
|
||||
# Default is not set
|
||||
#
|
||||
# blossom_directory =
|
||||
|
||||
|
||||
# Whether to allow negentropy syncing or not
|
||||
#
|
||||
# If this is enabled, keep in mind that some negentropy syncs are scrapes and if you want to
|
||||
# allow those, you should also enable allow_scraping. But this will require scans of the entire
|
||||
# database since scrapes have no indexes.
|
||||
#
|
||||
# Default is false
|
||||
#
|
||||
enable_negentropy = false
|
||||
|
||||
@ -276,3 +276,13 @@ Our implementation makes all files publicly readable, but only chorus users can
|
||||
or delete. See https://github.com/hzrd149/blossom
|
||||
|
||||
Default is None
|
||||
|
||||
### enable_negentropy
|
||||
|
||||
Whether to allow negentropy syncing or not
|
||||
|
||||
If this is enabled, keep in mind that some negentropy syncs are scrapes and if you want to
|
||||
allow those, you should also enable allow_scraping. But this will require scans of the entire
|
||||
database since scrapes have no indexes.
|
||||
|
||||
Default is false
|
||||
|
||||
@ -33,4 +33,4 @@ minimum_ban_seconds = 1
|
||||
timeout_seconds = 60
|
||||
max_connections_per_ip = 5
|
||||
throttling_bytes_per_second = 131072
|
||||
throttling_burst = 4194304
|
||||
throttling_burst = 4194304
|
||||
|
||||
@ -42,6 +42,7 @@ pub struct FriendlyConfig {
|
||||
pub throttling_bytes_per_second: usize,
|
||||
pub throttling_burst: usize,
|
||||
pub blossom_directory: Option<String>,
|
||||
pub enable_negentropy: bool,
|
||||
}
|
||||
|
||||
impl Default for FriendlyConfig {
|
||||
@ -81,6 +82,7 @@ impl Default for FriendlyConfig {
|
||||
throttling_bytes_per_second: 1024 * 1024,
|
||||
throttling_burst: 1024 * 1024 * 16,
|
||||
blossom_directory: None,
|
||||
enable_negentropy: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -122,6 +124,7 @@ impl FriendlyConfig {
|
||||
throttling_bytes_per_second,
|
||||
throttling_burst,
|
||||
blossom_directory,
|
||||
enable_negentropy,
|
||||
} = self;
|
||||
|
||||
let mut public_key: Option<Pubkey> = None;
|
||||
@ -185,6 +188,7 @@ impl FriendlyConfig {
|
||||
throttling_bytes_per_second,
|
||||
throttling_burst,
|
||||
blossom_directory,
|
||||
enable_negentropy,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -227,6 +231,7 @@ pub struct Config {
|
||||
pub throttling_bytes_per_second: usize,
|
||||
pub throttling_burst: usize,
|
||||
pub blossom_directory: Option<String>,
|
||||
pub enable_negentropy: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
||||
17
src/nostr.rs
17
src/nostr.rs
@ -468,6 +468,12 @@ impl WebSocketService {
|
||||
subid
|
||||
};
|
||||
|
||||
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?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Read the filter into the session buffer
|
||||
let filter = {
|
||||
eat_whitespace(input, &mut inpos);
|
||||
@ -497,7 +503,7 @@ impl WebSocketService {
|
||||
|
||||
// NEG-ERR if the message was empty
|
||||
if incoming_msg.is_empty() {
|
||||
let reply = NostrReply::NegErr(&subid, "Empty negentropy message".to_owned());
|
||||
let reply = NostrReply::NegErr(&subid, "error: Empty negentropy message".to_owned());
|
||||
self.send(Message::text(reply.as_json())).await?;
|
||||
return Ok(());
|
||||
}
|
||||
@ -574,6 +580,7 @@ impl WebSocketService {
|
||||
let input = msg.as_bytes();
|
||||
|
||||
// ["NEG-MSG", "<subid>", "<hex-message>"]
|
||||
|
||||
eat_whitespace(input, &mut inpos);
|
||||
verify_char(input, b',', &mut inpos)?;
|
||||
eat_whitespace(input, &mut inpos);
|
||||
@ -593,6 +600,12 @@ impl WebSocketService {
|
||||
subid
|
||||
};
|
||||
|
||||
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?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Read the negentropy message
|
||||
let incoming_msg = {
|
||||
eat_whitespace(input, &mut inpos);
|
||||
@ -610,7 +623,7 @@ impl WebSocketService {
|
||||
|
||||
// NEG-ERR if the message was empty
|
||||
if incoming_msg.is_empty() {
|
||||
let reply = NostrReply::NegErr(&subid, "Empty negentropy message".to_owned());
|
||||
let reply = NostrReply::NegErr(&subid, "error: Empty negentropy message".to_owned());
|
||||
self.send(Message::text(reply.as_json())).await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user