using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; namespace Tor { /// /// A class containing the configurations needed to connect to a remotely hosted tor application executable. /// [DebuggerStepThrough] [Serializable] public sealed class ClientRemoteParams { private string address; private string controlPassword; private int controlPort; /// /// Initializes a new instance of the class. /// public ClientRemoteParams() : this(null, 9051, "") { } /// /// Initializes a new instance of the class. /// /// The address of the hosted tor application. public ClientRemoteParams(string address) : this(address, 9051, "") { } /// /// Initializes a new instance of the class. /// /// The address of the hosted tor application. /// The port number which the application will listening on for control connections. public ClientRemoteParams(string address, int controlPort) : this(address, controlPort, "") { } /// /// Initializes a new instance of the class. /// /// The address of the hosted tor application. /// The port number which the application will listening on for control connections. /// The password used when authenticating with the control connection. public ClientRemoteParams(string address, int controlPort, string controlPassword) { this.address = address; this.controlPassword = controlPassword; this.controlPort = controlPort; } #region Properties /// /// Gets or sets the address of the hosted tor application. /// public string Address { get { return address; } set { address = value; } } /// /// Gets or sets the password used when authenticating with the tor application on the control connection. A value of /// null or blank indicates that no password has been configured. /// public string ControlPassword { get { return controlPassword; } set { controlPassword = value; } } /// /// Gets or sets the port number which the application will be listening on for control connections. /// public int ControlPort { get { return controlPort; } set { controlPort = value; } } #endregion /// /// Validates the parameters assigned to the object, and throws relevant exceptions where necessary. /// internal void ValidateParameters() { if (string.IsNullOrWhiteSpace(address)) throw new TorException("The address cannot be null or white-space"); if (controlPort <= 0 || short.MaxValue < controlPort) throw new TorException("The control port number must be within a valid port range"); } } }