diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:45:34 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:46:01 +0000 |
| commit | 52489d3b1a7d79e164b4cc901b53fd06c05ce1b1 (patch) | |
| tree | 9be147a22a95b7634a8120a60f2cd8899805088a /src | |
| parent | 6d0447f31eb9f9282e60ac3c90c665a8b3781331 (diff) | |
sync: test sync works without negentropy and add disable option in sync
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 7 | ||||
| -rw-r--r-- | src/http/nip11.rs | 2 | ||||
| -rw-r--r-- | src/sync/mod.rs | 11 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs index f3a3e2a..8c6de05 100644 --- a/src/config.rs +++ b/src/config.rs | |||
| @@ -104,6 +104,12 @@ pub struct Config { | |||
| 104 | /// Note: The connection timeout is capped at this value | 104 | /// Note: The connection timeout is capped at this value |
| 105 | #[arg(long, env = "NGIT_SYNC_BASE_BACKOFF_SECS", default_value_t = 5)] | 105 | #[arg(long, env = "NGIT_SYNC_BASE_BACKOFF_SECS", default_value_t = 5)] |
| 106 | pub sync_base_backoff_secs: u64, | 106 | pub sync_base_backoff_secs: u64, |
| 107 | |||
| 108 | /// Disable NIP-77 negentropy sync (default: false) | ||
| 109 | /// When enabled, sync will use REQ+EOSE instead of negentropy for history sync. | ||
| 110 | /// Primarily useful for testing that sync works without negentropy support. | ||
| 111 | #[arg(long, env = "NGIT_SYNC_DISABLE_NEGENTROPY", default_value_t = false)] | ||
| 112 | pub sync_disable_negentropy: bool, | ||
| 107 | } | 113 | } |
| 108 | 114 | ||
| 109 | impl Config { | 115 | impl Config { |
| @@ -163,6 +169,7 @@ impl Config { | |||
| 163 | sync_max_backoff_secs: 3600, | 169 | sync_max_backoff_secs: 3600, |
| 164 | sync_disconnect_check_interval_secs: 60, | 170 | sync_disconnect_check_interval_secs: 60, |
| 165 | sync_base_backoff_secs: 5, | 171 | sync_base_backoff_secs: 5, |
| 172 | sync_disable_negentropy: false, | ||
| 166 | } | 173 | } |
| 167 | } | 174 | } |
| 168 | } | 175 | } |
diff --git a/src/http/nip11.rs b/src/http/nip11.rs index 8c18dde..7df8306 100644 --- a/src/http/nip11.rs +++ b/src/http/nip11.rs | |||
| @@ -109,6 +109,7 @@ mod tests { | |||
| 109 | sync_max_backoff_secs: 3600, | 109 | sync_max_backoff_secs: 3600, |
| 110 | sync_disconnect_check_interval_secs: 60, | 110 | sync_disconnect_check_interval_secs: 60, |
| 111 | sync_base_backoff_secs: 5, | 111 | sync_base_backoff_secs: 5, |
| 112 | sync_disable_negentropy: false, | ||
| 112 | }; | 113 | }; |
| 113 | 114 | ||
| 114 | let doc = RelayInformationDocument::from_config(&config); | 115 | let doc = RelayInformationDocument::from_config(&config); |
| @@ -147,6 +148,7 @@ mod tests { | |||
| 147 | sync_max_backoff_secs: 3600, | 148 | sync_max_backoff_secs: 3600, |
| 148 | sync_disconnect_check_interval_secs: 60, | 149 | sync_disconnect_check_interval_secs: 60, |
| 149 | sync_base_backoff_secs: 5, | 150 | sync_base_backoff_secs: 5, |
| 151 | sync_disable_negentropy: false, | ||
| 150 | }; | 152 | }; |
| 151 | 153 | ||
| 152 | let doc = RelayInformationDocument::from_config(&config); | 154 | let doc = RelayInformationDocument::from_config(&config); |
diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 3f3966a..c4c3c7f 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs | |||
| @@ -511,8 +511,9 @@ impl SyncManager { | |||
| 511 | } | 511 | } |
| 512 | }; | 512 | }; |
| 513 | 513 | ||
| 514 | // Check if relay supports NIP-77 negentropy | 514 | // Check if relay supports NIP-77 negentropy AND negentropy is not disabled |
| 515 | let use_negentropy = connection.supports_negentropy().await; | 515 | let use_negentropy = !self.config.sync_disable_negentropy |
| 516 | && connection.supports_negentropy().await; | ||
| 516 | 517 | ||
| 517 | // Unsubscribe all current subscriptions | 518 | // Unsubscribe all current subscriptions |
| 518 | connection.unsubscribe_all().await; | 519 | connection.unsubscribe_all().await; |
| @@ -948,7 +949,11 @@ impl SyncManager { | |||
| 948 | ); | 949 | ); |
| 949 | 950 | ||
| 950 | // Check if relay supports NIP-77 negentropy for efficient sync | 951 | // Check if relay supports NIP-77 negentropy for efficient sync |
| 951 | let use_negentropy = if let Some(connection) = self.connections.get(relay_url) { | 952 | // Respect the sync_disable_negentropy config option |
| 953 | let use_negentropy = if self.config.sync_disable_negentropy { | ||
| 954 | tracing::debug!(relay = %relay_url, "Negentropy disabled via config"); | ||
| 955 | false | ||
| 956 | } else if let Some(connection) = self.connections.get(relay_url) { | ||
| 952 | connection.supports_negentropy().await | 957 | connection.supports_negentropy().await |
| 953 | } else { | 958 | } else { |
| 954 | false | 959 | false |