From 4f8fcb7c6567bb315b7cddd448055d1910624bc5 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Tue, 21 Jan 2025 09:22:43 +1300 Subject: [PATCH] config: enable_negentropy --- contrib/chorus.toml | 11 +++++++++++ docs/CONFIG.md | 10 ++++++++++ sample/sample.config.toml | 2 +- src/config.rs | 5 +++++ src/nostr.rs | 17 +++++++++++++++-- 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/contrib/chorus.toml b/contrib/chorus.toml index c0594f3..2ec7cc3 100644 --- a/contrib/chorus.toml +++ b/contrib/chorus.toml @@ -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 diff --git a/docs/CONFIG.md b/docs/CONFIG.md index f58b46f..e3aa32b 100644 --- a/docs/CONFIG.md +++ b/docs/CONFIG.md @@ -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 diff --git a/sample/sample.config.toml b/sample/sample.config.toml index a9c989c..5ae74d4 100644 --- a/sample/sample.config.toml +++ b/sample/sample.config.toml @@ -33,4 +33,4 @@ minimum_ban_seconds = 1 timeout_seconds = 60 max_connections_per_ip = 5 throttling_bytes_per_second = 131072 -throttling_burst = 4194304 \ No newline at end of file +throttling_burst = 4194304 diff --git a/src/config.rs b/src/config.rs index b2ba592..b77bede 100644 --- a/src/config.rs +++ b/src/config.rs @@ -42,6 +42,7 @@ pub struct FriendlyConfig { pub throttling_bytes_per_second: usize, pub throttling_burst: usize, pub blossom_directory: Option, + 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 = 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, + pub enable_negentropy: bool, } impl Default for Config { diff --git a/src/nostr.rs b/src/nostr.rs index 039abb5..f171476 100644 --- a/src/nostr.rs +++ b/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", "", ""] + 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(()); }