Class NetMQTransport
Implementation of ITransport interface using NetMQ.
Namespace: Libplanet.Net.Transports
Assembly: Libplanet.Net.dll
Syntax
public class NetMQTransport : object, ITransport, IDisposable
Properties
| Improve this Doc View SourceAsPeer
The current BoundPeer representation of ITransport.
Declaration
public BoundPeer AsPeer { get; }
Property Value
Type | Description |
---|---|
BoundPeer |
Remarks
This creates a new instance of BoundPeer on the fly and can be different at different points of time depending on implementation, as ITransport may account for changing endpoint.
LastMessageTimestamp
The
Declaration
public DateTimeOffset? LastMessageTimestamp { get; }
Property Value
Type | Description |
---|---|
Nullable<DateTimeOffset> |
ProcessMessageHandler
The list of tasks invoked when a message that is not a reply is received. To handle reply, please use SendMessageAsync(BoundPeer, Message, Nullable<TimeSpan>, CancellationToken).
Declaration
public AsyncDelegate<Message> ProcessMessageHandler { get; }
Property Value
Type | Description |
---|---|
AsyncDelegate<Message> |
Running
Whether this ITransport instance is running.
When the value is true
, the ITransport can recieve outside
requests. When the value is false
, the ITransport stops recieving
outside requests.
Declaration
public bool Running { get; }
Property Value
Type | Description |
---|---|
Boolean | The value indicating whether the instance is running. |
Methods
| Improve this Doc View SourceBroadcastMessage(IEnumerable<BoundPeer>, Message)
Broadcasts a Message to peers selected from the routing table.
Declaration
public void BroadcastMessage(IEnumerable<BoundPeer> peers, Message message)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<BoundPeer> | peers | The BoundPeers to broadcast the
|
Message | message | A Message to broadcast. |
Create(PrivateKey, AppProtocolVersion, IImmutableSet<PublicKey>, Int32, String, Nullable<Int32>, IEnumerable<IceServer>, DifferentAppProtocolVersionEncountered, Nullable<TimeSpan>)
Creates an initialized NetMQTransport instance.
Declaration
public static async Task<NetMQTransport> Create(PrivateKey privateKey, AppProtocolVersion appProtocolVersion, IImmutableSet<PublicKey> trustedAppProtocolVersionSigners, int workers, string host, int? listenPort, IEnumerable<IceServer> iceServers, DifferentAppProtocolVersionEncountered differentAppProtocolVersionEncountered, TimeSpan? messageTimestampBuffer = null)
Parameters
Type | Name | Description |
---|---|---|
PrivateKey | privateKey | PrivateKey of the transport layer. |
AppProtocolVersion | appProtocolVersion | AppProtocolVersion-typed version of the transport layer. |
IImmutableSet<PublicKey> | trustedAppProtocolVersionSigners | PublicKeys of parties
to trust AppProtocolVersions they signed. To trust any party, pass
|
Int32 | workers | The number of background workers (i.e., threads). |
String | host | A hostname to be a part of a public endpoint, that peers use when they connect to this node. Note that this is not a hostname to listen to; NetMQTransport always listens to 0.0.0.0 & ::/0. |
Nullable<Int32> | listenPort | A port number to listen to. |
IEnumerable<IceServer> | iceServers | ICE servers to use for TURN/STUN. Purposes to traverse NAT. |
DifferentAppProtocolVersionEncountered | differentAppProtocolVersionEncountered | A delegate called back when a peer
with one different from |
Nullable<TimeSpan> | messageTimestampBuffer | The amount in |
Returns
Type | Description |
---|---|
Task<NetMQTransport> | An awaitable |
Dispose()
Declaration
public void Dispose()
ReplyMessageAsync(Message, CancellationToken)
Sends a Message as a reply.
Declaration
public async Task ReplyMessageAsync(Message message, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Message | message | The Message to send as a reply. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable task without value. |
Remarks
The Identity of given message
must
match the Identity of the request Message
corresponding to message
.
SendMessageAsync(BoundPeer, Message, Nullable<TimeSpan>, CancellationToken)
Declaration
public async Task<Message> SendMessageAsync(BoundPeer peer, Message message, TimeSpan? timeout, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
BoundPeer | peer | The BoundPeer to send message to. |
Message | message | The Message to send. |
Nullable<TimeSpan> | timeout | A timeout of waiting for the reply of the message. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task<Message> | The replies of the |
Exceptions
Type | Condition |
---|---|
CommunicationFailException | Thrown when fail send or receive a Message. |
SendMessageAsync(BoundPeer, Message, Nullable<TimeSpan>, Int32, Boolean, CancellationToken)
Declaration
public async Task<IEnumerable<Message>> SendMessageAsync(BoundPeer peer, Message message, TimeSpan? timeout, int expectedResponses, bool returnWhenTimeout, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
BoundPeer | peer | The BoundPeer to send message to. |
Message | message | The Message to send. |
Nullable<TimeSpan> | timeout | A timeout of waiting for the reply of the message. |
Int32 | expectedResponses | The number of expected replies for the message. |
Boolean | returnWhenTimeout | Determines the behavior when failed to receive
|
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task<IEnumerable<Message>> | The replies of the |
Exceptions
Type | Condition |
---|---|
CommunicationFailException | Thrown when fail send or receive a Message. |
StartAsync(CancellationToken)
Starts running a transport layer as to put it in a Running state.
Declaration
public async Task StartAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The cancellation token to propagate a notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable |
StopAsync(TimeSpan, CancellationToken)
Stops running a transport layer as to put it in a not Running state.
Declaration
public async Task StopAsync(TimeSpan waitFor, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | waitFor | The |
CancellationToken | cancellationToken | The cancellation token to propagate a notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable |
WaitForRunningAsync()
Waits until this ITransport instance gets started to run.
Declaration
public Task WaitForRunningAsync()
Returns
Type | Description |
---|---|
Task | A |