| | 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.Interfaces; |
| | 9 | | using Domain.Serialization.Interfaces; |
| | 10 | | using Domain.Transport; |
| | 11 | | using Infrastructure.Crypto.Interfaces; |
| | 12 | | using Services; |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// Factory for creating a transport service. |
| | 16 | | /// </summary> |
| | 17 | | /// <remarks> |
| | 18 | | /// This class is used to create a transport service in test environments. |
| | 19 | | /// </remarks> |
| | 20 | | public sealed class TransportServiceFactory : ITransportServiceFactory |
| | 21 | | { |
| | 22 | | private readonly IEcdh _ecdh; |
| | 23 | | private readonly ILoggerFactory _loggerFactory; |
| | 24 | | private readonly IMessageSerializer _messageSerializer; |
| | 25 | | private readonly NodeOptions _nodeOptions; |
| | 26 | |
|
| 0 | 27 | | public TransportServiceFactory(IEcdh ecdh, ILoggerFactory loggerFactory, IMessageSerializer messageSerializer, |
| 0 | 28 | | IOptions<NodeOptions> nodeOptions) |
| | 29 | | { |
| 0 | 30 | | _ecdh = ecdh; |
| 0 | 31 | | _loggerFactory = loggerFactory; |
| 0 | 32 | | _messageSerializer = messageSerializer; |
| 0 | 33 | | _nodeOptions = nodeOptions.Value; |
| 0 | 34 | | } |
| | 35 | |
|
| | 36 | | /// <inheritdoc /> |
| | 37 | | public ITransportService CreateTransportService(bool isInitiator, ReadOnlySpan<byte> s, ReadOnlySpan<byte> rs, |
| | 38 | | TcpClient tcpClient) |
| | 39 | | { |
| | 40 | | // Create a specific logger for the TransportService class |
| 0 | 41 | | var logger = _loggerFactory.CreateLogger<TransportService>(); |
| | 42 | |
|
| 0 | 43 | | return new TransportService(_ecdh, logger, _messageSerializer, _nodeOptions.NetworkTimeout, isInitiator, s, rs, |
| 0 | 44 | | tcpClient); |
| | 45 | | } |
| | 46 | | } |