Table of Contents

Class TcpService

Namespace
NLightning.Infrastructure.Transport.Services
Assembly
NLightning.Infrastructure.dll
public class TcpService : ITcpService
Inheritance
TcpService
Implements
Inherited Members

Constructors

TcpService(ILogger<TcpService>, IOptions<NodeOptions>)

public TcpService(ILogger<TcpService> logger, IOptions<NodeOptions> nodeOptions)

Parameters

logger ILogger<TcpService>
nodeOptions IOptions<NodeOptions>

Methods

ConnectToPeerAsync(PeerAddressInfo)

Establishes a connection to a peer specified by the provided address information.

public Task<ConnectedPeer> ConnectToPeerAsync(PeerAddressInfo peerAddressInfo)

Parameters

peerAddressInfo PeerAddressInfo

The address information of the peer to connect to.

Returns

Task<ConnectedPeer>

A task representing the asynchronous operation. The result contains a ConnectedPeer object representing the connected peer.

Exceptions

ConnectionException

Thrown when the connection to the peer fails.

StartListeningAsync(CancellationToken)

Starts the TCP listener service and begins listening for incoming connections on the configured addresses.

public Task StartListeningAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

A token to monitor for cancellation requests, which can be used to stop listening.

Returns

Task

A task representing the asynchronous operation.

StopListeningAsync()

Stops the TCP listener service and cleans up all active listeners, ensuring that no further connections can be made.

public Task StopListeningAsync()

Returns

Task

A task representing the asynchronous operation.

Events

OnNewPeerConnected

Event triggered when a new peer successfully establishes a connection.

public event EventHandler<NewPeerConnectedEventArgs>? OnNewPeerConnected

Event Type

EventHandler<NewPeerConnectedEventArgs>

Remarks

This event provides the means to handle actions or logic that should occur when a new peer connects to the TCP listener.