Crate vstp

Crate vstp 

Source
Expand description

§VSTP - Vishu’s Secure Transfer Protocol

A general-purpose, binary, extensible application-layer protocol designed to be:

  • Secure by default on TCP (TLS 1.3)
  • Fast on UDP (no TLS initially)
  • Minimal but extensible with binary headers
  • Easy to implement across languages

§Quick Start

use vstp::easy::{VstpClient, VstpServer};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize)]
struct Message {
    content: String,
}

// Start a TCP server
let server = VstpServer::bind_tcp("127.0.0.1:8080").await?;
tokio::spawn(async move {
    server.serve(|msg: Message| async move {
        println!("Received: {}", msg.content);
        Ok(msg) // Echo the message back
    }).await
});

// Connect a client
let mut client = VstpClient::connect_tcp("127.0.0.1:8080").await?;

// Send a message
let msg = Message { content: "Hello, VSTP!".to_string() };
client.send(msg).await?;

// Receive the response
let response: Message = client.receive().await?;
println!("Got response: {}", response.content);

§Protocol Overview

VSTP frames have the following wire format:

  • MAGIC (2B): Protocol identifier
  • VER (1B): Protocol version
  • TYPE (1B): Message type
  • FLAGS (1B): Bit flags
  • HDR_LEN (2B LE): Header section length (little-endian)
  • PAY_LEN (4B BE): Payload length (big-endian)
  • HEADERS: Variable-length header section
  • PAYLOAD: Variable-length payload section
  • CRC32: 32-bit checksum

Where:

  • MAGIC: 0x56 0x54 (“VT”) to identify VSTP
  • VER: Protocol version (0x01 for v1)
  • TYPE: Message type (Hello, Welcome, Data, etc.)
  • FLAGS: Bit flags (REQ_ACK, CRC, FRAG, COMP)
  • HDR_LEN: Little-endian header section length
  • PAY_LEN: Big-endian payload length
  • HEADERS: Concatenated binary K/V entries
  • PAYLOAD: Raw bytes (UTF-8 text, JSON, binary, etc.)
  • CHECKSUM: CRC16-IBM over HEADERS|PAYLOAD (optional)

§Transport Modes

  • TCP mode: Reliable + encrypted (TLS 1.3 via rustls)
  • UDP mode: Connectionless + fast (no TLS in v0.1)

§Message Types

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

Re-exports§

pub use types::Flags;
pub use types::Frame;
pub use types::FrameType;
pub use types::Header;
pub use types::SessionId;
pub use types::VstpError;
pub use types::VSTP_MAGIC;
pub use types::VSTP_VERSION;
pub use codec::VstpFrameCodec;
pub use frame::encode_frame;
pub use frame::try_decode_frame;
pub use tcp::VstpTcpClient;
pub use tcp::VstpTcpServer;
pub use udp::VstpUdpClient;
pub use udp::VstpUdpServer;
pub use easy::VstpClient;
pub use easy::VstpServer;

Modules§

codec
easy
frame
tcp
TCP transport implementation for VSTP
types
udp
UDP transport implementation for VSTP