Skip to content

Commit 1d804d5

Browse files
committed
pool: drop support for deprecated negentropy protocol
Closes #848 Pull-Request: #853 Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent f6c38a8 commit 1d804d5

File tree

7 files changed

+10
-200
lines changed

7 files changed

+10
-200
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
## Unreleased
2929

30+
### Breaking changes
31+
32+
* pool: drop support for deprecated negentropy protocol ([Yuki Kishimoto] at https://github.com/rust-nostr/nostr/pull/853)
33+
3034
### Changed
3135

3236
* Bump `lru` from 0.13.0 to 0.14.0 ([Yuki Kishimoto])

Cargo.lock

Lines changed: 2 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ clap = "=4.4.18"
1919
js-sys = "0.3"
2020
lru = { version = "0.14", default-features = false }
2121
negentropy = { version = "0.5", default-features = false }
22-
negentropy-deprecated = { package = "negentropy", version = "0.3", default-features = false }
2322
nostr = { version = "0.41", path = "./crates/nostr", default-features = false }
2423
nostr-connect = { version = "0.41", path = "./crates/nostr-connect", default-features = false }
2524
nostr-database = { version = "0.41", path = "./crates/nostr-database", default-features = false }

crates/nostr-relay-pool/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ async-wsocket = { workspace = true, features = ["socks"] }
2222
atomic-destructor.workspace = true
2323
lru.workspace = true
2424
negentropy = { workspace = true, features = ["std"] }
25-
negentropy-deprecated = { workspace = true, features = ["std"] }
2625
nostr = { workspace = true, features = ["std"] }
2726
nostr-database.workspace = true
2827
tokio = { workspace = true, features = ["macros", "sync"] }

crates/nostr-relay-pool/src/relay/error.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ pub enum Error {
3333
Hex(hex::Error),
3434
/// Negentropy error
3535
Negentropy(negentropy::Error),
36-
/// Negentropy error
37-
NegentropyDeprecated(negentropy_deprecated::Error),
3836
/// Database error
3937
Database(DatabaseError),
4038
/// Generic timeout
@@ -133,7 +131,6 @@ impl fmt::Display for Error {
133131
Self::EventBuilder(e) => write!(f, "{e}"),
134132
Self::Hex(e) => write!(f, "{e}"),
135133
Self::Negentropy(e) => write!(f, "{e}"),
136-
Self::NegentropyDeprecated(e) => write!(f, "{e}"),
137134
Self::Database(e) => write!(f, "{e}"),
138135
Self::Timeout => write!(f, "timeout"),
139136
Self::NotRepliedToPing => write!(f, "not replied to ping"),
@@ -234,12 +231,6 @@ impl From<negentropy::Error> for Error {
234231
}
235232
}
236233

237-
impl From<negentropy_deprecated::Error> for Error {
238-
fn from(e: negentropy_deprecated::Error) -> Self {
239-
Self::NegentropyDeprecated(e)
240-
}
241-
}
242-
243234
impl From<DatabaseError> for Error {
244235
fn from(e: DatabaseError) -> Self {
245236
Self::Database(e)

crates/nostr-relay-pool/src/relay/inner.rs

Lines changed: 1 addition & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use async_wsocket::futures_util::{self, SinkExt, StreamExt};
1616
use async_wsocket::{ConnectionMode, Message};
1717
use atomic_destructor::AtomicDestroyer;
1818
use negentropy::{Id, Negentropy, NegentropyStorageVector};
19-
use negentropy_deprecated::{Bytes as BytesDeprecated, Negentropy as NegentropyDeprecated};
2019
use nostr::secp256k1::rand::{self, Rng};
2120
use nostr_database::prelude::*;
2221
use tokio::sync::mpsc::{self, Receiver, Sender};
@@ -1780,7 +1779,7 @@ impl InnerRelay {
17801779

17811780
/// New negentropy protocol
17821781
#[inline(never)]
1783-
pub(super) async fn sync_new(
1782+
pub(super) async fn sync(
17841783
&self,
17851784
filter: &Filter,
17861785
items: Vec<(EventId, Timestamp)>,
@@ -1932,163 +1931,6 @@ impl InnerRelay {
19321931

19331932
Ok(())
19341933
}
1935-
1936-
/// Deprecated negentropy protocol
1937-
#[inline(never)]
1938-
pub(super) async fn sync_deprecated(
1939-
&self,
1940-
filter: &Filter,
1941-
items: Vec<(EventId, Timestamp)>,
1942-
opts: &SyncOptions,
1943-
output: &mut Reconciliation,
1944-
) -> Result<(), Error> {
1945-
// Compose negentropy struct, add items and seal
1946-
let mut negentropy = NegentropyDeprecated::new(32, Some(NEGENTROPY_FRAME_SIZE_LIMIT))?;
1947-
for (id, timestamp) in items.into_iter() {
1948-
let id = BytesDeprecated::from_slice(id.as_bytes());
1949-
negentropy.add_item(timestamp.as_u64(), id)?;
1950-
}
1951-
negentropy.seal()?;
1952-
1953-
// Initiate message
1954-
let initial_message = negentropy.initiate()?;
1955-
1956-
// Subscribe to notifications
1957-
let mut notifications = self.internal_notification_sender.subscribe();
1958-
let mut temp_notifications = self.internal_notification_sender.subscribe();
1959-
1960-
// Send the initial negentropy message
1961-
let sub_id = SubscriptionId::generate();
1962-
let open_msg: ClientMessage = ClientMessage::NegOpen {
1963-
subscription_id: Cow::Borrowed(&sub_id),
1964-
filter: Cow::Borrowed(filter),
1965-
id_size: Some(32),
1966-
initial_message: Cow::Owned(hex::encode(initial_message)),
1967-
};
1968-
self.send_msg(open_msg)?;
1969-
1970-
// Check if negentropy is supported
1971-
check_negentropy_support(&sub_id, opts, &mut temp_notifications).await?;
1972-
1973-
let mut in_flight_up: HashSet<EventId> = HashSet::new();
1974-
let mut in_flight_down: bool = false;
1975-
let mut sync_done: bool = false;
1976-
let mut have_ids: Vec<EventId> = Vec::new();
1977-
let mut need_ids: Vec<EventId> = Vec::new();
1978-
let down_sub_id: SubscriptionId = SubscriptionId::generate();
1979-
1980-
// Start reconciliation
1981-
while let Ok(notification) = notifications.recv().await {
1982-
match notification {
1983-
RelayNotification::Message { message } => {
1984-
match message {
1985-
RelayMessage::NegMsg {
1986-
subscription_id,
1987-
message,
1988-
} => {
1989-
if subscription_id.as_ref() == &sub_id {
1990-
let mut curr_have_ids: Vec<BytesDeprecated> = Vec::new();
1991-
let mut curr_need_ids: Vec<BytesDeprecated> = Vec::new();
1992-
1993-
// Parse message
1994-
let query: BytesDeprecated =
1995-
BytesDeprecated::from_hex(message.as_ref())?;
1996-
1997-
// Reconcile
1998-
let msg: Option<BytesDeprecated> = negentropy.reconcile_with_ids(
1999-
&query,
2000-
&mut curr_have_ids,
2001-
&mut curr_need_ids,
2002-
)?;
2003-
2004-
// Handle the message
2005-
self.handle_neg_msg(
2006-
&subscription_id,
2007-
msg.map(|m| m.to_bytes()),
2008-
curr_have_ids.into_iter().filter_map(neg_depr_to_event_id),
2009-
curr_need_ids.into_iter().filter_map(neg_depr_to_event_id),
2010-
opts,
2011-
output,
2012-
&mut have_ids,
2013-
&mut need_ids,
2014-
&mut sync_done,
2015-
)?;
2016-
}
2017-
}
2018-
RelayMessage::NegErr {
2019-
subscription_id,
2020-
message,
2021-
} => {
2022-
if subscription_id.as_ref() == &sub_id {
2023-
return Err(Error::RelayMessage(message.into_owned()));
2024-
}
2025-
}
2026-
RelayMessage::Ok {
2027-
event_id,
2028-
status,
2029-
message,
2030-
} => {
2031-
self.handle_neg_ok(
2032-
&mut in_flight_up,
2033-
event_id,
2034-
status,
2035-
message,
2036-
output,
2037-
);
2038-
}
2039-
RelayMessage::Event {
2040-
subscription_id,
2041-
event,
2042-
} => {
2043-
if subscription_id.as_ref() == &down_sub_id {
2044-
output.received.insert(event.id);
2045-
}
2046-
}
2047-
RelayMessage::EndOfStoredEvents(id) => {
2048-
if id.as_ref() == &down_sub_id {
2049-
in_flight_down = false;
2050-
}
2051-
}
2052-
RelayMessage::Closed {
2053-
subscription_id, ..
2054-
} => {
2055-
if subscription_id.as_ref() == &down_sub_id {
2056-
in_flight_down = false;
2057-
}
2058-
}
2059-
_ => (),
2060-
}
2061-
2062-
// Send events
2063-
self.upload_neg_events(&mut have_ids, &mut in_flight_up, opts)
2064-
.await?;
2065-
2066-
// Get events
2067-
self.req_neg_events(&mut need_ids, &mut in_flight_down, &down_sub_id, opts)?;
2068-
}
2069-
RelayNotification::RelayStatus { status } => {
2070-
if status.is_disconnected() {
2071-
return Err(Error::NotConnected);
2072-
}
2073-
}
2074-
RelayNotification::Shutdown => return Err(Error::ReceivedShutdown),
2075-
_ => (),
2076-
};
2077-
2078-
if sync_done
2079-
&& have_ids.is_empty()
2080-
&& need_ids.is_empty()
2081-
&& in_flight_up.is_empty()
2082-
&& !in_flight_down
2083-
{
2084-
break;
2085-
}
2086-
}
2087-
2088-
tracing::info!(url = %self.url, "Deprecated negentropy reconciliation terminated.");
2089-
2090-
Ok(())
2091-
}
20921934
}
20931935

20941936
/// Send WebSocket messages with timeout set to [WEBSOCKET_TX_TIMEOUT].
@@ -2114,11 +1956,6 @@ fn neg_id_to_event_id(id: Id) -> EventId {
21141956
EventId::from_byte_array(id.to_bytes())
21151957
}
21161958

2117-
#[inline]
2118-
fn neg_depr_to_event_id(id: BytesDeprecated) -> Option<EventId> {
2119-
EventId::from_slice(id.as_bytes()).ok()
2120-
}
2121-
21221959
fn prepare_negentropy_storage(
21231960
items: Vec<(EventId, Timestamp)>,
21241961
) -> Result<NegentropyStorageVector, Error> {

crates/nostr-relay-pool/src/relay/mod.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -713,22 +713,9 @@ impl Relay {
713713

714714
let mut output: Reconciliation = Reconciliation::default();
715715

716-
match self
717-
.inner
718-
.sync_new(&filter, items.clone(), opts, &mut output)
719-
.await
720-
{
721-
Ok(..) => {}
722-
Err(e) => match e {
723-
Error::NegentropyNotSupported
724-
| Error::Negentropy(negentropy::Error::UnsupportedProtocolVersion) => {
725-
self.inner
726-
.sync_deprecated(&filter, items, opts, &mut output)
727-
.await?;
728-
}
729-
e => return Err(e),
730-
},
731-
}
716+
self.inner
717+
.sync(&filter, items.clone(), opts, &mut output)
718+
.await?;
732719

733720
Ok(output)
734721
}

0 commit comments

Comments
 (0)