diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-11-23 18:38:02 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-11-23 18:38:02 -0600 |
| commit | 3e69af61e6ab42d79b9ff86adf7729e8abc70eed (patch) | |
| tree | 41c799babd5509638bee59afe9bd995fc6e8c6c5 /src/slskd/Core | |
| parent | 119a3925da7fdf5f659bfa4c8e61e39a7148ba3e (diff) | |
| parent | 318d1c16f80f6d48a408fb95b77c5a42402bf7df (diff) | |
| download | slskd-3e69af61e6ab42d79b9ff86adf7729e8abc70eed.tar.gz | |
Merge remote-tracking branch 'origin/master' into statistics
Diffstat (limited to 'src/slskd/Core')
| -rw-r--r-- | src/slskd/Core/API/Controllers/OptionsController.cs | 5 | ||||
| -rw-r--r-- | src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs | 4 | ||||
| -rw-r--r-- | src/slskd/Core/Data/SqlitePragmaInterceptor.cs | 55 | ||||
| -rw-r--r-- | src/slskd/Core/Extensions.cs | 6 | ||||
| -rw-r--r-- | src/slskd/Core/Options.cs | 44 |
5 files changed, 109 insertions, 5 deletions
diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs index e39c5fe1..25e9095a 100644 --- a/src/slskd/Core/API/Controllers/OptionsController.cs +++ b/src/slskd/Core/API/Controllers/OptionsController.cs @@ -190,6 +190,11 @@ namespace slskd.Core.API { var options = yaml.FromYaml<Options>(); + if (options is null) + { + return true; + } + if (!options.TryValidate(out var result)) { error = result.GetResultView(); diff --git a/src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs b/src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs index 9b3f14a8..8ae13734 100644 --- a/src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs +++ b/src/slskd/Core/Data/Migrations/Z07062025_TransferIndexesMigration.cs @@ -41,8 +41,8 @@ public class Z07062025_TransferIndexesMigration : IMigration var idxes = SchemaInspector.GetDatabaseIndexes(ConnectionString); var txfers = idxes["Transfers"]; - var directionExists = txfers.Any(c => c.Name == "IDX_Transfers_Direction"); - var stateExists = txfers.Any(c => c.Name == "IDX_Transfers_State"); + var directionExists = txfers.Any(c => c.Name.Equals("IDX_Transfers_Direction", StringComparison.OrdinalIgnoreCase)); + var stateExists = txfers.Any(c => c.Name.Equals("IDX_Transfers_State", StringComparison.OrdinalIgnoreCase)); if (directionExists && stateExists) { diff --git a/src/slskd/Core/Data/SqlitePragmaInterceptor.cs b/src/slskd/Core/Data/SqlitePragmaInterceptor.cs new file mode 100644 index 00000000..b32982b1 --- /dev/null +++ b/src/slskd/Core/Data/SqlitePragmaInterceptor.cs @@ -0,0 +1,55 @@ +// <copyright file="SqlitePragmaInterceptor.cs" company="slskd Team"> +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// </copyright> + +namespace slskd +{ + using System.Data.Common; + using System.Threading; + using System.Threading.Tasks; + using Microsoft.Data.Sqlite; + using Microsoft.EntityFrameworkCore.Diagnostics; + + /// <summary> + /// Intercepts SQLite database connections to set PRAGMAs immediately after opening. + /// </summary> + public class SqliteConnectionOpenedInterceptor : DbConnectionInterceptor + { + public override void ConnectionOpened(DbConnection connection, ConnectionEndEventData eventData) + { + if (connection is SqliteConnection) + { + using var cmd = connection.CreateCommand(); + cmd.CommandText = "PRAGMA synchronous=1;"; + cmd.ExecuteNonQuery(); + } + + base.ConnectionOpened(connection, eventData); + } + + public override async Task ConnectionOpenedAsync(DbConnection connection, ConnectionEndEventData eventData, CancellationToken cancellationToken = default) + { + if (connection is SqliteConnection) + { + using var cmd = connection.CreateCommand(); + cmd.CommandText = "PRAGMA synchronous=1;"; + await cmd.ExecuteNonQueryAsync(cancellationToken); + } + + await base.ConnectionOpenedAsync(connection, eventData, cancellationToken); + } + } +} diff --git a/src/slskd/Core/Extensions.cs b/src/slskd/Core/Extensions.cs index 65942180..db75cc9c 100644 --- a/src/slskd/Core/Extensions.cs +++ b/src/slskd/Core/Extensions.cs @@ -51,7 +51,7 @@ namespace slskd /// <param name="connectTimeout">The connection timeout, in milliseconds, for client and peer TCP connections.</param> /// <param name="inactivityTimeout">The inactivity timeout, in milliseconds, for peer TCP connections.</param> /// <param name="proxyOptions">Optional SOCKS 5 proxy configuration options.</param> - /// <param name="configureSocketAction"> + /// <param name="configureSocket"> /// The delegate invoked during instantiation to configure the server Socket instance. /// </param> /// <returns>The new instance.</returns> @@ -63,14 +63,14 @@ namespace slskd int? connectTimeout = null, int? inactivityTimeout = null, ProxyOptions proxyOptions = null, - Action<Socket> configureSocketAction = null) => new ConnectionOptions( + Action<Socket> configureSocket = null) => new ConnectionOptions( readBufferSize: readBufferSize ?? o.ReadBufferSize, writeBufferSize: writeBufferSize ?? o.WriteBufferSize, writeQueueSize: writeQueueSize ?? o.WriteQueueSize, connectTimeout: connectTimeout ?? o.ConnectTimeout, inactivityTimeout: inactivityTimeout ?? o.InactivityTimeout, proxyOptions: proxyOptions ?? o.ProxyOptions, - configureSocket: configureSocketAction ?? o.ConfigureSocket); + configureSocket: configureSocket ?? o.ConfigureSocket); /// <summary> /// Creates a new instance of <see cref="UserStatisticsState"/> from this instance of <see cref="UserStatistics"/>. diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 4d4c1e68..ec94afcb 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -418,6 +418,15 @@ namespace slskd public bool LogSQL { get; init; } = false; /// <summary> + /// Gets a value indicating whether to log unobserved Exceptions. + /// </summary> + [Argument(default, "log-unobserved-exceptions")] + [EnvironmentVariable("LOG_UNOBSERVED_EXCEPTIONS")] + [Description("log unobserved exceptions (caution: verbose)")] + [RequiresRestart] + public bool LogUnobservedExceptions { get; init; } = false; + + /// <summary> /// Gets a value indicating whether the application should run in experimental mode. /// </summary> [Argument(default, "experimental")] @@ -461,6 +470,22 @@ namespace slskd [EnvironmentVariable("OPTIMISTIC_RELAY_FILE_INFO")] [Description("use uploaded relay shares as source of truth for file existence and size")] public bool OptimisticRelayFileInfo { get; init; } = false; + + /// <summary> + /// Gets a value indicating whether SQLite cache sharing should be disabled (set to Private). + /// </summary> + [Argument(default, "no-sqlite-cache-sharing")] + [EnvironmentVariable("NO_SQLITE_CACHE_SHARING")] + [Description("disable SQLite cache sharing")] + public bool NoSqliteCacheSharing { get; init; } = false; + + /// <summary> + /// Gets a value indicating whether SQLite pooling should be disabled. + /// </summary> + [Argument(default, "no-sqlite-pooling")] + [EnvironmentVariable("NO_SQLITE_POOLING")] + [Description("disable SQLite pooling")] + public bool NoSqlitePooling { get; init; } = false; } /// <summary> @@ -1675,6 +1700,15 @@ namespace slskd [Description("connection inactivity timeout, in milliseconds")] [Range(1000, int.MaxValue)] public int Inactivity { get; init; } = 15000; + + /// <summary> + /// Gets the transfer connection timeout, in milliseconds. + /// </summary> + [Argument(default, "slsk-transfer-timeout")] + [EnvironmentVariable("SLSK_TRANSFER_TIMEOUT")] + [Description("transfer connection timeout, in milliseconds")] + [Range(30_000, int.MaxValue)] + public int Transfer { get; init; } = 60000; } /// <summary> @@ -1807,6 +1841,16 @@ namespace slskd public int Port { get; init; } = 5030; /// <summary> + /// Gets the HTTP listen unix domain socket (UDS) path. + /// </summary> + [Argument(default, "http-socket")] + [EnvironmentVariable("HTTP_SOCKET")] + [Description("HTTP listen unix domain socket (UDS) path for web UI")] + [AbsoluteFilePath] + [RequiresRestart] + public string Socket { get; init; } + + /// <summary> /// Gets HTTPS options. /// </summary> [Validate] |
