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
loggerILogger<TcpService>nodeOptionsIOptions<NodeOptions>
Properties
ListeningTo
Gets the list of IP endpoints that the service is currently listening to for incoming connections.
public List<EndPoint> ListeningTo { get; }
Property Value
Remarks
This property provides the collection of addresses and ports actively used by the TCP listener to accept connections. The list remains updated as the service starts and stops listening to various addresses.
Methods
ConnectToPeerAsync(PeerAddress)
Establishes a connection to a peer specified by the provided address information.
public Task<ConnectedPeer> ConnectToPeerAsync(PeerAddress peerAddress)
Parameters
peerAddressPeerAddress
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
cancellationTokenCancellationTokenA 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
Remarks
This event provides the means to handle actions or logic that should occur when a new peer connects to the TCP listener.