Init
This commit is contained in:
51
TorWebClient/TorClient/Streams/Enumerators/StreamPurpose.cs
Normal file
51
TorWebClient/TorClient/Streams/Enumerators/StreamPurpose.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
/// <summary>
|
||||
/// An enumerator containing the different purposes for a stream, which is provided when extended events are enabled.
|
||||
/// </summary>
|
||||
public enum StreamPurpose
|
||||
{
|
||||
/// <summary>
|
||||
/// A purpose was not provided.
|
||||
/// </summary>
|
||||
[Description(null)]
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// The stream was generated internally for fetching directory information.
|
||||
/// </summary>
|
||||
[Description("DIR_FETCH")]
|
||||
DirectoryFetch,
|
||||
|
||||
/// <summary>
|
||||
/// The stream was generated internally for uploading information to a directory authority.
|
||||
/// </summary>
|
||||
[Description("DIR_READ")]
|
||||
DirectoryRead,
|
||||
|
||||
/// <summary>
|
||||
/// The stream is a user-initiated DNS request.
|
||||
/// </summary>
|
||||
[Description("DNS_REQUEST")]
|
||||
DNSRequest,
|
||||
|
||||
/// <summary>
|
||||
/// The stream is used explicitly for testing whether our hosted directory port is accessible.
|
||||
/// </summary>
|
||||
[Description("DIRPORT_TEST")]
|
||||
DirectoryPortTest,
|
||||
|
||||
/// <summary>
|
||||
/// The stream is likely handling a user request. This could also be an internal stream, and none of the other
|
||||
/// purposes match the real purpose of the stream.
|
||||
/// </summary>
|
||||
[Description("USER")]
|
||||
User,
|
||||
}
|
||||
}
|
||||
116
TorWebClient/TorClient/Streams/Enumerators/StreamReason.cs
Normal file
116
TorWebClient/TorClient/Streams/Enumerators/StreamReason.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
/// <summary>
|
||||
/// An enumerator containing the reasons for a stream's failed, closed or detached events.
|
||||
/// </summary>
|
||||
public enum StreamReason : int
|
||||
{
|
||||
/// <summary>
|
||||
/// No reason was provided.
|
||||
/// </summary>
|
||||
[Description(null)]
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// A miscellaneous error occurred.
|
||||
/// </summary>
|
||||
[Description("MISC")]
|
||||
Misc = 1,
|
||||
|
||||
/// <summary>
|
||||
/// The stream failed to resolve an address.
|
||||
/// </summary>
|
||||
[Description("RESOLVEFAILED")]
|
||||
ResolveFailed = 2,
|
||||
|
||||
/// <summary>
|
||||
/// The stream connect attempt was refused.
|
||||
/// </summary>
|
||||
[Description("CONNECTREFUSED")]
|
||||
ConnectRefused = 3,
|
||||
|
||||
/// <summary>
|
||||
/// The exit policy failed.
|
||||
/// </summary>
|
||||
[Description("EXITPOLICY")]
|
||||
ExitPolicy = 4,
|
||||
|
||||
/// <summary>
|
||||
/// The stream was destroyed.
|
||||
/// </summary>
|
||||
[Description("DESTROY")]
|
||||
Destroy = 5,
|
||||
|
||||
/// <summary>
|
||||
/// The stream closed normally.
|
||||
/// </summary>
|
||||
[Description("DONE")]
|
||||
Done = 6,
|
||||
|
||||
/// <summary>
|
||||
/// The stream timed out.
|
||||
/// </summary>
|
||||
[Description("TIMEOUT")]
|
||||
Timeout = 7,
|
||||
|
||||
/// <summary>
|
||||
/// There is no route to the host.
|
||||
/// </summary>
|
||||
[Description("NOROUTE")]
|
||||
NoRoute = 8,
|
||||
|
||||
/// <summary>
|
||||
/// The server is hibernating.
|
||||
/// </summary>
|
||||
[Description("HIBERNATING")]
|
||||
Hibernating = 9,
|
||||
|
||||
/// <summary>
|
||||
/// An internal error occurred.
|
||||
/// </summary>
|
||||
[Description("INTERNAL")]
|
||||
Internal = 10,
|
||||
|
||||
/// <summary>
|
||||
/// The server ran out of resources.
|
||||
/// </summary>
|
||||
[Description("RESOURCELIMIT")]
|
||||
ResourceLimit = 11,
|
||||
|
||||
/// <summary>
|
||||
/// The connection was reset.
|
||||
/// </summary>
|
||||
[Description("CONNRESET")]
|
||||
ConnReset = 12,
|
||||
|
||||
/// <summary>
|
||||
/// There was a tor protocol error.
|
||||
/// </summary>
|
||||
[Description("TORPROTOCOL")]
|
||||
TorProtocol = 13,
|
||||
|
||||
/// <summary>
|
||||
/// The stream was not accessing a directory.
|
||||
/// </summary>
|
||||
[Description("NOTDIRECTORY")]
|
||||
NotDirectory = 14,
|
||||
|
||||
/// <summary>
|
||||
/// A relay-end cell was received.
|
||||
/// </summary>
|
||||
[Description("END")]
|
||||
End = -1,
|
||||
|
||||
/// <summary>
|
||||
/// The client tried to connect to a private address.
|
||||
/// </summary>
|
||||
[Description("PRIVATE_ADDR")]
|
||||
PrivateAddr = -1,
|
||||
}
|
||||
}
|
||||
74
TorWebClient/TorClient/Streams/Enumerators/StreamStatus.cs
Normal file
74
TorWebClient/TorClient/Streams/Enumerators/StreamStatus.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
/// <summary>
|
||||
/// An enumerator containing the different possible statuses for a stream.
|
||||
/// </summary>
|
||||
public enum StreamStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// The stream status was not provided.
|
||||
/// </summary>
|
||||
[Description(null)]
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// A new request to connect.
|
||||
/// </summary>
|
||||
[Description("NEW")]
|
||||
New,
|
||||
|
||||
/// <summary>
|
||||
/// A new request to resolve an address.
|
||||
/// </summary>
|
||||
[Description("NEWRESOLVE")]
|
||||
NewResolve,
|
||||
|
||||
/// <summary>
|
||||
/// An address was re-mapped to another.
|
||||
/// </summary>
|
||||
[Description("REMAP")]
|
||||
Remap,
|
||||
|
||||
/// <summary>
|
||||
/// A connect cell was sent along a circuit.
|
||||
/// </summary>
|
||||
[Description("SENTCONNECT")]
|
||||
SentConnect,
|
||||
|
||||
/// <summary>
|
||||
/// A resolve cell was sent along the circuit.
|
||||
/// </summary>
|
||||
[Description("SENTRESOLVE")]
|
||||
SentResolve,
|
||||
|
||||
/// <summary>
|
||||
/// A reply was received and the stream was established.
|
||||
/// </summary>
|
||||
[Description("SUCCEEDED")]
|
||||
Succeeded,
|
||||
|
||||
/// <summary>
|
||||
/// The stream failed and cannot be retried.
|
||||
/// </summary>
|
||||
[Description("FAILED")]
|
||||
Failed,
|
||||
|
||||
/// <summary>
|
||||
/// The stream is closed.
|
||||
/// </summary>
|
||||
[Description("CLOSED")]
|
||||
Closed,
|
||||
|
||||
/// <summary>
|
||||
/// The stream was detached from a circuit, but can be retried.
|
||||
/// </summary>
|
||||
[Description("DETACHED")]
|
||||
Detached,
|
||||
}
|
||||
}
|
||||
120
TorWebClient/TorClient/Streams/Stream.cs
Normal file
120
TorWebClient/TorClient/Streams/Stream.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Tor
|
||||
{
|
||||
/// <summary>
|
||||
/// A class containing information about an active or inactive stream within the tor network service.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Stream"/> class.
|
||||
/// </summary>
|
||||
/// <param name="client">The client for which the stream belongs.</param>
|
||||
/// <param name="id">The unique identifier of the stream within the tor session.</param>
|
||||
/// <param name="target">The target of the stream.</param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the circuit which owns this stream. This will be zero if the stream has been detached.
|
||||
/// </summary>
|
||||
public int CircuitID
|
||||
{
|
||||
get { return circuitID; }
|
||||
internal set { circuitID = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the unique identifier of the stream in the tor session.
|
||||
/// </summary>
|
||||
public int ID
|
||||
{
|
||||
get { return id; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the purpose for the stream. This will be <c>StreamPurpose.None</c> unless extended events are enabled.
|
||||
/// </summary>
|
||||
public StreamPurpose Purpose
|
||||
{
|
||||
get { return purpose; }
|
||||
internal set { purpose = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason for the stream being closed, failed or detached. This will be <c>StreamReason.None</c> until the stream
|
||||
/// has reached either of the aforementioned states.
|
||||
/// </summary>
|
||||
public StreamReason Reason
|
||||
{
|
||||
get { return reason; }
|
||||
internal set { reason = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the status of the stream.
|
||||
/// </summary>
|
||||
public StreamStatus Status
|
||||
{
|
||||
get { return status; }
|
||||
internal set { status = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the target of the stream.
|
||||
/// </summary>
|
||||
public Host Target
|
||||
{
|
||||
get { return target; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Closes the stream.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the stream is closed successfully; otherwise, <c>false</c>.</returns>
|
||||
public bool Close()
|
||||
{
|
||||
return client.Controller.CloseStream(this, StreamReason.Misc);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A class containing a read-only collection of <see cref="Stream"/> objects.
|
||||
/// </summary>
|
||||
public sealed class StreamCollection : ReadOnlyCollection<Stream>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StreamCollection"/> class.
|
||||
/// </summary>
|
||||
/// <param name="list">The list of streams.</param>
|
||||
internal StreamCollection(IList<Stream> list) : base(list)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user