Files
godoxy-yusing/agent/pkg/agent/stream/PROTOCOL.md
yusing 63f96b8d76 refactor(agent/stream): update header size calculation and field types
- Adjusted headerSize calculation to reflect the correct size based on field definitions.
- Changed HostLength and PortLength types from uint8 to byte.
- Updated PROTOCOL.md to reflect the new header size and structure.
2026-01-07 22:33:24 +08:00

1.4 KiB

Stream proxy protocol

This package implements a small header-based handshake that allows an authenticated client to request forwarding to a (host, port) destination.

Header

The on-wire header is a fixed-size binary blob:

  • Version (8 bytes)
  • HostLength (1 byte)
  • Host (255 bytes, NUL padded)
  • PortLength (1 byte)
  • Port (5 bytes, NUL padded)
  • Checksum (4 bytes, big-endian CRC32)

Total: headerSize = 8 + 1 + 255 + 1 + 5 + 4 = 273 bytes.

Checksum is crc32.ChecksumIEEE(header[0:headerSize-4]).

See StreamRequestHeader.

TCP behavior

  1. Client establishes a TLS connection to the stream server.
  2. Client sends exactly one header as a handshake.
  3. After the handshake, both sides proxy raw TCP bytes between client and destination.

Server reads the header using io.ReadFull to avoid dropping bytes.

See NewTCPClient() and (*TCPServer).redirect().

UDP-over-DTLS behavior

  1. Client establishes a DTLS connection to the stream server.
  2. Client sends exactly one header as a handshake.
  3. After the handshake, both sides proxy raw UDP datagrams:
    • client → destination: DTLS payload is written to destination UDPConn
    • destination → client: destination payload is written back to the DTLS connection

Responses do not include a header.

See NewUDPClient() and (*UDPServer).handleDTLSConnection().