aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-01-31 22:47:53 -0600
committerGitHub <noreply@github.com>2021-01-31 22:47:53 -0600
commit9c23e32a43241c2d5553d2800560fc74e8e531be (patch)
tree0eaa6b77c8bc3f4352e1a12290ee96a79539a32f /src
parent36ecf12404338bacf1fdd90334c252f89c897b3e (diff)
parent2ae3d78e9bc56de3dde214d647ee9d0ec5008194 (diff)
downloadslskd-9c23e32a43241c2d5553d2800560fc74e8e531be.tar.gz
Merge pull request #25 from slskd/more-config
Migrate remaining options
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Controllers/TransfersController.cs7
-rw-r--r--src/slskd/Options.cs62
-rw-r--r--src/slskd/Program.cs4
-rw-r--r--src/slskd/Startup.cs37
-rw-r--r--src/slskd/slskd.yml78
5 files changed, 106 insertions, 82 deletions
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;
/// <summary>
/// Transfers
@@ -26,12 +27,12 @@
/// <summary>
/// Initializes a new instance of the <see cref="TransfersController"/> class.
/// </summary>
- /// <param name="configuration"></param>
+ /// <param name="options"></param>
/// <param name="client"></param>
/// <param name="tracker"></param>
- public TransfersController(IConfiguration configuration, ISoulseekClient client, ITransferTracker tracker)
+ public TransfersController(IOptionsSnapshot<slskd.Options> options, ISoulseekClient client, ITransferTracker tracker)
{
- OutputDirectory = configuration.GetValue<string>("OUTPUT_DIR");
+ OutputDirectory = options.Value.Directories.Downloads;
Client = client;
Tracker = tracker;
}
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)
{
@@ -70,6 +70,22 @@
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",
EnvironmentVariable: "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',
@@ -196,6 +212,14 @@
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",
EnvironmentVariable: "SOULSEEK_NO_DNET",
Key: "slskd:soulseek:distributednetwork:disabled",
@@ -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;
}
}
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;
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<string>("OUTPUT_DIR");
- SharedDirectory = Configuration.GetValue<string>("SHARED_DIR");
- SharedCacheTTL = Configuration.GetValue<long>("SHARED_CACHE_TTL", 3600000); // 1 hour
- DiagnosticLevel = Configuration.GetValue<DiagnosticLevel>("DIAGNOSTIC", DiagnosticLevel.Info);
- RoomMessageLimit = Configuration.GetValue<int>("ROOM_MESSAGE_LIMIT", 250);
- XmlDocFile = Configuration.GetValue<string>("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<Options>()
.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<ISearchTracker, SearchTracker>();
services.AddSingleton<IBrowseTracker, BrowseTracker>();
services.AddSingleton<IConversationTracker, ConversationTracker>();
- services.AddSingleton<IRoomTracker, RoomTracker>(_ => new RoomTracker(messageLimit: RoomMessageLimit));
+ services.AddSingleton<IRoomTracker, RoomTracker>(_ => 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<BrowseResponse> 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)))));
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