using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Tor.Controller { /// /// A class containing the command to close an existing circuit. /// internal sealed class CloseCircuitCommand : Command { private readonly Circuit circuit; /// /// Initializes a new instance of the class. /// /// The circuit which should be closed. public CloseCircuitCommand(Circuit circuit) { this.circuit = circuit; } #region Tor.Controller.Command<> /// /// Dispatches the command to the client control port and produces a response result. /// /// The control connection where the command should be dispatched. /// /// A object instance containing the response data. /// protected override Response Dispatch(Connection connection) { if (circuit == null || circuit.Status == CircuitStatus.Closed) return new Response(false); if (connection.Write("closecircuit {0}", circuit.ID)) { ConnectionResponse response = connection.Read(); return new Response(response.Success); } return new Response(false); } #endregion } }