Don't copy exit policies around; instead use Arc.

This commit is contained in:
George Kadianakis 2021-03-16 18:50:03 +02:00 committed by Nick Mathewson
parent 2dce8fda0b
commit 508f4c4f39
4 changed files with 11 additions and 13 deletions

View File

@ -211,9 +211,9 @@ impl CircEntry {
#[derive(Clone, Debug)]
struct ExitPolicy {
/// Permitted IPv4 ports.
v4: PortPolicy, // XXXX refcount!
v4: Arc<PortPolicy>,
/// Permitted IPv6 ports.
v6: PortPolicy, // XXXX refcount!
v6: Arc<PortPolicy>,
}
/// A port that we want to connect to as a client.

View File

@ -53,9 +53,6 @@ impl<'a> TorPath<'a> {
/// is a path for use with exit circuits.
pub(crate) fn exit_policy(&self) -> Option<super::ExitPolicy> {
if let Some(exit_relay) = self.exit_relay() {
// TODO: Doing these clones is wasteful; maybe we should
// have Arcs for all exit policies. That could also
// save some memory.
Some(super::ExitPolicy {
v4: exit_relay.ipv4_policy().clone(),
v6: exit_relay.ipv6_policy().clone(),

View File

@ -446,12 +446,12 @@ impl<'a> Relay<'a> {
}
/// Return the IPv4 exit policy for this relay.
pub fn ipv4_policy(&self) -> &'a PortPolicy {
pub fn ipv4_policy(&self) -> &Arc<PortPolicy> {
self.md.ipv4_policy()
}
/// Return the IPv6 exit policy for this relay.
pub fn ipv6_policy(&self) -> &'a PortPolicy {
pub fn ipv6_policy(&self) -> &Arc<PortPolicy> {
self.md.ipv6_policy()
}
}

View File

@ -26,6 +26,7 @@ use tor_llcrypto::pk::{curve25519, ed25519, rsa};
use digest::Digest;
use once_cell::sync::Lazy;
use std::sync::Arc;
use std::time;
@ -59,9 +60,9 @@ pub struct Microdesc {
/// Declared family for this relay.
family: RelayFamily,
/// List of IPv4 ports to which this relay will exit
ipv4_policy: PortPolicy,
ipv4_policy: Arc<PortPolicy>,
/// List of IPv6 ports to which this relay will exit
ipv6_policy: PortPolicy,
ipv6_policy: Arc<PortPolicy>,
/// Ed25519 identity for this relay
ed25519_id: ed25519::Ed25519Identity,
// addr is obsolete and doesn't go here any more
@ -78,11 +79,11 @@ impl Microdesc {
&self.ntor_onion_key
}
/// Return the ipv4 exit policy for this microdesc
pub fn ipv4_policy(&self) -> &PortPolicy {
pub fn ipv4_policy(&self) -> &Arc<PortPolicy> {
&self.ipv4_policy
}
/// Return the ipv6 exit policy for this microdesc
pub fn ipv6_policy(&self) -> &PortPolicy {
pub fn ipv6_policy(&self) -> &Arc<PortPolicy> {
&self.ipv6_policy
}
/// Return the relay family for this microdesc
@ -308,8 +309,8 @@ impl Microdesc {
tap_onion_key,
ntor_onion_key,
family,
ipv4_policy,
ipv6_policy,
ipv4_policy: Arc::new(ipv4_policy),
ipv6_policy: Arc::new(ipv6_policy),
ed25519_id,
};
Ok((md, location))