From a8deb4361362ed01c930447dcfa92a9b756d03c0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 25 Jun 2022 19:10:27 -0500 Subject: move some things into Core --- src/slskd/Core/CoreExtensions.cs | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/slskd/Core/CoreExtensions.cs (limited to 'src/slskd/Core/CoreExtensions.cs') diff --git a/src/slskd/Core/CoreExtensions.cs b/src/slskd/Core/CoreExtensions.cs new file mode 100644 index 00000000..aef187b8 --- /dev/null +++ b/src/slskd/Core/CoreExtensions.cs @@ -0,0 +1,75 @@ +// +// 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/. +// + +namespace slskd +{ + using System; + using System.Net.Sockets; + using Soulseek; + + /// + /// Core extensions; extensions for types specific to Soulseek or slskd. + /// + public static class CoreExtensions + { + /// + /// 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; + } + + /// + /// 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 configureSocketAction = 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); + } +} -- cgit v1.2.3