aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2024-05-06 13:14:04 -0400
committerNick Mathewson <nickm@torproject.org>2024-05-09 16:34:17 -0400
commit42539ed458bd3f8fe3a0dae8a684ec83f7a5a40e (patch)
treecb225089a910caf36aafb61fd08104a206140132
parentcf99a17f6b2c9a919016bf1273d44be0a5ffc028 (diff)
downloadarti-42539ed458bd3f8fe3a0dae8a684ec83f7a5a40e.tar.gz
arti-42539ed458bd3f8fe3a0dae8a684ec83f7a5a40e.zip
rpc: Add an isolated-client method on TorClient.
-rw-r--r--crates/arti-client/src/lib.rs2
-rw-r--r--crates/arti-client/src/rpc.rs28
2 files changed, 27 insertions, 3 deletions
diff --git a/crates/arti-client/src/lib.rs b/crates/arti-client/src/lib.rs
index 0d2948015..bc2229366 100644
--- a/crates/arti-client/src/lib.rs
+++ b/crates/arti-client/src/lib.rs
@@ -45,7 +45,7 @@ mod address;
mod builder;
mod client;
#[cfg(feature = "rpc")]
-mod rpc;
+pub mod rpc;
mod util;
pub mod config;
diff --git a/crates/arti-client/src/rpc.rs b/crates/arti-client/src/rpc.rs
index 6af391290..9e866dead 100644
--- a/crates/arti-client/src/rpc.rs
+++ b/crates/arti-client/src/rpc.rs
@@ -17,8 +17,9 @@ impl<R: Runtime> crate::TorClient<R> {
/// parameterized.
pub fn rpc_methods() -> Vec<rpc::dispatch::InvokerEnt> {
rpc::invoker_ent_list![
- get_client_status::<R>, //
- watch_client_status::<R>
+ get_client_status::<R>,
+ watch_client_status::<R>,
+ isolated_client::<R>,
]
}
}
@@ -113,3 +114,26 @@ async fn watch_client_status<R: Runtime>(
// This can only happen if the client exits.
Ok(rpc::NIL)
}
+
+/// RPC method: Return an owned ID for a new isolated client instance.
+#[derive(Deftly, Debug, Serialize, Deserialize)]
+#[derive_deftly(rpc::DynMethod)]
+#[deftly(rpc(method_name = "arti::isolated-client"))]
+#[non_exhaustive]
+pub struct IsolatedClient {}
+
+impl rpc::Method for IsolatedClient {
+ type Output = rpc::SingletonId;
+ type Update = rpc::NoUpdates;
+}
+
+/// RPC method implementation: return a new isolated client based on a given client.
+async fn isolated_client<R: Runtime>(
+ client: Arc<TorClient<R>>,
+ _method: Box<IsolatedClient>,
+ ctx: Box<dyn rpc::Context>,
+) -> Result<rpc::SingletonId, rpc::RpcError> {
+ let new_client = Arc::new(client.isolated_client());
+ let client_id = ctx.register_owned(new_client);
+ Ok(rpc::SingletonId::from(client_id))
+}