Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize AkkaSpec and Akka.Remote DotNetty transport settings #6854

Merged

Conversation

Arkatufus
Copy link
Contributor

@Arkatufus Arkatufus commented Jul 26, 2023

  • The Akka.Remote code is full of byte rot and needs cleaning.
  • AkkaSpec failed to inject its internal configuration with its ActorSystemSetup constructor variant

Changes

  • Makes sure that AkkaSpec injects _akkaSpecConfig into the ActorSystemSetup ctor argument
  • Modernize DotNettyTransportSettings:
    • Change to record
    • Use #nullable enable
    • Add Setup support.
    • Use pattern matching
  • Add DotNettySslSetup

Checklist

For significant changes, please ensure that the following have been completed (delete if not relevant):

HandshakeTimeout = config.GetTimeSpan("akka.remote.dot-netty.tcp.connection-timeout", null);
else if (enabledTransports.Contains("akka.remote.dot-netty.ssl"))
HandshakeTimeout = config.GetTimeSpan("akka.remote.dot-netty.ssl.connection-timeout", null);
HandshakeTimeout = config.GetTimeSpan("akka.remote.dot-netty.tcp.connection-timeout", TimeSpan.FromSeconds(15), allowInfinite:false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add default value to config value

Comment on lines -55 to -56
else if (enabledTransports.Contains("akka.remote.dot-netty.ssl"))
HandshakeTimeout = config.GetTimeSpan("akka.remote.dot-netty.ssl.connection-timeout", null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed akka.remote.dot-netty.ssl, this HOCON path has not been used since 5 years ago

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

else
HandshakeTimeout = config.GetTimeSpan("akka.remote.handshake-timeout", TimeSpan.FromSeconds(20), allowInfinite:false);
HandshakeTimeout = config.GetTimeSpan("akka.remote.handshake-timeout", TimeSpan.FromSeconds(15), allowInfinite:false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change default value to 15 to reflect actual HOCON default

Comment on lines -355 to -356
# necessary to keep backwards compatibility
helios.tcp.transport-class = "Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote.Transport.Helios"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to code since this causes bugs

Comment on lines +524 to +555
ssl {
certificate {
# Valid certificate path required
path = ""
# Valid certificate password required
password = ""
# Default key storage flag is "default-key-set"
# Available flags include:
# default-key-set | exportable | machine-key-set | persist-key-set | user-key-set | user-protected
# flags = [ "default-key-set" ]

# To use a Thumbprint instead of a file, set this to true
# And specify a thumbprint and it's storage location below
use-thumbprint-over-file = false

# Valid Thumbprint required (if use-thumbprint-over-file is true)
# A typical thumbprint is a format similar to: "45df32e258c92a7abf6c112e54912ab15bbb9eb0"
# On Windows machines, The thumbprint for an installed certificate can be located
# By using certlm.msc and opening the certificate under the 'Details' tab.
thumbprint = ""

# The Store name. Under windows The most common option is "My", which indicates the personal store.
# See System.Security.Cryptography.X509Certificates.StoreName for other common values.
store-name = ""

# Valid options : local-machine or current-user
# current-user indicates a certificate stored under the user's account
# local-machine indicates a certificate stored at an operating system level (potentially shared by users)
store-location = "current-user"
}
suppress-validation = false
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the SSL configuration to its proper place

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +12 to +24
public sealed class DotNettySslSetup: Setup
{
public DotNettySslSetup(X509Certificate2 certificate, bool suppressValidation)
{
Certificate = certificate;
SuppressValidation = suppressValidation;
}

public X509Certificate2 Certificate { get; }
public bool SuppressValidation { get; }

internal SslSettings Settings => new SslSettings(Certificate, SuppressValidation);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Setup class allows users to inject X509Certificate2 instance directly

Comment on lines +137 to +138
var heliosFallbackConfig = system.Settings.Config.GetConfig("akka.remote.helios.tcp")
.WithFallback("transport-class = \"Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote.Transport.Helios\"");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the hard coded HOCON settings from pidgeon.conf here, value only get added when necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need to support Helios?

Comment on lines +142 to +144
var setup = system.Settings.Setup.Get<DotNettySslSetup>();
var sslSettings = setup.HasValue ? setup.Value.Settings : null;
Settings = DotNettyTransportSettings.Create(config, sslSettings);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setup class injection

/// <param name="BatchWriterSettings">
/// Used for performance-tuning the DotNetty channels to maximize I/O performance.
/// </param>
internal sealed record DotNettyTransportSettings(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to record, safe API change, internal

Comment on lines +145 to +147
var setup = system.Settings.Setup.Get<DotNettySslSetup>();
var sslSettings = setup.HasValue ? setup.Value.Settings : null;
return Create(config, sslSettings);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setup class injection

Comment on lines +173 to +178
var host = config.GetString("hostname");
if (string.IsNullOrWhiteSpace(host))
host = IPAddress.Any.ToString();

var publicHost = config.GetString("public-hostname");
var publicPort = config.GetInt("public-port");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unnecessary default values

ServerSocketWorkerPoolSize: ComputeWorkerPoolSize(config.GetConfig("server-socket-worker-pool")),
ClientSocketWorkerPoolSize: ComputeWorkerPoolSize(config.GetConfig("client-socket-worker-pool")),
MaxFrameSize: ToNullableInt(config.GetByteSize("maximum-frame-size", null)) ?? 128000,
Ssl: enableSsl ? SslSettings.CreateOrDefault(config.GetConfig("ssl"), sslSettings) : SslSettings.Empty,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the "ssl" path will always be present now since we fix the default HOCON.

Comment on lines +231 to +233
floor: config.GetInt("pool-size-min", 2),
scalar: config.GetDouble("pool-size-factor", 1.0),
ceiling: config.GetInt("pool-size-max", 2));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add sensible default values

Copy link
Member

@Aaronontheweb Aaronontheweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}
namespace Akka.Remote.Transport.DotNetty
{
public sealed class DotNettySslSetup : Akka.Actor.Setup.Setup
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - need this for programmatic setup I take it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines -55 to -56
else if (enabledTransports.Contains("akka.remote.dot-netty.ssl"))
HandshakeTimeout = config.GetTimeSpan("akka.remote.dot-netty.ssl.connection-timeout", null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +524 to +555
ssl {
certificate {
# Valid certificate path required
path = ""
# Valid certificate password required
password = ""
# Default key storage flag is "default-key-set"
# Available flags include:
# default-key-set | exportable | machine-key-set | persist-key-set | user-key-set | user-protected
# flags = [ "default-key-set" ]

# To use a Thumbprint instead of a file, set this to true
# And specify a thumbprint and it's storage location below
use-thumbprint-over-file = false

# Valid Thumbprint required (if use-thumbprint-over-file is true)
# A typical thumbprint is a format similar to: "45df32e258c92a7abf6c112e54912ab15bbb9eb0"
# On Windows machines, The thumbprint for an installed certificate can be located
# By using certlm.msc and opening the certificate under the 'Details' tab.
thumbprint = ""

# The Store name. Under windows The most common option is "My", which indicates the personal store.
# See System.Security.Cryptography.X509Certificates.StoreName for other common values.
store-name = ""

# Valid options : local-machine or current-user
# current-user indicates a certificate stored under the user's account
# local-machine indicates a certificate stored at an operating system level (potentially shared by users)
store-location = "current-user"
}
suppress-validation = false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Aaronontheweb Aaronontheweb added this to the 1.5.11 milestone Jul 27, 2023
@Aaronontheweb Aaronontheweb merged commit 588d5d6 into akkadotnet:dev Jul 27, 2023
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants