Protocols
Wire protocols and packet formats
Protocols
Technical reference for OctoMY™'s wire protocols, packet formats, and communication layers.
Security Note
All established OctoMY sessions use AES-256-GCM encryption with RSA-2048 key exchange. The "multimagic" header (
OctoMYM!) allows rapid packet filtering before any crypto operations, providing efficient DoS protection while maintaining full encryption for authenticated traffic.
Protocol stack
Default ports
| Node Type | Port | Description |
|---|---|---|
| Zoo | 8123 | NAT traversal and discovery service |
| Agent | 8124 | Robot node |
| Remote | 8125 | Controller app |
| Hub | 8126 | Fleet management |
Packet structure
Basic packet format
Multimagic header
The first 8 bytes identify OctoMY™ packets:
const uint64_t MULTIMAGIC = 0x4F63746F4D594D21; // "OctoMYM!"
Purpose:
- Identify OctoMY™ packets vs. other UDP traffic
- Protocol version detection
- Early packet rejection for security
Session ID
8-byte unique session identifier:
struct SessionID {
uint32_t local_id; // Unique per node
uint32_t remote_id; // Assigned by peer
};
Sequence and ack numbers
| Field | Size | Description |
|---|---|---|
| Sequence | 2 bytes | Packet sequence (0-65535, wraps) |
| Ack | 2 bytes | Last received sequence |
Packet flags
| Bit | Flag | Description |
|---|---|---|
| 0 | SYN | Connection request |
| 1 | ACK | Acknowledgment |
| 2 | FIN | Connection close |
| 3 | RST | Reset connection |
| 4 | REL | Reliable delivery requested |
| 5 | ENC | Payload encrypted |
| 6 | CMP | Payload compressed |
| 7 | FRG | Fragmented packet |
Common flag combinations
| Flags | Meaning |
|---|---|
SYN |
Handshake initiation |
SYN|ACK |
Handshake response |
ACK |
Normal data with ack |
REL|ACK |
Reliable data |
FIN |
Graceful close |
RST |
Immediate close |
ENC|ACK |
Encrypted data |
Handshake protocol
Three-way handshake
Handshake packet content
SYN Packet:
| Field | Size | Description |
|---|---|---|
| Version | 2 | Protocol version |
| Node Type | 1 | Agent/Remote/Hub |
| Capabilities | 2 | Feature flags |
| Nonce | 32 | Random challenge |
| Public Key | 256 | RSA-2048 public key |
| Personality ID | 64 | Node identity hash |
SYN|ACK Packet:
| Field | Size | Description |
|---|---|---|
| Version | 2 | Protocol version |
| Node Type | 1 | Agent/Remote/Hub |
| Capabilities | 2 | Feature flags |
| Nonce | 32 | Random challenge |
| Public Key | 256 | RSA-2048 public key |
| Personality ID | 64 | Node identity hash |
| Session Key | 32 | AES-256 key (encrypted) |
Encryption
Key exchange
- Both nodes generate RSA-2048 key pairs
- Exchange public keys in SYN/SYN|ACK
- Derive shared AES-256 session key using:
- Both nonces
- ECDH key agreement
- HKDF key derivation
Encrypted payload
| Field | Size | Description |
|---|---|---|
| IV | 16 bytes | AES initialization |
| Ciphertext | Variable | AES-256-GCM |
| Auth Tag | 16 bytes | GCM authentication |
Reliability system
Reliable vs. Unreliable
| Mode | Use Case | Behavior |
|---|---|---|
| Unreliable | Sensors, joystick | Fire and forget |
| Reliable | Commands, blobs | Retransmit until ack |
Reliable delivery
Retransmission
| Parameter | Default | Description |
|---|---|---|
| Initial timeout | 100ms | First retry delay |
| Max retries | 5 | Before declaring failure |
| Backoff factor | 2x | Exponential backoff |
| Max timeout | 5000ms | Maximum retry delay |
Flow control
Sliding window
Congestion control
| State | Behavior |
|---|---|
| Slow Start | Double window each RTT |
| Congestion Avoidance | Linear increase |
| Fast Recovery | Halve window on loss |
Discovery protocol
Multicast discovery
Discovery packet
| Field | Size | Description |
|---|---|---|
| Magic | 8 | "OctoMYD!" |
| Version | 2 | Protocol version |
| Node Type | 1 | Agent/Remote/Hub |
| Flags | 1 | Request/Response |
| Personality | 64 | Node identity |
| Name | 32 | Display name |
| Addresses | Var | IP:Port list |
NAT traversal
Hole punching
Punch protocol
- Both nodes register with Zoo server
- Zoo provides peer's external address
- Both send simultaneous UDP packets
- NAT creates mapping, allowing responses
- Direct communication established
Blob transfer protocol
Large data transfer
For data larger than MTU (~1400 bytes):
Blob Header:
| Field | Size | Description |
|---|---|---|
| Blob ID | 4 bytes | Unique identifier |
| Total Size | 4 bytes | Total blob size |
| Chunk Count | 2 bytes | Number of chunks |
| Chunk Size | 2 bytes | Size per chunk |
Chunk Packet:
| Field | Size | Description |
|---|---|---|
| Blob ID | 4 bytes | Unique identifier |
| Chunk Index | 2 bytes | Chunk sequence number |
| Flags | 1 byte | FIRST, LAST, etc. |
| Data | Variable | Up to chunk size |
Blob reassembly
Courier protocol
Courier ID allocation
| ID Range | Purpose |
|---|---|
| 0-15 | System couriers |
| 16-127 | Built-in couriers |
| 128-255 | Custom couriers |
Standard courier IDs
| ID | Courier | Description |
|---|---|---|
| 0 | System | Handshake, keepalive |
| 1 | Discovery | Peer discovery |
| 2 | AgentState | State synchronization |
| 3 | Sensors | Sensor data stream |
| 4 | Blob | Large data transfer |
| 5-15 | Reserved | Future system use |
Heartbeat and keepalive
Keepalive mechanism
Ping/pong packet
| Field | Size | Description |
|---|---|---|
| Type | 1 | PING (0) / PONG (1) |
| Timestamp | 8 | Sender time (ms) |
| RTT | 4 | Last measured RTT |
Error handling
Protocol errors
| Error | Code | Response |
|---|---|---|
| Invalid magic | 0x01 | Drop packet |
| Version mismatch | 0x02 | Send version error |
| Invalid session | 0x03 | Send RST |
| Decryption failed | 0x04 | Drop packet |
| CRC mismatch | 0x05 | Drop packet |
| Unknown courier | 0x06 | Drop packet |
Connection errors
| Error | Detection | Recovery |
|---|---|---|
| Packet loss | No ACK | Retransmit |
| Connection lost | Keepalive timeout | Reconnect |
| NAT timeout | Hole closed | Re-punch |
Security considerations
Protections
| Threat | Protection |
|---|---|
| Eavesdropping | AES-256-GCM encryption |
| Replay attacks | Sequence numbers, nonces |
| Impersonation | RSA key verification |
| DoS | Rate limiting, multimagic filter |
| MitM | Certificate pinning (optional) |
Best practices
- Regenerate session keys periodically
- Use secure random for nonces
- Validate all packet fields
- Rate limit connection attempts