Show / Hide Table of Contents

Class NetMQTransport

Implementation of ITransport interface using NetMQ.

Inheritance
Object
NetMQTransport
Implements
ITransport
IDisposable
Namespace: Libplanet.Net.Transports
Assembly: Libplanet.Net.dll
Syntax
public class NetMQTransport : object, ITransport, IDisposable

Properties

| Improve this Doc View Source

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.

| Improve this Doc View Source

LastMessageTimestamp

The of the last message received.

Declaration
public DateTimeOffset? LastMessageTimestamp { get; }
Property Value
Type Description
Nullable<DateTimeOffset>
| Improve this Doc View Source

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>
| Improve this Doc View Source

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 Source

BroadcastMessage(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 message

A Message to broadcast.

| Improve this Doc View Source

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 null.

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 appProtocolVersion, and their version is signed by a trusted party (i.e., trustedAppProtocolVersionSigners). If this callback returns false, an encountered peer is ignored. If this callback is omitted, all peers with different AppProtocolVersions are ignored.

Nullable<TimeSpan> messageTimestampBuffer

The amount in 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 messageTimestampBuffer will be ignored. If null, any timestamp is accepted.

Returns
Type Description
Task<NetMQTransport>

An awaitable returning a NetMQTransport when awaited that is ready to send request Messages and receive reply Messages.

| Improve this Doc View Source

Dispose()

Declaration
public void Dispose()
| Improve this Doc View Source

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.

| Improve this Doc View Source

SendMessageAsync(BoundPeer, Message, Nullable<TimeSpan>, CancellationToken)

Sends a Message to a given BoundPeer and waits for its single reply.

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 message sent by peer.

Exceptions
Type Condition
CommunicationFailException

Thrown when fail send or receive a Message.

| Improve this Doc View Source

SendMessageAsync(BoundPeer, Message, Nullable<TimeSpan>, Int32, Boolean, CancellationToken)

Sends a Message to a given BoundPeer and waits for its multiple replies.

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 expectedResponses messages and timeout occurred.

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 message sent by peer.

Exceptions
Type Condition
CommunicationFailException

Thrown when fail send or receive a Message.

| Improve this Doc View Source

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 without a value.

| Improve this Doc View Source

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 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 without a value.

| Improve this Doc View Source

WaitForRunningAsync()

Waits until this ITransport instance gets started to run.

Declaration
public Task WaitForRunningAsync()
Returns
Type Description
Task

A completed when Running property becomes true.

Implements

ITransport
IDisposable
  • Improve this Doc
  • View Source
In This Article
Back to top Copyright © 2018–2022 Planetarium