Commit 77b425ea authored by Ian Jackson's avatar Ian Jackson
Browse files

Move ProxyConfig to arti crate

We put this in cfg.rs, rather than (say) socks.rs, because it has
config relating to both socks.rs and dns.rs.

Code motion and import fixups.
parent 98105da7
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -51,9 +51,7 @@ mod cmdline;
mod options;

pub use cmdline::CmdLine;
pub use options::{
    ApplicationConfig, ApplicationConfigBuilder, ProxyConfig, ProxyConfigBuilder, ARTI_DEFAULTS,
};
pub use options::{ApplicationConfig, ApplicationConfigBuilder, ARTI_DEFAULTS};
use tor_config::CfgPath;

/// The synchronous configuration builder type we use.
+0 −48
Original line number Diff line number Diff line
@@ -33,51 +33,3 @@ impl ApplicationConfig {
        self.watch_configuration
    }
}

/// Configuration for one or more proxy listeners.
#[derive(Deserialize, Debug, Clone, Builder, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
#[builder(build_fn(error = "ConfigBuildError"))]
#[builder(derive(Deserialize))]
pub struct ProxyConfig {
    /// Port to listen on (at localhost) for incoming SOCKS
    /// connections.
    #[serde(default = "default_socks_port")]
    #[builder(default = "default_socks_port()")]
    socks_port: Option<u16>,
    /// Port to lisen on (at localhost) for incoming DNS connections.
    #[serde(default)]
    #[builder(default)]
    dns_port: Option<u16>,
}

/// Return the default value for `socks_port`
#[allow(clippy::unnecessary_wraps)]
fn default_socks_port() -> Option<u16> {
    Some(9150)
}

impl Default for ProxyConfig {
    fn default() -> Self {
        Self::builder().build().expect("Default builder failed")
    }
}

impl ProxyConfig {
    /// Return a new [`ProxyConfigBuilder`].
    pub fn builder() -> ProxyConfigBuilder {
        ProxyConfigBuilder::default()
    }

    /// Return the configured SOCKS port for this proxy configuration,
    /// if one is enabled.
    pub fn socks_port(&self) -> Option<u16> {
        self.socks_port
    }

    /// Return the configured DNS port for this proxy configuration,
    /// if one is enabled.
    pub fn dns_port(&self) -> Option<u16> {
        self.dns_port
    }
}
+50 −1
Original line number Diff line number Diff line
@@ -4,15 +4,64 @@

use std::convert::TryFrom;

use derive_builder::Builder;
use serde::Deserialize;

use arti_client::config::{SystemConfig, SystemConfigBuilder, TorClientConfigBuilder};
use arti_client::TorClientConfig;
use arti_config::{ApplicationConfig, ApplicationConfigBuilder, ProxyConfig, ProxyConfigBuilder};
use arti_config::{ApplicationConfig, ApplicationConfigBuilder};
use tor_config::ConfigBuildError;

use crate::{LoggingConfig, LoggingConfigBuilder};

/// Configuration for one or more proxy listeners.
#[derive(Deserialize, Debug, Clone, Builder, Eq, PartialEq)]
#[serde(deny_unknown_fields)]
#[builder(build_fn(error = "ConfigBuildError"))]
#[builder(derive(Deserialize))]
pub struct ProxyConfig {
    /// Port to listen on (at localhost) for incoming SOCKS
    /// connections.
    #[serde(default = "default_socks_port")]
    #[builder(default = "default_socks_port()")]
    socks_port: Option<u16>,
    /// Port to lisen on (at localhost) for incoming DNS connections.
    #[serde(default)]
    #[builder(default)]
    dns_port: Option<u16>,
}

/// Return the default value for `socks_port`
#[allow(clippy::unnecessary_wraps)]
fn default_socks_port() -> Option<u16> {
    Some(9150)
}

impl Default for ProxyConfig {
    fn default() -> Self {
        Self::builder().build().expect("Default builder failed")
    }
}

impl ProxyConfig {
    /// Return a new [`ProxyConfigBuilder`].
    pub fn builder() -> ProxyConfigBuilder {
        ProxyConfigBuilder::default()
    }

    /// Return the configured SOCKS port for this proxy configuration,
    /// if one is enabled.
    pub fn socks_port(&self) -> Option<u16> {
        self.socks_port
    }

    /// Return the configured DNS port for this proxy configuration,
    /// if one is enabled.
    pub fn dns_port(&self) -> Option<u16> {
        self.dns_port
    }
}

/// Structure to hold Arti's configuration options, whether from a
/// configuration file or the command line.
//
+1 −1
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ pub mod process;
pub mod socks;
pub mod watch_cfg;

pub use cfg::{ArtiConfig, ArtiConfigBuilder};
pub use cfg::{ArtiConfig, ArtiConfigBuilder, ProxyConfig, ProxyConfigBuilder};
pub use logging::{LoggingConfig, LoggingConfigBuilder};

use arti_client::{TorClient, TorClientConfig};