Commit Graph

27 Commits

Author SHA1 Message Date
Joseph Doherty
2e2ffee41a feat(mqtt): add MQTT packet parser, dispatch, and ReadLoop integration
Implement Task 2 of MQTT orchestration:
- Create MqttParser.cs with loop-based packet parser and dispatch switch
- Add MqttReader field to MqttHandler for per-connection parsing state
- Wire ReadLoop to call MqttParser for MQTT connections
- Implement PINGREQ handler (enqueues PINGRESP)
- CONNECT-first enforcement (rejects non-CONNECT as first packet)
- Partial packet handling via MqttReader pending buffer
- 13 unit tests covering parser, dispatch, partial packets, and edge cases
- Stub dispatch entries for CONNECT, PUBLISH, SUB, UNSUB, DISCONNECT (NotImplementedException)
2026-03-01 15:41:45 -05:00
Joseph Doherty
6fb7f43335 feat(mqtt): add MQTT listener, client creation, and shutdown wiring
Wire up the MQTT server-side orchestration layer (Task 1 of 7):
- Create NatsServer.Mqtt.cs with StartMqttListener(), CreateMqttClient(), MqttAddr()
- Forward MqttHandler.StartMqtt() to server.StartMqttListener()
- Add _mqttListener to Shutdown() doneExpected counting
- Fix ReadyForConnections to recognize active MQTT listener
- Handle RandomPort (-1) as ephemeral for MQTT listener
- Remove duplicate Mqtt field from ClientConnection.cs (already in ClientConnection.Mqtt.cs)
- Add 2 MQTT boot integration tests (accept + shutdown lifecycle)
2026-03-01 15:35:41 -05:00
Joseph Doherty
96e395a113 feat(batch43): implement account resolvers and service latency tracking
Implements 37 deferred features from Batch 43:

Group A - Type methods:
- ServiceRespType.String: already existed via ToNatsString extension
- NewMapDest: already existed as MapDest.New factory
- ServiceLatency.merge → ServiceLatencyExtensions.Merge + Sanitize

Group B - Tracing headers (new TracingHeaders static class in AccountTypes.cs):
- newB3Header → TracingHeaders.NewB3Header
- newUberHeader → TracingHeaders.NewUberHeader
- newTraceCtxHeader → TracingHeaders.NewTraceCtxHeader
- shouldSample → TracingHeaders.ShouldSample

Group C - Service export timers (new extension methods in AccountTypes.cs):
- serviceImport.isRespServiceImport → ServiceImportEntryExtensions.IsRespServiceImport
- serviceExport.setResponseThresholdTimer → ServiceExportEntryExtensions.SetResponseThresholdTimer
- serviceExport.clearResponseThresholdTimer → ServiceExportEntryExtensions.ClearResponseThresholdTimer
- serviceExport.checkExpiredResponses → ServiceExportEntryExtensions.CheckExpiredResponses

Group D - Latency & client updates:
- sanitizeLatencyMetric → ServiceLatencyExtensions.SanitizeLatencyMetric
- updateAllClientsServiceExportResponseTime → ServiceExportClientHelpers.UpdateAllClientsServiceExportResponseTime
- ClientConnection.UpdateRrTrackingThreshold (helper for above)

Group E - Account resolvers (NatsServer.AccountResolvers.cs):
- authAccounts → NatsServer.AuthAccounts
- Server.SetAccountResolver + GetAccountResolver
- Server.UpdateAccountClaims + UpdateAccountClaimsWithRefresh
- buildPermissionsFromJwt → NatsServer.BuildPermissionsFromJwt (with JwtPermissions stub types)
- buildInternalNkeyUser → NatsServer.BuildInternalNkeyUser (with JwtUserClaims stub type)
- fetchAccount → NatsServer.FetchAccountFromResolverAsync
- respondToUpdate → NatsServer.RespondToUpdate (with ClaimUpdateResponse/Status/Error types)
- handleListRequest → NatsServer.HandleListRequest
- handleDeleteRequest → NatsServer.HandleDeleteRequest
- getOperatorKeys → NatsServer.GetOperatorKeys
- claimValidate → NatsServer.ClaimValidate
- removeCb → NatsServer.RemoveCb

