Technical Documentation

Deep dive into the architecture, threading model, and security layers of RSC.

1. System Architecture

RSC uses a standard client-server architecture. The server listens on TCP port 4444 and is heavily multi-threaded:

2. The Wire Protocol

Communication is line-based TCP. Authentication supports two formats:

# Legacy
AUTH:<token>

# Identity (Phase 8+)
AUTH:<server_uuid>:<payload_uuid>:<token>

Sentinel Framing: Because TCP is a stream, command responses are wrapped in explicit markers to prevent race conditions:

<<<RSC_BEGIN>>>
<actual output>
<<<RSC_END>>>

3. Server Implementation (Thread Race Fix)

Initially, both send_command and the read loop tried to call recv() on the socket, causing a race condition where keepalives were consumed as command output.

This was solved by making _client_read_loop the sole reader. It feeds raw bytes into session.response_queue.put(chunk). send_command then blocks on the queue until it sees the <<<RSC_END>>> sentinel.

4. Client Hibernation

If the server goes offline, the client does not crash. It enters a hibernation loop, logging [hibernate] <reason> — retry #N in 30s. It retries every 30 seconds until the server comes back online.

5. Security Architecture

6. Exporter Wrappers

The Base64 payload is wrapped differently per format:

7. Web Dashboard (Flask + SSE)

Real-time updates are pushed using Server-Sent Events at /api/logs/stream. The server uses an EventBus singleton to broadcast logs, session additions, and disconnects to the frontend JavaScript.