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",
"tor-circmgr",
"tor-error",
"tor-linkspec",
"tor-llcrypto",
"tor-netdoc",
"tor-proto",

View File

@ -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" }

View File

@ -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

View File

@ -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
}
}