Commit Graph

498 Commits

Author SHA1 Message Date
Joseph Doherty
5f50e12829 docs: mark all 93 remaining gaps as IMPLEMENTED in structuregaps.md
Updated all gap sections (3-15) with IMPLEMENTED status markers,
implementation file references, and test file names covering all
8 phases of the remaining gaps plan.
2026-02-25 13:25:37 -05:00
Joseph Doherty
4ba87c4175 feat: add OCSP peer reject and chain validation events (Gap 10.10)
Add OcspChainValidationEvent DTO, OcspStatus enum, and OcspEventBuilder
helper with BuildPeerReject, BuildChainValidation, and ParseStatus methods.
Register OcspChainValidationEvent in EventJsonContext source-gen context.
Add OcspPeerReject and OcspChainValidation subject constants to EventSubjects.
10 new tests in OcspEventTests cover all DTOs, builder methods, status
parsing, and JSON round-trip.
2026-02-25 13:15:44 -05:00
Joseph Doherty
b314e3f510 feat: add S2 compression for system events (Gap 10.9)
Add EventCompressor static class with Snappy/S2 compress/decompress,
threshold-based ShouldCompress, CompressIfBeneficial with stats tracking,
and GetCompressionRatio helpers. Port 10 tests covering round-trip,
threshold logic, stats (TotalCompressed, BytesSaved, ResetStats).
Go reference: server/events.go:2082-2098 compressionType / snappyCompression.
2026-02-25 13:15:24 -05:00
Joseph Doherty
74473d81cf feat: add WebSocket-specific TLS configuration (Gap 15.1) 2026-02-25 13:14:47 -05:00
Joseph Doherty
4b9384dfcf feat: add auth error event publication (Gap 10.5)
Add SendAuthErrorEvent, SendConnectEvent, SendDisconnectEvent to
InternalEventSystem, plus AuthErrorEventCount counter and the three
companion detail record types (AuthErrorDetail, ConnectEventDetail,
DisconnectEventDetail). 10 new tests in AuthErrorEventTests all pass.
2026-02-25 13:12:52 -05:00
Joseph Doherty
10ac904b5c feat: add remote server events for cluster visibility (Gap 10.8)
Add RemoteServerShutdownEvent, RemoteServerUpdateEvent, LeafNodeConnectEvent,
and LeafNodeDisconnectEvent types plus matching EventSubjects constants, with
10 unit tests covering type identity, field assignment, format placeholders,
and JSON roundtrip serialization.
2026-02-25 13:11:59 -05:00
Joseph Doherty
a6e7778c6c feat: complete system event payload fields (Gap 10.6)
Add EventBuilder static class to EventTypes.cs with helpers for constructing
fully-populated ConnectEventMsg, DisconnectEventMsg, AccountNumConns, and
ServerStatsMsg. Also add RemoteServerShutdownEvent, RemoteServerUpdateEvent,
LeafNodeConnectEvent, and LeafNodeDisconnectEvent advisory types.

Add FullEventPayloadTests.cs (10 tests) covering all builders, GenerateEventId
uniqueness, GetTimestamp ISO 8601 format, DataStats zero defaults, and
ConnectEventMsg JSON roundtrip.
2026-02-25 13:11:58 -05:00
Joseph Doherty
619acc3c08 feat: add sort options to /connz (Gap 10.3)
Add ConnzSortOption enum (ConnectionId, Start, BytesTo, BytesFrom,
MsgsTo, MsgsFrom, Subscriptions, Pending, Uptime, Idle, LastActivity)
and ConnzSorter static class with Parse(string?) and Sort(IEnumerable<ConnInfo>,
ConnzSortOption, bool) methods.

Add SortBy and SortDescending properties to ConnzFilterOptions and wire
them through ConnzFilterOptions.Parse (?sort= and ?desc= query params).

Add 10 unit tests in ConnzSortTests covering Parse defaults, known values,
unknown string fallback, and sort ordering for key fields.

