Table of Contents

Class StreamPacketChannel

Namespace
VpnHood.Core.Tunneling.Channels
Assembly
VpnHood.Core.Tunneling.dll

Represents a packet channel on a stream connection: packets go out back to back on the stream, and the ones read from it go up.

public class StreamPacketChannel : PacketTransport, IStreamPacketChannel, IPacketChannel, IPacketTransport, IChannel, IDisposable, IAsyncDisposable
Inheritance
StreamPacketChannel
Implements
Inherited Members

Remarks

Its own close, by its lifespan's end or its owner, makes it Disconnecting and tells the peer with a close message behind the packets already queued; the peer's close makes it Disconnecting too, with no answer. It then goes after its grace, in which what is on its way still arrives, unless the channel manager ends it sooner, and its graceful close releases its connection, which a reusable one may survive.

Constructors

StreamPacketChannel(StreamPacketChannelOptions)

Initializes a new instance of the StreamPacketChannel class.

public StreamPacketChannel(StreamPacketChannelOptions options)

Parameters

options StreamPacketChannelOptions

The options.

Exceptions

ArgumentOutOfRangeException

The options' queue capacity is less than 1.

Properties

ChannelId

Gets the channel's ID.

public string ChannelId { get; }

Property Value

string

CloseTime

Gets when the channel's close began, in UTC, or null while it is open; the channel manager lets the oldest closes go first.

public DateTime? CloseTime { get; }

Property Value

DateTime?

LastActivityTime

Gets when the channel last sent or received, in UTC.

public DateTime LastActivityTime { get; }

Property Value

DateTime

Name

Gets the name the transport's log lines carry. The default is its type's name.

protected override string Name { get; }

Property Value

string

Remarks

It is the type's name and the channel's ID.

RequestTime

Gets the time of the request that made the channel, by the client's clock.

public DateTime RequestTime { get; }

Property Value

DateTime

State

Gets the channel's state.

public PacketChannelState State { get; }

Property Value

PacketChannelState

Traffic

Gets what the channel has sent and received.

public Traffic Traffic { get; }

Property Value

Traffic

Methods

Close()

Starts the channel's close: it is Disconnecting at once, tells its peer, and goes after its grace, or sooner where the channel manager ends it. One already closing or gone is left as it is.

public void Close()

Remarks

It closes as its lifespan's end does, where Dispose() would end it at once. One already gone is left with no throw, as its owner's list may still hold it.

Dispose()

Closes the send queue, which refuses later sends and releases waiting ones, then disposes the transport. Packets left in the queue are dropped and disposed by the sending loop, which may finish after this method returns. Calling it again does nothing.

public override void Dispose()

Remarks

The quick close: the channel stops at once and asks its connection to close, with no reuse, without waiting for it.

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

Remarks

The graceful close: the channel stops, then releases its connection. A second call waits for the first one's end.

DisposeManaged()

Releases managed resources; the base detaches the PacketReceived handlers. A derived class must catch its own errors.

protected override void DisposeManaged()

OnPacketReceived(IpPacket)

Counts a received packet and raises PacketReceived with it. A packet that cannot be delivered (the transport is disposed, no handler is attached, or the handler throws) is disposed.

protected override void OnPacketReceived(IpPacket ipPacket)

Parameters

ipPacket IpPacket

The packet, which the handler takes.

Remarks

A packet message is the channel's own: a close message starts its close, and any other it drops, as one from a newer peer.

SendPacketsAsync(IReadOnlyList<IpPacket>)

Sends a batch of packets: one packet in single mode. It runs on the sending loop, one batch at a time; in passthrough mode, on the sender's thread.

protected override ValueTask SendPacketsAsync(IReadOnlyList<IpPacket> ipPackets)

Parameters

ipPackets IReadOnlyList<IpPacket>

The batch. The list is reused after the call.

Returns

ValueTask

A task that represents the asynchronous operation.

Remarks

It must end once the transport is disposed. A throw counts the whole batch dropped and disposes it, except in passthrough mode without AutoDisposePackets, where the derived class disposes what it does not hand on; so it must not throw after handing a packet on. A packet it gives up without failing the batch, it reports with DropPacket(IpPacket), or the packet counts as sent. In passthrough mode it must complete at once and never send on its own transport.

Exceptions

ObjectDisposedException

The channel is disposed.

Start()

Starts the channel, which then reads from its peer.

public void Start()

Remarks

Its read's end, by its peer or a failure, starts its graceful close.

Exceptions

ObjectDisposedException

The channel is disposed.

InvalidOperationException

The channel is already started.