Skip to main content

Protocol Overview

Undying Terminal’s recovery protocol ensures zero data loss during network disruptions using a sequence-based buffering system. Every byte of terminal output is numbered, buffered, and can be replayed on reconnection.

Sequence Numbers

What Are Sequence Numbers?

Each packet exchanged between client and terminal has a monotonically increasing sequence number:
Properties:
  • 64-bit unsigned integers (18 quintillion possible values)
  • Never reset during session lifetime
  • Increment by 1 for each message
  • Separate counters for client→terminal and terminal→client

Sequence Tracking

Terminal maintains:
  • last_sent_seq: Last sequence number sent to client
  • last_acked_seq: Last sequence number client confirmed receiving
Client maintains:
  • last_received_seq: Last sequence number received from terminal
  • next_expected_seq: Next sequence number expected
On reconnection:

Recovery Buffer

Buffer Architecture

The server maintains a circular buffer for each terminal session:
Characteristics:
  • Fixed size (configurable in server config)
  • Circular: Old data overwritten when full
  • Per-session: Each terminal has its own buffer
  • In-memory: Not persisted to disk

Buffer Sizing

Default: 64MB How to configure:
Restart server for changes to take effect.

Buffer Capacity Examples

64MB buffer can hold:
Formula:

Reconnection Flow

Normal Reconnection

1

Client loses connection

Network drops, client closes, etc. Client notes last_received_seq = 1234.
2

Client reconnects

3

Server checks buffer

4

Server replays missed data

5

Session resumes normally

Client is now caught up to seq 1456, continues from there.
Visual timeline:

Buffer Overflow Scenario

What happens when buffer fills during disconnect:
1

Long disconnect begins

Client has seq 1000, buffer is empty.
2

Terminal produces data

Terminal generates output seq 1001-10000 (more than buffer can hold).
3

Buffer overflows

Buffer keeps seq 9936-10000 (newest 64MB), discards seq 1001-9935.
4

Client reconnects

5

Client receives gap notification

Client displays:
User experience:
  • Clear indication of data loss
  • Session still functional
  • New data appears normally
  • Gap is a one-time warning, not ongoing issue

Keepalive Mechanism

Why Keepalives?

Network devices (routers, firewalls) close “idle” TCP connections: Without keepalives, an idle terminal would disconnect within minutes.

How It Works

Default: 5-second keepalive interval
Keepalive logic:

Configuration

Server-side (ut.cfg):
Client-side:
  • Clients automatically respond to keepalives
  • No configuration needed
  • Keepalives are transparent to user

Keepalive Overhead

Network usage:
CPU usage:
  • Negligible (less than 0.1% per session)
  • Simple timestamp check and small packet send

Data Integrity

Checksums

Every packet includes a CRC32 checksum:
On receive:
  1. Calculate CRC32 of received data
  2. Compare with packet’s CRC32
  3. If mismatch: Discard packet, request retransmission
Corruption detection:
  • Bit flips during transmission
  • Memory corruption
  • Network equipment errors

Out-of-Order Delivery

TCP guarantees in-order delivery, so Undying Terminal assumes packets arrive in sequence order. However, on reconnection: Scenario: Client reconnects during active transmission
Solution: Client-side reordering buffer Client maintains a small reorder window (100 packets):
  1. Receive packet with seq 1238
  2. Expected seq 1236, so buffer 1238
  3. Receive 1236, deliver to terminal
  4. Receive 1237, deliver to terminal
  5. Check buffer: 1238 is now next, deliver it

Duplicate Suppression

Scenario: Retransmission due to network glitch
Solution: Sequence number tracking

Protocol Efficiency

Overhead Analysis

Per-packet overhead: Efficiency for different data sizes: Takeaway: Overhead is negligible for normal terminal use (hundreds of bytes per packet).

Compression

Current status: Not implemented Potential benefit: Trade-off:
  • CPU cost: ~5-10% overhead for compression/decompression
  • Latency cost: +1-2ms for compression
  • Bandwidth savings: 50-70% for text-heavy workloads
Could be added as optional feature for low-bandwidth scenarios.

Advanced Scenarios

Session Cloning

Can you clone a buffer to a new client? Currently not supported, but architecturally possible:
Use cases:
  • Training: Instructor shares live session with students
  • Debugging: Observer connects to user’s session mid-problem
  • Monitoring: Audit trail of session activity

Multi-Path Redundancy

Can you connect over multiple networks simultaneously? Not currently supported, but theoretically possible:
Requires protocol extension for path management.

Comparison to Other Recovery Protocols

Key difference:
  • Mosh: Predicts what you’ll type (works offline)
  • Undying Terminal: Buffers what actually happened (perfect replay)
  • SSH: Gives up on disconnect (no recovery)

Next Steps