Class Muxer
Supports multiple protocols over a single channel (stream).
Inherited Members
Namespace: PeerTalk.Multiplex
Assembly: PeerTalk.dll
Syntax
public class Muxer
Remarks
See https://github.com/libp2p/mplex for the spec.
Fields
| Improve this Doc View SourceSubstreams
The substreams that are open.
Declaration
public ConcurrentDictionary<long, Substream> Substreams
Field Value
| Type | Description |
|---|---|
| ConcurrentDictionary<Int64, Substream> | The key is stream ID and the value is a Substream. |
Properties
| Improve this Doc View SourceChannel
The signle channel to exchange protocol messages.
Declaration
public Stream Channel { get; set; }
Property Value
| Type | Description |
|---|---|
| Stream | A Stream to exchange protocol messages. |
Connection
The peer connection.
Declaration
public PeerConnection Connection { get; set; }
Property Value
| Type | Description |
|---|---|
| PeerConnection | The peer connection that owns this muxer. |
Initiator
Determines if the muxer is the initiator.
Declaration
public bool Initiator { get; set; }
Property Value
| Type | Description |
|---|---|
| Boolean | true if the muxer is the initiator. |
See Also
| Improve this Doc View SourceNextStreamId
The next stream ID to create.
Declaration
public long NextStreamId { get; }
Property Value
| Type | Description |
|---|---|
| Int64 | The session initiator allocates even IDs and the session receiver allocates odd IDs. |
Receiver
Determines if the muxer is the receiver.
Declaration
public bool Receiver { get; set; }
Property Value
| Type | Description |
|---|---|
| Boolean | true if the muxer is the receiver. |
See Also
Methods
| Improve this Doc View SourceAcquireWriteAccessAsync()
Acquire permission to write to the Channel.
Declaration
public Task<IDisposable> AcquireWriteAccessAsync()
Returns
| Type | Description |
|---|---|
| Task<IDisposable> | A task that represents the asynchronous get operation. The task's value is an IDisposable that releases the lock. |
CreateStreamAsync(String, CancellationToken)
Creates a new stream with the specified name.
Declaration
public Task<Substream> CreateStreamAsync(string name = "", CancellationToken cancel = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| String | name | A name for the stream. |
| CancellationToken | cancel | Is used to stop the task. When cancelled, the TaskCanceledException is raised. |
Returns
| Type | Description |
|---|---|
| Task<Substream> | A duplex stream. |
ProcessRequestsAsync(CancellationToken)
Read the multiplex packets.
Declaration
public Task ProcessRequestsAsync(CancellationToken cancel = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancel |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
A background task that reads and processes the multiplex packets while
the Channel is open and not cancel.
Any encountered errors will close the Channel.
RemoveStreamAsync(Substream, CancellationToken)
Remove the stream.
Declaration
public Task<Substream> RemoveStreamAsync(Substream stream, CancellationToken cancel = default(CancellationToken))
Parameters
| Type | Name | Description |
|---|---|---|
| Substream | stream | |
| CancellationToken | cancel |
Returns
| Type | Description |
|---|---|
| Task<Substream> |
Remarks
Internal method called by Substream.Dispose().
Events
| Improve this Doc View SourceSubstreamClosed
Raised when the remote end closes a stream.
Declaration
public event EventHandler<Substream> SubstreamClosed
Event Type
| Type | Description |
|---|---|
| EventHandler<Substream> |
SubstreamCreated
Raised when the remote end creates a new stream.
Declaration
public event EventHandler<Substream> SubstreamCreated
Event Type
| Type | Description |
|---|---|
| EventHandler<Substream> |