diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-12-13 16:59:51 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-12-13 16:59:51 -0600 |
| commit | 1d27718843b0d62afa8a52847eadcbdbcbf44b98 (patch) | |
| tree | bc6d2bd7fd959d0740a68b5b35a3baf8f1de31c0 /src/slskd/Program.cs | |
| parent | 6dbedb038a152a22dd9ee4b04a41a8b3ffde5d1f (diff) | |
| parent | 54584b8edd08f704427355d59323163086102207 (diff) | |
| download | slskd-1d27718843b0d62afa8a52847eadcbdbcbf44b98.tar.gz | |
Merge branch 'master' into copilot/add-sort-directories-files
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 71 |
1 files changed, 61 insertions, 10 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 6b50aedb..cb1961a2 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -23,8 +23,6 @@ namespace slskd using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; - using System.Diagnostics; - using System.IO; using System.Linq; using System.Net; @@ -42,6 +40,7 @@ namespace slskd using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -70,6 +69,7 @@ namespace slskd using slskd.Search; using slskd.Search.API; using slskd.Shares; + using slskd.Telemetry; using slskd.Transfers; using slskd.Transfers.Downloads; using slskd.Transfers.Uploads; @@ -91,6 +91,11 @@ namespace slskd public static readonly string AppName = "slskd"; /// <summary> + /// The DateTime of the 'genesis' of the application (the initial commit). + /// </summary> + public static readonly DateTime GenesisDateTime = new(2020, 12, 30, 6, 22, 0, DateTimeKind.Utc); + + /// <summary> /// The name of the local share host. /// </summary> public static readonly string LocalHostName = "local"; @@ -474,19 +479,39 @@ namespace slskd .UseUrls() .UseKestrel(options => { - Log.Information($"Listening for HTTP requests at http://{IPAddress.Any}:{OptionsAtStartup.Web.Port}/"); - options.Listen(IPAddress.Any, OptionsAtStartup.Web.Port); + // configure HTTP, either by listening at any IP or by each of the IPs provided in the + // config (note: they've already been validated at this point!) + if (string.IsNullOrWhiteSpace(OptionsAtStartup.Web.IpAddress)) + { + Log.Information("Listening for HTTP requests at http://{IP}:{Port}/", IPAddress.IPv6Any, OptionsAtStartup.Web.Port); + options.Listen(IPAddress.IPv6Any, OptionsAtStartup.Web.Port); // [::]; any IPv4 or IPv6 address + } + else + { + var httpIps = OptionsAtStartup.Web.IpAddress + .Split(',') + .Select(ip => ip.Trim()) + .Select(ip => IPAddress.Parse(ip)); + foreach (var ip in httpIps) + { + Log.Information("Listening for HTTP requests at http://{IP}:{Port}/", ip, OptionsAtStartup.Web.Port); + options.Listen(ip, OptionsAtStartup.Web.Port); + } + } + + // configure UDS, if supplied if (OptionsAtStartup.Web.Socket != null) { Log.Information($"Listening for HTTP requests on unix domain socket (UDS) {OptionsAtStartup.Web.Socket}"); options.ListenUnixSocket(OptionsAtStartup.Web.Socket); } - if (!OptionsAtStartup.Web.Https.Disabled) + // configure HTTPS, again listening on any IP or on a list of supplied IPs + // use a local function because Microsoft can't get enough of the obtuse builder pattern + static void ListenHttps(KestrelServerOptions o, IPAddress ip) { - Log.Information($"Listening for HTTPS requests at https://{IPAddress.Any}:{OptionsAtStartup.Web.Https.Port}/"); - options.Listen(IPAddress.Any, OptionsAtStartup.Web.Https.Port, listenOptions => + o.Listen(ip, OptionsAtStartup.Web.Https.Port, listenOptions => { var cert = OptionsAtStartup.Web.Https.Certificate; @@ -502,6 +527,28 @@ namespace slskd } }); } + + if (!OptionsAtStartup.Web.Https.Disabled) + { + if (string.IsNullOrWhiteSpace(OptionsAtStartup.Web.Https.IpAddress)) + { + Log.Information("Listening for HTTPS requests at https://{IP}:{Port}/", IPAddress.IPv6Any, OptionsAtStartup.Web.Https.Port); + ListenHttps(options, IPAddress.IPv6Any); + } + else + { + var httpsIps = OptionsAtStartup.Web.Https.IpAddress + .Split(',') + .Select(ip => ip.Trim()) + .Select(ip => IPAddress.Parse(ip)); + + foreach (var ip in httpsIps) + { + Log.Information("Listening for HTTPS requests at https://{IP}:{Port}/", ip, OptionsAtStartup.Web.Https.Port); + ListenHttps(options, ip); + } + } + } }); builder.Services @@ -639,8 +686,9 @@ namespace slskd services.AddSingleton<EventService>(); services.AddSingleton<EventBus>(); - services.AddSingleton<TelemetryService>(); services.AddSingleton<PrometheusService>(); + services.AddSingleton<ReportsService>(); + services.AddSingleton<TelemetryService>(); services.AddSingleton<ScriptService>(); services.AddSingleton<WebhookService>(); @@ -720,7 +768,7 @@ namespace slskd var jwtSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(OptionsAtStartup.Web.Authentication.Jwt.Key)); services.AddSingleton(jwtSigningKey); - services.AddSingleton<ISecurityService, SecurityService>(); + services.AddSingleton<SecurityService>(); if (!OptionsAtStartup.Web.Authentication.Disabled) { @@ -787,7 +835,7 @@ namespace slskd try { // check to see if the provided value is a valid API key - var service = services.BuildServiceProvider().GetRequiredService<ISecurityService>(); + var service = services.BuildServiceProvider().GetRequiredService<SecurityService>(); var (name, role) = service.AuthenticateWithApiKey(token, callerIpAddress: context.HttpContext.Connection.RemoteIpAddress); // the API key is valid. create a new, short lived jwt for the key name and role @@ -903,6 +951,9 @@ namespace slskd }, }); + // allow endpoints marked with multiple content types in [Produces] to generate properly + options.OperationFilter<ContentNegotiationOperationFilter>(); + if (IOFile.Exists(XmlDocumentationFile)) { options.IncludeXmlComments(XmlDocumentationFile); |
