# 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
