Commit 219ad39e authored by trinity-1686a's avatar trinity-1686a
Browse files

remove usage of 'token' where it's no longer a token

parent 85fb91de
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ 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 `StreamPrefs`).
    /// to the `stream_isolation` 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.
@@ -257,7 +257,7 @@ impl StreamPrefs {
        self
    }

    /// Return a token to describe which connections might use
    /// Return an [`Isolation`] to describe which connections might use
    /// the same circuit as this one.
    fn isolation(&self) -> Option<Box<dyn Isolation>> {
        use StreamIsolationPreference as SIP;
@@ -825,7 +825,7 @@ impl<R: Runtime> TorClient<R> {
            b.owner_token(self.client_isolation);
            // Consider stream isolation too, if it's set.
            if let Some(tok) = prefs.isolation() {
                b.stream_token(tok);
                b.stream_isolation(tok);
            }
            // Failure should be impossible with this builder.
            b.build().expect("Failed to construct StreamIsolation")
+15 −12
Original line number Diff line number Diff line
@@ -346,9 +346,9 @@ tuple_impls! {
/// a circuit.
#[derive(Clone, Debug, derive_builder::Builder)]
pub struct StreamIsolation {
    /// Any isolation token set on the stream.
    /// Any isolation set on the stream.
    #[builder(default = "Box::new(IsolationToken::no_isolation())")]
    stream_token: Box<dyn Isolation>,
    stream_isolation: Box<dyn Isolation>,
    /// Any additional isolation token set on an object that "owns" this
    /// stream.  This is typically owned by a `TorClient`.
    #[builder(default = "IsolationToken::no_isolation()")]
@@ -373,17 +373,19 @@ impl StreamIsolation {
impl IsolationHelper for StreamIsolation {
    fn compatible_same_type(&self, other: &StreamIsolation) -> bool {
        self.owner_token == other.owner_token
            && self.stream_token.compatible(other.stream_token.as_ref())
            && self
                .stream_isolation
                .compatible(other.stream_isolation.as_ref())
    }

    fn join_same_type(&self, other: &StreamIsolation) -> Option<StreamIsolation> {
        if self.owner_token != other.owner_token {
            return None;
        }
        self.stream_token
            .join(other.stream_token.as_ref())
            .map(|stream_token| StreamIsolation {
                stream_token,
        self.stream_isolation
            .join(other.stream_isolation.as_ref())
            .map(|stream_isolation| StreamIsolation {
                stream_isolation,
                owner_token: self.owner_token,
            })
    }
@@ -456,7 +458,8 @@ pub(crate) mod test {

    impl IsolationTokenEq for StreamIsolation {
        fn isol_eq(&self, other: &Self) -> bool {
            self.stream_token.isol_eq(other.stream_token.as_ref())
            self.stream_isolation
                .isol_eq(other.stream_isolation.as_ref())
                && self.owner_token == other.owner_token
        }
    }
@@ -551,18 +554,18 @@ pub(crate) mod test {
        let no_isolation = StreamIsolation::no_isolation();
        let no_isolation2 = StreamIsolation::builder()
            .owner_token(IsolationToken::no_isolation())
            .stream_token(Box::new(IsolationToken::no_isolation()))
            .stream_isolation(Box::new(IsolationToken::no_isolation()))
            .build()
            .unwrap();
        assert_eq!(no_isolation.owner_token, no_isolation2.owner_token);
        assert_eq!(
            no_isolation
                .stream_token
                .stream_isolation
                .as_ref()
                .as_any()
                .downcast_ref::<IsolationToken>(),
            no_isolation2
                .stream_token
                .stream_isolation
                .as_ref()
                .as_any()
                .downcast_ref::<IsolationToken>()
@@ -572,7 +575,7 @@ pub(crate) mod test {
        let tok = IsolationToken::new();
        let some_isolation = StreamIsolation::builder().owner_token(tok).build().unwrap();
        let some_isolation2 = StreamIsolation::builder()
            .stream_token(Box::new(tok))
            .stream_isolation(Box::new(tok))
            .build()
            .unwrap();
        assert!(!no_isolation.compatible(&some_isolation));
+1 −1
Original line number Diff line number Diff line
@@ -276,7 +276,7 @@ impl crate::mgr::AbstractSpec for SupportedCircUsage {
            }
            (Exit { policy, isolation }, TargetCircUsage::Preemptive { port, .. }) => {
                if isolation.is_some() {
                    // If the circuit has a stream isolation token, we might not be able to use it
                    // If the circuit has a stream isolation, we might not be able to use it
                    // for new streams that don't share it.
                    return false;
                }