Skip to content

Commit

Permalink
Make ring default provider, add tmp tcp-client
Browse files Browse the repository at this point in the history
  • Loading branch information
lbirkert committed Sep 1, 2024
1 parent 588c249 commit 1bda44b
Show file tree
Hide file tree
Showing 14 changed files with 648 additions and 92 deletions.
1 change: 1 addition & 0 deletions 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 qb-app-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ qb-ext-local = { path = "../qb-ext-local" }
qb-ext-tcp = { path = "../qb-ext-tcp", default-features = false }

[features]
default = ["ipc", "aws_lc_rs"]
default = ["ipc", "ring"]
ipc = ["dep:interprocess"]
aws_lc_rs = ["qb-ext-tcp/aws_lc_rs"]
aws-lc-rs = ["aws_lc_rs"]
Expand Down
11 changes: 11 additions & 0 deletions qb-daemon/src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,21 @@ impl QBDaemon {
Ok(val) => {
// success: add the descriptor to this daemon
self.add_already_setup(val).await.unwrap();

if id.is_root() {
return;
}

let handle = self.handles.get(&id).unwrap();
handle.send(QBCResponse::Success).await;
}
Err(err) => {
warn!("error while setting up extension: {err}");

if id.is_root() {
return;
}

// error: forward error to the QBCHandle which issued setup
let handle = self.handles.get(&id).unwrap();
handle
Expand Down
3 changes: 2 additions & 1 deletion qb-ext-tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ tracing = "0.1.40"
qb-core = { path = "../qb-core" }
qb-proto = { path = "../qb-proto" }
qb-ext = { path = "../qb-ext" }
tokio-rustls = { version = "0.26.0", default-features = false, features = [] }
tokio-rustls = { version = "0.26.0", default-features = false }
rcgen = "0.13.1"
rustls-cert-gen = "0.1.0"
rustls-pemfile = "2.1.3"
webpki-roots = "0.26.3"

[features]
default = ["ring"]
aws_lc_rs = ["tokio-rustls/aws_lc_rs"]
aws-lc-rs = ["aws_lc_rs"]
ring = ["tokio-rustls/ring"]
8 changes: 8 additions & 0 deletions qb-ext/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ impl QBCId {
Self(rng.gen::<u64>())
}

pub fn root() -> Self {
Self(0)
}

/// Get the string representation of this id in hex format
pub fn to_hex(&self) -> String {
let id_bytes = self.0.to_be_bytes();
Expand All @@ -52,6 +56,10 @@ impl QBCId {
hex::decode_to_slice(hex.as_ref(), &mut id_bytes)?;
Ok(Self(u64::from_be_bytes(id_bytes)))
}

pub fn is_root(&self) -> bool {
self.0 == 0
}
}

/// A request comming from a controlling task.
Expand Down
5 changes: 5 additions & 0 deletions qb-mobile/lib/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ void onStart(ServiceInstance service) async {
final dir = await getApplicationDocumentsDirectory();
print("directory: $dir");
final daemon = await DaemonWrapper.init(path: dir.path);
await daemon.add(
name: "tcp-client",
contentType: "application/json",
content: utf8.encode('{"addr":"192.168.178.84:6969","auth":[]}'),
);

service.on("stop").listen((event) {
service.stopSelf();
Expand Down
37 changes: 34 additions & 3 deletions qb-mobile/lib/src/rust/api/daemon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,45 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<DaemonWrapper>>
abstract class DaemonWrapper implements RustOpaqueInterface {
/// Cancel processing the daemon.
/// Add an extension to this daemon
///
/// This will cancel cancelable tasks, which block execution,
/// as they require mutable access to the daemon.
Future<void> add(
{required String name,
required String contentType,
required List<int> content});

/// Cancel cancelable tasks.
Future<void> cancel();

/// Initialize a new daemon process.
static Future<DaemonWrapper> init({required String path}) =>
RustLib.instance.api.crateApiDaemonDaemonWrapperInit(path: path);

/// Process the daemon. This can be canceled using the cancel method.
/// If called twice, this will cancel the previous execution.
/// Process the daemon.
///
/// This will cancel cancelable tasks, which block execution,
/// as they require mutable access to the daemon.
///
/// This task is cancelable using the cancel method.
Future<void> process();

/// Remove an extension to this daemon.
///
/// This will cancel cancelable tasks, which block execution,
/// as they require mutable access to the daemon.
Future<void> remove({required BigInt id});

/// Start an extension for this daemon.
///
/// This will cancel cancelable tasks, which block execution,
/// as they require mutable access to the daemon.
Future<void> start({required BigInt id});

/// Stop an extension for this daemon.
///
/// This will cancel cancelable tasks, which block execution,
/// as they require mutable access to the daemon.
Future<void> stop({required BigInt id});
}
Loading

0 comments on commit 1bda44b

Please sign in to comment.