feat: port session 07 — Protocol Parser, Auth extras (TPM/certidp/certstore), Internal utilities & data structures
Session 07 scope (5 features, 17 tests, ~1165 Go LOC): - Protocol/ParserTypes.cs: ParserState enum (79 states), PublishArgument, ParseContext - Protocol/IProtocolHandler.cs: handler interface decoupling parser from client - Protocol/ProtocolParser.cs: Parse(), ProtoSnippet(), OverMaxControlLineLimit(), ProcessPub/HeaderPub/RoutedMsgArgs/RoutedHeaderMsgArgs, ClonePubArg(), GetHeader() - tests/Protocol/ProtocolParserTests.cs: 17 tests via TestProtocolHandler stub Auth extras from session 06 (committed separately): - Auth/TpmKeyProvider.cs, Auth/CertificateIdentityProvider/, Auth/CertificateStore/ Internal utilities & data structures (session 06 overflow): - Internal/AccessTimeService.cs, ElasticPointer.cs, SystemMemory.cs, ProcessStatsProvider.cs - Internal/DataStructures/GenericSublist.cs, HashWheel.cs - Internal/DataStructures/SubjectTree.cs, SubjectTreeNode.cs, SubjectTreeParts.cs All 461 tests pass (460 unit + 1 integration). DB updated for features 2588-2592 and tests 2598-2614.
This commit is contained in:
@@ -194,6 +194,10 @@ After leaves are done, modules that depended only on those leaves become ready.
|
||||
Leaf utilities -> Protocol types -> Parser -> Connection handler -> Server
|
||||
```
|
||||
|
||||
### Server module session plan
|
||||
|
||||
The server module (~103K Go LOC, 3,394 features, 3,137 tests) is too large for a single pass. It has been broken into **23 sessions** with dependency ordering and sub-batching guidance. See [phase6sessions/readme.md](phase6sessions/readme.md) for the full session map, dependency graph, and execution instructions.
|
||||
|
||||
### Port tests alongside features
|
||||
|
||||
When porting a feature, also port its associated tests in the same pass. This provides immediate validation:
|
||||
|
||||
143
docs/plans/phases/phase6sessions/readme.md
Normal file
143
docs/plans/phases/phase6sessions/readme.md
Normal file
@@ -0,0 +1,143 @@
|
||||
# Phase 6 Sessions: Server Module Breakdown
|
||||
|
||||
The server module (module 8) contains **3,394 features**, **3,137 unit tests**, and **~103K Go LOC** across 64 source files. It has been split into **23 sessions** targeting ~5K Go LOC each, ordered by dependency (bottom-up).
|
||||
|
||||
## Session Map
|
||||
|
||||
| Session | Name | Go LOC | Features | Tests | Go Files |
|
||||
|---------|------|--------|----------|-------|----------|
|
||||
| [01](session-01.md) | Foundation Types | 626 | 46 | 17 | const, errors, errors_gen, proto, ring, rate_counter, sdm, nkey |
|
||||
| [02](session-02.md) | Utilities & Queues | 1,325 | 68 | 57 | util, ipqueue, sendq, scheduler, subject_transform |
|
||||
| [03](session-03.md) | Configuration & Options | 5,400 | 86 | 89 | opts |
|
||||
| [04](session-04.md) | Logging, Signals & Services | 534 | 34 | 27 | log, signal*, service* |
|
||||
| [05](session-05.md) | Subscription Index | 1,416 | 81 | 96 | sublist |
|
||||
| [06](session-06.md) | Auth & JWT | 2,196 | 43 | 131 | auth, auth_callout, jwt, ciphersuites |
|
||||
| [07](session-07.md) | Protocol Parser | 1,165 | 5 | 17 | parser |
|
||||
| [08](session-08.md) | Client Connection | 5,953 | 195 | 113 | client, client_proxyproto |
|
||||
| [09](session-09.md) | Server Core — Init & Config | ~1,950 | ~76 | ~20 | server.go (first half) |
|
||||
| [10](session-10.md) | Server Core — Runtime & Lifecycle | ~1,881 | ~98 | ~27 | server.go (second half) |
|
||||
| [11](session-11.md) | Accounts & Directory Store | 4,493 | 234 | 84 | accounts, dirstore |
|
||||
| [12](session-12.md) | Events, Monitoring & Tracing | 6,319 | 218 | 188 | events, monitor, monitor_sort_opts, msgtrace |
|
||||
| [13](session-13.md) | Configuration Reload | 2,085 | 89 | 73 | reload |
|
||||
| [14](session-14.md) | Routes | 2,988 | 57 | 70 | route |
|
||||
| [15](session-15.md) | Leaf Nodes | 3,091 | 71 | 120 | leafnode |
|
||||
| [16](session-16.md) | Gateways | 2,816 | 91 | 88 | gateway |
|
||||
| [17](session-17.md) | Store Interfaces & Memory Store | 2,879 | 135 | 58 | store, memstore, disk_avail* |
|
||||
| [18](session-18.md) | File Store | 11,421 | 312 | 249 | filestore |
|
||||
| [19](session-19.md) | JetStream Core | 9,504 | 374 | 406 | jetstream, jetstream_api, jetstream_errors*, jetstream_events, jetstream_versioning, jetstream_batching |
|
||||
| [20](session-20.md) | JetStream Cluster & Raft | 14,176 | 429 | 617 | raft, jetstream_cluster |
|
||||
| [21](session-21.md) | Streams & Consumers | 12,700 | 402 | 315 | stream, consumer |
|
||||
| [22](session-22.md) | MQTT | 4,758 | 153 | 162 | mqtt |
|
||||
| [23](session-23.md) | WebSocket & OCSP | 2,962 | 97 | 113 | websocket, ocsp, ocsp_peer, ocsp_responsecache |
|
||||
| | **Totals** | **~103K** | **3,394** | **3,137** | |
|
||||
|
||||
## Dependency Graph
|
||||
|
||||
```
|
||||
S01 Foundation
|
||||
├── S02 Utilities
|
||||
├── S03 Options
|
||||
├── S04 Logging
|
||||
├── S05 Sublist ← S02
|
||||
├── S06 Auth ← S03
|
||||
└── S07 Parser
|
||||
|
||||
S08 Client ← S02, S03, S05, S07
|
||||
|
||||
S09 Server Init ← S03, S04, S05, S06
|
||||
S10 Server Runtime ← S08, S09
|
||||
|
||||
S11 Accounts ← S02, S03, S05, S06
|
||||
S12 Events & Monitor ← S08, S09, S11
|
||||
S13 Reload ← S03, S09
|
||||
|
||||
S14 Routes ← S07, S08, S09
|
||||
S15 Leafnodes ← S07, S08, S09, S14
|
||||
S16 Gateways ← S07, S08, S09, S11, S14
|
||||
|
||||
S17 Store Interfaces ← S01, S02
|
||||
S18 FileStore ← S17
|
||||
S19 JetStream Core ← S08, S09, S11, S17
|
||||
S20 JetStream Cluster ← S14, S17, S19
|
||||
S21 Streams & Consumers ← S08, S09, S11, S17, S19
|
||||
|
||||
S22 MQTT ← S08, S09, S11, S17, S19
|
||||
S23 WebSocket & OCSP ← S08, S09
|
||||
```
|
||||
|
||||
## Multi-Sitting Sessions
|
||||
|
||||
Sessions 18, 19, 20, and 21 exceed the ~5K target and include sub-batching guidance in their individual files. Plan for 2-3 sittings each.
|
||||
|
||||
| Session | Go LOC | Recommended Sittings |
|
||||
|---------|--------|---------------------|
|
||||
| S18 File Store | 11,421 | 2-3 |
|
||||
| S19 JetStream Core | 9,504 | 2-3 |
|
||||
| S20 JetStream Cluster & Raft | 14,176 | 3-4 |
|
||||
| S21 Streams & Consumers | 12,700 | 2-3 |
|
||||
|
||||
## Execution Order
|
||||
|
||||
Sessions should be executed roughly in order (S01 → S23), but parallel tracks are possible:
|
||||
|
||||
**Track A (Core):** S01 → S02 → S03 → S04 → S05 → S07 → S08 → S09 → S10
|
||||
|
||||
**Track B (Auth/Accounts):** S06 → S11 (after S03, S05)
|
||||
|
||||
**Track C (Networking):** S14 → S15 → S16 (after S08, S09)
|
||||
|
||||
**Track D (Storage):** S17 → S18 (after S01, S02)
|
||||
|
||||
**Track E (JetStream):** S19 → S20 → S21 (after S09, S11, S17)
|
||||
|
||||
**Track F (Protocols):** S22 → S23 (after S08, S09, S19)
|
||||
|
||||
**Cross-cutting:** S12, S13 (after S09, S11)
|
||||
|
||||
## How to Use
|
||||
|
||||
### Starting point
|
||||
|
||||
Begin with **Session 01** (Foundation Types). It has no dependencies and everything else builds on it.
|
||||
|
||||
### Session loop
|
||||
|
||||
Repeat until all 23 sessions are complete:
|
||||
|
||||
1. **Pick the next session.** Work through sessions in numerical order (S01 → S23). The numbering follows the dependency graph, so each session's prerequisites are already done by the time you reach it. If you want to parallelise, check the dependency graph above — any session whose dependencies are all complete is eligible.
|
||||
|
||||
2. **Open a new Claude Code session.** Reference the session file:
|
||||
```
|
||||
Port session N per docs/plans/phases/phase6sessions/session-NN.md
|
||||
```
|
||||
|
||||
3. **Port features.** For each feature in the session:
|
||||
- Mark as `stub` in `porting.db`
|
||||
- Implement the .NET code referencing the Go source
|
||||
- Mark as `complete` in `porting.db`
|
||||
|
||||
4. **Port tests.** For each test listed in the session file:
|
||||
- Implement the xUnit test
|
||||
- Run it: `dotnet test --filter "FullyQualifiedName~ClassName"`
|
||||
- Mark as `complete` in `porting.db`
|
||||
|
||||
5. **Verify the build.** Run `dotnet build` and `dotnet test` to confirm nothing is broken.
|
||||
|
||||
6. **Commit.** Commit all changes with a message like `feat: port session NN — <session name>`.
|
||||
|
||||
7. **Check progress.**
|
||||
```bash
|
||||
dotnet run --project tools/NatsNet.PortTracker -- report summary --db porting.db
|
||||
```
|
||||
|
||||
### Multi-sitting sessions
|
||||
|
||||
Sessions 18, 19, 20, and 21 are too large for a single sitting. Each session file contains sub-batching guidance (e.g., 18a, 18b, 18c). Commit after each sub-batch rather than waiting for the entire session.
|
||||
|
||||
### Completion
|
||||
|
||||
All 23 sessions are done when:
|
||||
- Every feature in module 8 is `complete` or `n/a`
|
||||
- Every unit test in module 8 is `complete` or `n/a`
|
||||
- `dotnet build` succeeds
|
||||
- `dotnet test` passes
|
||||
48
docs/plans/phases/phase6sessions/session-01.md
Normal file
48
docs/plans/phases/phase6sessions/session-01.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# Session 01: Foundation Types
|
||||
|
||||
## Summary
|
||||
|
||||
Constants, error types, error catalog, protocol definitions, ring buffer, rate counter, stream distribution model, and NKey utilities. These are the leaf types with no internal dependencies — everything else builds on them.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/const.go | 2 | 582–583 | 18 |
|
||||
| server/errors.go | 15 | 833–847 | 92 |
|
||||
| server/errors_gen.go | 6 | 848–853 | 158 |
|
||||
| server/proto.go | 6 | 2593–2598 | 237 |
|
||||
| server/ring.go | 6 | 2889–2894 | 34 |
|
||||
| server/rate_counter.go | 3 | 2797–2799 | 34 |
|
||||
| server/sdm.go | 5 | 2966–2970 | 39 |
|
||||
| server/nkey.go | 3 | 2440–2442 | 14 |
|
||||
| **Total** | **46** | | **626** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `Constants` — server constants and version info
|
||||
- `ServerErrorCatalog` — generated error codes and messages
|
||||
- `Protocol` — NATS protocol string constants
|
||||
- `RingBuffer` — fixed-size circular buffer
|
||||
- `RateCounter` — sliding window rate measurement
|
||||
- `StreamDistributionModel` — stream distribution enum/types
|
||||
- `NkeyUser` — NKey authentication types
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/errors_test.go | 2 | 297–298 |
|
||||
| server/ring_test.go | 2 | 2794–2795 |
|
||||
| server/rate_counter_test.go | 1 | 2720 |
|
||||
| server/nkey_test.go | 9 | 2362–2370 |
|
||||
| server/trust_test.go | 3 | 3058–3060 |
|
||||
| **Total** | **17** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- None (leaf session)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/` — types and enums at root or `Internal/`
|
||||
42
docs/plans/phases/phase6sessions/session-02.md
Normal file
42
docs/plans/phases/phase6sessions/session-02.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Session 02: Utilities & Queues
|
||||
|
||||
## Summary
|
||||
|
||||
General utility functions, IP-based queue, send queue, task scheduler, and subject transform engine. These are infrastructure pieces used across the server.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/util.go | 21 | 3485–3505 | 244 |
|
||||
| server/ipqueue.go | 14 | 1354–1367 | 175 |
|
||||
| server/sendq.go | 3 | 2971–2973 | 76 |
|
||||
| server/scheduler.go | 14 | 2952–2965 | 260 |
|
||||
| server/subject_transform.go | 16 | 3388–3403 | 570 |
|
||||
| **Total** | **68** | | **1,325** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `ServerUtilities` — string/byte helpers, random, hashing
|
||||
- `IpQueue<T>` — lock-free concurrent queue with IP grouping
|
||||
- `SendQueue` — outbound message queue
|
||||
- `Scheduler` — time-based task scheduler
|
||||
- `SubjectTransform` — NATS subject rewriting/mapping engine
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/util_test.go | 13 | 3061–3073 |
|
||||
| server/ipqueue_test.go | 28 | 688–715 |
|
||||
| server/subject_transform_test.go | 4 | 2958–2961 |
|
||||
| server/split_test.go | 12 | 2929–2940 |
|
||||
| **Total** | **57** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Internal/`
|
||||
37
docs/plans/phases/phase6sessions/session-03.md
Normal file
37
docs/plans/phases/phase6sessions/session-03.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Session 03: Configuration & Options
|
||||
|
||||
## Summary
|
||||
|
||||
The server options/configuration system. Parses config files, command-line args, and environment variables into the `ServerOptions` struct. This is large (5.4K LOC) but self-contained.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/opts.go | 86 | 2502–2587 | 5,400 |
|
||||
| **Total** | **86** | | **5,400** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `ServerOptions` — all configuration properties, parsing, validation, and defaults
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/opts_test.go | 86 | 2512–2597 |
|
||||
| server/config_check_test.go | 3 | 271–273 |
|
||||
| **Total** | **89** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types — constants, errors)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/ServerOptions.cs`
|
||||
|
||||
## Notes
|
||||
|
||||
- This is a large flat file. Consider splitting `ServerOptions` into partial classes by concern (TLS options, cluster options, JetStream options, etc.)
|
||||
- Many options have default values defined in `const.go` (Session 01)
|
||||
48
docs/plans/phases/phase6sessions/session-04.md
Normal file
48
docs/plans/phases/phase6sessions/session-04.md
Normal file
@@ -0,0 +1,48 @@
|
||||
# Session 04: Logging, Signals & Services
|
||||
|
||||
## Summary
|
||||
|
||||
Logging infrastructure, OS signal handling (Unix/Windows/WASM), and Windows service management. Small session — good opportunity to also address platform-specific abstractions.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/log.go | 18 | 2050–2067 | 207 |
|
||||
| server/signal.go | 5 | 3155–3159 | 156 |
|
||||
| server/signal_wasm.go | 2 | 3160–3161 | 6 |
|
||||
| server/signal_windows.go | 2 | 3162–3163 | 79 |
|
||||
| server/service.go | 2 | 3148–3149 | 7 |
|
||||
| server/service_windows.go | 5 | 3150–3154 | 79 |
|
||||
| **Total** | **34** | | **534** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `NatsLogger` (or logging integration) — server logging wrapper
|
||||
- `SignalHandler` — OS signal handling (SIGTERM, SIGHUP, etc.)
|
||||
- `ServiceManager` — Windows service lifecycle
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/log_test.go | 6 | 2017–2022 |
|
||||
| server/signal_test.go | 19 | 2910–2928 |
|
||||
| server/service_test.go | 1 | 2908 |
|
||||
| server/service_windows_test.go | 1 | 2909 |
|
||||
| **Total** | **27** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Internal/` (logging)
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server.Host/` (signal/service)
|
||||
|
||||
## Notes
|
||||
|
||||
- .NET uses `Microsoft.Extensions.Logging` + Serilog per standards
|
||||
- Windows service support maps to `Microsoft.Extensions.Hosting.WindowsServices`
|
||||
- Signal handling maps to `Console.CancelKeyPress` + `AppDomain.ProcessExit`
|
||||
40
docs/plans/phases/phase6sessions/session-05.md
Normal file
40
docs/plans/phases/phase6sessions/session-05.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Session 05: Subscription Index
|
||||
|
||||
## Summary
|
||||
|
||||
The subscription list (sublist) — a trie-based data structure for matching NATS subjects to subscriptions. Core to message routing performance.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/sublist.go | 81 | 3404–3484 | 1,416 |
|
||||
| **Total** | **81** | | **1,416** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `SubscriptionIndex` — trie-based subject matching
|
||||
- `SubscriptionIndexResult` — match result container
|
||||
- `SublistStats` — statistics for the subscription index
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/sublist_test.go | 96 | 2962–3057 |
|
||||
| **Total** | **96** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 02 (Utilities — subject parsing helpers)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Internal/DataStructures/SubscriptionIndex.cs`
|
||||
|
||||
## Notes
|
||||
|
||||
- Performance-critical: hot path for every message published
|
||||
- Use `ReadOnlySpan<byte>` for subject matching on hot paths
|
||||
- The existing `SubjectTree` (already ported in stree module) is different from this — sublist is the subscription matcher
|
||||
45
docs/plans/phases/phase6sessions/session-06.md
Normal file
45
docs/plans/phases/phase6sessions/session-06.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Session 06: Authentication & JWT
|
||||
|
||||
## Summary
|
||||
|
||||
Authentication handlers (user/pass, token, NKey, TLS cert), auth callout (external auth service), JWT processing, and cipher suite definitions.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/auth.go | 31 | 350–380 | 1,498 |
|
||||
| server/auth_callout.go | 3 | 381–383 | 456 |
|
||||
| server/jwt.go | 6 | 1973–1978 | 205 |
|
||||
| server/ciphersuites.go | 3 | 384–386 | 37 |
|
||||
| **Total** | **43** | | **2,196** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `AuthHandler` — authentication dispatch and credential checking
|
||||
- `AuthCallout` — external auth callout service
|
||||
- `JwtProcessor` — NATS JWT validation and claims extraction
|
||||
- `CipherSuites` — TLS cipher suite definitions
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/auth_test.go | 12 | 142–153 |
|
||||
| server/auth_callout_test.go | 31 | 111–141 |
|
||||
| server/jwt_test.go | 88 | 1809–1896 |
|
||||
| **Total** | **131** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types — errors, constants)
|
||||
- Session 03 (Configuration — ServerOptions for auth config)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Auth/`
|
||||
|
||||
## Notes
|
||||
|
||||
- Auth is already partially scaffolded from leaf modules (certidp, certstore, tpm)
|
||||
- JWT test file is large (88 tests) — may need careful batching within the session
|
||||
39
docs/plans/phases/phase6sessions/session-07.md
Normal file
39
docs/plans/phases/phase6sessions/session-07.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Session 07: Protocol Parser
|
||||
|
||||
## Summary
|
||||
|
||||
The NATS protocol parser — parses raw bytes from client connections into protocol operations (PUB, SUB, UNSUB, CONNECT, etc.). Extremely performance-critical.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/parser.go | 5 | 2588–2592 | 1,165 |
|
||||
| **Total** | **5** | | **1,165** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `ProtocolParser` — state-machine parser for NATS wire protocol
|
||||
- `ClientConnection` (partial — parser-related methods only)
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/parser_test.go | 17 | 2598–2614 |
|
||||
| **Total** | **17** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types — protocol constants, errors)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Protocol/`
|
||||
|
||||
## Notes
|
||||
|
||||
- Only 5 features but 1,165 LOC — these are large state-machine functions
|
||||
- Must use `ReadOnlySpan<byte>` and avoid allocations in the parse loop
|
||||
- The parser is called for every byte received — benchmark after porting
|
||||
- Consider using `System.IO.Pipelines` for buffer management
|
||||
49
docs/plans/phases/phase6sessions/session-08.md
Normal file
49
docs/plans/phases/phase6sessions/session-08.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Session 08: Client Connection
|
||||
|
||||
## Summary
|
||||
|
||||
The client connection handler — manages individual client TCP connections, message processing, subscription management, and client lifecycle. The largest single class in the server.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/client.go | 185 | 387–571 | 5,680 |
|
||||
| server/client_proxyproto.go | 10 | 572–581 | 273 |
|
||||
| **Total** | **195** | | **5,953** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `ClientConnection` — client state, read/write loops, publish, subscribe, unsubscribe
|
||||
- `ClientFlag` — client state flags
|
||||
- `ClientInfo` — client metadata
|
||||
- `ProxyProtocolAddress` — PROXY protocol v1/v2 parsing
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/client_test.go | 82 | 182–263 |
|
||||
| server/client_proxyproto_test.go | 23 | 159–181 |
|
||||
| server/closed_conns_test.go | 7 | 264–270 |
|
||||
| server/ping_test.go | 1 | 2615 |
|
||||
| **Total** | **113** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 02 (Utilities — queues)
|
||||
- Session 03 (Configuration — ServerOptions)
|
||||
- Session 05 (Subscription Index)
|
||||
- Session 07 (Protocol Parser)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/ClientConnection.cs`
|
||||
|
||||
## Notes
|
||||
|
||||
- This is the core networking class — every connected client has one
|
||||
- Heavy use of `sync.Mutex` in Go → consider `lock` or `SemaphoreSlim`
|
||||
- Write coalescing and flush logic is performance-critical
|
||||
- May need partial class split: `ClientConnection.Read.cs`, `ClientConnection.Write.cs`, etc.
|
||||
52
docs/plans/phases/phase6sessions/session-09.md
Normal file
52
docs/plans/phases/phase6sessions/session-09.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Session 09: Server Core — Initialization & Configuration
|
||||
|
||||
## Summary
|
||||
|
||||
First half of server.go: server construction, validation, account configuration, resolver setup, trusted keys, and the `Start()` method. This is the server bootstrap path.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/server.go (lines 85–2575) | ~76 | 2974–3050 | ~1,950 |
|
||||
| **Total** | **~76** | | **~1,950** |
|
||||
|
||||
### Key Features
|
||||
|
||||
- `New`, `NewServer`, `NewServerFromConfig` — constructors
|
||||
- `validateOptions`, `validateCluster`, `validatePinnedCerts` — config validation
|
||||
- `configureAccounts`, `configureResolver`, `checkResolvePreloads` — account setup
|
||||
- `processTrustedKeys`, `initStampedTrustedKeys` — JWT trust chain
|
||||
- `Start` — main server startup (313 LOC)
|
||||
- Compression helpers (`selectCompressionMode`, `s2WriterOptions`, etc.)
|
||||
- Account lookup/register/update methods
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `NatsServer` (partial — initialization, configuration, accounts)
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/server_test.go (partial) | ~20 | 2866–2885 |
|
||||
| **Total** | **~20** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 03 (Configuration — ServerOptions)
|
||||
- Session 04 (Logging)
|
||||
- Session 05 (Subscription Index)
|
||||
- Session 06 (Authentication)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/NatsServer.cs` (partial class)
|
||||
- Consider: `NatsServer.Init.cs`, `NatsServer.Accounts.cs`
|
||||
|
||||
## Notes
|
||||
|
||||
- `Server.Start()` is 313 LOC — the single largest function. Port carefully.
|
||||
- Account configuration deeply intertwines with JWT and resolver subsystems
|
||||
- Many methods reference route, gateway, and leafnode structures (forward declarations needed)
|
||||
57
docs/plans/phases/phase6sessions/session-10.md
Normal file
57
docs/plans/phases/phase6sessions/session-10.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# Session 10: Server Core — Runtime & Lifecycle
|
||||
|
||||
## Summary
|
||||
|
||||
Second half of server.go: accept loops, client creation, monitoring HTTP server, TLS handling, lame duck mode, shutdown, and runtime query methods.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/server.go (lines 2577–4782) | ~98 | 3051–3147 | ~1,881 |
|
||||
| **Total** | **~98** | | **~1,881** |
|
||||
|
||||
### Key Features
|
||||
|
||||
- `Shutdown` — graceful shutdown (172 LOC)
|
||||
- `AcceptLoop`, `acceptConnections` — TCP listener
|
||||
- `createClientEx` — client connection factory (305 LOC)
|
||||
- `startMonitoring`, `StartHTTPMonitoring` — HTTP monitoring server
|
||||
- `lameDuckMode`, `sendLDMToRoutes`, `sendLDMToClients` — lame duck
|
||||
- `readyForConnections`, `readyForListeners` — startup synchronization
|
||||
- Numerous `Num*` query methods (routes, clients, subscriptions, etc.)
|
||||
- `getConnectURLs`, `PortsInfo` — connection metadata
|
||||
- `removeClient`, `saveClosedClient` — client lifecycle
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `NatsServer` (partial — runtime, lifecycle, queries)
|
||||
- `CaptureHTTPServerLog` — HTTP log adapter
|
||||
- `TlsMixConn` — mixed TLS/plain connection
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/server_test.go (partial) | ~22 | 2886–2907 |
|
||||
| server/benchmark_publish_test.go | 1 | 154 |
|
||||
| server/core_benchmarks_test.go | 4 | 274–277 |
|
||||
| **Total** | **~27** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 04 (Logging)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/NatsServer.cs` (partial class)
|
||||
- Consider: `NatsServer.Lifecycle.cs`, `NatsServer.Listeners.cs`
|
||||
|
||||
## Notes
|
||||
|
||||
- `createClientEx` is 305 LOC — second largest function in the file
|
||||
- `Shutdown` involves coordinating across all subsystems
|
||||
- Monitoring HTTP server maps to ASP.NET Core Kestrel or minimal API
|
||||
- Lame duck mode requires careful timer/signal coordination
|
||||
52
docs/plans/phases/phase6sessions/session-11.md
Normal file
52
docs/plans/phases/phase6sessions/session-11.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Session 11: Accounts & Directory Store
|
||||
|
||||
## Summary
|
||||
|
||||
Multi-tenancy account system and directory-based JWT store. Accounts manage per-tenant state including JetStream limits, imports/exports, and user authentication.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/accounts.go | 200 | 150–349 | 3,918 |
|
||||
| server/dirstore.go | 34 | 793–826 | 575 |
|
||||
| **Total** | **234** | | **4,493** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `Account` — per-tenant account with limits, imports, exports
|
||||
- `DirectoryAccountResolver` — file-system-based account resolver
|
||||
- `CacheDirAccountResolver` — caching resolver wrapper
|
||||
- `MemoryAccountResolver` — in-memory resolver
|
||||
- `UriAccountResolver` — HTTP-based resolver
|
||||
- `DirJwtStore` — JWT file storage
|
||||
- `DirectoryStore` — directory abstraction
|
||||
- `ExpirationTracker` — JWT expiration tracking
|
||||
- `LocalCache` — local account cache
|
||||
- `ServiceExport`, `ServiceImport`, `ServiceLatency` — service mesh types
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/accounts_test.go | 65 | 46–110 |
|
||||
| server/dirstore_test.go | 19 | 278–296 |
|
||||
| **Total** | **84** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 02 (Utilities)
|
||||
- Session 03 (Configuration)
|
||||
- Session 05 (Subscription Index)
|
||||
- Session 06 (Auth & JWT)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Accounts/`
|
||||
|
||||
## Notes
|
||||
|
||||
- `Account` is the 4th largest class (4.5K LOC across multiple Go files)
|
||||
- accounts.go alone has 200 features — will need methodical batching within the session
|
||||
- Account methods are spread across accounts.go, consumer.go, events.go, jetstream.go, etc. — this session covers only accounts.go features
|
||||
53
docs/plans/phases/phase6sessions/session-12.md
Normal file
53
docs/plans/phases/phase6sessions/session-12.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Session 12: Events, Monitoring & Message Tracing
|
||||
|
||||
## Summary
|
||||
|
||||
Server-side event system (system events, advisory messages), HTTP monitoring endpoints (varz, connz, routez, etc.), and message tracing infrastructure.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/events.go | 97 | 854–950 | 2,445 |
|
||||
| server/monitor.go | 70 | 2166–2235 | 3,257 |
|
||||
| server/monitor_sort_opts.go | 16 | 2236–2251 | 48 |
|
||||
| server/msgtrace.go | 35 | 2405–2439 | 569 |
|
||||
| **Total** | **218** | | **6,319** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `EventsHandler` — system event publishing
|
||||
- `MonitoringHandler` — HTTP monitoring endpoints
|
||||
- `ConnInfo`, `ClosedState` — connection monitoring types
|
||||
- `HealthZErrorType` — health check error types
|
||||
- `MsgTrace`, `MsgTraceEvent`, `MsgTraceEvents` — message tracing
|
||||
- `MessageTracer` — tracing engine
|
||||
- Various sort option types (16 types)
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/events_test.go | 52 | 299–350 |
|
||||
| server/monitor_test.go | 103 | 2064–2166 |
|
||||
| server/msgtrace_test.go | 33 | 2329–2361 |
|
||||
| **Total** | **188** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Session 11 (Accounts)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Monitoring/`
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Events/`
|
||||
|
||||
## Notes
|
||||
|
||||
- Monitor endpoints map to ASP.NET Core minimal API or controller endpoints
|
||||
- Events system uses internal pub/sub — publishes to `$SYS.*` subjects
|
||||
- This is a larger session (~6.3K LOC) but the code is relatively straightforward
|
||||
- Monitor has 103 tests — allocate time accordingly
|
||||
39
docs/plans/phases/phase6sessions/session-13.md
Normal file
39
docs/plans/phases/phase6sessions/session-13.md
Normal file
@@ -0,0 +1,39 @@
|
||||
# Session 13: Configuration Reload
|
||||
|
||||
## Summary
|
||||
|
||||
Hot-reload system for server configuration. Detects config changes and applies them without restarting the server. Each option type has a reload handler.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/reload.go | 89 | 2800–2888 | 2,085 |
|
||||
| **Total** | **89** | | **2,085** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `ConfigReloader` — reload orchestrator
|
||||
- 50+ individual option reload types (e.g., `AuthOption`, `TlsOption`, `ClusterOption`, `JetStreamOption`, etc.)
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/reload_test.go | 73 | 2721–2793 |
|
||||
| **Total** | **73** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 03 (Configuration — ServerOptions)
|
||||
- Session 09 (Server Core Part 1)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/ConfigReloader.cs`
|
||||
|
||||
## Notes
|
||||
|
||||
- Many small reload option types — consider using a single file with nested classes or a separate `Reload/` folder
|
||||
- Each option type implements a common interface for diff/apply pattern
|
||||
- 73 tests cover each option type's reload behavior
|
||||
41
docs/plans/phases/phase6sessions/session-14.md
Normal file
41
docs/plans/phases/phase6sessions/session-14.md
Normal file
@@ -0,0 +1,41 @@
|
||||
# Session 14: Routes
|
||||
|
||||
## Summary
|
||||
|
||||
Inter-server routing — how NATS servers form a full mesh cluster and route messages between nodes.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/route.go | 57 | 2895–2951 | 2,988 |
|
||||
| **Total** | **57** | | **2,988** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `RouteHandler` — route connection management
|
||||
- `ClientConnection` (partial — route-specific methods, 25 features from client.go already counted in S08)
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/routes_test.go | 70 | 2796–2865 |
|
||||
| **Total** | **70** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 07 (Protocol Parser)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Routing/`
|
||||
|
||||
## Notes
|
||||
|
||||
- Route connections are `ClientConnection` instances with special handling
|
||||
- Protocol includes route-specific INFO, SUB, UNSUB, MSG operations
|
||||
- Cluster gossip and route solicitation logic lives here
|
||||
45
docs/plans/phases/phase6sessions/session-15.md
Normal file
45
docs/plans/phases/phase6sessions/session-15.md
Normal file
@@ -0,0 +1,45 @@
|
||||
# Session 15: Leaf Nodes
|
||||
|
||||
## Summary
|
||||
|
||||
Leaf node connections — lightweight connections from edge servers to hub servers. Simpler than full routes but with subject interest propagation.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/leafnode.go | 71 | 1979–2049 | 3,091 |
|
||||
| **Total** | **71** | | **3,091** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `LeafNodeHandler` — leaf node connection management
|
||||
- `LeafNodeCfg` — leaf node configuration
|
||||
- `LeafNodeOption` — leaf node reload option
|
||||
- `ClientConnection` (partial — leafnode-specific methods)
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/leafnode_test.go | 111 | 1906–2016 |
|
||||
| server/leafnode_proxy_test.go | 9 | 1897–1905 |
|
||||
| **Total** | **120** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 07 (Protocol Parser)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Session 14 (Routes — shared routing infrastructure)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/LeafNode/`
|
||||
|
||||
## Notes
|
||||
|
||||
- 111 + 9 = 120 tests — this is a test-heavy session
|
||||
- Leaf nodes support TLS, auth, and subject deny lists
|
||||
- WebSocket transport for leaf nodes adds complexity
|
||||
47
docs/plans/phases/phase6sessions/session-16.md
Normal file
47
docs/plans/phases/phase6sessions/session-16.md
Normal file
@@ -0,0 +1,47 @@
|
||||
# Session 16: Gateways
|
||||
|
||||
## Summary
|
||||
|
||||
Gateway connections — inter-cluster message routing. Gateways enable NATS super-clusters where messages flow between independent clusters.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/gateway.go | 91 | 1263–1353 | 2,816 |
|
||||
| **Total** | **91** | | **2,816** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `GatewayHandler` — gateway connection management
|
||||
- `GatewayCfg` — gateway configuration
|
||||
- `ServerGateway` — per-server gateway state
|
||||
- `GatewayInterestMode` — interest/optimistic mode tracking
|
||||
- `GwReplyMapping` — reply-to subject mapping for gateways
|
||||
- `ClientConnection` (partial — gateway-specific methods)
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/gateway_test.go | 88 | 600–687 |
|
||||
| **Total** | **88** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 07 (Protocol Parser)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Session 11 (Accounts — for interest propagation)
|
||||
- Session 14 (Routes)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Gateway/`
|
||||
|
||||
## Notes
|
||||
|
||||
- Gateway protocol has optimistic and interest-only modes
|
||||
- Account-aware interest propagation is complex
|
||||
- 88 tests — thorough coverage of gateway scenarios
|
||||
53
docs/plans/phases/phase6sessions/session-17.md
Normal file
53
docs/plans/phases/phase6sessions/session-17.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Session 17: Store Interfaces & Memory Store
|
||||
|
||||
## Summary
|
||||
|
||||
Storage abstraction layer (interfaces for streams and consumers) and the in-memory storage implementation. Also includes disk availability checks.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/store.go | 31 | 3164–3194 | 391 |
|
||||
| server/memstore.go | 98 | 2068–2165 | 2,434 |
|
||||
| server/disk_avail.go | 1 | 827 | 15 |
|
||||
| server/disk_avail_netbsd.go | 1 | 828 | 3 |
|
||||
| server/disk_avail_openbsd.go | 1 | 829 | 15 |
|
||||
| server/disk_avail_solaris.go | 1 | 830 | 15 |
|
||||
| server/disk_avail_wasm.go | 1 | 831 | 3 |
|
||||
| server/disk_avail_windows.go | 1 | 832 | 3 |
|
||||
| **Total** | **135** | | **2,879** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `StorageEngine` — storage interface definitions (`StreamStore`, `ConsumerStore`)
|
||||
- `StoreMsg` — stored message type
|
||||
- `StorageType`, `StoreCipher`, `StoreCompression` — storage enums
|
||||
- `DeleteBlocks`, `DeleteRange`, `DeleteSlice` — deletion types
|
||||
- `JetStreamMemoryStore` — in-memory stream store
|
||||
- `ConsumerMemStore` — in-memory consumer store
|
||||
- `DiskAvailability` — disk space checker (platform-specific)
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/store_test.go | 17 | 2941–2957 |
|
||||
| server/memstore_test.go | 41 | 2023–2063 |
|
||||
| **Total** | **58** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 02 (Utilities)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/JetStream/Storage/`
|
||||
|
||||
## Notes
|
||||
|
||||
- Store interfaces define the contract for both memory and file stores
|
||||
- MemStore is simpler than FileStore — good to port first as a reference implementation
|
||||
- Disk availability uses platform-specific syscalls — map to `DriveInfo` in .NET
|
||||
- Most disk_avail variants can be N/A (use .NET cross-platform API instead)
|
||||
50
docs/plans/phases/phase6sessions/session-18.md
Normal file
50
docs/plans/phases/phase6sessions/session-18.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Session 18: File Store
|
||||
|
||||
## Summary
|
||||
|
||||
The persistent file-based storage engine for JetStream. Handles message persistence, compaction, encryption, compression, and recovery. This is the largest single-file session.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/filestore.go | 312 | 951–1262 | 11,421 |
|
||||
| **Total** | **312** | | **11,421** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `JetStreamFileStore` — file-based stream store (174 features, 7,255 LOC)
|
||||
- `MessageBlock` — individual message block on disk (95 features, 3,314 LOC)
|
||||
- `ConsumerFileStore` — file-based consumer store (33 features, 700 LOC)
|
||||
- `CompressionInfo` — compression metadata
|
||||
- `ErrBadMsg` — bad message error type
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/filestore_test.go | 249 | 351–599 |
|
||||
| **Total** | **249** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 02 (Utilities)
|
||||
- Session 17 (Store Interfaces)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/JetStream/Storage/`
|
||||
|
||||
## Notes
|
||||
|
||||
- **This is a multi-sitting session** — 11.4K Go LOC and 249 tests
|
||||
- Suggested sub-batching:
|
||||
- **18a**: `MessageBlock` (95 features, 3.3K LOC) — the on-disk block format
|
||||
- **18b**: `JetStreamFileStore` core (load, store, recover, compact) — ~90 features
|
||||
- **18c**: `JetStreamFileStore` remaining (snapshots, encryption, purge) — ~84 features
|
||||
- **18d**: `ConsumerFileStore` (33 features, 700 LOC)
|
||||
- **18e**: Tests (249 tests)
|
||||
- File I/O should use `FileStream` with `RandomAccess` APIs for .NET 10
|
||||
- Encryption maps to `System.Security.Cryptography`
|
||||
- S2/Snappy compression maps to existing NuGet packages
|
||||
67
docs/plans/phases/phase6sessions/session-19.md
Normal file
67
docs/plans/phases/phase6sessions/session-19.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# Session 19: JetStream Core
|
||||
|
||||
## Summary
|
||||
|
||||
JetStream engine core — initialization, API handlers, error definitions, event types, versioning, and batching. The central JetStream coordination layer.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/jetstream.go | 84 | 1368–1451 | 2,481 |
|
||||
| server/jetstream_api.go | 56 | 1452–1507 | 4,269 |
|
||||
| server/jetstream_errors.go | 5 | 1751–1755 | 62 |
|
||||
| server/jetstream_errors_generated.go | 203 | 1756–1958 | 1,924 |
|
||||
| server/jetstream_events.go | 1 | 1959 | 25 |
|
||||
| server/jetstream_versioning.go | 13 | 1960–1972 | 175 |
|
||||
| server/jetstream_batching.go | 12 | 1508–1519 | 568 |
|
||||
| **Total** | **374** | | **9,504** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `JetStreamEngine` — JetStream lifecycle, enable/disable, account tracking
|
||||
- `JetStreamApi` — REST-like API handlers for stream/consumer CRUD
|
||||
- `JetStreamErrors` — error code registry (208 entries)
|
||||
- `JetStreamEvents` — advisory event types
|
||||
- `JetStreamVersioning` — feature version compatibility
|
||||
- `JetStreamBatching` — batch message processing
|
||||
- `JsAccount` — per-account JetStream state
|
||||
- `JsOutQ` — JetStream output queue
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/jetstream_test.go | 320 | 1466–1785 |
|
||||
| server/jetstream_errors_test.go | 4 | 1381–1384 |
|
||||
| server/jetstream_versioning_test.go | 18 | 1791–1808 |
|
||||
| server/jetstream_batching_test.go | 29 | 716–744 |
|
||||
| server/jetstream_jwt_test.go | 18 | 1385–1402 |
|
||||
| server/jetstream_tpm_test.go | 5 | 1786–1790 |
|
||||
| server/jetstream_benchmark_test.go | 12 | 745–756 |
|
||||
| **Total** | **406** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 03 (Configuration)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Session 11 (Accounts)
|
||||
- Session 17 (Store Interfaces)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/JetStream/`
|
||||
|
||||
## Notes
|
||||
|
||||
- **This is a multi-sitting session** — 9.5K Go LOC and 406 tests
|
||||
- JetStream errors generated file is 203 features but mostly boilerplate error codes
|
||||
- jetstream_test.go has 320 tests — the largest test file
|
||||
- Suggested sub-batching:
|
||||
- **19a**: Error definitions and events (209 features, 2K LOC) — mostly mechanical
|
||||
- **19b**: JetStream engine core (84 features, 2.5K LOC)
|
||||
- **19c**: JetStream API (56 features, 4.3K LOC)
|
||||
- **19d**: Versioning + batching (25 features, 743 LOC)
|
||||
- **19e**: Tests (406 tests, batched by test file)
|
||||
70
docs/plans/phases/phase6sessions/session-20.md
Normal file
70
docs/plans/phases/phase6sessions/session-20.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Session 20: JetStream Cluster & Raft
|
||||
|
||||
## Summary
|
||||
|
||||
Raft consensus algorithm implementation and JetStream clustering — how streams and consumers are replicated across server nodes.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/raft.go | 198 | 2599–2796 | 4,078 |
|
||||
| server/jetstream_cluster.go | 231 | 1520–1750 | 10,098 |
|
||||
| **Total** | **429** | | **14,176** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `RaftNode` — Raft consensus implementation (169 features)
|
||||
- `AppendEntry`, `AppendEntryResponse` — Raft log entries
|
||||
- `Checkpoint` — Raft snapshots
|
||||
- `CommittedEntry`, `Entry`, `EntryType` — entry types
|
||||
- `VoteRequest`, `VoteResponse`, `RaftState` — election types
|
||||
- `RaftGroup` — Raft group configuration
|
||||
- `JetStreamCluster` — cluster-wide JetStream coordination (51 features)
|
||||
- `Consumer` (cluster) — consumer assignment tracking (7 features)
|
||||
- `ConsumerAssignment` — consumer placement
|
||||
- `StreamAssignment`, `UnsupportedStreamAssignment` — stream placement
|
||||
- Plus ~69 `JetStreamEngine` methods for cluster operations
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/raft_test.go | 104 | 2616–2719 |
|
||||
| server/jetstream_cluster_1_test.go | 151 | 757–907 |
|
||||
| server/jetstream_cluster_2_test.go | 123 | 908–1030 |
|
||||
| server/jetstream_cluster_3_test.go | 97 | 1031–1127 |
|
||||
| server/jetstream_cluster_4_test.go | 85 | 1128–1212 |
|
||||
| server/jetstream_cluster_long_test.go | 7 | 1213–1219 |
|
||||
| server/jetstream_super_cluster_test.go | 47 | 1419–1465 |
|
||||
| server/jetstream_meta_benchmark_test.go | 2 | 1416–1417 |
|
||||
| server/jetstream_sourcing_scaling_test.go | 1 | 1418 |
|
||||
| **Total** | **617** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Session 14 (Routes)
|
||||
- Session 17 (Store Interfaces)
|
||||
- Session 19 (JetStream Core)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/JetStream/Cluster/`
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Raft/`
|
||||
|
||||
## Notes
|
||||
|
||||
- **This is a multi-sitting session** — 14.2K Go LOC and 617 tests (the largest session)
|
||||
- Suggested sub-batching:
|
||||
- **20a**: Raft types and election (entries, votes, state — ~30 features)
|
||||
- **20b**: Raft core (log replication, append, commit — ~85 features)
|
||||
- **20c**: Raft remaining (snapshots, checkpoints, recovery — ~83 features)
|
||||
- **20d**: JetStream cluster types and assignments (~30 features)
|
||||
- **20e**: JetStream cluster operations Part 1 (~130 features)
|
||||
- **20f**: JetStream cluster operations Part 2 (~71 features)
|
||||
- **20g**: Tests (617 tests, batched by test file)
|
||||
- Raft is the most algorithmically complex code in the server
|
||||
- Cluster tests often require multi-server setups — integration test candidates
|
||||
60
docs/plans/phases/phase6sessions/session-21.md
Normal file
60
docs/plans/phases/phase6sessions/session-21.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Session 21: Streams & Consumers
|
||||
|
||||
## Summary
|
||||
|
||||
Stream and consumer implementations — the core JetStream data plane. Streams store messages; consumers track delivery state and manage acknowledgments.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/stream.go | 193 | 3195–3387 | 6,980 |
|
||||
| server/consumer.go | 209 | 584–792 | 5,720 |
|
||||
| **Total** | **402** | | **12,700** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `NatsStream` — stream lifecycle, message ingestion, purge, snapshots (193 features)
|
||||
- `NatsConsumer` — consumer lifecycle, delivery, ack, nak, redelivery (174 features)
|
||||
- `ConsumerAction`, `ConsumerConfig`, `AckPolicy`, `DeliverPolicy`, `ReplayPolicy` — consumer types
|
||||
- `StreamConfig`, `StreamSource`, `ExternalStream` — stream types
|
||||
- `PriorityPolicy`, `RetentionPolicy`, `DiscardPolicy`, `PersistModeType` — policy enums
|
||||
- `WaitQueue`, `WaitingRequest`, `WaitingDelivery` — consumer wait types
|
||||
- `JSPubAckResponse`, `PubMsg`, `JsPubMsg`, `InMsg`, `CMsg` — message types
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/jetstream_consumer_test.go | 161 | 1220–1380 |
|
||||
| server/jetstream_leafnode_test.go | 13 | 1403–1415 |
|
||||
| server/norace_1_test.go | 100 | 2371–2470 |
|
||||
| server/norace_2_test.go | 41 | 2471–2511 |
|
||||
| **Total** | **315** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 02 (Utilities)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Session 11 (Accounts)
|
||||
- Session 17 (Store Interfaces)
|
||||
- Session 19 (JetStream Core)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/JetStream/`
|
||||
|
||||
## Notes
|
||||
|
||||
- **This is a multi-sitting session** — 12.7K Go LOC and 315 tests
|
||||
- Suggested sub-batching:
|
||||
- **21a**: Stream/consumer types and enums (~40 features, ~500 LOC)
|
||||
- **21b**: NatsStream core (create, delete, purge — ~95 features)
|
||||
- **21c**: NatsStream remaining (snapshots, sources, mirrors — ~98 features)
|
||||
- **21d**: NatsConsumer core (create, deliver, ack — ~90 features)
|
||||
- **21e**: NatsConsumer remaining (redelivery, pull, push — ~84 features)
|
||||
- **21f**: Tests (315 tests)
|
||||
- `norace_*_test.go` files contain tests that must run without the Go race detector — these may have concurrency timing sensitivities
|
||||
- Consumer pull/push patterns need careful async design in C#
|
||||
51
docs/plans/phases/phase6sessions/session-22.md
Normal file
51
docs/plans/phases/phase6sessions/session-22.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Session 22: MQTT
|
||||
|
||||
## Summary
|
||||
|
||||
MQTT 3.1.1/5.0 protocol adapter — allows MQTT clients to connect to NATS and interact with JetStream for persistence.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/mqtt.go | 153 | 2252–2404 | 4,758 |
|
||||
| **Total** | **153** | | **4,758** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `MqttHandler` — MQTT protocol handler (35 features)
|
||||
- `MqttAccountSessionManager` — per-account MQTT session tracking (26 features)
|
||||
- `MqttSession` — individual MQTT session state (15 features)
|
||||
- `MqttJetStreamAdapter` — bridges MQTT to JetStream (22 features)
|
||||
- `MqttReader` — MQTT packet reader (8 features)
|
||||
- `MqttWriter` — MQTT packet writer (5 features)
|
||||
- Various MQTT reload options
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/mqtt_test.go | 159 | 2170–2328 |
|
||||
| server/mqtt_ex_test_test.go | 2 | 2168–2169 |
|
||||
| server/mqtt_ex_bench_test.go | 1 | 2167 |
|
||||
| **Total** | **162** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Session 11 (Accounts)
|
||||
- Session 17 (Store Interfaces)
|
||||
- Session 19 (JetStream Core)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Mqtt/`
|
||||
|
||||
## Notes
|
||||
|
||||
- MQTT is a self-contained protocol layer — could potentially be a separate assembly
|
||||
- 159 MQTT tests cover connection, subscribe, publish, QoS levels, sessions, retained messages
|
||||
- MQTT ↔ JetStream bridging is the most complex part
|
||||
- Consider using `System.IO.Pipelines` for MQTT packet parsing
|
||||
52
docs/plans/phases/phase6sessions/session-23.md
Normal file
52
docs/plans/phases/phase6sessions/session-23.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Session 23: WebSocket & OCSP
|
||||
|
||||
## Summary
|
||||
|
||||
WebSocket transport layer (allows browser clients to connect via WebSocket) and OCSP certificate stapling/checking infrastructure.
|
||||
|
||||
## Scope
|
||||
|
||||
| Go File | Features | Feature IDs | Go LOC |
|
||||
|---------|----------|-------------|--------|
|
||||
| server/websocket.go | 38 | 3506–3543 | 1,265 |
|
||||
| server/ocsp.go | 20 | 2443–2462 | 880 |
|
||||
| server/ocsp_peer.go | 9 | 2463–2471 | 356 |
|
||||
| server/ocsp_responsecache.go | 30 | 2472–2501 | 461 |
|
||||
| **Total** | **97** | | **2,962** |
|
||||
|
||||
## .NET Classes
|
||||
|
||||
- `WebSocketHandler` — WebSocket upgrade and frame handling
|
||||
- `WsReadInfo` — WebSocket read state
|
||||
- `SrvWebsocket` — WebSocket server configuration
|
||||
- `OcspHandler` — OCSP stapling orchestrator
|
||||
- `OCSPMonitor` — background OCSP response refresher
|
||||
- `NoOpCache` — no-op OCSP cache implementation
|
||||
|
||||
## Test Files
|
||||
|
||||
| Test File | Tests | Test IDs |
|
||||
|-----------|-------|----------|
|
||||
| server/websocket_test.go | 109 | 3074–3182 |
|
||||
| server/certstore_windows_test.go | 4 | 155–158 |
|
||||
| **Total** | **113** | |
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Session 01 (Foundation Types)
|
||||
- Session 08 (Client Connection)
|
||||
- Session 09 (Server Core Part 1)
|
||||
- Leaf module: certidp (already complete)
|
||||
- Leaf module: certstore (already complete)
|
||||
|
||||
## .NET Target Location
|
||||
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/WebSocket/`
|
||||
- `dotnet/src/ZB.MOM.NatsNet.Server/Auth/Ocsp/`
|
||||
|
||||
## Notes
|
||||
|
||||
- WebSocket maps to ASP.NET Core WebSocket middleware or `System.Net.WebSockets`
|
||||
- OCSP integrates with the already-ported certidp and certstore modules
|
||||
- WebSocket test file has 109 tests — covers masking, framing, compression, upgrade
|
||||
- OCSP response cache has 30 features — manage certificate stapling lifecycle
|
||||
Reference in New Issue
Block a user