Commit 87a3f6b5 authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

dirclient: Remember the source of each resposne we receive.

parent 138287be
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3314,6 +3314,7 @@ dependencies = [
 "thiserror",
 "tor-circmgr",
 "tor-error",
 "tor-linkspec",
 "tor-llcrypto",
 "tor-netdoc",
 "tor-proto",
+1 −0
Original line number Diff line number Diff line
@@ -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" }
+1 −1
Original line number Diff line number Diff line
@@ -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
+15 −6
Original line number Diff line number Diff line
//! 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
    }
}