Skip to content

Commit

Permalink
sdk: add Connection::embedded_tor_with_path
Browse files Browse the repository at this point in the history
Fix UniFFI checksum mismatch issue.

Closes mozilla/uniffi-rs#2321

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Dec 16, 2024
1 parent 4c88d71 commit 3b988fb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* database: add `SaveEventStatus` enum ([Yuki Kishimoto])
* pool: add `ReceiverStream` ([Yuki Kishimoto])
* sdk: automatically resend event after NIP-42 authentication ([Yuki Kishimoto])
* sdk: add `Connection::embedded_tor_with_path` ([Yuki Kishimoto])
* relay-builder: add NIP42 support ([Yuki Kishimoto])
* relay-builder: add negentropy support ([Yuki Kishimoto])
* relay-builder: add read/write policy plugins ([v0l])
Expand All @@ -81,6 +82,7 @@
* sdk: fix NIP42 authentication for auto-closing REQ ([Yuki Kishimoto])
* sdk: fix min POW is not updated to already existing relays ([Yuki Kishimoto])
* bindings: allow passing empty string as relay url without return an error ([Yuki Kishimoto])
* ffi: fix UniFFI checksum mismatch issue ([Yuki Kishimoto])
* flutter: fix `default` is reserved in dart ([J. Azad EMERY])

### Removed
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rust-version = "1.70.0"
async-trait = "0.1"
async-utility = "0.3"
#async-wsocket = "0.11"
async-wsocket = { git = "https://github.com/yukibtc/async-wsocket", rev = "27f606af6b2028634022a97b5e56c332dfe3f611" }
async-wsocket = { git = "https://github.com/yukibtc/async-wsocket", rev = "259c0bc372e7d60d94827b484178bf995afdcbe6" }
atomic-destructor = { version = "0.3", default-features = false }
js-sys = "0.3"
negentropy = { version = "0.4", default-features = false }
Expand Down
17 changes: 7 additions & 10 deletions bindings/nostr-sdk-ffi/src/client/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,23 @@ impl Connection {
builder.inner = builder.inner.proxy(addr);
Ok(builder)
}
}

#[cfg(all(not(target_os = "android"), not(target_os = "ios")))]
#[uniffi::export]
impl Connection {
/// Use embedded tor client
///
/// This not work on `android` and/or `ios` targets.
/// Use [`Connection::embedded_tor_with_path`] instead.
pub fn embedded_tor(&self) -> Self {
let mut builder = self.clone();
builder.inner = builder.inner.embedded_tor();
builder
}
}

#[cfg(any(target_os = "android", target_os = "ios"))]
#[uniffi::export]
impl Connection {
/// Use embedded tor client
pub fn embedded_tor(&self, data_path: String) -> Self {
///
/// Specify a path where to store data
pub fn embedded_tor_with_path(&self, data_path: String) -> Self {
let mut builder = self.clone();
builder.inner = builder.inner.embedded_tor(data_path);
builder.inner = builder.inner.embedded_tor_with_path(data_path);
builder
}
}
12 changes: 7 additions & 5 deletions crates/nostr-sdk/src/client/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#[cfg(not(target_arch = "wasm32"))]
use std::net::SocketAddr;
#[cfg(all(feature = "tor", any(target_os = "android", target_os = "ios")))]
#[cfg(feature = "tor")]
use std::path::Path;
use std::time::Duration;

Expand Down Expand Up @@ -238,20 +238,22 @@ impl Connection {

/// Use embedded tor client
#[inline]
#[cfg(all(feature = "tor", not(target_os = "android"), not(target_os = "ios")))]
#[cfg(feature = "tor")]
pub fn embedded_tor(mut self) -> Self {
self.mode = ConnectionMode::tor();
self
}

/// Use embedded tor client
///
/// Specify a path where to store data
#[inline]
#[cfg(all(feature = "tor", any(target_os = "android", target_os = "ios")))]
pub fn embedded_tor<P>(mut self, path: P) -> Self
#[cfg(feature = "tor")]
pub fn embedded_tor_with_path<P>(mut self, path: P) -> Self
where
P: AsRef<Path>,
{
self.mode = ConnectionMode::tor(path.as_ref().to_path_buf());
self.mode = ConnectionMode::tor_with_path(path);
self
}
}

0 comments on commit 3b988fb

Please sign in to comment.