Group F - Directory resolvers:
- Server.fetch → NatsServer.ServerFetch (stub falls back to direct resolver)
- DirAccResolver.Fetch, NewDirAccResolver, FetchTimeout already in AccountResolver.cs
- NewCacheDirAccResolver, CacheDirAccResolver.Reload already in AccountResolver.cs

Supporting changes:
- Account.cs: expose ExpiredTimeout as internal, add ReadLock/ReadUnlock/WriteLock/WriteUnlock
  helpers plus GetResponseCount/GetResponseEntries for CheckExpiredResponses
- AccountTypes.cs: add using System.Globalization for hex parsing
- NatsServerTypes.cs: add AccountClaims.Name property (JWT name tag)
2026-03-01 08:32:40 -05:00
Joseph Doherty
e9be0751ec feat(batch25): implement gateway reply map and inbound message pipeline 2026-03-01 02:07:25 -05:00
Joseph Doherty
a83339fe71 feat(batch25): implement gateway bootstrap and solicitation 2026-03-01 01:47:07 -05:00
Joseph Doherty
3e9ad16033 feat(batch24): complete leaf nodes implementation and verification 2026-03-01 01:31:57 -05:00
Joseph Doherty
3653345a37 feat(batch26): implement websocket frame/core feature group A 2026-02-28 21:45:05 -05:00
Joseph Doherty
e51cdd64f4 feat(batch23): implement route protocol and info/perms foundation 2026-02-28 21:09:00 -05:00
Joseph Doherty
f2bc957229 chore(batch23): start routes batch 2026-02-28 20:59:47 -05:00
Joseph Doherty
5dbab2daa7 feat(batch19): merge accounts-core 2026-02-28 20:39:43 -05:00
Joseph Doherty
f4dfbf49bd feat(batch19): implement service import maps and response subscription methods 2026-02-28 20:10:06 -05:00
Joseph Doherty
4974339b52 feat(batch17): port lifecycle, tls, and rate-limited logging features 2026-02-28 19:32:59 -05:00
Joseph Doherty
8d5964efff feat(batch17): port inbound, header, and service-import client features 2026-02-28 19:18:37 -05:00
Joseph Doherty
1baba5ac0e feat(batch17): port subscription and delivery client core features 2026-02-28 19:12:58 -05:00
Joseph Doherty
1849780369 test(batch16): resolve route slow-consumer recover status with evidence 2026-02-28 19:01:57 -05:00
Joseph Doherty
a0b0b45f5e feat(batch16): port outbound and parser-facing client core features 2026-02-28 18:58:52 -05:00
Joseph Doherty
46ea749ad0 feat(batch16): port client helper and permission core features 2026-02-28 18:53:59 -05:00
Joseph Doherty
78d222a86d feat(batch9): implement f1 auth and dirstore foundations 2026-02-28 12:12:50 -05:00
Joseph Doherty
beab0e60da feat(batch3): implement send queue feature group 2026-02-28 07:31:12 -05:00
Joseph Doherty
6b67c83c0e feat(batch3): verify client proxy protocol feature group 2026-02-28 07:24:45 -05:00
Joseph Doherty
3ace39d606 feat(batch2): verify parser remainder features 2026-02-28 07:06:09 -05:00
Joseph Doherty
8849265780 Eliminate PortTracker stub backlog by implementing Raft/file-store/stream/server/client/OCSP stubs and adding coverage. This makes all tracked stub features/tests executable and verified in the current porting phase. 2026-02-27 08:56:26 -05:00
Joseph Doherty
917cd33442 feat(p7-05): fill signal & log stubs — SignalHandlerTests, ServerLoggerTests
- Add RemovePassFromTrace, RemoveAuthTokenFromTrace, RemoveSecretsFromTrace
  static methods to ServerLogging (mirrors removeSecretsFromTrace/redact in
  server/client.go); uses same regex patterns as Go source to redact only the
  first match's value with [REDACTED].
- Update ClientConnection.RemoveSecretsFromTrace stub to delegate to
  ServerLogging.RemoveSecretsFromTrace.
- Add 2 unit tests to SignalHandlerTests (T:2919 invalid command, T:2920 invalid
  PID); mark 14 process-injection/subprocess tests as deferred ([Fact(Skip=…)]).
- Create ServerLoggerTests with 3 test methods (T:2020, T:2021, T:2022) covering
  NoPasswordsFromConnectTrace, RemovePassFromTrace (8 theory cases),
  RemoveAuthTokenFromTrace (8 theory cases).
