Files
sor/Server/src/SOR.Networking.Abstractions/Transport/AuthenticatedConnection.cs
T
d21adbc8d0 Add networking foundation — 9-project C# solution (compiles clean)
Implements the modular networking layer for SOR Server:
- SOR.Networking.Abstractions: pure interfaces (ITransport, IClientConnection,
  IMessageSerializer, IMessageDispatcher, IMessageHandler, IEventBus, IClientPush)
- SOR.Networking.WebSocket: ITransport + IClientConnection over System.Net.WebSockets
- SOR.Networking.Nats: IEventBus over NATS.Net (INatsConnection)
- SOR.Networking.Redis: IClientPush over Redis Pub/Sub
- SOR.Shared: ServiceResult<T>, RedisKeys, NatsSubjects, ServerMessage, JSON serializer
- SOR.Shared.Proto: auth.proto with gRPC AuthService contract
- SOR.Gateway: accept loop, auth handshake, dispatcher, Redis push subscriber
- SOR.Auth: stub gRPC handler (placeholder responses)
- SOR.Host: multi-service runner via ENABLED_SERVICES env var; wires all DI

All concrete implementations are wired exclusively in SOR.Host — every transport,
broker, and push implementation can be swapped by changing only Program.cs.

dotnet build SOR.slnx → 0 errors, 0 warnings

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-02-24 21:01:38 -05:00

41 lines
1.6 KiB
C#

namespace SOR.Networking.Abstractions.Transport;
/// <summary>
/// An IClientConnection that has completed the auth handshake successfully.
///
/// Created by ConnectionLoop.RunAsync() after GatewayAuthValidator confirms the
/// session token is valid. Immutable — properties are set once and never changed.
///
/// This is the context object passed to every IMessageHandler. Handlers use it to:
/// - Know which user sent the message (UserId, DisplayName)
/// - Send replies back to the correct client (Connection.SendBytesAsync)
///
/// 'record' in C# generates equality comparison (by value of all properties),
/// a ToString() override, and a constructor automatically. The 'sealed' modifier
/// means no class can inherit from it.
/// </summary>
public sealed record AuthenticatedConnection(
/// <summary>The underlying transport connection for sending replies.</summary>
IClientConnection Connection,
/// <summary>
/// The authenticated user's unique identifier. A GUID stored as a string.
/// This is the authoritative identity for all service calls made on behalf
/// of this connection.
/// </summary>
string UserId,
/// <summary>
/// The user's display name at the time of authentication.
/// Cached here to avoid repeated lookups during the session.
/// </summary>
string DisplayName,
/// <summary>
/// The session token used to authenticate this connection.
/// Stored for revocation checks — if the token is invalidated mid-session,
/// the connection can be closed.
/// </summary>
string SessionToken
);