diff --git a/NostrStreamer/Services/LndNode.cs b/NostrStreamer/Services/LndNode.cs index d0739cb..ca2e42e 100644 --- a/NostrStreamer/Services/LndNode.cs +++ b/NostrStreamer/Services/LndNode.cs @@ -12,9 +12,11 @@ namespace NostrStreamer.Services; public class LndNode { private readonly Network _network; + private readonly ILogger _logger; - public LndNode(Config config) + public LndNode(Config config, ILogger logger) { + _logger = logger; _network = Network.GetNetwork(config.Network) ?? Network.RegTest; var channelOptions = new GrpcChannelOptions(); ConfigureClient(channelOptions, config.Lnd); @@ -28,7 +30,7 @@ public class LndNode public Lightning.LightningClient LightningClient { get; } public Router.RouterClient RouterClient { get; } - + public Invoicesrpc.Invoices.InvoicesClient InvoicesClient { get; } public async Task AddInvoice(ulong mSats, TimeSpan? expire = null, string? memo = null, @@ -121,7 +123,7 @@ public class LndNode throw new InvalidOperationException("CLTV delta too high"); } - var knownBits = new[] {8, 9, 14, 15, 16, 17}; + var knownBits = new[] { 8, 9, 14, 15, 16, 17 }; for (var x = 0; x < 64; x++) { var n = 1L << x; @@ -152,26 +154,33 @@ public class LndNode return await InvoicesClient.AddHoldInvoiceAsync(req); } - private static void ConfigureClient(GrpcChannelOptions opt, LndConfig conf) + private void ConfigureClient(GrpcChannelOptions opt, LndConfig conf) { - var macaroon = File.ReadAllBytes(Environment.ExpandEnvironmentVariables(conf.MacaroonPath)); - var cert = File.ReadAllBytes(Environment.ExpandEnvironmentVariables(conf.CertPath)); - - var asyncInterceptor = new AsyncAuthInterceptor((_, meta) => + try { - meta.Add("macaroon", Convert.ToHexString(macaroon)); - return Task.CompletedTask; - }); + var macaroon = File.ReadAllBytes(Environment.ExpandEnvironmentVariables(conf.MacaroonPath)); + var cert = File.ReadAllBytes(Environment.ExpandEnvironmentVariables(conf.CertPath)); - var httpHandler = new HttpClientHandler(); - httpHandler.ServerCertificateCustomValidationCallback = (_, certificate2, _, _) => + var asyncInterceptor = new AsyncAuthInterceptor((_, meta) => + { + meta.Add("macaroon", Convert.ToHexString(macaroon)); + return Task.CompletedTask; + }); + + var httpHandler = new HttpClientHandler(); + httpHandler.ServerCertificateCustomValidationCallback = (_, certificate2, _, _) => + { + var serverCert = new X509Certificate2(cert); + return certificate2!.Thumbprint == serverCert.Thumbprint; + }; + + opt.HttpHandler = httpHandler; + opt.Credentials = ChannelCredentials.Create(ChannelCredentials.SecureSsl, + CallCredentials.FromInterceptor(asyncInterceptor)); + } + catch (Exception ex) { - var serverCert = new X509Certificate2(cert); - return certificate2!.Thumbprint == serverCert.Thumbprint; - }; - - opt.HttpHandler = httpHandler; - opt.Credentials = ChannelCredentials.Create(ChannelCredentials.SecureSsl, - CallCredentials.FromInterceptor(asyncInterceptor)); + _logger.LogError(ex, "Configure failed"); + } } -} +} \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index a0a05e3..a6c41dc 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -4,7 +4,7 @@ services: srs-origin: image: ossrs/srs:5 volumes: - - "./docker/srs-origin.conf:/usr/local/srs/conf/srs.conf" + - "./docker/srs-origin.conf:/usr/local/srs/conf/docker.conf" ports: - "9001:1935" - "9002:1985" @@ -13,7 +13,7 @@ services: srs-edge: image: ossrs/srs:5 volumes: - - "./docker/srs-edge.conf:/usr/local/srs/conf/srs.conf" + - "./docker/srs-edge.conf:/usr/local/srs/conf/docker.conf" ports: - "9005:1935" - "1985:1985" @@ -42,4 +42,8 @@ services: - "9010:9000" - "9011:9001" volumes: - - "minio-dvr:/data" \ No newline at end of file + - "minio-dvr:/data" + redis: + image: redis + ports: + - "6666:6379" \ No newline at end of file diff --git a/docker/srs-edge.conf b/docker/srs-edge.conf index ea01965..0369c4d 100644 --- a/docker/srs-edge.conf +++ b/docker/srs-edge.conf @@ -118,6 +118,6 @@ vhost full.in.zap.stream { vhost __defaultVhost__ { forward { enabled on; - backend http://10.100.2.226:5295/api/srs; + backend http://host.docker.internal:5295/api/srs; } } \ No newline at end of file diff --git a/docker/srs-origin.conf b/docker/srs-origin.conf index e01a313..93ee91b 100644 --- a/docker/srs-origin.conf +++ b/docker/srs-origin.conf @@ -32,10 +32,10 @@ vhost hls.zap.stream { http_hooks { enabled on; - on_publish http://10.100.2.226:5295/api/srs; - on_unpublish http://10.100.2.226:5295/api/srs; - on_hls http://10.100.2.226:5295/api/srs; - on_dvr http://10.100.2.226:5295/api/srs; + on_publish http://host.docker.internal:5295/api/srs; + on_unpublish http://host.docker.internal:5295/api/srs; + on_hls http://host.docker.internal:5295/api/srs; + on_dvr http://host.docker.internal:5295/api/srs; } dvr {