- DB: 3 log tests → complete, 2 signal tests → complete, 14 signal tests → deferred.
- All 663 unit tests pass (was 645), 14 deferred skipped.
2026-02-26 19:15:57 -05:00
Joseph Doherty
a0c9c0094c fix: session B — Go-faithful auth error states, NKey padding, permissions, signal disposal 2026-02-26 17:49:13 -05:00
Joseph Doherty
8c380e7ca6 feat: session B — auth implementation + signals (26 stubs complete)
Implement ConfigureAuthorization, CheckAuthentication, and full auth
dispatch in NatsServer.Auth.cs; add HandleSignals in NatsServer.Signals.cs;
extend AuthHandler with GetAuthErrClosedState, ValidateProxies,
GetTlsAuthDcs, CheckClientTlsCertSubject, ProcessUserPermissionsTemplate;
add ReadOperatorJwt/ValidateTrustedOperators to JwtProcessor; add
AuthCallout stub; add auth accessor helpers to ClientConnection; add
NATS.NKeys package for NKey signature verification; 12 new tests pass.
2026-02-26 17:38:46 -05:00
Joseph Doherty
06779a1f77 feat: port session 10 — Server Core Runtime, Accept Loops & Listeners
Ports server/server.go lines 2577–4782 (~1,881 Go LOC), implementing ~97
features (IDs 3051–3147) across three new partial-class files.

New files:
- NatsServer.Lifecycle.cs: Shutdown, WaitForShutdown, RemoveClient,
  SendLDMToClients, LameDuckMode, LDMClientByID, rate-limit logging,
  DisconnectClientByID, SendAsyncInfoToClients
- NatsServer.Listeners.cs: AcceptLoop, GetServerListener, InProcessConn,
  AcceptConnections, GenerateInfoJson, CopyInfo, CreateClient/Ex/InProcess,
  StartMonitoring (HTTP/HTTPS), AddConnectURLs/RemoveConnectURLs,
  TlsVersion/TlsVersionFromString, GetClientConnectURLs, ResolveHostPorts,
  PortsInfo/PortFile/LogPorts, ReadyForListeners, GetRandomIP, AcceptError
- Internal/WaitGroup.cs: Go-style WaitGroup using TaskCompletionSource

Modified:
- Auth/AuthTypes.cs: Account now implements INatsAccount (stub)
- NatsServerTypes.cs: ServerInfo.ShallowClone(), removed duplicate RefCountedUrlSet
- NatsServer.cs: _info promoted to internal for test access
- Properties/AssemblyInfo.cs: InternalsVisibleTo(DynamicProxyGenAssembly2)
- ServerTests.cs: 20 new session-10 unit tests (GenerateInfoJson, TlsVersion,
  CopyInfo, GetRandomIP — Test IDs 2895, 2906)

All 565 unit tests + 1 integration test pass.
2026-02-26 15:08:23 -05:00
Joseph Doherty
11b387e442 feat: port session 08 — Client Connection & PROXY Protocol
- ClientConnection: full connection lifecycle, string/identity helpers,
  SplitSubjectQueue, KindString, MsgParts, SetHeader, message header
  manipulation (GenHeader, RemoveHeader, SliceHeader, GetHeader)
- ClientTypes: ClientConnectionType, ClientProtocol, ClientFlags,
  ReadCacheFlags, ClosedState, PmrFlags, DenyType, ClientOptions,
  ClientInfo, NbPool, RouteTarget, ClientKindHelpers
- NatsMessageHeaders: complete header utility class (GenHeader,
  RemoveHeaderIfPrefixPresent, RemoveHeaderIfPresent, SliceHeader,
  GetHeader, SetHeader, GetHeaderKeyIndex)
- ProxyProtocol: PROXY protocol v1/v2 parser (ReadV1Header,
  ParseV2Header, ReadProxyProtoHeader sync entry point)
- ServerErrors: add ErrAuthorization sentinel
- Tests: 32 standalone unit tests (proxy protocol: IDs 159-168,
  171-178, 180-181; client: IDs 200-201, 247-256)
- DB: 195 features → complete (387-581); 32 tests → complete;
  81 server-dependent tests → n/a

Features: 667 complete, 274 unit tests complete (17.2% overall)
2026-02-26 13:50:38 -05:00