Table of Contents

Class PeerCommunicationService

Namespace
NLightning.Infrastructure.Node.Services
Assembly
NLightning.Infrastructure.dll

Service for communication with a single peer.

public class PeerCommunicationService : IPeerCommunicationService
Inheritance
PeerCommunicationService
Implements
Inherited Members

Constructors

PeerCommunicationService(ILogger<PeerCommunicationService>, IMessageService, IMessageFactory, CompactPubKey, IPingPongService, IServiceProvider)

Initializes a new instance of the PeerCommunicationService class.

public PeerCommunicationService(ILogger<PeerCommunicationService> logger, IMessageService messageService, IMessageFactory messageFactory, CompactPubKey peerCompactPubKey, IPingPongService pingPongService, IServiceProvider serviceProvider)

Parameters

logger ILogger<PeerCommunicationService>

The logger.

messageService IMessageService

The message service.

messageFactory IMessageFactory

The message factory.

peerCompactPubKey CompactPubKey

The peer's public key.

pingPongService IPingPongService

The ping pong service.

serviceProvider IServiceProvider

The service provider.

Properties

IsConnected

Gets a value indicating whether the connection is established.

public bool IsConnected { get; }

Property Value

bool

PeerCompactPubKey

Gets the peer's public key.

public CompactPubKey PeerCompactPubKey { get; }

Property Value

CompactPubKey

Methods

Disconnect()

Disconnects from the peer.

public void Disconnect()

InitializeAsync(TimeSpan)

Initializes the communication with the peer.

public Task InitializeAsync(TimeSpan networkTimeout)

Parameters

networkTimeout TimeSpan

The network timeout.

Returns

Task

A task that represents the asynchronous operation.

SendMessageAsync(IMessage, CancellationToken)

Sends a message to the peer.

public Task SendMessageAsync(IMessage message, CancellationToken cancellationToken = default)

Parameters

message IMessage

The message to send.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task that represents the asynchronous operation.

Events

DisconnectEvent

Event raised when the peer is disconnected.

public event EventHandler? DisconnectEvent

Event Type

EventHandler

ExceptionRaised

Event raised when an exception occurs.

public event EventHandler<Exception>? ExceptionRaised

Event Type

EventHandler<Exception>

MessageReceived

Event raised when a message is received from the peer.

public event EventHandler<IMessage?>? MessageReceived

Event Type

EventHandler<IMessage>