LCOV - code coverage report
Current view: top level - waltz/h2 - fd_h2_proto.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 34 35 97.1 %
Date: 2025-07-01 05:00:49 Functions: 7 44 15.9 %

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_h2_fd_h2_proto
       2             : #define HEADER_fd_src_waltz_h2_fd_h2_proto
       3             : 
       4             : /* fd_h2_proto.h contains constants and data structures taken from
       5             :    HTTP/2 specs. */
       6             : 
       7             : #include "fd_h2_base.h"
       8             : 
       9             : /* FD_H2_FRAME_TYPE_* give HTTP/2 frame IDs.
      10             :    https://www.iana.org/assignments/http2-parameters/http2-parameters.xhtml#frame-type */
      11             : 
      12          57 : #define FD_H2_FRAME_TYPE_DATA            ((uchar)0x00)
      13          39 : #define FD_H2_FRAME_TYPE_HEADERS         ((uchar)0x01)
      14           3 : #define FD_H2_FRAME_TYPE_PRIORITY        ((uchar)0x02)
      15          12 : #define FD_H2_FRAME_TYPE_RST_STREAM      ((uchar)0x03)
      16          24 : #define FD_H2_FRAME_TYPE_SETTINGS        ((uchar)0x04)
      17          21 : #define FD_H2_FRAME_TYPE_PUSH_PROMISE    ((uchar)0x05)
      18          15 : #define FD_H2_FRAME_TYPE_PING            ((uchar)0x06)
      19           3 : #define FD_H2_FRAME_TYPE_GOAWAY          ((uchar)0x07)
      20           6 : #define FD_H2_FRAME_TYPE_WINDOW_UPDATE   ((uchar)0x08)
      21           3 : #define FD_H2_FRAME_TYPE_CONTINUATION    ((uchar)0x09)
      22           3 : #define FD_H2_FRAME_TYPE_ALTSVC          ((uchar)0x0a)
      23           3 : #define FD_H2_FRAME_TYPE_ORIGIN          ((uchar)0x0c)
      24           3 : #define FD_H2_FRAME_TYPE_PRIORITY_UPDATE ((uchar)0x10)
      25             : 
      26             : /* fd_h2_frame_{length,type} pack/unpack the typlen field as found in a
      27             :    frame header. */
      28             : 
      29             : FD_FN_CONST static inline uchar
      30          18 : fd_h2_frame_type( uint typlen ) {
      31          18 :   return (uchar)( typlen>>24 ); /* in [0,2^8) */
      32          18 : }
      33             : 
      34             : FD_FN_CONST static inline uint
      35          18 : fd_h2_frame_length( uint typlen ) {
      36          18 :   return fd_uint_bswap( typlen<<8 ) & 0xFFFFFF; /* in [0,2^24) */
      37          18 : }
      38             : 
      39             : /* fd_h2_frame_typlen packs the typlen field for use in a frame header. */
      40             : 
      41             : FD_FN_CONST static inline uint
      42             : fd_h2_frame_typlen( ulong type,      /* in [0,2^8) */
      43          36 :                     ulong length ) { /* in [0,2^24) */
      44          36 :   return (fd_uint_bswap( (uint)length )>>8) | ((uint)type<<24);
      45          36 : }
      46             : 
      47             : FD_FN_CONST static inline uint
      48          18 : fd_h2_frame_stream_id( uint r_stream_id ) {
      49          18 :   return fd_uint_bswap( r_stream_id ) & 0x7fffffffu;
      50          18 : }
      51             : 
      52             : /* fd_h2_frame_hdr_t matches the encoding of a HTTP/2 frame header.
      53             :    https://www.rfc-editor.org/rfc/rfc9113.html#section-4.1 */
      54             : 
      55             : struct __attribute__((packed)) fd_h2_frame_hdr {
      56             :   uint  typlen;
      57             :   uchar flags;
      58             :   uint  r_stream_id;
      59             : };
      60             : 
      61             : typedef struct fd_h2_frame_hdr fd_h2_frame_hdr_t;
      62             : 
      63          21 : #define FD_H2_FLAG_ACK         ((uchar)0x01)
      64          33 : #define FD_H2_FLAG_END_STREAM  ((uchar)0x01)
      65          60 : #define FD_H2_FLAG_END_HEADERS ((uchar)0x04)
      66           0 : #define FD_H2_FLAG_PADDED      ((uchar)0x08)
      67             : #define FD_H2_FLAG_PRIORITY    ((uchar)0x20)
      68             : 
      69             : 
      70             : /* fd_h2_priority_t matches the encoding of a PRIORITY frame. */
      71             : 
      72             : struct __attribute__((packed)) fd_h2_priority {
      73             :   fd_h2_frame_hdr_t hdr;
      74             :   uint r_stream_dep;
      75             :   uchar weight;
      76             : };
      77             : 
      78             : typedef struct fd_h2_priority fd_h2_priority_t;
      79             : 
      80             : 
      81             : /* A SETTINGS frame contains a series of fd_h2_setting_t. */
      82             : 
      83             : struct __attribute__((packed)) fd_h2_setting {
      84             :   ushort id;
      85             :   uint   value;
      86             : };
      87             : 
      88             : typedef struct fd_h2_setting fd_h2_setting_t;
      89             : 
      90             : /* FD_H2_SETTINGS_* give HTTP/2 setting IDs.
      91             :    https://www.iana.org/assignments/http2-parameters/http2-parameters.xhtml#settings
      92             :    https://www.rfc-editor.org/rfc/rfc9113.html#section-6.5.2 */
      93             : 
      94           6 : #define FD_H2_SETTINGS_HEADER_TABLE_SIZE      ((ushort)0x01)
      95          12 : #define FD_H2_SETTINGS_ENABLE_PUSH            ((ushort)0x02)
      96          12 : #define FD_H2_SETTINGS_MAX_CONCURRENT_STREAMS ((ushort)0x03)
      97          12 : #define FD_H2_SETTINGS_INITIAL_WINDOW_SIZE    ((ushort)0x04)
      98          12 : #define FD_H2_SETTINGS_MAX_FRAME_SIZE         ((ushort)0x05)
      99          12 : #define FD_H2_SETTINGS_MAX_HEADER_LIST_SIZE   ((ushort)0x06)
     100             : 
     101             : 
     102             : /* fd_h2_ping_t matches the encoding of a PING frame.
     103             :    https://www.rfc-editor.org/rfc/rfc9113.html#name-ping
     104             :    Valid flags: ACK */
     105             : 
     106             : struct __attribute__((packed)) fd_h2_ping {
     107             :   fd_h2_frame_hdr_t hdr;
     108             : 
     109             :   ulong payload;
     110             : };
     111             : 
     112             : typedef struct fd_h2_ping fd_h2_ping_t;
     113             : 
     114             : 
     115             : /* fd_h2_goaway_t matches the encoding of a GOAWAY frame.
     116             :    https://www.rfc-editor.org/rfc/rfc9113.html#name-goaway */
     117             : 
     118             : struct __attribute__((packed)) fd_h2_goaway {
     119             :   fd_h2_frame_hdr_t hdr;
     120             : 
     121             :   uint last_stream_id;
     122             :   uint error_code;
     123             :   /* variable length debug data follows ... */
     124             : };
     125             : 
     126             : typedef struct fd_h2_goaway fd_h2_goaway_t;
     127             : 
     128             : 
     129             : /* fd_h2_window_update_t matches the encoding of a WINDOW_UPDATE frame.
     130             :    https://www.rfc-editor.org/rfc/rfc9113.html#name-window_update */
     131             : 
     132             : struct __attribute__((packed)) fd_h2_window_update {
     133             :   fd_h2_frame_hdr_t hdr;
     134             : 
     135             :   uint increment;
     136             : };
     137             : 
     138             : typedef struct fd_h2_window_update fd_h2_window_update_t;
     139             : 
     140             : 
     141             : /* fd_h2_rst_stream_t matches the encoding of a RST_STREAM frame.
     142             :    https://www.rfc-editor.org/rfc/rfc9113.html#name-rst_stream */
     143             : 
     144             : struct __attribute__((packed)) fd_h2_rst_stream {
     145             :   fd_h2_frame_hdr_t hdr;
     146             : 
     147             :   uint error_code;
     148             : };
     149             : 
     150             : typedef struct fd_h2_rst_stream fd_h2_rst_stream_t;
     151             : 
     152             : 
     153             : FD_PROTOTYPES_BEGIN
     154             : 
     155             : /* fd_h2_frame_name returns a static-lifetime uppercase cstr with the
     156             :    name of a HTTP/2 frame. */
     157             : 
     158             : FD_FN_CONST char const *
     159             : fd_h2_frame_name( uint frame_id );
     160             : 
     161             : /* fd_h2_setting_name returns a static-lifetime uppercase cstr with the
     162             :    name of a HTTP/2 setting. */
     163             : 
     164             : FD_FN_CONST char const *
     165             : fd_h2_setting_name( uint setting_id );
     166             : 
     167             : FD_PROTOTYPES_END
     168             : 
     169             : #endif /* HEADER_fd_src_waltz_h2_fd_h2_proto */

Generated by: LCOV version 1.14