Skip to content

Commit e153339

Browse files
frankomoshyukibtc
andcommitted
nostr: convert NIP-11 module to be I/O-free
- Remove reqwest dependency - Remove `nip11` feature - Remove HTTP URL conversion utilities (with_http_scheme) - Remove NIP-11 support from `nostr-relay-pool` Close #930 Pull-Request: #950 Co-authored-by: Yuki Kishimoto <[email protected]> Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 3a6ba36 commit e153339

File tree

14 files changed

+78
-223
lines changed

14 files changed

+78
-223
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
- nostr: remove `TagStandard::Delegation` and `TagKind::Delegation` (https://github.com/rust-nostr/nostr/pull/929)
3737
- nostr: remove `nip05` cargo feature (https://github.com/rust-nostr/nostr/pull/936)
3838
- nostr: convert `nip05` module to be I/O-free (https://github.com/rust-nostr/nostr/pull/936)
39+
- nostr: convert `nip11` module to be I/O-free (https://github.com/rust-nostr/nostr/pull/950)
3940
- nostr: convert `nip96` module to be I/O-free (https://github.com/rust-nostr/nostr/pull/935)
4041
- connect: remove `NostrConnect::get_relays` (https://github.com/rust-nostr/nostr/pull/894)
4142
- database: merge traits into `NostrDatabase` (https://github.com/rust-nostr/nostr/pull/916)
4243
- database: remove `NostrDatabase::has_coordinate_been_deleted` (https://github.com/rust-nostr/nostr/pull/917)
44+
- pool: remove NIP-11 support (https://github.com/rust-nostr/nostr/pull/950)
4345
- mls: changed return type of `NostrMls::add_members` and `NostrMls::self_update` (https://github.com/rust-nostr/nostr/pull/934)
4446
- mls: changed return type of all group and message methods to return Events instead of serialized MLS objects. (https://github.com/rust-nostr/nostr/pull/940)
4547

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/nostr-relay-pool/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ keywords = ["nostr", "relay", "pool"]
1414
[features]
1515
default = []
1616
tor = ["async-wsocket/tor"]
17-
nip11 = ["nostr/nip11"]
1817

1918
[dependencies]
2019
async-utility.workspace = true

crates/nostr-relay-pool/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ The following crate feature flags are available:
77
| Feature | Default | Description |
88
|---------|:-------:|-------------------------------------------|
99
| `tor` | No | Enable support for embedded tor client |
10-
| `nip11` | No | Enable NIP-11: Relay Information Document |
1110

1211
## State
1312

@@ -19,4 +18,4 @@ The following crate feature flags are available:
1918

2019
## License
2120

22-
This project is distributed under the MIT software license - see the [LICENSE](../../LICENSE) file for details
21+
This project is distributed under the MIT software license - see the [LICENSE](../../LICENSE) file for details

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

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use std::borrow::Cow;
66
use std::cmp;
77
use std::collections::{HashMap, HashSet};
8-
#[cfg(feature = "nip11")]
9-
use std::sync::atomic::AtomicU64;
108
use std::sync::atomic::{AtomicBool, Ordering};
119
use std::sync::Arc;
1210
use std::time::Duration;
@@ -135,10 +133,6 @@ impl Default for SubscriptionData {
135133
#[derive(Debug)]
136134
pub(super) struct AtomicPrivateData {
137135
status: AtomicRelayStatus,
138-
#[cfg(feature = "nip11")]
139-
pub(super) document: RwLock<RelayInformationDocument>,
140-
#[cfg(feature = "nip11")]
141-
last_document_fetch: AtomicU64,
142136
channels: RelayChannels,
143137
subscriptions: RwLock<HashMap<SubscriptionId, SubscriptionData>>,
144138
running: AtomicBool,
@@ -171,10 +165,6 @@ impl InnerRelay {
171165
url,
172166
atomic: Arc::new(AtomicPrivateData {
173167
status: AtomicRelayStatus::default(),
174-
#[cfg(feature = "nip11")]
175-
document: RwLock::new(RelayInformationDocument::new()),
176-
#[cfg(feature = "nip11")]
177-
last_document_fetch: AtomicU64::new(0),
178168
channels: RelayChannels::new(),
179169
subscriptions: RwLock::new(HashMap::new()),
180170
running: AtomicBool::new(false),
@@ -289,50 +279,6 @@ impl InnerRelay {
289279
Ok(())
290280
}
291281

292-
#[cfg(feature = "nip11")]
293-
fn request_nip11_document(&self) {
294-
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
295-
let mut opts: Nip11GetOptions =
296-
Nip11GetOptions::default().timeout(DEFAULT_CONNECTION_TIMEOUT);
297-
298-
let allowed: bool = match self.opts.connection_mode {
299-
ConnectionMode::Direct => true,
300-
#[cfg(not(target_arch = "wasm32"))]
301-
ConnectionMode::Proxy(proxy) => {
302-
// Update proxy
303-
opts.proxy = Some(proxy);
304-
true
305-
}
306-
#[cfg(all(feature = "tor", not(target_arch = "wasm32")))]
307-
ConnectionMode::Tor { .. } => false,
308-
};
309-
310-
if allowed {
311-
let now: u64 = Timestamp::now().as_u64();
312-
313-
// Check last fetch
314-
if self.atomic.last_document_fetch.load(Ordering::SeqCst) + 3600 < now {
315-
// Update last fetch
316-
self.atomic.last_document_fetch.store(now, Ordering::SeqCst);
317-
318-
// Fetch
319-
let url = self.url.clone();
320-
let atomic = self.atomic.clone();
321-
task::spawn(async move {
322-
match RelayInformationDocument::get(url.clone().into(), opts).await {
323-
Ok(document) => {
324-
let mut d = atomic.document.write().await;
325-
*d = document
326-
}
327-
Err(e) => {
328-
tracing::warn!(url = %url, error = %e, "Can't get information document.")
329-
}
330-
};
331-
});
332-
}
333-
}
334-
}
335-
336282
pub async fn subscriptions(&self) -> HashMap<SubscriptionId, Filter> {
337283
let subscription = self.atomic.subscriptions.read().await;
338284
subscription
@@ -757,10 +703,6 @@ impl InnerRelay {
757703
ws_rx: BoxStream,
758704
rx_nostr: &mut MutexGuard<'_, Receiver<Vec<ClientMessageJson>>>,
759705
) {
760-
// Request information document
761-
#[cfg(feature = "nip11")]
762-
self.request_nip11_document();
763-
764706
// (Re)subscribe to relay
765707
if self.flags.can_read() {
766708
if let Err(e) = self.resubscribe().await {

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,6 @@ impl Relay {
186186
&self.inner.flags
187187
}
188188

189-
/// Get [`RelayInformationDocument`]
190-
#[inline]
191-
#[cfg(feature = "nip11")]
192-
pub async fn document(&self) -> RelayInformationDocument {
193-
let document = self.inner.atomic.document.read().await;
194-
document.clone()
195-
}
196-
197189
/// Get subscriptions
198190
#[inline]
199191
pub async fn subscriptions(&self) -> HashMap<SubscriptionId, Filter> {

crates/nostr-sdk/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ tor = ["nostr-relay-pool/tor"]
2121
lmdb = ["dep:nostr-lmdb"]
2222
ndb = ["dep:nostr-ndb"]
2323
indexeddb = ["dep:nostr-indexeddb"]
24-
all-nips = ["nostr/all-nips", "nip04", "nip06", "nip11", "nip44", "nip47", "nip49", "nip57", "nip59", "nip96", "nip98"]
24+
all-nips = ["nostr/all-nips", "nip04", "nip06", "nip44", "nip47", "nip49", "nip57", "nip59", "nip96", "nip98"]
2525
nip03 = ["nostr/nip03"]
2626
nip04 = ["nostr/nip04"]
2727
nip06 = ["nostr/nip06"]
28-
nip11 = ["nostr/nip11", "nostr-relay-pool/nip11"]
2928
nip44 = ["nostr/nip44"]
3029
nip47 = ["nostr/nip47"]
3130
nip49 = ["nostr/nip49"]

crates/nostr-sdk/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ The following crate feature flags are available:
112112
| `nip03` | No | Enable NIP-03: OpenTimestamps Attestations for Events |
113113
| `nip04` | No | Enable NIP-04: Encrypted Direct Message |
114114
| `nip06` | No | Enable NIP-06: Basic key derivation from mnemonic seed phrase |
115-
| `nip11` | No | Enable NIP-11: Relay Information Document |
116115
| `nip44` | No | Enable NIP-44: Encrypted Payloads (Versioned) |
117116
| `nip47` | No | Enable NIP-47: Nostr Wallet Connect |
118117
| `nip49` | No | Enable NIP-49: Private Key Encryption |

crates/nostr/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ alloc = [
4545
"serde/alloc",
4646
"serde_json/alloc",
4747
]
48-
all-nips = ["nip04", "nip06", "nip11", "nip44", "nip46", "nip47", "nip49", "nip57", "nip59", "nip96", "nip98"]
48+
all-nips = ["nip04", "nip06", "nip44", "nip46", "nip47", "nip49", "nip57", "nip59", "nip96", "nip98"]
4949
nip03 = ["dep:nostr-ots"]
5050
nip04 = ["dep:aes", "dep:base64", "dep:cbc"]
5151
nip06 = ["dep:bip39"]
52-
nip11 = ["dep:reqwest"]
5352
nip44 = ["dep:base64", "dep:chacha20"]
5453
nip46 = ["nip04", "nip44"]
5554
nip47 = ["nip04"]
@@ -69,7 +68,6 @@ cbc = { version = "0.1", optional = true }
6968
chacha20 = { version = "0.9", optional = true }
7069
chacha20poly1305 = { version = "0.10", default-features = false, features = ["getrandom"], optional = true }
7170
nostr-ots = { version = "0.2", optional = true }
72-
reqwest = { workspace = true, features = ["json", "rustls-tls", "socks"], optional = true }
7371
scrypt = { version = "0.11", default-features = false, optional = true }
7472
secp256k1 = { version = "0.29", default-features = false, features = ["rand", "serde"] }
7573
serde = { workspace = true, default-features = false, features = ["derive"] }
@@ -83,6 +81,7 @@ getrandom = { version = "0.2", features = ["js"] }
8381
instant = { version = "0.1", features = ["wasm-bindgen", "inaccurate"] }
8482

8583
[dev-dependencies]
84+
reqwest = { workspace = true, features = ["rustls-tls"] }
8685
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
8786

8887
[[example]]
@@ -103,7 +102,7 @@ required-features = ["std"]
103102

104103
[[example]]
105104
name = "nip11"
106-
required-features = ["std", "nip11"]
105+
required-features = ["std"]
107106

108107
[[example]]
109108
name = "nip13"

crates/nostr/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ The following crate feature flags are available:
9191
| `nip03` | No | Enable NIP-03: OpenTimestamps Attestations for Events |
9292
| `nip04` | No | Enable NIP-04: Encrypted Direct Message |
9393
| `nip06` | No | Enable NIP-06: Basic key derivation from mnemonic seed phrase |
94-
| `nip11` | No | Enable NIP-11: Relay Information Document |
9594
| `nip44` | No | Enable NIP-44: Encrypted Payloads (Versioned) |
9695
| `nip46` | No | Enable NIP-46: Nostr Connect |
9796
| `nip47` | No | Enable NIP-47: Nostr Wallet Connect |

0 commit comments

Comments
 (0)