packet definitions
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// packet.h
|
||||
// On-the-wire packet headers, one packet per datagram
|
||||
// bravais_packet_t is a transport-neutral view.
|
||||
// Raw encoding (ints are big-endian):
|
||||
//
|
||||
// Handshake packet (INIT, RESPONSE), 18-byte header:
|
||||
// type (1) | version (1) | dcid (8) | scid (8) | CRYPTO frames, in the clear
|
||||
//
|
||||
// Data packet (DATA), 17-byte header:
|
||||
// type (1) | dcid (8) | packet number (8) | AEAD(frames) | tag (16)
|
||||
//
|
||||
|
||||
#ifndef BRAVAIS_PACKET_H
|
||||
#define BRAVAIS_PACKET_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "bravais.h"
|
||||
#include "bravais_internal.h"
|
||||
|
||||
#define BRAVAIS_PACKET_VERSION 1
|
||||
|
||||
#define BRAVAIS_PACKET_HANDSHAKE_HEADER_LENGTH (1 + 1 + BRAVAIS_CID_LENGTH + BRAVAIS_CID_LENGTH) // 18
|
||||
#define BRAVAIS_PACKET_DATA_HEADER_LENGTH (1 + BRAVAIS_CID_LENGTH + 8) // 17
|
||||
|
||||
typedef enum {
|
||||
BRAVAIS_PACKET_TYPE_INVALID = 0,
|
||||
BRAVAIS_PACKET_TYPE_INIT = 1,
|
||||
BRAVAIS_PACKET_TYPE_RESPONSE = 2,
|
||||
BRAVAIS_PACKET_TYPE_DATA = 3
|
||||
} bravais_packet_type_t;
|
||||
|
||||
typedef struct {
|
||||
bravais_packet_type_t type;
|
||||
uint8_t version; // Handshake packets only
|
||||
uint8_t dcid[BRAVAIS_CID_LENGTH];
|
||||
uint8_t scid[BRAVAIS_CID_LENGTH]; // Handshake packets only
|
||||
uint64_t packetNumber; // Data packets only
|
||||
const uint8_t* header; // The raw header bytes - AEAD associated data
|
||||
size_t headerLen;
|
||||
const uint8_t* payload; // Borrows from the datagram
|
||||
size_t payloadLen;
|
||||
} bravais_packet_t;
|
||||
|
||||
bool bravais_packet_type_is_handshake(bravais_packet_type_t type); // true for INIT and RESPONSE
|
||||
size_t bravais_packet_header_length_raw(bravais_packet_type_t type); // 0 is an invalid type
|
||||
bravais_result_t bravais_packet_parse_raw(const uint8_t* data, size_t dataLen, bravais_packet_t* outPacket); // zeroes on failure
|
||||
bravais_result_t bravais_packet_write_header_raw(const bravais_packet_t* packet, uint8_t* out, size_t outCap, size_t* outLen);
|
||||
|
||||
#endif // BRAVAIS_PACKET_H
|
||||
Reference in New Issue
Block a user