diff --git a/crates/tor-proto/semver.md b/crates/tor-proto/semver.md index df03b656f..d8c59a803 100644 --- a/crates/tor-proto/semver.md +++ b/crates/tor-proto/semver.md @@ -7,3 +7,4 @@ and returns a `Result` BREAKING: `ClientCirc::allow_stream_requests` now expects `self` to be `&Arc` ADDED: `HopNum` is now public +ADDED: `ClientCirc::last_hop_num` diff --git a/crates/tor-proto/src/circuit.rs b/crates/tor-proto/src/circuit.rs index fb12f547b..3d02a9d05 100644 --- a/crates/tor-proto/src/circuit.rs +++ b/crates/tor-proto/src/circuit.rs @@ -283,6 +283,20 @@ impl ClientCirc { } } + /// Return the [`HopNum`](crate::HopNum) of the last hop of this circuit. + /// + /// Returns an error if there is no last hop. (This should be impossible outside of the + /// tor-proto crate, but within the crate it's possible to have a circuit with no hops.) + pub fn last_hop_num(&self) -> Result { + Ok(self + .mutable + .lock() + .expect("poisoned lock") + .path + .last_hop_num() + .ok_or_else(|| internal!("no last hop index"))?) + } + /// Return a description of all the hops in this circuit. /// /// This method is **deprecated** for several reasons: