Skip to content
Snippets Groups Projects
Commit 85a20ae4 authored by Nick Mathewson's avatar Nick Mathewson :game_die:
Browse files

Alternative API for set_isolation_group().

Instead of requiring a `Box<dyn Isolation>`, it now takes either a
`Box<dyn Isolation>`, or an arbitrary `T` that implements
`Isolation`.

This API still allows the user to pass in a `Box<dyn Isolation>` if
that's what they have, but it doesn't require them to Box the
isolation on their own.

Part of #414.
parent 2c5d9852
No related branches found
No related tags found
No related merge requests found
......@@ -684,7 +684,7 @@ impl<R: Runtime> Benchmark<R> {
self.run(BenchmarkType::Arti, |run| {
let mut prefs = arti_client::StreamPrefs::new();
prefs.set_isolation_group(Box::new(iso.next_in(run)));
prefs.set_isolation_group(iso.next_in(run));
tor_client.connect(addr.clone())
})
......
......@@ -231,8 +231,11 @@ impl StreamPrefs {
/// [`TorClient::isolated_client`]. Connections made with an `isolated_client` (and its
/// clones) will not share circuits with the original client, even if the same
/// `isolation_group` is specified via the `ConnectionPrefs` in force.
pub fn set_isolation_group(&mut self, isolation_group: Box<dyn Isolation>) -> &mut Self {
self.isolation = StreamIsolationPreference::Explicit(isolation_group);
pub fn set_isolation_group<T>(&mut self, isolation_group: T) -> &mut Self
where
T: Into<Box<dyn Isolation>>,
{
self.isolation = StreamIsolationPreference::Explicit(isolation_group.into());
self
}
......
......@@ -69,7 +69,7 @@ where
let mut answers = Vec::new();
let mut prefs = StreamPrefs::new();
prefs.set_isolation_group(Box::new(DnsIsolationKey(socket_id, addr.ip())));
prefs.set_isolation_group(DnsIsolationKey(socket_id, addr.ip()));
for query in query.queries() {
let mut a = Vec::new();
......
......@@ -176,7 +176,7 @@ See <a href="https://gitlab.torproject.org/tpo/core/arti/#todo-need-to-change-wh
// Determine whether we want to ask for IPv4/IPv6 addresses.
let mut prefs = stream_preference(&request, &addr);
prefs.set_isolation_group(Box::new(SocksIsolationKey(source_address, ip, auth)));
prefs.set_isolation_group(SocksIsolationKey(source_address, ip, auth));
match request.command() {
SocksCmd::CONNECT => {
......
......@@ -115,6 +115,11 @@ pub trait Isolation: Downcast + DynClone + std::fmt::Debug + Send + Sync + 'stat
}
impl_downcast!(Isolation);
clone_trait_object!(Isolation);
impl<T: Isolation> From<T> for Box<dyn Isolation> {
fn from(isolation: T) -> Self {
Box::new(isolation)
}
}
impl<T: IsolationHelper + Clone + std::fmt::Debug + Send + Sync + 'static> Isolation for T {
fn compatible(&self, other: &dyn Isolation) -> bool {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment