From 2c6ba935770b855d6f583e3129466eaee47ee6b9 Mon Sep 17 00:00:00 2001 From: Shargon Date: Fri, 3 Jan 2020 10:00:24 +0100 Subject: [PATCH 1/4] Add some limits to rpc --- src/RpcServer/RpcServer.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/RpcServer/RpcServer.cs b/src/RpcServer/RpcServer.cs index d263f3dac..22276872c 100644 --- a/src/RpcServer/RpcServer.cs +++ b/src/RpcServer/RpcServer.cs @@ -91,6 +91,10 @@ protected override void OnPluginsLoaded() { host = new WebHostBuilder().UseKestrel(options => options.Listen(Settings.Default.BindAddress, Settings.Default.Port, listenOptions => { + options.Limits.MaxConcurrentConnections = 40; + options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(1); + options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(15); + if (string.IsNullOrEmpty(Settings.Default.SslCert)) return; listenOptions.UseHttps(Settings.Default.SslCert, Settings.Default.SslCertPassword, httpsConnectionAdapterOptions => { From c57f39035c6f202589df213cf2cbf10d67dccab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Naz=C3=A1rio=20Coelho?= Date: Mon, 6 Jan 2020 17:22:11 -0300 Subject: [PATCH 2/4] Updating to peer and comments --- src/RpcServer/RpcServer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/RpcServer/RpcServer.cs b/src/RpcServer/RpcServer.cs index 22276872c..91280c699 100644 --- a/src/RpcServer/RpcServer.cs +++ b/src/RpcServer/RpcServer.cs @@ -91,8 +91,11 @@ protected override void OnPluginsLoaded() { host = new WebHostBuilder().UseKestrel(options => options.Listen(Settings.Default.BindAddress, Settings.Default.Port, listenOptions => { - options.Limits.MaxConcurrentConnections = 40; + // Default value is unlimited + options.Limits.MaxConcurrentConnections = Peer.DefaultMaxConnections; + // Default value is 2 minutes options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(1); + // Default value is 30 seconds options.Limits.RequestHeadersTimeout = TimeSpan.FromSeconds(15); if (string.IsNullOrEmpty(Settings.Default.SslCert)) return; From 6c629700d291a53ab6986f89d26d5fd7d06e0e8d Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 13 Jan 2020 14:07:31 +0100 Subject: [PATCH 3/4] Allow to configure MaxConcurrentConnections --- src/RpcServer/RpcServer.cs | 2 +- src/RpcServer/RpcServer/config.json | 1 + src/RpcServer/Settings.cs | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/RpcServer/RpcServer.cs b/src/RpcServer/RpcServer.cs index 91280c699..ee027543e 100644 --- a/src/RpcServer/RpcServer.cs +++ b/src/RpcServer/RpcServer.cs @@ -92,7 +92,7 @@ protected override void OnPluginsLoaded() host = new WebHostBuilder().UseKestrel(options => options.Listen(Settings.Default.BindAddress, Settings.Default.Port, listenOptions => { // Default value is unlimited - options.Limits.MaxConcurrentConnections = Peer.DefaultMaxConnections; + options.Limits.MaxConcurrentConnections = Settings.Default.MaxConcurrentConnections; // Default value is 2 minutes options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(1); // Default value is 30 seconds diff --git a/src/RpcServer/RpcServer/config.json b/src/RpcServer/RpcServer/config.json index 39d4639c0..d51daac31 100644 --- a/src/RpcServer/RpcServer/config.json +++ b/src/RpcServer/RpcServer/config.json @@ -9,6 +9,7 @@ "RpcPass": "", "MaxGasInvoke": 10, "MaxFee": 0.1, + "MaxConcurrentConnections": 40, "DisabledMethods": [ "openwallet" ] } } diff --git a/src/RpcServer/Settings.cs b/src/RpcServer/Settings.cs index d955e48d8..f225ef393 100644 --- a/src/RpcServer/Settings.cs +++ b/src/RpcServer/Settings.cs @@ -17,7 +17,7 @@ internal class Settings public long MaxGasInvoke { get; } public long MaxFee { get; } public string[] DisabledMethods { get; } - + public int MaxConcurrentConnections { get; } public static Settings Default { get; private set; } private Settings(IConfigurationSection section) @@ -32,6 +32,7 @@ private Settings(IConfigurationSection section) this.MaxGasInvoke = (long)BigDecimal.Parse(section.GetValue("MaxGasInvoke", "10"), NativeContract.GAS.Decimals).Value; this.MaxFee = (long)BigDecimal.Parse(section.GetValue("MaxFee", "0.1"), NativeContract.GAS.Decimals).Value; this.DisabledMethods = section.GetSection("DisabledMethods").GetChildren().Select(p => p.Get()).ToArray(); + this.MaxConcurrentConnections = section.GetValue("MaxConcurrentConnections", 40); } public static void Load(IConfigurationSection section) From aab817c6ddaebd365f18f5f8674eabcfdad7b35f Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 13 Jan 2020 14:08:18 +0100 Subject: [PATCH 4/4] Enter --- src/RpcServer/Settings.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/RpcServer/Settings.cs b/src/RpcServer/Settings.cs index f225ef393..1b6a6acd6 100644 --- a/src/RpcServer/Settings.cs +++ b/src/RpcServer/Settings.cs @@ -18,6 +18,7 @@ internal class Settings public long MaxFee { get; } public string[] DisabledMethods { get; } public int MaxConcurrentConnections { get; } + public static Settings Default { get; private set; } private Settings(IConfigurationSection section)