dirclient: Remember the source of each resposne we receive.

This commit is contained in:
Nick Mathewson 2022-03-18 10:11:27 -04:00
parent 138287beb5
commit 87a3f6b58a
4 changed files with 18 additions and 7 deletions

1
Cargo.lock generated
View File

@ -3314,6 +3314,7 @@ dependencies = [
"thiserror", "thiserror",
"tor-circmgr", "tor-circmgr",
"tor-error", "tor-error",
"tor-linkspec",
"tor-llcrypto", "tor-llcrypto",
"tor-netdoc", "tor-netdoc",
"tor-proto", "tor-proto",

View File

@ -20,6 +20,7 @@ routerdesc = []
[dependencies] [dependencies]
tor-circmgr = { path = "../tor-circmgr", version = "0.1.0" } tor-circmgr = { path = "../tor-circmgr", version = "0.1.0" }
tor-error = { path = "../tor-error", 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-llcrypto = { path = "../tor-llcrypto", version = "0.1.0" }
tor-proto = { path = "../tor-proto", version = "0.1.0" } tor-proto = { path = "../tor-proto", version = "0.1.0" }
tor-netdoc = { path = "../tor-netdoc", version = "0.1.0" } tor-netdoc = { path = "../tor-netdoc", version = "0.1.0" }

View File

@ -111,7 +111,7 @@ where
// TODO(nickm) This should be an option, and is too long. // TODO(nickm) This should be an option, and is too long.
let begin_timeout = Duration::from_secs(5); let begin_timeout = Duration::from_secs(5);
let source = SourceInfo::new(circuit.unique_id()); let source = SourceInfo::from_circuit(&circuit);
// Launch the stream. // Launch the stream.
let mut stream = runtime let mut stream = runtime

View File

@ -1,6 +1,7 @@
//! Define a response type for directory requests. //! 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; use crate::Error;
@ -22,13 +23,12 @@ pub struct DirResponse {
/// ///
/// We use this to remember when a request has failed, so we can /// We use this to remember when a request has failed, so we can
/// abandon the circuit. /// 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)] #[derive(Debug, Clone)]
pub struct SourceInfo { pub struct SourceInfo {
/// Unique identifier for the circuit we're using /// Unique identifier for the circuit we're using
circuit: UniqId, circuit: UniqId,
/// Identity of the directory cache that provided us this information.
cache_id: OwnedChanTarget,
} }
impl DirResponse { impl DirResponse {
@ -85,12 +85,21 @@ impl DirResponse {
impl SourceInfo { impl SourceInfo {
/// Construct a new SourceInfo /// Construct a new SourceInfo
pub(crate) fn new(circuit: UniqId) -> Self { pub(crate) fn from_circuit(circuit: &ClientCirc) -> Self {
SourceInfo { circuit } SourceInfo {
circuit: circuit.unique_id(),
cache_id: circuit.first_hop(),
}
} }
/// Return the unique circuit identifier for the circuit on which /// Return the unique circuit identifier for the circuit on which
/// we received this info. /// we received this info.
pub fn unique_circ_id(&self) -> &UniqId { pub fn unique_circ_id(&self) -> &UniqId {
&self.circuit &self.circuit
} }
/// Return information about the peer from which we received this info.
pub fn cache_id(&self) -> &OwnedChanTarget {
&self.cache_id
}
} }