From 35d5a1dacd432fe2d5b3aad0a04aaa4480b489bf Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 26 Nov 2021 15:39:13 -0600 Subject: update Soulseek.NET --- src/slskd/slskd.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd') diff --git a/src/slskd/slskd.csproj b/src/slskd/slskd.csproj index 2b81d689..75d7b90d 100644 --- a/src/slskd/slskd.csproj +++ b/src/slskd/slskd.csproj @@ -68,7 +68,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive -- cgit v1.2.3 From fa08611a9ac686cce6c783276f518e5f0ccaab0c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 26 Nov 2021 15:39:28 -0600 Subject: remove write timeout option --- src/slskd/Options.cs | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index 66cb0e19..4a9df941 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -568,15 +568,6 @@ namespace slskd [Range(1000, int.MaxValue)] public int Connect { get; private set; } = 10000; - /// - /// Gets the write timeout value, in milliseconds. - /// - [Argument(default, "slsk-write-timeout")] - [EnvironmentVariable("SLSK_WRITE_TIMEOUT")] - [Description("write timeout, in milliseconds")] - [Range(500, int.MaxValue)] - public int Write { get; private set; } = 5000; - /// /// Gets the connection inactivity timeout, in milliseconds. /// -- cgit v1.2.3 From 98ea758c1ff05831d79088a52c43c7ecec7aa4a1 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 26 Nov 2021 15:40:03 -0600 Subject: add ConnectionOptions.With extension --- src/slskd/Common/Extensions.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/slskd') diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index 4d463092..32a9b26e 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -21,10 +21,12 @@ namespace slskd using System.Collections.Generic; using System.IO; using System.Linq; + using System.Net.Sockets; using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.RegularExpressions; + using Soulseek; using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; @@ -282,6 +284,36 @@ namespace slskd return Path.Combine(path, sanitizedFilename).TrimStart('\\').TrimStart('/'); } + /// + /// 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, + configureSocketAction: configureSocketAction ?? o.ConfigureSocketAction); + /// /// Deserializes this string from json to an object of type . /// -- cgit v1.2.3 From eb662b4f198e60d54e278e5ab56ad1f49f4200b0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 26 Nov 2021 15:42:03 -0600 Subject: configure keepalive for server and distributed connections --- src/slskd/Application.cs | 57 +++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 23 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index c4dfa46d..3914483e 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -24,6 +24,7 @@ namespace slskd using System.IO; using System.Linq; using System.Net; + using System.Net.Sockets; using System.Reflection; using System.Threading; using System.Threading.Tasks; @@ -199,19 +200,23 @@ namespace slskd writeBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Write, writeQueueSize: OptionsAtStartup.Soulseek.Connection.Buffer.WriteQueue, connectTimeout: OptionsAtStartup.Soulseek.Connection.Timeout.Connect, - writeTimeout: OptionsAtStartup.Soulseek.Connection.Timeout.Write, inactivityTimeout: OptionsAtStartup.Soulseek.Connection.Timeout.Inactivity, proxyOptions: proxyOptions); - var transferOptions = new ConnectionOptions( + var configureKeepAlive = new Action(socket => + { + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); + socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, OptionsAtStartup.Soulseek.Connection.Timeout.Inactivity / 1000); + socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, OptionsAtStartup.Soulseek.Connection.Timeout.Inactivity / 1000); + socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, 3); + }); + + var serverOptions = connectionOptions.With(configureSocketAction: configureKeepAlive); + var distributedOptions = connectionOptions.With(configureSocketAction: configureKeepAlive); + + var transferOptions = connectionOptions.With( readBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer, - writeBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer, - writeQueueSize: OptionsAtStartup.Soulseek.Connection.Buffer.WriteQueue, - connectTimeout: OptionsAtStartup.Soulseek.Connection.Timeout.Connect, - writeTimeout: 0, - inactivityTimeout: -1, - keepAlive: true, - proxyOptions: proxyOptions); + writeBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer); var patch = new SoulseekClientOptionsPatch( listenPort: OptionsAtStartup.Soulseek.ListenPort, @@ -222,10 +227,10 @@ namespace slskd acceptDistributedChildren: !OptionsAtStartup.Soulseek.DistributedNetwork.DisableChildren, autoAcknowledgePrivateMessages: false, acceptPrivateRoomInvitations: true, - serverConnectionOptions: connectionOptions, + serverConnectionOptions: serverOptions, peerConnectionOptions: connectionOptions, transferConnectionOptions: transferOptions, - distributedConnectionOptions: connectionOptions, + distributedConnectionOptions: distributedOptions, userInfoResponseResolver: UserInfoResponseResolver, browseResponseResolver: BrowseResponseResolver, directoryContentsResponseResolver: DirectoryContentsResponseResolver, @@ -598,6 +603,8 @@ namespace slskd var connectionDiff = old.Connection.DiffWith(update.Connection); ConnectionOptions connectionPatch = null; + ConnectionOptions serverPatch = null; + ConnectionOptions distributedPatch = null; ConnectionOptions transferPatch = null; if (connectionDiff.Any()) @@ -620,19 +627,23 @@ namespace slskd writeBufferSize: connection.Buffer.Write, writeQueueSize: connection.Buffer.WriteQueue, connectTimeout: connection.Timeout.Connect, - writeTimeout: connection.Timeout.Write, inactivityTimeout: connection.Timeout.Inactivity, proxyOptions: proxyPatch); - transferPatch = new ConnectionOptions( - readBufferSize: connection.Buffer.Transfer, - writeBufferSize: connection.Buffer.Transfer, - writeQueueSize: connection.Buffer.WriteQueue, - connectTimeout: connection.Timeout.Connect, - writeTimeout: 0, - inactivityTimeout: -1, - keepAlive: true, - proxyOptions: proxyPatch); + var configureKeepAlive = new Action(socket => + { + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.TcpKeepAliveTime, connection.Timeout.Inactivity / 1000); + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.TcpKeepAliveInterval, connection.Timeout.Inactivity / 1000); + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.TcpKeepAliveRetryCount, 3); + }); + + serverPatch = connectionPatch.With(configureSocketAction: configureKeepAlive); + distributedPatch = connectionPatch.With(configureSocketAction: configureKeepAlive); + + transferPatch = connectionPatch.With( + readBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer, + writeBufferSize: OptionsAtStartup.Soulseek.Connection.Buffer.Transfer); } var patch = new SoulseekClientOptionsPatch( @@ -640,11 +651,11 @@ namespace slskd enableDistributedNetwork: old.DistributedNetwork.Disabled == update.DistributedNetwork.Disabled ? null : !update.DistributedNetwork.Disabled, distributedChildLimit: old.DistributedNetwork.ChildLimit == update.DistributedNetwork.ChildLimit ? null : update.DistributedNetwork.ChildLimit, acceptDistributedChildren: old.DistributedNetwork.DisableChildren == update.DistributedNetwork.DisableChildren ? null : !update.DistributedNetwork.DisableChildren, - serverConnectionOptions: connectionPatch, + serverConnectionOptions: serverPatch, peerConnectionOptions: connectionPatch, transferConnectionOptions: transferPatch, incomingConnectionOptions: connectionPatch, - distributedConnectionOptions: connectionPatch); + distributedConnectionOptions: distributedPatch); Logger.Debug("Patching Soulseek options with {Patch}", patch.ToJson()); -- cgit v1.2.3