diff --git a/Cargo.lock b/Cargo.lock index 932defa4c..4b5c64ffe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3314,6 +3314,7 @@ dependencies = [ "thiserror", "tor-circmgr", "tor-error", + "tor-linkspec", "tor-llcrypto", "tor-netdoc", "tor-proto", diff --git a/crates/tor-dirclient/Cargo.toml b/crates/tor-dirclient/Cargo.toml index 041e63ca5..2a3b730bc 100644 --- a/crates/tor-dirclient/Cargo.toml +++ b/crates/tor-dirclient/Cargo.toml @@ -20,6 +20,7 @@ routerdesc = [] [dependencies] tor-circmgr = { path = "../tor-circmgr", version = "0.1.0" } tor-error = { path = "../tor-error", version = "0.1.0" } +tor-linkspec = { path = "../tor-linkspec", version = "0.1.0" } tor-llcrypto = { path = "../tor-llcrypto", version = "0.1.0" } tor-proto = { path = "../tor-proto", version = "0.1.0" } tor-netdoc = { path = "../tor-netdoc", version = "0.1.0" } diff --git a/crates/tor-dirclient/src/lib.rs b/crates/tor-dirclient/src/lib.rs index 4dfa75fbe..d9f2e3490 100644 --- a/crates/tor-dirclient/src/lib.rs +++ b/crates/tor-dirclient/src/lib.rs @@ -111,7 +111,7 @@ where // TODO(nickm) This should be an option, and is too long. let begin_timeout = Duration::from_secs(5); - let source = SourceInfo::new(circuit.unique_id()); + let source = SourceInfo::from_circuit(&circuit); // Launch the stream. let mut stream = runtime diff --git a/crates/tor-dirclient/src/response.rs b/crates/tor-dirclient/src/response.rs index 0d27ca9ed..dff122164 100644 --- a/crates/tor-dirclient/src/response.rs +++ b/crates/tor-dirclient/src/response.rs @@ -1,6 +1,7 @@ //! Define a response type for directory requests. -use tor_proto::circuit::UniqId; +use tor_linkspec::OwnedChanTarget; +use tor_proto::circuit::{ClientCirc, UniqId}; use crate::Error; @@ -22,13 +23,12 @@ pub struct DirResponse { /// /// We use this to remember when a request has failed, so we can /// abandon the circuit. -/// -/// (In the future, we will probably want to use this structure to -/// remember that the cache isn't working.) #[derive(Debug, Clone)] pub struct SourceInfo { /// Unique identifier for the circuit we're using circuit: UniqId, + /// Identity of the directory cache that provided us this information. + cache_id: OwnedChanTarget, } impl DirResponse { @@ -85,12 +85,21 @@ impl DirResponse { impl SourceInfo { /// Construct a new SourceInfo - pub(crate) fn new(circuit: UniqId) -> Self { - SourceInfo { circuit } + pub(crate) fn from_circuit(circuit: &ClientCirc) -> Self { + SourceInfo { + circuit: circuit.unique_id(), + cache_id: circuit.first_hop(), + } } + /// Return the unique circuit identifier for the circuit on which /// we received this info. pub fn unique_circ_id(&self) -> &UniqId { &self.circuit } + + /// Return information about the peer from which we received this info. + pub fn cache_id(&self) -> &OwnedChanTarget { + &self.cache_id + } }