Class NetMQTransport
Implementation of ITransport interface using NetMQ.
Inherited Members
Namespace: Libplanet.Net.Transports
Assembly: Libplanet.Net.dll
Syntax
public class NetMQTransport : ITransport, IDisposable
Properties
| Improve this Doc View SourceAppProtocolVersion
The application protocol version to comply.
Declaration
public AppProtocolVersion AppProtocolVersion { get; }
Property Value
Type | Description |
---|---|
AppProtocolVersion |
AsPeer
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.
DifferentAppProtocolVersionEncountered
The callback triggered when a node encounters an AppProtocolVersion that is different from AppProtocolVersion that is signed by a trusted party, that is, one of TrustedAppProtocolVersionSigners. Does nothing by default.
Declaration
public DifferentAppProtocolVersionEncountered DifferentAppProtocolVersionEncountered { get; }
Property Value
Type | Description |
---|---|
DifferentAppProtocolVersionEncountered |
LastMessageTimestamp
The DateTimeOffset of the last message received.
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.
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 receive outside requests. When the value is false, the ITransport stops receiving outside requests.
Declaration
public bool Running { get; }
Property Value
Type | Description |
---|---|
Boolean | The value indicating whether the instance is running. |
TrustedAppProtocolVersionSigners
The set of PublicKeys to trust when a node encounters a Message with an AppProtocolVersion that is different from AppProtocolVersion. Any Message with an untrusted AppProtocolVersion is ignored by the node. Set to an empty set of PublicKeys by default, i.e. not to trust any Message with a different AppProtocolVersion.
Declaration
public IImmutableSet<PublicKey> TrustedAppProtocolVersionSigners { get; }
Property Value
Type | Description |
---|---|
IImmutableSet<PublicKey> |
Methods
| Improve this Doc View SourceBroadcastMessage(IEnumerable<BoundPeer>, MessageContent)
Broadcasts a MessageContent to peers selected from the routing table.
Declaration
public void BroadcastMessage(IEnumerable<BoundPeer> peers, MessageContent content)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<BoundPeer> | peers | The BoundPeers to broadcast the
|
MessageContent | content | A MessageContent to broadcast. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Thrown when ITransport instance is already disposed. |
Create(PrivateKey, AppProtocolVersionOptions, HostOptions, Nullable<TimeSpan>)
Creates an initialized NetMQTransport instance.
Declaration
public static async Task<NetMQTransport> Create(PrivateKey privateKey, AppProtocolVersionOptions appProtocolVersionOptions, HostOptions hostOptions, TimeSpan? messageTimestampBuffer = null)
Parameters
Type | Name | Description |
---|---|---|
PrivateKey | privateKey | PrivateKey of the transport layer. |
AppProtocolVersionOptions | appProtocolVersionOptions | The AppProtocolVersionOptions to use when handling an AppProtocolVersion attached to a Message. |
HostOptions | hostOptions | The HostOptions to use when binding to the network. |
Nullable<TimeSpan> | messageTimestampBuffer | The amount in TimeSpan
that is allowed for the timestamp of a Message to differ from
the current time of a local node. Every Message with its timestamp
differing greater than |
Returns
Type | Description |
---|---|
Task<NetMQTransport> | An awaitable Task returning a NetMQTransport when awaited that is ready to send request Messages and receive reply Messages. |
Dispose()
Implementation of ITransport interface using NetMQ.
Declaration
public void Dispose()
ReplyMessageAsync(MessageContent, Byte[], CancellationToken)
Sends a MessageContent as a reply.
Declaration
public async Task ReplyMessageAsync(MessageContent content, byte[] identity, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
MessageContent | content | The MessageContent to send as a reply. |
Byte[] | identity | The byte array that represents identification of the MessageContent to respond. |
CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable task without value. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Thrown when ITransport instance is already disposed. |
SendMessageAsync(BoundPeer, MessageContent, Nullable<TimeSpan>, Int32, Boolean, CancellationToken)
Sends a MessageContent to a given BoundPeer and waits for its multiple replies.
Declaration
public async Task<IEnumerable<Message>> SendMessageAsync(BoundPeer peer, MessageContent content, TimeSpan? timeout, int expectedResponses, bool returnWhenTimeout, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
BoundPeer | peer | The BoundPeer to send message to. |
MessageContent | content | The MessageContent 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. |
ObjectDisposedException | Thrown when ITransport instance is already disposed. |
SendMessageAsync(BoundPeer, MessageContent, Nullable<TimeSpan>, CancellationToken)
Sends a MessageContent to a given BoundPeer and waits for its single reply.
Declaration
public async Task<Message> SendMessageAsync(BoundPeer peer, MessageContent content, TimeSpan? timeout, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
BoundPeer | peer | The BoundPeer to send message to. |
MessageContent | content | The MessageContent 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. |
ObjectDisposedException | Thrown when ITransport instance is already disposed. |
StartAsync(CancellationToken)
Starts running a transport layer as to put it in a Running state.
Declaration
public async Task StartAsync(CancellationToken cancellationToken = default(CancellationToken))
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 Task without a value. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Thrown when the instance is already disposed. |
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 = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | waitFor | The TimeSpan to delay before actual stopping. |
CancellationToken | cancellationToken | The cancellation token to propagate a notification that this operation should be canceled. |
Returns
Type | Description |
---|---|
Task | An awaitable Task without a value. |
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | Thrown when the instance is already disposed. |
WaitForRunningAsync()
Waits until this ITransport instance gets started to run.
Declaration
public Task WaitForRunningAsync()
Returns
Type | Description |
---|---|
Task |