From 4f2c54b924fa1277367a264c79fe1db6d67532d8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 31 Jan 2021 21:44:43 -0600 Subject: add diagnostics and directires options --- src/slskd/Options.cs | 62 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index b5968b9f..a966f3dc 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -1,9 +1,9 @@ namespace slskd { + using Soulseek.Diagnostics; using System; using System.Collections.Generic; using System.Diagnostics; - using YamlDotNet.Serialization; public record Option(char ShortName, string LongName, string EnvironmentVariable, string Key, Type Type, object Default = null, string Description = null) { @@ -69,6 +69,22 @@ Type: typeof(string), Default: "default", Description: "optional; a unique name for this instance"), + new( + ShortName: 'o', + LongName: "downloads", + EnvironmentVariable: "DOWNLOADS_DIR", + Key: "slskd:directories:downloads", + Type: typeof(string), + Default: null, + Description: "the path where downloaded files are saved"), + new( + ShortName: 's', + LongName: "shared", + EnvironmentVariable: "SHARED_DIR", + Key: "slskd:directories:shared", + Type: typeof(string), + Default: null, + Description: "the path to shared files"), new( ShortName: 'l', LongName: "http-port", @@ -83,7 +99,7 @@ EnvironmentVariable: "HTTPS_PORT", Key: "slskd:web:https:port", Type: typeof(int), - Default: 5000, + Default: 5001, Description: "HTTPS listen port for web server"), new( ShortName: 'f', @@ -194,6 +210,14 @@ Type: typeof(int), Default: 50000, Description: "the port on which to listen for incoming connections"), + new( + ShortName: default, + LongName: "soulseek-diagnostic-level", + EnvironmentVariable: "SOULSEEK_DIAGNOSTIC_LEVEL", + Key: "slskd:soulseek:diagnosticlevel", + Type: typeof(DiagnosticLevel), + Default: DiagnosticLevel.Info, + Description: "the minimum diagnostic level (None, Warning, Info, Debug)"), new( ShortName: default, LongName: "soulseek-no-dnet", @@ -247,11 +271,18 @@ public bool Debug { get; private set; } = Debugger.IsAttached; public bool NoLogo { get; private set; } = false; public string InstanceName { get; private set; } = "default"; + public DirectoriesOptions Directories { get; private set; } = new DirectoriesOptions(); public WebOptions Web { get; private set; } = new WebOptions(); public LoggerOptions Logger { get; private set; } = new LoggerOptions(); public FeatureOptions Feature { get; private set; } = new FeatureOptions(); public SoulseekOptions Soulseek { get; private set; } = new SoulseekOptions(); + public class DirectoriesOptions + { + public string Shared { get; private set; } + public string Downloads { get; private set; } + } + public class FeatureOptions { public bool Prometheus { get; private set; } = false; @@ -265,34 +296,35 @@ public class SoulseekOptions { - public string Password { get; set; } - public string Username { get; set; } - public int? ListenPort { get; set; } = 50000; - public DistributedNetworkOptions DistributedNetwork { get; set; } = new DistributedNetworkOptions(); - public ConnectionOptions Connection { get; set; } = new ConnectionOptions(); + public string Password { get; private set; } + public string Username { get; private set; } + public int? ListenPort { get; private set; } = 50000; + public DiagnosticLevel DiagnosticLevel { get; private set; } = DiagnosticLevel.Info; + public DistributedNetworkOptions DistributedNetwork { get; private set; } = new DistributedNetworkOptions(); + public ConnectionOptions Connection { get; private set; } = new ConnectionOptions(); public class ConnectionOptions { - public TimeoutOptions Timeout { get; set; } = new TimeoutOptions(); - public BufferOptions Buffer { get; set; } = new BufferOptions(); + public TimeoutOptions Timeout { get; private set; } = new TimeoutOptions(); + public BufferOptions Buffer { get; private set; } = new BufferOptions(); public class BufferOptions { - public int Read { get; set; } = 16384; - public int Write { get; set; } = 16384; + public int Read { get; private set; } = 16384; + public int Write { get; private set; } = 16384; } public class TimeoutOptions { - public int Connect { get; set; } = 5000; - public int Inactivity { get; set; } = 15000; + public int Connect { get; private set; } = 5000; + public int Inactivity { get; private set; } = 15000; } } public class DistributedNetworkOptions { - public bool Disabled { get; set; } = false; - public int ChildLimit { get; set; } = 25; + public bool Disabled { get; private set; } = false; + public int ChildLimit { get; private set; } = 25; } } -- cgit v1.2.3 From 0691de39e853f0d7e7fbffac76b0d57f70d60beb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 31 Jan 2021 22:32:57 -0600 Subject: comment out config file --- src/slskd/slskd.yml | 78 ++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/slskd/slskd.yml b/src/slskd/slskd.yml index d698f8fb..e1808ffd 100644 --- a/src/slskd/slskd.yml +++ b/src/slskd/slskd.yml @@ -1,37 +1,41 @@ -slskd: - debug: false - no_logo: false - instance_name: default - web: - port: 5000 - https: - port: 5001 - force: false - url_base: / - content_path: wwwroot - authentication: - disable: false - username: slskd - password: slskd - jwt: - key: ~ - ttl: 604800000 - logger: - loki: ~ - feature: - prometheus: false - swagger: false - soulseek: - username: ~ - password: ~ - listen_port: 50000 - distributed_network: - disabled: false - child_limit: 25 - connection: - timeout: - connect: 5000 - inactivity: 15000 - buffer: - read: 16384 - write: 16384 \ No newline at end of file +# slskd: +# debug: false +# no_logo: false +# instance_name: default +# web: +# port: 5000 +# https: +# port: 5001 +# force: false +# url_base: / +# content_path: wwwroot +# authentication: +# disable: false +# username: slskd +# password: slskd +# jwt: +# key: ~ +# ttl: 604800000 +# directories: +# shared: ~ +# downloads: ~ +# logger: +# loki: ~ +# feature: +# prometheus: false +# swagger: false +# soulseek: +# username: ~ +# password: ~ +# listen_port: 50000 +# diagnostic_level: Info +# distributed_network: +# disabled: false +# child_limit: 25 +# connection: +# timeout: +# connect: 5000 +# inactivity: 15000 +# buffer: +# read: 16384 +# write: 16384 \ No newline at end of file -- cgit v1.2.3 From 35eda81d130f84912396de9f2e4771ff03aad20e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 31 Jan 2021 22:33:10 -0600 Subject: use correct dir --- src/slskd/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 6e3c0f3e..0a633635 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -24,7 +24,7 @@ prefix: environmentVariablePrefix, map: Options.Map.Select(o => o.ToEnvironmentVariable())) .AddYamlFile( - path: Path.Combine(Directory.GetCurrentDirectory(), configurationFile), + path: Path.Combine(AppContext.BaseDirectory, configurationFile), optional: true, reloadOnChange: false) .AddCommandLine( @@ -37,7 +37,7 @@ { private static readonly string ConfigurationFile = "slskd.yml"; private static readonly string EnvironmentVariablePrefix = "SLSKD_"; - + public static Guid InvocationId { get; } = Guid.NewGuid(); public static int ProcessId { get; } = Environment.ProcessId; public static Version AssemblyVersion { get; } = Assembly.GetExecutingAssembly().GetName().Version; -- cgit v1.2.3 From 2ae3d78e9bc56de3dde214d647ee9d0ec5008194 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 31 Jan 2021 22:34:29 -0600 Subject: remove remaining legacy options --- src/slskd/Controllers/TransfersController.cs | 7 +++--- src/slskd/Startup.cs | 37 +++++++++------------------- 2 files changed, 16 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/slskd/Controllers/TransfersController.cs b/src/slskd/Controllers/TransfersController.cs index d4fa3f79..505e84e5 100644 --- a/src/slskd/Controllers/TransfersController.cs +++ b/src/slskd/Controllers/TransfersController.cs @@ -12,6 +12,7 @@ using System.Threading.Tasks; using slskd.DTO; using slskd.Trackers; + using Microsoft.Extensions.Options; /// /// Transfers @@ -26,12 +27,12 @@ /// /// Initializes a new instance of the class. /// - /// + /// /// /// - public TransfersController(IConfiguration configuration, ISoulseekClient client, ITransferTracker tracker) + public TransfersController(IOptionsSnapshot options, ISoulseekClient client, ITransferTracker tracker) { - OutputDirectory = configuration.GetValue("OUTPUT_DIR"); + OutputDirectory = options.Value.Directories.Downloads; Client = client; Tracker = tracker; } diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index 3479926b..31542f1a 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -36,13 +36,7 @@ { private readonly int MaxReconnectAttempts = 3; private int CurrentReconnectAttempts = 0; - - internal static string OutputDirectory { get; set; } - internal static string SharedDirectory { get; set; } - internal static long SharedCacheTTL { get; set; } - internal static DiagnosticLevel DiagnosticLevel { get; set; } - internal static int RoomMessageLimit { get; set; } - internal static string XmlDocFile { get; set; } + private static readonly string XmlDocFile = Path.Combine(AppContext.BaseDirectory, typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml"); private SoulseekClient Client { get; set; } private ISharedFileCache SharedFileCache { get; set; } @@ -60,14 +54,14 @@ o.BindNonPublicProperties = true; }); - OutputDirectory = Configuration.GetValue("OUTPUT_DIR"); - SharedDirectory = Configuration.GetValue("SHARED_DIR"); - SharedCacheTTL = Configuration.GetValue("SHARED_CACHE_TTL", 3600000); // 1 hour - DiagnosticLevel = Configuration.GetValue("DIAGNOSTIC", DiagnosticLevel.Info); - RoomMessageLimit = Configuration.GetValue("ROOM_MESSAGE_LIMIT", 250); - XmlDocFile = Configuration.GetValue("XML_DOC_FILE", Path.Combine(AppContext.BaseDirectory, typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml")); - - SharedFileCache = new SharedFileCache(SharedDirectory, SharedCacheTTL); + SharedFileCache = new SharedFileCache(Options.Directories.Shared, 3600000); + + UrlBase = Options.Web.UrlBase; + UrlBase = UrlBase.StartsWith("/") ? UrlBase : "/" + UrlBase; + + ContentPath = Path.GetFullPath(Options.Web.ContentPath); + + JwtSigningKey = new SymmetricSecurityKey(PBKDF2.GetKey(Options.Web.Jwt.Key)); } private IConfiguration Configuration { get; } @@ -81,13 +75,6 @@ services.AddOptions() .Bind(Configuration.GetSection("slskd"), o => { o.BindNonPublicProperties = true; }); - UrlBase = Options.Web.UrlBase; - UrlBase = UrlBase.StartsWith("/") ? UrlBase : "/" + UrlBase; - - ContentPath = Path.GetFullPath(Options.Web.ContentPath); - - JwtSigningKey = new SymmetricSecurityKey(PBKDF2.GetKey(Options.Web.Jwt.Key)); - services.AddCors(options => options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())); services.AddSingleton(JwtSigningKey); @@ -164,7 +151,7 @@ services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(_ => new RoomTracker(messageLimit: RoomMessageLimit)); + services.AddSingleton(_ => new RoomTracker(messageLimit: 250)); } public void Configure( @@ -296,7 +283,7 @@ userEndPointCache: new UserEndPointCache(), distributedChildLimit: Options.Soulseek.DistributedNetwork.ChildLimit, enableDistributedNetwork: !Options.Soulseek.DistributedNetwork.Disabled, - minimumDiagnosticLevel: DiagnosticLevel, + minimumDiagnosticLevel: Options.Soulseek.DiagnosticLevel, autoAcknowledgePrivateMessages: false, acceptPrivateRoomInvitations: true, serverConnectionOptions: connectionOptions, @@ -465,7 +452,7 @@ private Task BrowseResponseResolver(string username, IPEndPoint endpoint) { var directories = System.IO.Directory - .GetDirectories(SharedDirectory, "*", SearchOption.AllDirectories) + .GetDirectories(Options.Directories.Shared, "*", SearchOption.AllDirectories) .Select(dir => new Soulseek.Directory(dir, System.IO.Directory.GetFiles(dir) .Select(f => new Soulseek.File(1, Path.GetFileName(f), new FileInfo(f).Length, Path.GetExtension(f))))); -- cgit v1.2.3