Class NetMQTransport
Implementation of ITransport interface using NetMQ.
Namespace: Libplanet.Net.Transports
Assembly: Libplanet.dll
Syntax
public class NetMQTransport : object, ITransport, IDisposable
Constructors
| Improve this Doc View SourceNetMQTransport(RoutingTable, PrivateKey, AppProtocolVersion, IImmutableSet<PublicKey>, Int32, String, Nullable<Int32>, IEnumerable<IceServer>, DifferentAppProtocolVersionEncountered, Int32, Nullable<TimeSpan>)
Creates NetMQTransport instance.
Declaration
public NetMQTransport(RoutingTable table, PrivateKey privateKey, AppProtocolVersion appProtocolVersion, IImmutableSet<PublicKey> trustedAppProtocolVersionSigners, int workers, string host, int? listenPort, IEnumerable<IceServer> iceServers, DifferentAppProtocolVersionEncountered differentAppProtocolVersionEncountered, int minimumBroadcastTarget, TimeSpan? messageLifespan = null)
Parameters
| Type | Name | Description |
|---|---|---|
| RoutingTable | table | The RoutingTable that manages Peers which are connected with this Peer. |
| 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 |
| Int32 | minimumBroadcastTarget | The number of minimum peers to broadcast messages. |
| Nullable<TimeSpan> | messageLifespan | The lifespan of a message.
Messages generated before this value from the current time are ignored.
If |
Properties
| Improve this Doc View SourceAsPeer
Peer representation of ITransport.
Declaration
public Peer AsPeer { get; }
Property Value
| Type | Description |
|---|---|
| Peer |
LastMessageTimestamp
The
Declaration
public DateTimeOffset? LastMessageTimestamp { get; }
Property Value
| Type | Description |
|---|---|
| Nullable<DateTimeOffset> |
Running
Whether this ITransport instance is running.
Declaration
public bool Running { get; }
Property Value
| Type | Description |
|---|---|
| Boolean | Gets the value indicates whether the instance is running. |
Methods
| Improve this Doc View SourceBroadcastMessage(Nullable<Address>, Message)
Broadcasts the message to peers selected from the routing table.
Declaration
public void BroadcastMessage(Address? except, Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Nullable<Address> | except | An Address to exclude from broadcasting.
If |
| Message | message | A Message to broadcast. |
Dispose()
Declaration
public void Dispose()
ReplyMessage(Message)
Replies message.
Declaration
public void ReplyMessage(Message message)
Parameters
| Type | Name | Description |
|---|---|---|
| Message | message | A Message to reply. |
Remarks
The Identity of the given message must be
matched to Identity of a message corresponding to the given
message.
RunAsync(CancellationToken)
Starts running transport layer. To RunAsync(CancellationToken), you should call StartAsync(CancellationToken) first.
Declaration
public async Task RunAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
| Type | Description |
|---|---|
| Task | An awaitable task without value. |
SendMessageAsync(BoundPeer, Message, CancellationToken)
Sends the message to given peer.
Declaration
public Task SendMessageAsync(BoundPeer peer, Message message, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundPeer | peer | A Peer to send message to. |
| Message | message | A Message to send. |
| CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
| Type | Description |
|---|---|
| Task | An awaitable task without value. |
SendMessageWithReplyAsync(BoundPeer, Message, Nullable<TimeSpan>, CancellationToken)
Sends the message
to given peer and waits for its single reply.
Declaration
public async Task<Message> SendMessageWithReplyAsync(BoundPeer peer, Message message, TimeSpan? timeout, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundPeer | peer | A Peer to send message to. |
| Message | message | A 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 |
SendMessageWithReplyAsync(BoundPeer, Message, Nullable<TimeSpan>, Int32, Boolean, CancellationToken)
Sends the message
to given peer and waits for its multiple replies.
Declaration
public async Task<IEnumerable<Message>> SendMessageWithReplyAsync(BoundPeer peer, Message message, TimeSpan? timeout, int expectedResponses, bool returnWhenTimeout, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| BoundPeer | peer | A Peer to send message to. |
| Message | message | A 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 |
StartAsync(CancellationToken)
Initiates transport layer.
Declaration
public async Task StartAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
| Type | Description |
|---|---|
| Task | An awaitable task without value. |
StopAsync(TimeSpan, CancellationToken)
Stops running transport layer.
Declaration
public async Task StopAsync(TimeSpan waitFor, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | waitFor | The |
| CancellationToken | cancellationToken | A cancellation token used to propagate notification that this operation should be canceled. |
Returns
| Type | Description |
|---|---|
| Task | An awaitable task without value. |
WaitForRunningAsync()
Waits until this NetMQTransport instance gets started to run.
Declaration
public Task WaitForRunningAsync()
Returns
| Type | Description |
|---|---|
| Task | A |
See Also
Events
| Improve this Doc View SourceProcessMessageHandler
The
Declaration
public event EventHandler<Message> ProcessMessageHandler
Event Type
| Type | Description |
|---|---|
| EventHandler<Message> |