Go reference: server/monitor_sort_opts.go, server/monitor.go Connz().
2026-02-25 13:09:11 -05:00
Joseph Doherty
9ece600ebc feat: add closed connection ring buffer for /connz?state=closed (Gap 10.1)
Replace ConcurrentQueue<ClosedClient> with ClosedConnectionRingBuffer — a
fixed-size ring buffer that overwrites oldest entries when full, eliminating
the manual dequeue-to-cap loop. Adds TotalClosed lifetime counter, GetRecent(),
and Clear(). Wires the ring buffer into NatsServer including capacity resize
on config reload. Adds 10 unit tests covering capacity, ordering, wrapping,
TotalClosed tracking, and Clear behavior.
2026-02-25 13:07:16 -05:00
Joseph Doherty
9fb2ae205c feat: add message trace propagation across servers (Gap 10.4)
Add TraceContextPropagator and TraceContext to Internal/MessageTraceContext.cs
for Nats-Trace-Parent header injection and extraction across server hops.
Also add ConnzSortOption/ConnzSorter stubs to fix pre-existing build errors
in Monitoring/Connz.cs. Covered by 10 new tests in TraceContextPropagationTests.cs.
2026-02-25 13:06:58 -05:00
Joseph Doherty
eb801cd4cf feat: add account-scoped filtering to /connz (Gap 10.2)
Add ConnzConnectionInfo, ConnzFilterResult, ConnzFilterOptions, and
ConnzFilter static class to Connz.cs, providing a pure unit-testable
layer for account-scoped filtering and pagination that mirrors the Go
server's /connz ?acc= query-parameter behaviour.  Ten new tests in
ConnzAccountFilterTests.cs cover FilterByAccount (match, no-match,
case-insensitive), ConnzFilterOptions.Parse (acc param, defaults,
offset/limit), and ApplyFilters (account filter, offset, limit,
no-filter pass-through).
2026-02-25 13:04:20 -05:00
Joseph Doherty
68b8a0cee5 feat: add service import shadowing detection (Gap 9.10)
Implements ServiceImportShadowed, GetShadowedServiceImports, HasShadowedImports,
and CheckServiceImportShadowing on Account to detect when local SubList subscriptions
would intercept messages before a service import can receive them. Adds ShadowCheckResult
record and 10 tests covering exact, wildcard, and gt-wildcard shadowing scenarios.
2026-02-25 13:00:48 -05:00
Joseph Doherty
ce452febd7 feat: add reverse response mapping for cross-account request-reply (Gap 9.9) 2026-02-25 12:59:49 -05:00
Joseph Doherty
e4b5ed9a83 feat: add JWT activation claim expiration checking (Gap 9.7)
Add ActivationClaim and ActivationCheckResult types plus five methods on
Account (RegisterActivation, CheckActivationExpiry, IsActivationExpired,
GetExpiredActivations, RemoveExpiredActivations) and an ActiveActivationCount
property, mirroring Go accounts.go checkActivation / activationExpired logic.
Adds 10 targeted tests in Auth/ActivationExpirationTests.cs (all pass).
2026-02-25 12:57:41 -05:00
Joseph Doherty
e2bfca48e4 feat: add account expiration with TTL-based cleanup (Gap 9.5)
Add ExpiresAt, IsExpired, TimeToExpiry, SetExpiration, ClearExpiration,
SetExpirationFromTtl, and GetExpirationInfo to Account. Expiry is stored
as UTC ticks in a long field (long.MinValue sentinel) for lock-free reads
via Interlocked. Add AccountExpirationInfo record. 10 new tests cover all
behaviours.
2026-02-25 12:56:48 -05:00
Joseph Doherty
2bdf0e75ed feat: add stream import cycle detection (Gap 9.3)
Add StreamImportFormsCycle DFS method to Account plus GetStreamImportSources
and HasStreamImportFrom helpers. Add GetStreamImportSourceAccounts to ImportMap.
10 tests cover direct, indirect, self, diamond, and empty import scenarios.
2026-02-25 12:53:04 -05:00
Joseph Doherty
3107615885 feat: add service export latency tracking with p50/p90/p99 (Gap 9.1)
Add ServiceLatencyTracker with sorted-sample histogram, percentile getters (p50/p90/p99), average/min/max, reset, and immutable snapshot. Wire LatencyTracker and RecordServiceLatency onto Account. Cover with 11 xUnit tests.
2026-02-25 12:52:05 -05:00
Joseph Doherty
dcd6b78a89 feat: add leaf node JetStream migration checks (Gap 12.4)
Implements CheckJetStreamMigrate, GetActiveJetStreamDomains,
IsJetStreamDomainInUse, and JetStreamEnabledConnectionCount on
LeafNodeManager. Adds JetStreamMigrationResult/JetStreamMigrationStatus
result types. Ten unit tests cover all validation paths (10/10 pass).
2026-02-25 12:24:30 -05:00
Joseph Doherty
1a9d3f06e6 feat: add leaf cluster registration and topology tracking (Gap 12.6) 2026-02-25 12:24:03 -05:00
Joseph Doherty
80e5cc1be5 feat: add leaf node WebSocket support with stream adapter (Gap 12.5)
Implements WebSocketStreamAdapter — a Stream subclass that wraps
System.Net.WebSockets.WebSocket for use by LeafConnection. Handles
message framing (per-message receive/send), tracks BytesRead/BytesWritten
and MessagesRead/MessagesWritten counters, and exposes IsConnected. Ten
NSubstitute-based unit tests cover all capability flags, delegation, and
telemetry (10/10 pass).
2026-02-25 12:23:53 -05:00
Joseph Doherty
2683e6b7ed feat: add no-pool route fallback for backward compatibility (Gap 13.6)
Add SupportsPooling/IsLegacyRoute properties to RouteConnection and
GetLegacyRoute/GetLegacyRoutes/HasLegacyRoutes to RouteManager. Update
GetRouteForAccount to fall back to legacy routes when no dedicated or
pool-capable route is available, matching Go route.go getRoutesExcludePool.
2026-02-25 12:19:56 -05:00
Joseph Doherty
4f3187ae62 feat: add leaf node permission and account syncing (Gap 12.2)
Add SetPermissions/PermsSynced/AllowedPublishSubjects/AllowedSubscribeSubjects/AccountName
to LeafConnection, and SendPermsAndAccountInfo/InitLeafNodeSmapAndSendSubs/GetPermSyncStatus
plus LeafPermSyncResult to LeafNodeManager. Add OnConnectionRegistered internal callback for
test synchronization. 10 new unit tests in LeafPermissionSyncTests.cs all passing.
2026-02-25 12:11:50 -05:00
Joseph Doherty
629bbd13fa feat: add leaf connection state validation on reconnect (Gap 12.3)
Adds ValidateRemoteLeafNode to LeafNodeManager with self-connect,
duplicate-connection, and JetStream domain conflict checks, plus
IsSelfConnect, HasConnection, and GetConnectionByRemoteId helpers.
Introduces LeafValidationResult and LeafValidationError types.
Adds 10 unit tests in LeafValidationTests covering all error codes.
2026-02-25 12:10:44 -05:00
Joseph Doherty
ef425db187 feat: add leaf node TLS certificate hot-reload (Gap 12.1)
Add UpdateTlsConfig to LeafNodeManager with CurrentCertPath, CurrentKeyPath,
IsTlsEnabled, and TlsReloadCount. Add LeafTlsReloadResult record. Add 10 unit
tests in LeafTlsReloadTests covering change detection, no-op idempotency, path
tracking, counter semantics, and result payload.
2026-02-25 12:08:15 -05:00
Joseph Doherty
b9c83d6b3b feat: add route pool size negotiation (Gap 13.3)
Add NegotiatePoolSize static method and NegotiatedPoolSize property to
RouteConnection, and ConfiguredPoolSize / GetEffectivePoolSize to
RouteManager. Includes 14 tests covering negotiation semantics, backward
compatibility (zero means no pooling), default state, and deterministic
pool index computation.
2026-02-25 12:05:57 -05:00
Joseph Doherty
071717dcbf feat: add cluster split handling (Gap 13.5)
Add RemoveRoute, RemoveAllRoutesExcept, RegisterRoute (internal), and
DetectClusterSplit to RouteManager with ClusterSplitResult record, plus
10 tests covering partition detection and route removal behavior.
2026-02-25 12:03:05 -05:00
Joseph Doherty
3192caeab8 feat: add route hash storage for O(1) lookup (Gap 13.4)
Add ConcurrentDictionary<ulong, RouteConnection> _routesByHash with FNV-1a
64-bit hash key, RegisterRouteByHash/UnregisterRouteByHash/GetRouteByHash/
GetRouteByServerId methods, and HashedRouteCount property to RouteManager.
Includes 10 unit tests covering determinism, distinct hashes, CRUD lifecycle,
overwrite semantics, and no-op unregister.
2026-02-25 12:02:35 -05:00
Joseph Doherty
7f3e2e0e0b feat: add account-specific dedicated routes (Gap 13.2)
Add _accountRoutes ConcurrentDictionary to RouteManager with full
CRUD API: RegisterAccountRoute, UnregisterAccountRoute,
GetDedicatedAccountRoute, HasDedicatedRoute,
GetAccountsWithDedicatedRoutes, and DedicatedRouteCount property.
Update GetRouteForAccount to check dedicated routes before falling
back to pool-based selection. Add 10 unit tests in AccountRouteTests.
2026-02-25 12:01:49 -05:00
Joseph Doherty
5fd23571dc feat: add gateway connection registration with state tracking (Gap 11.7)
Adds GatewayConnectionState enum, GatewayRegistration record with atomic
message counters, and a full registry API on GatewayManager: RegisterGateway,
UpdateState, GetRegistration, GetAllRegistrations, UnregisterGateway,
GetConnectedGatewayCount, IncrementMessagesSent, IncrementMessagesReceived.
Covers 11 new tests in GatewayRegistrationTests.cs (all passing).
2026-02-25 11:54:52 -05:00
Joseph Doherty
684254ad86 feat: add gateway command protocol with Go-compatible wire format (Gap 11.6)
Add GatewayCommands static class with wire-format byte sequences (GINFO, GS+, GS-,
GMODE, GMSG, GPING, GPONG) and FormatSub/FormatUnsub/FormatMode/ParseCommandType
helpers matching Go's gateway.go protocol constants. Add GatewayCommandType enum.
10 tests covering all wire formats and command parsing.
2026-02-25 11:54:30 -05:00
Joseph Doherty
dc8d28c222 feat: add reply subject mapping cache with TTL (Gap 11.5)
Add ReplyMapCache to ReplyMapper.cs — an LRU cache with TTL expiration
for gateway reply subject mappings, avoiding repeated string parsing on
the hot path. Includes 10 unit tests covering LRU eviction, TTL expiry,
hit/miss counters, PurgeExpired, and Count.
2026-02-25 11:51:55 -05:00
Joseph Doherty
455a91579a feat: add gateway reconnection with exponential backoff (Gap 11.2)
Adds GatewayReconnectPolicy with exponential backoff and jitter, and
reconnect attempt tracking (GetReconnectAttempts, ResetReconnectAttempts,
ReconnectGatewayAsync) to GatewayManager. 10 new tests cover delay
calculation, cap behaviour, jitter, and per-gateway counter isolation.
2026-02-25 11:51:40 -05:00
Joseph Doherty
d598276807 feat: add account-specific gateway routes (Gap 11.3)
Adds per-account subscription tracking to GatewayConnection via
AddAccountSubscription/RemoveAccountSubscription/GetAccountSubscriptions/
AccountSubscriptionCount, with corresponding SendAccountSubscriptions and
GetAccountSubscriptions helpers on GatewayManager. Covered by 10 new unit tests.
2026-02-25 11:51:09 -05:00
Joseph Doherty
4c53159de8 feat: add runtime logging level changes (Gap 14.5)
Adds LoggingChangeResult and ApplyLoggingChanges to ConfigReloader, deriving
an effective log level from Debug/Trace flags (Trace > Debug > Information) and
reporting flag-level and level-string changes for hot-reload notification.
2026-02-25 11:48:29 -05:00
Joseph Doherty
ff07137ea6 feat: add JetStream config change reload (Gap 14.6)
Add ApplyJetStreamConfigChanges to ConfigReloader for detecting MaxMemoryStore,
MaxFileStore, and Domain changes during hot reload. Add Domain property to
JetStreamOptions. Port 10 unit tests covering all change permutations.
2026-02-25 11:48:22 -05:00
Joseph Doherty
5116aed491 feat: add TLS certificate hot-reload for new connections (Gap 14.3)
Add ReloadTlsCertificates(oldOpts, newOpts) returning TlsReloadResult for
path-based cert comparison and validation during config hot-reload. Add 10
targeted tests covering no-change, path detection, missing file, null transitions,
and success cases.
2026-02-25 11:48:11 -05:00
Joseph Doherty
074ff6b287 feat: add cluster config hot reload (Gap 14.4)
Adds ClusterConfigChangeResult and ApplyClusterConfigChanges to ConfigReloader,
comparing route/gateway/leaf URL sets between old and new NatsOptions and reporting
added/removed routes for connection reconciliation on hot reload.
2026-02-25 11:47:02 -05:00
Joseph Doherty
42e072ad71 feat: add auth change propagation to existing connections (Gap 14.2)
Add PropagateAuthChanges to ConfigReloader that compares Users, Accounts,
and Authorization token between old and new NatsOptions, returning an
AuthChangeResult describing which auth fields changed for connection re-evaluation.
2026-02-25 11:46:28 -05:00
Joseph Doherty
5fea08dda0 feat: complete MQTT session flapper detection (Gap 6.6)
Add FlapperState class and per-client exponential backoff tracking to
MqttSessionStore. New TrackConnectDisconnect(string) overload returns
FlapperState with backoff level and expiry; IsFlapper, GetBackoffMs,
ClearFlapperState, and CheckAndClearStableClients give callers full
visibility and cleanup control. Legacy two-arg overload preserved for
backward compatibility. Ten unit tests cover counting, threshold,
exponential growth, 60s cap, window reset, and stable-client sweep.
2026-02-25 11:42:24 -05:00
Joseph Doherty
96db73d1c6 feat: deliver retained messages on MQTT SUBSCRIBE (Gap 6.5)
Add DeliverRetainedOnSubscribe to MqttRetainedStore, which iterates
GetMatchingRetained and fires a callback with (topic, payload, qos,
retain=true) for each match. Add 11 unit tests covering exact-match,
'+' single-level, '#' multi-level, no-match, cross-level rejection,
callback arguments, return count, and empty-store behaviour.
2026-02-25 11:40:50 -05:00
Joseph Doherty
f069fdc76a feat: add MQTT MaxAckPending flow control (Gap 6.4)
Implements MqttFlowController with per-subscription SemaphoreSlim-based
slot tracking for QoS 1/2 messages. Replaces the previous catch-and-swallow
pattern with an explicit CurrentCount guard on Release. 10 unit tests added.
2026-02-25 11:38:47 -05:00
Joseph Doherty
a44ad4b7fc feat: add MQTT will message delivery on abnormal disconnect (Gap 6.2)
Adds WillMessage class, SetWill/ClearWill/GetWill methods to MqttSessionStore,
PublishWillMessage that dispatches via OnPublish delegate (or tracks as delayed
when DelayIntervalSeconds > 0), and 10 unit tests covering all will message behaviors.
2026-02-25 11:38:43 -05:00
Joseph Doherty
18f0ca0587 feat: add consecutive short-read counter to prevent buffer oscillation (Gap 5.10)
Require 4 consecutive short reads before shrinking AdaptiveReadBuffer, matching
the Go server's readLoop behaviour and preventing buffer size thrashing.
2026-02-25 11:36:12 -05:00
Joseph Doherty
bd2504c8df feat: add SUB permission caching with generation invalidation (Gap 5.8)
Extend PermissionLruCache with SetSub/TryGetSub (internal key prefix "S:")
alongside existing PUB API ("P:" prefix, backward-compatible). Add Invalidate()
and Generation property for generation-based cache invalidation. Add
GenerationId/IncrementGeneration to Account for account-level change signalling.
10 new tests in SubPermissionCacheTests cover all paths.
2026-02-25 11:36:05 -05:00
Joseph Doherty
a6e8088526 test: verify internal client kinds (Gap 5.9) 2026-02-25 11:35:21 -05:00
Joseph Doherty
7e5c6e4fd9 feat: add slow consumer per-kind tracking with account counters (Gap 5.5)
Adds SlowConsumerTracker class for per-ClientKind slow consumer counting
with configurable threshold callbacks, and extends Account with atomic
IncrementSlowConsumers/SlowConsumerCount/ResetSlowConsumerCount members.
Includes 10 unit tests covering concurrency, threshold firing, and reset.
2026-02-25 11:33:58 -05:00
Joseph Doherty
774717d57c feat: add per-client trace delivery and echo control (Gap 5.7)
Implements ClientTraceInfo with TraceMsgDelivery recording and per-client
echo suppression; fixes AccountGoParityTests namespace ambiguity caused by
the new NATS.Server.Tests.Subscriptions test namespace.
2026-02-25 11:32:00 -05:00
Joseph Doherty
bc8f0e63bb feat: add dynamic write buffer pooling with broadcast drain (Gap 5.6)
Enhances OutboundBufferPool with tiered internal pools (512/4096/65536),
RentBuffer/ReturnBuffer raw-array surface, BroadcastDrain coalescing for
fan-out publish, and Interlocked stats counters (RentCount, ReturnCount,
BroadcastCount). Adds 10 DynamicBufferPoolTests covering all new paths.
2026-02-25 11:31:29 -05:00
Joseph Doherty
1a1e99f7d8 feat: add per-account subscription result cache with LRU (Gap 5.4)
Implements RouteResultCache with fixed-capacity LRU eviction and atomic
generation-based invalidation (Go ref: client.go routeCache, maxResultCacheSize=8192).
Fixes AccountGoParityTests namespace ambiguity introduced by new test file.
2026-02-25 11:31:17 -05:00
Joseph Doherty
0e1a39df96 feat: add source/mirror info reporting for monitoring (Gap 4.10)
Add GetMirrorInfo/GetSourceInfo methods to MirrorCoordinator and
SourceCoordinator returning structured MirrorInfoResponse/SourceInfoResponse
records (Name, Lag, Active ms, FilterSubject, Error). Wire both into
StreamManager.GetMirrorInfo and GetSourceInfos for the monitoring API path.
2026-02-25 11:26:34 -05:00