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:- 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 clientlast_acked_seq: Last sequence number client confirmed receiving
last_received_seq: Last sequence number received from terminalnext_expected_seq: Next sequence number expected
Recovery Buffer
Buffer Architecture
The server maintains a circular buffer for each terminal session:- 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:
Buffer Capacity Examples
64MB buffer can hold: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.
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:
- 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 intervalConfiguration
Server-side (ut.cfg):- Clients automatically respond to keepalives
- No configuration needed
- Keepalives are transparent to user
Keepalive Overhead
Network usage:- Negligible (less than 0.1% per session)
- Simple timestamp check and small packet send
Data Integrity
Checksums
Every packet includes a CRC32 checksum:- Calculate CRC32 of received data
- Compare with packet’s CRC32
- If mismatch: Discard packet, request retransmission
- 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- Receive packet with seq 1238
- Expected seq 1236, so buffer 1238
- Receive 1236, deliver to terminal
- Receive 1237, deliver to terminal
- Check buffer: 1238 is now next, deliver it
Duplicate Suppression
Scenario: Retransmission due to network glitchProtocol 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
Advanced Scenarios
Session Cloning
Can you clone a buffer to a new client? Currently not supported, but architecturally possible:- 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: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
- Understand Persistent Sessions for context
- Learn about Encryption for securing recovery data
- Review Architecture Overview for system design