VSTP Protocol Specification

v0.2.1

Protocol Overview

VSTP (Vishu's Secure Transfer Protocol) is a binary, application-layer protocol designed for secure and efficient data transfer. It provides a clean abstraction over TCP and UDP transports with built-in security features.

šŸŽÆ Design Goals

  • • Security: Built-in TLS 1.3 support for TCP
  • • Performance: Optimized for both TCP and UDP
  • • Simplicity: Easy to implement and use
  • • Extensibility: Custom headers and payload types
  • • Reliability: Built-in error handling and acknowledgments

Wire Format

VSTP frames have a fixed header structure followed by variable-length header and payload sections:

FieldSizeDescription
MAGIC2 bytesProtocol identifier (0x56 0x54)
VER1 byteProtocol version (0x01)
TYPE1 byteFrame type (see Frame Types)
FLAGS1 byteBit flags (see Flags)
HDR_LEN2 bytesHeader section length (little-endian)
PAY_LEN4 bytesPayload length (big-endian)
HEADERSVariableHeader section (see Headers)
PAYLOADVariablePayload data
CRC324 bytesChecksum (optional)

šŸ“Š Frame Layout

ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”
│ MAGIC   │ VER │ TYPE │ FLAGS │ HDR_LEN │ PAY_LEN │ HEADERS │ PAYLOAD │ CRC32 │
│ 2 bytes │ 1B  │ 1B   │ 1B    │ 2B LE   │ 4B BE   │ var     │ var     │ 4B    │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”“ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

Frame Types

VSTP defines several frame types for different purposes:

TypeNameDirectionDescription
0x01HELLOClient → ServerStart of session
0x02WELCOMEServer → ClientServer acceptance
0x03DATABothApplication data
0x04PINGBothKeepalive request
0x05PONGBothKeepalive response
0x06BYEBothGraceful close
0x07ACKBothAcknowledgement
0x08ERRBothError frame

Flags

VSTP uses bit flags to indicate frame properties:

BitFlagDescription
0x01REQ_ACKRequest acknowledgment
0x02CRCInclude CRC32 checksum
0x04FRAGFragmented frame
0x08COMPCompressed payload

Headers

VSTP supports custom headers in a simple key-value format:

// Header format
struct Header {
    key_len: u16,        // Key length (little-endian)
    key: [u8],           // Key bytes
    value_len: u16,      // Value length (little-endian)
    value: [u8],         // Value bytes
}

// Example headers
"content-type" -> "application/json"
"session-id" -> "abc123"
"priority" -> "high"

Security

VSTP provides security through multiple mechanisms:

šŸ”’ TCP Security

  • • TLS 1.3 encryption
  • • Perfect forward secrecy
  • • Certificate validation
  • • Secure key exchange

šŸ›”ļø UDP Security

  • • Application-level encryption
  • • Message authentication
  • • Replay protection
  • • Integrity checking

Transport Modes

VSTP supports both TCP and UDP transports with different characteristics:

🌐 TCP Mode

  • • Reliable delivery
  • • Ordered messages
  • • Built-in TLS 1.3
  • • Connection-oriented
  • • Automatic retransmission

⚔ UDP Mode

  • • Low latency
  • • High throughput
  • • Connectionless
  • • Fragmentation support
  • • Custom reliability

Implementation Notes

  • • All multi-byte integers use little-endian byte order except PAY_LEN (big-endian)
  • • Frame parsing should validate MAGIC and VER fields first
  • • CRC32 is calculated over HEADERS + PAYLOAD when CRC flag is set
  • • Fragmented frames should be reassembled before processing
  • • Timeouts should be implemented for all network operations