Table of Contents

Class PeerService

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

Service for peer communication

public sealed class PeerService : IPeerService, IDisposable
Inheritance
PeerService
Implements
Inherited Members

Constructors

PeerService(IPeerCommunicationService, FeatureOptions, ILogger<PeerService>, TimeSpan)

Initializes a new instance of the PeerService class.

public PeerService(IPeerCommunicationService peerCommunicationService, FeatureOptions features, ILogger<PeerService> logger, TimeSpan networkTimeout)

Parameters

peerCommunicationService IPeerCommunicationService

The peer communication service

features FeatureOptions

The feature options

logger ILogger<PeerService>

A logger

networkTimeout TimeSpan

Network timeout

Properties

Features

Gets the feature options for the peer.

public FeatureOptions Features { get; }

Property Value

FeatureOptions

PeerPubKey

Gets the peer's public key.

public CompactPubKey PeerPubKey { get; }

Property Value

CompactPubKey

PreferredHost

public string? PreferredHost { get; }

Property Value

string

PreferredPort

public ushort? PreferredPort { get; }

Property Value

ushort?

Methods

Disconnect(Exception?)

Disconnects from the peer.

public void Disconnect(Exception? exception = null)

Parameters

exception Exception

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

SendMessageAsync(IChannelMessage)

Sends an asynchronous message to the peer.

public Task SendMessageAsync(IChannelMessage replyMessage)

Parameters

replyMessage IChannelMessage

The message to be sent to the peer.

Returns

Task

A task that represents the asynchronous operation.

SendWarningAsync(WarningException)

Sends a warning message to the peer.

public Task SendWarningAsync(WarningException we)

Parameters

we WarningException

The warning exception containing the warning message to be sent to the peer.

Returns

Task

A task that represents the asynchronous operation.

Events

OnAttentionMessageReceived

Occurs when an Error or Warning message is received from the connected peer.

public event EventHandler<AttentionMessageEventArgs>? OnAttentionMessageReceived

Event Type

EventHandler<AttentionMessageEventArgs>

OnChannelMessageReceived

Occurs when a channel message is received from the connected peer.

public event EventHandler<ChannelMessageEventArgs>? OnChannelMessageReceived

Event Type

EventHandler<ChannelMessageEventArgs>

OnDisconnect

Event raised when the peer is disconnected.

public event EventHandler<PeerDisconnectedEventArgs>? OnDisconnect

Event Type

EventHandler<PeerDisconnectedEventArgs>

OnExceptionRaised

Occurs when an exception is raised during peer communication.

public event EventHandler<Exception>? OnExceptionRaised

Event Type

EventHandler<Exception>