Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ SPDX-FileCopyrightText: 2024 Foundation Devices Inc.
SPDX-License-Identifier: MIT
-->

## 0.2.1

* Tear down the Tor client deterministically on `stop()`: await the proxy
accept loop, cancel accepted connections, and dispose the Rust client
instead of waiting for Dart GC, which left `tor_cache/dir.lock` held and
forced a restarted client's directory store into silent read-only mode.

## 0.0.9

* Bumped arti to version 1.4.3
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.2.0"
version: "0.2.1"
typed_data:
dependency: transitive
description:
Expand Down
10 changes: 5 additions & 5 deletions ios/tor/rust_lib_tor.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,32 @@
<key>BinaryPath</key>
<string>rust_lib_tor.framework/rust_lib_tor</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>rust_lib_tor.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>rust_lib_tor.framework/rust_lib_tor</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>rust_lib_tor.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.2.0</string>
<string>0.2.1</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneOS</string>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.2.0</string>
<string>0.2.1</string>
<key>CFBundleSupportedPlatforms</key>
<array>
<string>iPhoneSimulator</string>
Expand Down
Binary file not shown.
27 changes: 11 additions & 16 deletions lib/tor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class Tor {
bool _started = false;

/// True while the client is starting or re-bootstrapping.
bool get starting =>
_startInFlight != null || _bootstrapInFlight != null;
bool get starting => _startInFlight != null || _bootstrapInFlight != null;

Future<void>? _startInFlight;
Future<void>? _bootstrapInFlight;
Expand Down Expand Up @@ -197,6 +196,9 @@ class Tor {
_client = torInstance.client;
_proxy = torInstance.proxy;
_proxyPort = torInstance.socksPort;
// The getters above clone; free the container now instead of at GC so
// it cannot keep an extra client reference (and dir.lock) alive.
torInstance.dispose();
_started = true;
_bootstrapped = true; // startTor creates a bootstrapped client

Expand Down Expand Up @@ -258,6 +260,7 @@ class Tor {
/// Stops the proxy
Future<void> stop() async {
final proxy = _proxy;
final client = _client;

// Stop publishing the route before awaiting native shutdown so callers
// cannot start new work against a proxy that is being torn down.
Expand All @@ -268,22 +271,14 @@ class Tor {
_bootstrapped = false;
broadcastState();

if (proxy == null) {
return;
}

try {
// This is now safe! FRB catches any panic and throws PanicException
await rust.stopProxy(proxy: proxy);
} on rust.TorError catch (e) {
if (kDebugMode) {
print('Error stopping proxy: $e');
}
} on PanicException catch (e) {
// Previously this would SIGABRT the app, now it's catchable!
if (kDebugMode) {
print('Proxy stop panicked (caught safely): ${e.message}');
if (proxy != null) {
await rust.stopProxy(proxy: proxy);
}
} finally {
// Drop the Rust client now instead of at GC: a lingering client holds
// tor_cache/dir.lock, forcing a restarted client's dirmgr into read-only.
client?.dispose();
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

name: tor
description: A multi-platform Flutter plugin for managing a Tor proxy. Based on arti.
version: 0.2.0
version: 0.2.1
homepage: https://github.com/Foundation-Devices/tor

environment:
Expand Down
6 changes: 5 additions & 1 deletion rust/Cargo.lock

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

7 changes: 6 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[package]
name = "rust_lib_tor"
version = "0.2.0"
version = "0.2.1"
authors = ["Igor Cota <igor@foundation.xyz>"]
edition = "2021"

Expand All @@ -13,8 +13,10 @@ crate-type = ["cdylib", "staticlib", "rlib"]

[dependencies]
flutter_rust_bridge = "=2.11.1"
futures = "0.3"
lazy_static = "1.4"
tokio = { version = "1", features = ["full"] }
tokio-util = { version = "0.7", features = ["rt"] }
libc = "0.2"
liblzma = { version = "0.4.7", features = ["static"] }
arti-client = { version = "0.44.0", features = ["static", "onion-service-client"] }
Expand All @@ -27,6 +29,9 @@ anyhow = "1.0.79"
time = "0.3.36"
thiserror = "1.0"

[dev-dependencies]
tempfile = "3"

[target.'cfg(target_os = "ios")'.dependencies]
# Specific version for iOS
security-framework = "=2.10.0"
Expand Down
Loading