feat: port session 03 — Configuration & Options types, Clone, MergeOptions, SetBaseline
- ServerOptionTypes.cs: all supporting types — ClusterOpts, GatewayOpts, LeafNodeOpts, WebsocketOpts, MqttOpts, RemoteLeafOpts, RemoteGatewayOpts, CompressionOpts, TlsConfigOpts, JsLimitOpts, JsTpmOpts, AuthCalloutOpts, ProxiesConfig, IAuthentication, IAccountResolver, enums (WriteTimeoutPolicy, StoreCipher, OcspMode) - ServerOptions.cs: full Options struct with ~100 properties across 10 subsystems (general, logging, networking, TLS, cluster, gateway, leafnode, websocket, MQTT, JetStream) - ServerOptions.Methods.cs: Clone (deep copy), MergeOptions, SetBaselineOptions, RoutesFromStr, NormalizeBasePath, OverrideTls, OverrideCluster, ExpandPath, HomeDir, MaybeReadPidFile, GetDefaultAuthTimeout, ConfigFlags.NoErrOnUnknownFields - 17 tests covering defaults, random port, merge, clone, expand path, auth timeout, routes parsing, normalize path, cluster override, config flags - Config file parsing (processConfigFileLine 765-line function) deferred to follow-up - All 130 tests pass (129 unit + 1 integration) - DB: features 344/3673 complete, tests 148/3257 complete (9.1% overall)
This commit is contained in:
234
dotnet/src/ZB.MOM.NatsNet.Server/ServerOptions.cs
Normal file
234
dotnet/src/ZB.MOM.NatsNet.Server/ServerOptions.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
// Copyright 2012-2025 The NATS Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// Adapted from server/opts.go in the NATS server Go source.
|
||||
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
using System.Threading;
|
||||
|
||||
namespace ZB.MOM.NatsNet.Server;
|
||||
|
||||
/// <summary>
|
||||
/// Server configuration options block.
|
||||
/// Mirrors <c>Options</c> struct in opts.go.
|
||||
/// </summary>
|
||||
public sealed partial class ServerOptions
|
||||
{
|
||||
// -------------------------------------------------------------------------
|
||||
// General / Startup
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public string ConfigFile { get; set; } = string.Empty;
|
||||
public string ServerName { get; set; } = string.Empty;
|
||||
public string Host { get; set; } = string.Empty;
|
||||
public int Port { get; set; }
|
||||
public bool DontListen { get; set; }
|
||||
public string ClientAdvertise { get; set; } = string.Empty;
|
||||
public bool CheckConfig { get; set; }
|
||||
public string PidFile { get; set; } = string.Empty;
|
||||
public string PortsFileDir { get; set; } = string.Empty;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Logging & Debugging
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public bool Trace { get; set; }
|
||||
public bool Debug { get; set; }
|
||||
public bool TraceVerbose { get; set; }
|
||||
public bool TraceHeaders { get; set; }
|
||||
public bool NoLog { get; set; }
|
||||
public bool NoSigs { get; set; }
|
||||
public bool Logtime { get; set; }
|
||||
public bool LogtimeUtc { get; set; }
|
||||
public string LogFile { get; set; } = string.Empty;
|
||||
public long LogSizeLimit { get; set; }
|
||||
public long LogMaxFiles { get; set; }
|
||||
public bool Syslog { get; set; }
|
||||
public string RemoteSyslog { get; set; } = string.Empty;
|
||||
public int ProfPort { get; set; }
|
||||
public int ProfBlockRate { get; set; }
|
||||
public int MaxTracedMsgLen { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Networking & Limits
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public int MaxConn { get; set; }
|
||||
public int MaxSubs { get; set; }
|
||||
public byte MaxSubTokens { get; set; }
|
||||
public int MaxControlLine { get; set; }
|
||||
public int MaxPayload { get; set; }
|
||||
public long MaxPending { get; set; }
|
||||
public bool NoFastProducerStall { get; set; }
|
||||
public bool ProxyRequired { get; set; }
|
||||
public bool ProxyProtocol { get; set; }
|
||||
public int MaxClosedClients { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Connectivity
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public TimeSpan PingInterval { get; set; }
|
||||
public int MaxPingsOut { get; set; }
|
||||
public TimeSpan WriteDeadline { get; set; }
|
||||
public WriteTimeoutPolicy WriteTimeout { get; set; }
|
||||
public TimeSpan LameDuckDuration { get; set; }
|
||||
public TimeSpan LameDuckGracePeriod { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// HTTP / Monitoring
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public string HttpHost { get; set; } = string.Empty;
|
||||
public int HttpPort { get; set; }
|
||||
public string HttpBasePath { get; set; } = string.Empty;
|
||||
public int HttpsPort { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Authentication & Authorization
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public string Username { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string Authorization { get; set; } = string.Empty;
|
||||
public double AuthTimeout { get; set; }
|
||||
public string NoAuthUser { get; set; } = string.Empty;
|
||||
public string DefaultSentinel { get; set; } = string.Empty;
|
||||
public string SystemAccount { get; set; } = string.Empty;
|
||||
public bool NoSystemAccount { get; set; }
|
||||
public AuthCalloutOpts? AuthCallout { get; set; }
|
||||
public bool AlwaysEnableNonce { get; set; }
|
||||
public IAuthentication? CustomClientAuthentication { get; set; }
|
||||
public IAuthentication? CustomRouterAuthentication { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Sublist
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public bool NoSublistCache { get; set; }
|
||||
public bool NoHeaderSupport { get; set; }
|
||||
public bool DisableShortFirstPing { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// TLS (Client)
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public double TlsTimeout { get; set; }
|
||||
public bool Tls { get; set; }
|
||||
public bool TlsVerify { get; set; }
|
||||
public bool TlsMap { get; set; }
|
||||
public string TlsCert { get; set; } = string.Empty;
|
||||
public string TlsKey { get; set; } = string.Empty;
|
||||
public string TlsCaCert { get; set; } = string.Empty;
|
||||
public SslServerAuthenticationOptions? TlsConfig { get; set; }
|
||||
public PinnedCertSet? TlsPinnedCerts { get; set; }
|
||||
public long TlsRateLimit { get; set; }
|
||||
public bool TlsHandshakeFirst { get; set; }
|
||||
public TimeSpan TlsHandshakeFirstFallback { get; set; }
|
||||
public bool AllowNonTls { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Cluster / Gateway / Leaf / WebSocket / MQTT
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public ClusterOpts Cluster { get; set; } = new();
|
||||
public GatewayOpts Gateway { get; set; } = new();
|
||||
public LeafNodeOpts LeafNode { get; set; } = new();
|
||||
public WebsocketOpts Websocket { get; set; } = new();
|
||||
public MqttOpts Mqtt { get; set; } = new();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Routing
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public List<Uri> Routes { get; set; } = [];
|
||||
public string RoutesStr { get; set; } = string.Empty;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// JetStream
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public bool JetStream { get; set; }
|
||||
public bool NoJetStreamStrict { get; set; }
|
||||
public long JetStreamMaxMemory { get; set; }
|
||||
public long JetStreamMaxStore { get; set; }
|
||||
public string JetStreamDomain { get; set; } = string.Empty;
|
||||
public string JetStreamExtHint { get; set; } = string.Empty;
|
||||
public string JetStreamKey { get; set; } = string.Empty;
|
||||
public string JetStreamOldKey { get; set; } = string.Empty;
|
||||
public StoreCipher JetStreamCipher { get; set; }
|
||||
public string JetStreamUniqueTag { get; set; } = string.Empty;
|
||||
public JsLimitOpts JetStreamLimits { get; set; } = new();
|
||||
public JsTpmOpts JetStreamTpm { get; set; } = new();
|
||||
public long JetStreamMaxCatchup { get; set; }
|
||||
public long JetStreamRequestQueueLimit { get; set; }
|
||||
public ulong JetStreamMetaCompact { get; set; }
|
||||
public ulong JetStreamMetaCompactSize { get; set; }
|
||||
public bool JetStreamMetaCompactSync { get; set; }
|
||||
public int StreamMaxBufferedMsgs { get; set; }
|
||||
public long StreamMaxBufferedSize { get; set; }
|
||||
public string StoreDir { get; set; } = string.Empty;
|
||||
public TimeSpan SyncInterval { get; set; }
|
||||
public bool SyncAlways { get; set; }
|
||||
public Dictionary<string, string> JsAccDefaultDomain { get; set; } = new();
|
||||
public bool DisableJetStreamBanner { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Security & Trust
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public List<string> TrustedKeys { get; set; } = [];
|
||||
public SslServerAuthenticationOptions? AccountResolverTlsConfig { get; set; }
|
||||
public IAccountResolver? AccountResolver { get; set; }
|
||||
public OcspConfig? OcspConfig { get; set; }
|
||||
public OcspResponseCacheConfig? OcspCacheConfig { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Tagging & Metadata
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public List<string> Tags { get; set; } = [];
|
||||
public Dictionary<string, string> Metadata { get; set; } = new();
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Proxies
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public ProxiesConfig? Proxies { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Connectivity error reporting
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public int ConnectErrorReports { get; set; }
|
||||
public int ReconnectErrorReports { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Internal / Private fields
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
internal Dictionary<string, bool> InConfig { get; set; } = new();
|
||||
internal Dictionary<string, bool> InCmdLine { get; set; } = new();
|
||||
internal List<string> OperatorJwt { get; set; } = [];
|
||||
internal Dictionary<string, string> ResolverPreloads { get; set; } = new();
|
||||
internal HashSet<string> ResolverPinnedAccounts { get; set; } = [];
|
||||
internal TimeSpan GatewaysSolicitDelay { get; set; }
|
||||
internal int OverrideProto { get; set; }
|
||||
internal bool MaxMemSet { get; set; }
|
||||
internal bool MaxStoreSet { get; set; }
|
||||
internal bool SyncSet { get; set; }
|
||||
internal bool AuthBlockDefined { get; set; }
|
||||
internal string ConfigDigestValue { get; set; } = string.Empty;
|
||||
internal TlsConfigOpts? TlsConfigOpts { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user