Commit ba591a81 authored by Ian Jackson's avatar Ian Jackson 💬
Browse files

Merge branch 'conn-prefs-rename' into 'main'

StreamPrefs: rename from ConnectPrefs

See merge request !256
parents 695a33c1 a79a2e87
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ Streams can be isolated in two ways:

- by calling [`TorClient::isolated_client`], which returns a new [`TorClient`] whose streams
  will use a different circuit
- by generating [`IsolationToken`]s, and passing them in via [`ConnectPrefs`] to
- by generating [`IsolationToken`]s, and passing them in via [`StreamPrefs`] to
  [`TorClient::connect`].

## Multiple runtime support
+12 −12
Original line number Diff line number Diff line
@@ -47,11 +47,11 @@ pub struct TorClient<R: Runtime> {
    /// Default isolation token for streams through this client.
    ///
    /// This is eventually used for `owner_token` in `tor-circmgr/src/usage.rs`, and is orthogonal
    /// to the `stream_token` which comes from `connect_prefs` (or a passed-in `ConnectPrefs`).
    /// to the `stream_token` which comes from `connect_prefs` (or a passed-in `StreamPrefs`).
    /// (ie, both must be the same to share a circuit).
    client_isolation: IsolationToken,
    /// Connection preferences.  Starts out as `Default`,  Inherited by our clones.
    connect_prefs: ConnectPrefs,
    connect_prefs: StreamPrefs,
    /// Circuit manager for keeping our circuits up to date and building
    /// them on-demand.
    circmgr: Arc<tor_circmgr::CircMgr<R>>,
@@ -78,7 +78,7 @@ pub struct TorClient<R: Runtime> {

/// Preferences for how to route a stream over the Tor network.
#[derive(Debug, Clone, Default)]
pub struct ConnectPrefs {
pub struct StreamPrefs {
    /// What kind of IPv6/IPv4 we'd prefer, and how strongly.
    ip_ver_pref: IpVersionPreference,
    /// How should we isolate connection(s) ?
@@ -104,8 +104,8 @@ impl Default for StreamIsolationPreference {
    }
}

impl ConnectPrefs {
    /// Construct a new ConnectPrefs.
impl StreamPrefs {
    /// Construct a new StreamPrefs.
    pub fn new() -> Self {
        Self::default()
    }
@@ -476,7 +476,7 @@ impl<R: Runtime> TorClient<R> {
    pub async fn connect_with_prefs<A: IntoTorAddr>(
        &self,
        target: A,
        prefs: &ConnectPrefs,
        prefs: &StreamPrefs,
    ) -> Result<DataStream> {
        let addr = target.into_tor_addr()?;
        addr.enforce_config(&self.addrcfg.get())?;
@@ -507,7 +507,7 @@ impl<R: Runtime> TorClient<R> {
    //
    // This function is private just because we're not sure we want to provide this API.
    // https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/250#note_2771238
    fn set_connect_prefs(&mut self, connect_prefs: ConnectPrefs) {
    fn set_stream_prefs(&mut self, connect_prefs: StreamPrefs) {
        self.connect_prefs = connect_prefs;
    }

@@ -516,9 +516,9 @@ impl<R: Runtime> TorClient<R> {
    /// Connections made with e.g. [`connect`](TorClient::connect) on the returned handle will use
    /// `connect_prefs`.  This is a convenience wrapper for `clone` and `set_connect_prefs`.
    #[must_use]
    pub fn clone_with_prefs(&self, connect_prefs: ConnectPrefs) -> Self {
    pub fn clone_with_prefs(&self, connect_prefs: StreamPrefs) -> Self {
        let mut result = self.clone();
        result.set_connect_prefs(connect_prefs);
        result.set_stream_prefs(connect_prefs);
        result
    }

@@ -531,7 +531,7 @@ impl<R: Runtime> TorClient<R> {
    pub async fn resolve_with_prefs(
        &self,
        hostname: &str,
        prefs: &ConnectPrefs,
        prefs: &StreamPrefs,
    ) -> Result<Vec<IpAddr>> {
        let addr = (hostname, 0).into_tor_addr()?;
        addr.enforce_config(&self.addrcfg.get())?;
@@ -560,7 +560,7 @@ impl<R: Runtime> TorClient<R> {
    pub async fn resolve_ptr_with_prefs(
        &self,
        addr: IpAddr,
        prefs: &ConnectPrefs,
        prefs: &StreamPrefs,
    ) -> Result<Vec<String>> {
        let circ = self.get_or_launch_exit_circ(&[], prefs).await?;

@@ -599,7 +599,7 @@ impl<R: Runtime> TorClient<R> {
    async fn get_or_launch_exit_circ(
        &self,
        exit_ports: &[TargetPort],
        prefs: &ConnectPrefs,
        prefs: &StreamPrefs,
    ) -> Result<ClientCirc> {
        let dir = self.dirmgr.netdir();

+2 −2
Original line number Diff line number Diff line
@@ -106,7 +106,7 @@
//!
//! - by calling [`TorClient::isolated_client`], which returns a new [`TorClient`] whose streams
//!   will use a different circuit
//! - by generating [`IsolationToken`]s, and passing them in via [`ConnectPrefs`] to
//! - by generating [`IsolationToken`]s, and passing them in via [`StreamPrefs`] to
//!   [`TorClient::connect`].
//!
//! # Multiple runtime support
@@ -179,7 +179,7 @@ pub mod config;
pub mod status;

pub use address::{DangerouslyIntoTorAddr, IntoTorAddr, TorAddr, TorAddrError};
pub use client::{ConnectPrefs, TorClient};
pub use client::{StreamPrefs, TorClient};
pub use config::TorClientConfig;

pub use tor_circmgr::IsolationToken;
+3 −3
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ use std::sync::{self, Arc};
use std::time::{Duration, Instant};
use tracing::{error, info, warn};

use arti_client::{ConnectPrefs, IsolationToken, TorClient};
use arti_client::{IsolationToken, StreamPrefs, TorClient};
use tor_rtcompat::{Runtime, TcpListener};
use tor_socksproto::{SocksAddr, SocksAuth, SocksCmd, SocksRequest};

@@ -23,8 +23,8 @@ use anyhow::{anyhow, Context, Result};

/// Find out which kind of address family we can/should use for a
/// given `SocksRequest`.
fn stream_preference(req: &SocksRequest, addr: &str) -> ConnectPrefs {
    let mut prefs = ConnectPrefs::new();
fn stream_preference(req: &SocksRequest, addr: &str) -> StreamPrefs {
    let mut prefs = StreamPrefs::new();
    if addr.parse::<Ipv4Addr>().is_ok() {
        // If they asked for an IPv4 address correctly, nothing else will do.
        prefs.ipv4_only();
+3 −3
Original line number Diff line number Diff line
@@ -88,15 +88,15 @@ impl TargetPort {
/// Using an isolation token to route streams differently over the Tor network:
///
/// ```ignore
/// use arti_client::ConnectPrefs;
/// use arti_client::StreamPrefs;
///
/// let token_1 = IsolationToken::new();
/// let token_2 = IsolationToken::new();
///
/// let mut prefs_1 = ConnectPrefs::new();
/// let mut prefs_1 = StreamPrefs::new();
/// prefs_1.set_isolation_group(token_1);
///
/// let mut prefs_2 = ConnectPrefs::new();
/// let mut prefs_2 = StreamPrefs::new();
/// prefs_2.set_isolation_group(token_2);
///
/// // These two connections will come from different source IP addresses.