Show / Hide Table of Contents

Interface ITransport

An interface to handle peer-to-peer networking, including Message exchange and BoundPeer managing.

Namespace: Libplanet.Net.Transports
Assembly: Libplanet.Net.dll
Syntax
public interface ITransport : IDisposable
Remarks

An instance of a transport implementing ITransport should always be able to send requests and recieve replies.

Properties

| Improve this Doc View Source

AsPeer

The current BoundPeer representation of ITransport.

Declaration
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
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
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
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
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

ReplyMessageAsync(Message, CancellationToken)

Sends a Message as a reply.

Declaration
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
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
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
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
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
Task WaitForRunningAsync()
Returns
Type Description
Task

A completed when Running property becomes true.

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