//
// ▄▄▄▄ ▄▄▄▄ ▄▄▄▄
// ▄▄▄▄▄▄█ █▄▄▄▄▄█ █▄▄▄▄▄█ █
// █__ --█ █__ --█ ◄█ - █
// █▄▄▄▄▄█▄▄█▄▄▄▄▄█▄▄█▄▄█▄▄▄▄▄█
// ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━ ━ ━┉ ┉ ┉
// │ Copyright (c) JP Dillingham.
// │
// │ 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, version 3.
// │
// │ 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/.
// │
// │ This program is distributed with Additional Terms pursuant to Section 7
// │ of the AGPLv3. See the LICENSE file in the root directory of this
// │ project for the complete terms and conditions.
// │
// │ https://slskd.org
// │
// ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ╌ ╌╌╌╌ ╌
// │ SPDX-FileCopyrightText: JP Dillingham
// │ SPDX-License-Identifier: AGPL-3.0-only
// ╰───────────────────────────────────────────╶──── ─ ─── ─ ── ──┈ ┈
//
namespace slskd
{
using System;
using System.Net.Sockets;
using Soulseek;
///
/// Core extensions; extensions for types specific to Soulseek or slskd.
///
public static class Extensions
{
///
/// Redacts this instance of Options, replacing properties marked with with '*****'.
///
///
/// Creates a deep clone before redacting.
///
/// The Options instance to redact.
/// A redacted instance.
public static Options Redact(this Options options)
{
var redacted = options.ToJson().FromJson();
Redactor.Redact(redacted, redactWith: "*****");
return redacted;
}
///
/// Redacts this instance of OptionsOverlay, replacing properties marked with with '*****'.
///
///
/// Creates a deep clone before redacting.
///
/// The OptionsOverlay instance to redact.
/// A redacted instance.
public static OptionsOverlay Redact(this OptionsOverlay options)
{
var redacted = options.ToJson().FromJson();
Redactor.Redact(redacted, redactWith: "*****");
return redacted;
}
///
/// Creates a copy of this instance with the specified parameters changed.
///
/// The options instance to copy.
/// The read buffer size for underlying TCP connections.
/// The write buffer size for underlying TCP connections.
/// The size of the write queue for double buffered writes.
/// The connection timeout, in milliseconds, for client and peer TCP connections.
/// The inactivity timeout, in milliseconds, for peer TCP connections.
/// Optional SOCKS 5 proxy configuration options.
///
/// The delegate invoked during instantiation to configure the server Socket instance.
///
/// The new instance.
public static ConnectionOptions With(
this ConnectionOptions o,
int? readBufferSize = null,
int? writeBufferSize = null,
int? writeQueueSize = null,
int? connectTimeout = null,
int? inactivityTimeout = null,
ProxyOptions proxyOptions = null,
Action 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: configureSocket ?? o.ConfigureSocket);
///
/// Creates a new instance of from this instance of .
///
/// The UserStatistics instance from which to copy data.
/// The new instance.
public static UserStatisticsState ToUserStatisticsState(this UserStatistics stats) => new()
{
AverageSpeed = stats.AverageSpeed,
DirectoryCount = stats.DirectoryCount,
FileCount = stats.FileCount,
UploadCount = stats.UploadCount,
};
}
}