lsquic_hq.h revision 5392f7a3
15392f7a3SLiteSpeed Tech/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
25392f7a3SLiteSpeed Tech/*
35392f7a3SLiteSpeed Tech * lsquic_hq.h -- HTTP over QUIC (HQ) types
45392f7a3SLiteSpeed Tech */
55392f7a3SLiteSpeed Tech
65392f7a3SLiteSpeed Tech#ifndef LSQUIC_HQ_H
75392f7a3SLiteSpeed Tech#define LSQUIC_HQ_H 1
85392f7a3SLiteSpeed Tech
95392f7a3SLiteSpeed Tech/* [draft-ietf-quic-http-15] Section 4 */
105392f7a3SLiteSpeed Techenum hq_frame_type
115392f7a3SLiteSpeed Tech{
125392f7a3SLiteSpeed Tech    HQFT_DATA           = 0,
135392f7a3SLiteSpeed Tech    HQFT_HEADERS        = 1,
145392f7a3SLiteSpeed Tech    HQFT_PRIORITY       = 2,
155392f7a3SLiteSpeed Tech    HQFT_CANCEL_PUSH    = 3,
165392f7a3SLiteSpeed Tech    HQFT_SETTINGS       = 4,
175392f7a3SLiteSpeed Tech    HQFT_PUSH_PROMISE   = 5,
185392f7a3SLiteSpeed Tech    HQFT_GOAWAY         = 7,
195392f7a3SLiteSpeed Tech    HQFT_MAX_PUSH_ID    = 0xD,
205392f7a3SLiteSpeed Tech    HQFT_DUPLICATE_PUSH = 0xE,
215392f7a3SLiteSpeed Tech    /* This frame is made up and its type is never written to stream.
225392f7a3SLiteSpeed Tech     * Nevertheless, just to be on the safe side, give it a value as
235392f7a3SLiteSpeed Tech     * described in [draft-ietf-quic-http-20] Section 4.2.10.
245392f7a3SLiteSpeed Tech     */
255392f7a3SLiteSpeed Tech    HQFT_PUSH_PREAMBLE  = 0x1F * 3 + 0x21,
265392f7a3SLiteSpeed Tech};
275392f7a3SLiteSpeed Tech
285392f7a3SLiteSpeed Tech
295392f7a3SLiteSpeed Techenum h3_prio_el_type
305392f7a3SLiteSpeed Tech{
315392f7a3SLiteSpeed Tech    H3PET_REQ_STREAM    = 0,
325392f7a3SLiteSpeed Tech    H3PET_PUSH_STREAM   = 1,
335392f7a3SLiteSpeed Tech    H3PET_PLACEHOLDER   = 2,
345392f7a3SLiteSpeed Tech    H3PET_CUR_STREAM    = 3,
355392f7a3SLiteSpeed Tech};
365392f7a3SLiteSpeed Tech
375392f7a3SLiteSpeed Tech
385392f7a3SLiteSpeed Techenum h3_dep_el_type
395392f7a3SLiteSpeed Tech{
405392f7a3SLiteSpeed Tech    H3DET_REQ_STREAM    = 0,
415392f7a3SLiteSpeed Tech    H3DET_PUSH_STREAM   = 1,
425392f7a3SLiteSpeed Tech    H3DET_PLACEHOLDER   = 2,
435392f7a3SLiteSpeed Tech    H3DET_ROOT          = 3,
445392f7a3SLiteSpeed Tech};
455392f7a3SLiteSpeed Tech
465392f7a3SLiteSpeed Tech
475392f7a3SLiteSpeed Tech#define HQ_PT_SHIFT 6
485392f7a3SLiteSpeed Tech#define HQ_DT_SHIFT 4
495392f7a3SLiteSpeed Tech
505392f7a3SLiteSpeed Tech
515392f7a3SLiteSpeed Techenum hq_setting_id
525392f7a3SLiteSpeed Tech{
535392f7a3SLiteSpeed Tech    HQSID_QPACK_MAX_TABLE_CAPACITY  = 1,
545392f7a3SLiteSpeed Tech    HQSID_MAX_HEADER_LIST_SIZE      = 6,
555392f7a3SLiteSpeed Tech    HQSID_QPACK_BLOCKED_STREAMS     = 7,
565392f7a3SLiteSpeed Tech    HQSID_NUM_PLACEHOLDERS          = 9,
575392f7a3SLiteSpeed Tech};
585392f7a3SLiteSpeed Tech
595392f7a3SLiteSpeed Tech/* As of 12/18/2018: */
605392f7a3SLiteSpeed Tech#define HQ_DF_QPACK_MAX_TABLE_CAPACITY 0
615392f7a3SLiteSpeed Tech#define HQ_DF_NUM_PLACEHOLDERS 0
625392f7a3SLiteSpeed Tech#define HQ_DF_MAX_HEADER_LIST_SIZE 0
635392f7a3SLiteSpeed Tech#define HQ_DF_QPACK_BLOCKED_STREAMS 0
645392f7a3SLiteSpeed Tech
655392f7a3SLiteSpeed Techstruct hq_priority
665392f7a3SLiteSpeed Tech{
675392f7a3SLiteSpeed Tech    lsquic_stream_id_t      hqp_prio_id;
685392f7a3SLiteSpeed Tech    lsquic_stream_id_t      hqp_dep_id;
695392f7a3SLiteSpeed Tech    enum h3_prio_el_type    hqp_prio_type:8;
705392f7a3SLiteSpeed Tech    enum h3_dep_el_type     hqp_dep_type:8;
715392f7a3SLiteSpeed Tech    uint8_t                 hqp_weight;
725392f7a3SLiteSpeed Tech};
735392f7a3SLiteSpeed Tech
745392f7a3SLiteSpeed Tech#define HQP_WEIGHT(p) ((p)->hqp_weight + 1)
755392f7a3SLiteSpeed Tech
765392f7a3SLiteSpeed Tech/* [draft-ietf-quic-http-19] Section 10.6,
775392f7a3SLiteSpeed Tech * [draft-ietf-quic-qpack-07] Section 8.2
785392f7a3SLiteSpeed Tech */
795392f7a3SLiteSpeed Techenum hq_uni_stream_type
805392f7a3SLiteSpeed Tech{
815392f7a3SLiteSpeed Tech    HQUST_CONTROL   = 0,
825392f7a3SLiteSpeed Tech    HQUST_PUSH      = 1,
835392f7a3SLiteSpeed Tech    HQUST_QPACK_ENC = 2,
845392f7a3SLiteSpeed Tech    HQUST_QPACK_DEC = 3,
855392f7a3SLiteSpeed Tech};
865392f7a3SLiteSpeed Tech
875392f7a3SLiteSpeed Techextern const char *const lsquic_h3det2str[];
885392f7a3SLiteSpeed Techextern const char *const lsquic_h3pet2str[];
895392f7a3SLiteSpeed Tech
905392f7a3SLiteSpeed Tech/* [draft-ietf-quic-http-22] Section 8.1 and
915392f7a3SLiteSpeed Tech * [draft-ietf-quic-qpack-08], Section 8.3
925392f7a3SLiteSpeed Tech */
935392f7a3SLiteSpeed Techenum http_error_code
945392f7a3SLiteSpeed Tech{
955392f7a3SLiteSpeed Tech    HEC_NO_ERROR                 =  0x00,
965392f7a3SLiteSpeed Tech    HEC_GENERAL_PROTOCOL_ERROR   =  0x01,
975392f7a3SLiteSpeed Tech    /* Error code 0x2 is reserved and has no meaning */
985392f7a3SLiteSpeed Tech    HEC_INTERNAL_ERROR           =  0x03,
995392f7a3SLiteSpeed Tech    /* Error code 0x4 is reserved and has no meaning */
1005392f7a3SLiteSpeed Tech    HEC_REQUEST_CANCELLED        =  0x05,
1015392f7a3SLiteSpeed Tech    HEC_INCOMPLETE_REQUEST       =  0x06,
1025392f7a3SLiteSpeed Tech    HEC_CONNECT_ERROR            =  0x07,
1035392f7a3SLiteSpeed Tech    HEC_EXCESSIVE_LOAD           =  0x08,
1045392f7a3SLiteSpeed Tech    HEC_VERSION_FALLBACK         =  0x09,
1055392f7a3SLiteSpeed Tech    HEC_WRONG_STREAM             =  0x0A,
1065392f7a3SLiteSpeed Tech    HEC_ID_ERROR                 =  0x0B,
1075392f7a3SLiteSpeed Tech    /* Error code 0xC is reserved and has no meaning */
1085392f7a3SLiteSpeed Tech    HEC_STREAM_CREATION_ERROR    =  0x0D,
1095392f7a3SLiteSpeed Tech    /* Error code 0xE is reserved and has no meaning */
1105392f7a3SLiteSpeed Tech    HEC_CLOSED_CRITICAL_STREAM   =  0x0F,
1115392f7a3SLiteSpeed Tech    /* Error code 0x10 is reserved and has no meaning */
1125392f7a3SLiteSpeed Tech    HEC_EARLY_RESPONSE           =  0x0011,
1135392f7a3SLiteSpeed Tech    HEC_MISSING_SETTINGS         =  0x0012,
1145392f7a3SLiteSpeed Tech    HEC_UNEXPECTED_FRAME         =  0x0013,
1155392f7a3SLiteSpeed Tech    HEC_REQUEST_REJECTED         =  0x14,
1165392f7a3SLiteSpeed Tech    HEC_SETTINGS_ERROR           =  0x00FF,
1175392f7a3SLiteSpeed Tech    HEC_MALFORMED_FRAME          =  0x0100,    /* add frame type */
1185392f7a3SLiteSpeed Tech    HEC_QPACK_DECOMPRESSION_FAILED  = 0x200,
1195392f7a3SLiteSpeed Tech    HEC_QPACK_ENCODER_STREAM_ERROR  = 0x201,
1205392f7a3SLiteSpeed Tech    HEC_QPACK_DECODER_STREAM_ERROR  = 0x202,
1215392f7a3SLiteSpeed Tech};
1225392f7a3SLiteSpeed Tech
1235392f7a3SLiteSpeed Tech
1245392f7a3SLiteSpeed Techstruct h3_prio_frame_read_state
1255392f7a3SLiteSpeed Tech{
1265392f7a3SLiteSpeed Tech    struct varint_read_state    h3pfrs_vint;
1275392f7a3SLiteSpeed Tech    struct hq_priority          h3pfrs_prio;
1285392f7a3SLiteSpeed Tech    enum {
1295392f7a3SLiteSpeed Tech        H3PFRS_STATE_TYPE = 0,
1305392f7a3SLiteSpeed Tech        H3PFRS_STATE_VINT_BEGIN,
1315392f7a3SLiteSpeed Tech        H3PFRS_STATE_VINT_CONTINUE,
1325392f7a3SLiteSpeed Tech        H3PFRS_STATE_WEIGHT,
1335392f7a3SLiteSpeed Tech    }                           h3pfrs_state;
1345392f7a3SLiteSpeed Tech    enum {
1355392f7a3SLiteSpeed Tech        H3PFRS_FLAG_HAVE_PRIO_ID = 1 << 0,
1365392f7a3SLiteSpeed Tech    }                           h3pfrs_flags;
1375392f7a3SLiteSpeed Tech};
1385392f7a3SLiteSpeed Tech
1395392f7a3SLiteSpeed Tech
1405392f7a3SLiteSpeed Techenum h3_prio_frame_read_status
1415392f7a3SLiteSpeed Tech{
1425392f7a3SLiteSpeed Tech    H3PFR_STATUS_DONE,
1435392f7a3SLiteSpeed Tech    H3PFR_STATUS_NEED,
1445392f7a3SLiteSpeed Tech};
1455392f7a3SLiteSpeed Tech
1465392f7a3SLiteSpeed Tech
1475392f7a3SLiteSpeed Tech/* When first called, h3pfrs_state should be set to 0 */
1485392f7a3SLiteSpeed Techenum h3_prio_frame_read_status
1495392f7a3SLiteSpeed Techlsquic_h3_prio_frame_read (const unsigned char **, size_t,
1505392f7a3SLiteSpeed Tech                                            struct h3_prio_frame_read_state *);
1515392f7a3SLiteSpeed Tech
1525392f7a3SLiteSpeed Tech#endif
153