| | 1 | | using System.Net.Sockets; |
| | 2 | | using Microsoft.Extensions.Logging; |
| | 3 | | using Microsoft.Extensions.Options; |
| | 4 | |
|
| | 5 | | namespace NLightning.Infrastructure.Transport.Factories; |
| | 6 | |
|
| | 7 | | using Domain.Node.Options; |
| | 8 | | using Domain.Protocol.Factories; |
| | 9 | | using Domain.Serialization.Messages; |
| | 10 | | using Domain.Transport; |
| | 11 | | using Services; |
| | 12 | |
|
| | 13 | | /// <summary> |
| | 14 | | /// Factory for creating a transport service. |
| | 15 | | /// </summary> |
| | 16 | | /// <remarks> |
| | 17 | | /// This class is used to create a transport service in test environments. |
| | 18 | | /// </remarks> |
| | 19 | | public sealed class TransportServiceFactory : ITransportServiceFactory |
| | 20 | | { |
| | 21 | | private readonly ILoggerFactory _loggerFactory; |
| | 22 | | private readonly IMessageSerializer _messageSerializer; |
| | 23 | | private readonly NodeOptions _nodeOptions; |
| | 24 | |
|
| 0 | 25 | | public TransportServiceFactory(ILoggerFactory loggerFactory, IMessageSerializer messageSerializer, |
| 0 | 26 | | IOptions<NodeOptions> nodeOptions) |
| | 27 | | { |
| 0 | 28 | | _loggerFactory = loggerFactory; |
| 0 | 29 | | _messageSerializer = messageSerializer; |
| 0 | 30 | | _nodeOptions = nodeOptions.Value; |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | /// <inheritdoc /> |
| | 34 | | public ITransportService CreateTransportService(bool isInitiator, ReadOnlySpan<byte> s, ReadOnlySpan<byte> rs, |
| | 35 | | TcpClient tcpClient) |
| | 36 | | { |
| | 37 | | // Create a specific logger for the TransportService class |
| 0 | 38 | | var logger = _loggerFactory.CreateLogger<TransportService>(); |
| | 39 | |
|
| 0 | 40 | | return new TransportService(logger, _messageSerializer, _nodeOptions.NetworkTimeout, isInitiator, s, rs, |
| 0 | 41 | | tcpClient); |
| | 42 | | } |
| | 43 | | } |