using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections.ObjectModel; namespace Tor { /// /// A class containing information about an active or inactive stream within the tor network service. /// public sealed class Stream : MarshalByRefObject { private readonly Client client; private readonly int id; private readonly Host target; private int circuitID; private StreamPurpose purpose; private StreamReason reason; private StreamStatus status; /// /// Initializes a new instance of the class. /// /// The client for which the stream belongs. /// The unique identifier of the stream within the tor session. /// The target of the stream. internal Stream(Client client, int id, Host target) { this.circuitID = 0; this.client = client; this.id = id; this.purpose = StreamPurpose.None; this.reason = StreamReason.None; this.status = StreamStatus.None; this.target = target; } #region Properties /// /// Gets the unique identifier of the circuit which owns this stream. This will be zero if the stream has been detached. /// public int CircuitID { get { return circuitID; } internal set { circuitID = value; } } /// /// Gets the unique identifier of the stream in the tor session. /// public int ID { get { return id; } } /// /// Gets the purpose for the stream. This will be StreamPurpose.None unless extended events are enabled. /// public StreamPurpose Purpose { get { return purpose; } internal set { purpose = value; } } /// /// Gets the reason for the stream being closed, failed or detached. This will be StreamReason.None until the stream /// has reached either of the aforementioned states. /// public StreamReason Reason { get { return reason; } internal set { reason = value; } } /// /// Gets the status of the stream. /// public StreamStatus Status { get { return status; } internal set { status = value; } } /// /// Gets the target of the stream. /// public Host Target { get { return target; } } #endregion /// /// Closes the stream. /// /// true if the stream is closed successfully; otherwise, false. public bool Close() { return client.Controller.CloseStream(this, StreamReason.Misc); } } /// /// A class containing a read-only collection of objects. /// public sealed class StreamCollection : ReadOnlyCollection { /// /// Initializes a new instance of the class. /// /// The list of streams. internal StreamCollection(IList list) : base(list) { } } }