LCOV - code coverage report
Current view: top level - waltz/quic - fd_quic.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 4 5 80.0 %
Date: 2025-01-08 12:08:44 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_waltz_quic_fd_quic_h
       2             : #define HEADER_fd_src_waltz_quic_fd_quic_h
       3             : 
       4             : /* fd_quic_t is a partial implementation of QUIC -- an encrypted,
       5             :    multiplexing transport layer network protocol.
       6             : 
       7             :    For now, IPv4 over Ethernet (EN10MB) flows are supported.
       8             : 
       9             :    This API is non-blocking and single-threaded.  Any requests to the
      10             :    peer (such as "open a connection") are queued and processed on RX
      11             :    or service call.  The user is notified of events via callbacks.
      12             :    The user must further ensure that RX (via fd_aio_t) is dispatched
      13             :    only from the thread with the active join to the target fd_quic_t.
      14             : 
      15             :    Scaling is achieved via fd_quic_t instances and steering of RX flows.
      16             :    For example, incoming RX that exceeds the throughput of one fd_quic_t
      17             :    may be load balanced based on QUIC dest conn ID, or UDP src flow ID.
      18             : 
      19             :    This implementation aims to be compliant to RFC 9000 and RFC 9001:
      20             :    - https://datatracker.ietf.org/doc/html/rfc9000
      21             :    - https://datatracker.ietf.org/doc/html/rfc9001
      22             : 
      23             :    ### Memory Management
      24             : 
      25             :    fd_quic is entirely pre-allocated.  Currently, a QUIC object reserves
      26             :    space for a number of connection slots, with uniform stream,
      27             :    reassembly, and ACK buffers.
      28             : 
      29             :    ### Memory Layout
      30             : 
      31             :    fd_quic_t is the publicly exported memory layout of a QUIC object.
      32             :    The private memory region of a QUIC object extends beyond the end of
      33             :    this struct.  fd_quic_t is not intended to be allocated directly,
      34             :    refer to the below for details.
      35             : 
      36             :    ### Lifecycle
      37             : 
      38             :    The below state diagram shows the lifecycle of an fd_quic_t.
      39             : 
      40             :       ┌───────────┐  new   ┌───────────┐ join  ┌──────────┐
      41             :       │           ├───────►│           ├──────►│          │
      42             :       │ allocated │        │ formatted │       │  joined  │
      43             :       │           │◄───────┤           │◄──────┤          │
      44             :       └───────────┘ delete └───────────┘ leave └───▲───┬──┘
      45             :                                                    │   │ set config
      46             :                                                    │   │ set callbacks
      47             :                                               fini │   │ init
      48             :                                                 ┌──┴───▼──┐
      49             :                                             ┌───│         │
      50             :                                     service │   │  ready  │
      51             :                                             └──►│         │
      52             :                                                 └─────────┘
      53             : 
      54             :    ### Lifecycle: Allocation & Formatting
      55             : 
      56             :    A QUIC object resides in a contiguous pre-allocated memory region.
      57             :    (Usually, in a Firedancer workspace)  The footprint and internal
      58             :    layout depends on the pre-configured fd_quic_limits_t parameters.
      59             :    These limits are constant throughout the lifetime of an fd_quic_t.
      60             : 
      61             :    Use fd_quic_{align,footprint} to determine size and alignment of the
      62             :    memory region to be used.  Use fd_quic_new to format such a memory
      63             :    region and to obtain an opaque handle.  In the formatted state, the
      64             :    fd_quic_t is position-independent (may be mapped at different virtual
      65             :    addresses).  This is useful for separating allocation and runtime use
      66             :    into different steps.
      67             : 
      68             :    ### Lifecycle: Joining
      69             : 
      70             :    Given an opaque handle, fd_quic_join runs basic coherence checks and
      71             :    returns a typed pointer to the object.  The object is not modified
      72             :    by this operation.  Each object may have multiple active joins, but
      73             :    only one of them may write.  (Typically, a single join is used for
      74             :    service, and secondary joins for read-only monitoring)
      75             : 
      76             :    ### Lifecycle: Usage
      77             : 
      78             :    fd_quic_init initializes an fd_quic_t for use.  On success, the QUIC
      79             :    becomes ready to serve from the thread that init was called from (it
      80             :    is invalid to service QUIC from another thread). */
      81             : 
      82             : /* TODO provide fd_quic on non-hosted targets */
      83             : 
      84             : #include "fd_quic_common.h"
      85             : #include "fd_quic_enum.h"
      86             : 
      87             : #include "../aio/fd_aio.h"
      88             : #include "../tls/fd_tls.h"
      89             : 
      90             : /* FD_QUIC_API marks public API declarations.  No-op for now. */
      91             : #define FD_QUIC_API
      92             : 
      93             : /* Forward declarations */
      94             : 
      95             : struct fd_quic_conn;
      96             : typedef struct fd_quic_conn fd_quic_conn_t;
      97             : 
      98             : struct fd_quic_stream;
      99             : typedef struct fd_quic_stream fd_quic_stream_t;
     100             : 
     101             : struct fd_quic_state_private;
     102             : typedef struct fd_quic_state_private fd_quic_state_t;
     103             : 
     104             : /* fd_quic_limits_t defines the memory layout of an fd_quic_t object.
     105             :    Limits are immutable and valid for the lifetime of an fd_quic_t
     106             :    (i.e. outlasts joins, until fd_quic_delete) */
     107             : 
     108             : struct __attribute__((aligned(16UL))) fd_quic_limits {
     109             :   ulong  conn_cnt;              /* instance-wide, max concurrent conn count      */
     110             :   ulong  handshake_cnt;         /* instance-wide, max concurrent handshake count */
     111             :   ulong  log_depth;             /* instance-wide, depth of shm log cache         */
     112             : 
     113             :   ulong  conn_id_cnt;           /* per-conn, max conn ID count (min 4UL)         */
     114             :   ulong  stream_id_cnt;         /* per-conn, max concurrent stream ID count      */
     115             :   ulong  inflight_pkt_cnt;      /* per-conn, max inflight packet count           */
     116             : 
     117             :   ulong  tx_buf_sz;             /* per-stream, tx buf sz in bytes                */
     118             :   /* the user consumes rx directly from the network buffer */
     119             : 
     120             :   ulong  stream_pool_cnt;  /* instance-wide, number of streams in stream pool */
     121             : };
     122             : typedef struct fd_quic_limits fd_quic_limits_t;
     123             : 
     124             : /* fd_quic_layout_t is an offset table describing the memory layout of
     125             :    an fd_quic_t object.  It is deived from fd_quic_limits_t. */
     126             : 
     127             : struct fd_quic_layout {
     128             :   ulong meta_sz;         /* size of this struct */
     129             :   ulong log_off;         /* offset to quic_log */
     130             :   ulong conns_off;       /* offset of connection mem region  */
     131             :   ulong conn_footprint;  /* sizeof a conn                    */
     132             :   ulong conn_map_off;    /* offset of conn map mem region    */
     133             :   int   lg_slot_cnt;     /* see conn_map_new                 */
     134             :   ulong hs_pool_off;     /* offset of the handshake pool     */
     135             :   ulong stream_pool_off; /* offset of the stream pool        */
     136             : };
     137             : 
     138             : typedef struct fd_quic_layout fd_quic_layout_t;
     139             : 
     140             : /* fd_quic_now_t is the clock source used internally by quic for
     141             :    scheduling events.  context is an arbitrary pointer earlier provided
     142             :    by the caller during config. */
     143             : 
     144             : typedef ulong
     145             : (*fd_quic_now_t)( void * context );
     146             : 
     147             : /* fd_quic_config_t defines mutable config of an fd_quic_t.  The config is
     148             :    immutable during an active join. */
     149             : 
     150             : struct __attribute__((aligned(16UL))) fd_quic_config {
     151             :   /* Protocol config ***************************************/
     152             : 
     153             :   /* role: one of FD_QUIC_ROLE_{CLIENT,SERVER} */
     154             :   int role;
     155             : 
     156             :   /* retry: whether address validation using retry packets is enabled (RFC 9000, Section 8.1.2) */
     157             :   int retry;
     158             : 
     159             :   /* tick_per_us: clock ticks per microsecond */
     160             :   float tick_per_us;
     161             : 
     162             :   /* idle_timeout: Upper bound on conn idle timeout.
     163             :      Also sent to peer via max_idle_timeout transport param.
     164             :      If the peer specifies a lower idle timeout, that is used instead. */
     165             :   ulong idle_timeout;
     166        4257 : # define FD_QUIC_DEFAULT_IDLE_TIMEOUT (ulong)(1e9) /* 1s */
     167             : 
     168             :   /* ack_delay: median delay on outgoing ACKs.  Greater delays allow
     169             :      fd_quic to coalesce packet ACKs. */
     170             :   ulong ack_delay;
     171        4257 : # define FD_QUIC_DEFAULT_ACK_DELAY (ulong)(50e6) /* 50ms */
     172             : 
     173             :   /* ack_threshold: immediately send an ACK when the number of
     174             :      unacknowledged stream bytes exceeds this value. */
     175             :   ulong ack_threshold;
     176        2130 : # define FD_QUIC_DEFAULT_ACK_THRESHOLD (65536UL) /* 64 KiB */
     177             : 
     178             :   /* retry_ttl: time-to-live for retry tokens */
     179             :   ulong retry_ttl;
     180        2130 : # define FD_QUIC_DEFAULT_RETRY_TTL (ulong)(1e9) /* 1s */
     181             : 
     182             :   /* TLS config ********************************************/
     183             : 
     184             :   /* identity_key: Ed25519 public key of node identity */
     185             :   uchar identity_public_key[ 32 ];
     186             : 
     187             :   /* Callback for signing TLS 1.3 certificate verify payload */
     188             :   fd_tls_sign_fn_t sign;
     189             :   void *           sign_ctx;
     190             : 
     191           0 : # define FD_QUIC_PATH_LEN 1023UL
     192             :   char keylog_file[ FD_QUIC_PATH_LEN+1UL ];
     193             : 
     194             :   ulong initial_rx_max_stream_data; /* per-stream, rx buf sz in bytes, set by the user. */
     195             : 
     196             :   /* Network config ****************************************/
     197             : 
     198             :   struct { /* Internet config */
     199             :     uint   ip_addr;         /* IP address (for outgoing traffic) */
     200             :     ushort listen_udp_port; /* UDP port (server only) */
     201             : 
     202             :     struct { /* Ephemeral UDP port range (client only) */
     203             :       ushort lo;
     204             :       ushort hi;
     205             :       /* we need an ephemeral UDP port range for at least two reasons:
     206             :          1. Some network hardware assumes src_ip:src_port:dst_ip:dst_port is a unique connection
     207             :          2. For receive-side scaling, the server will be using the source port for load balancing */
     208             :     } ephem_udp_port;
     209             : 
     210             :     /* dscp: Differentiated services code point.
     211             :        Set on all outgoing IPv4 packets. */
     212             :     uchar dscp;
     213             :   } net;
     214             : };
     215             : 
     216             : /* Callback API *******************************************************/
     217             : 
     218             : /* Note: QUIC library invokes callbacks during RX or service.  Callback
     219             :    may only invoke fd_quic API methods labelled CB-safe.  Callbacks are
     220             :    not re-entrant. */
     221             : 
     222             : /* fd_quic_cb_conn_new_t: server received a new conn and completed
     223             :    handshakes. */
     224             : typedef void
     225             : (* fd_quic_cb_conn_new_t)( fd_quic_conn_t * conn,
     226             :                            void *           quic_ctx );
     227             : 
     228             : /* fd_quic_cb_conn_handshake_complete_t: client completed a handshake
     229             :    of a conn it created. */
     230             : typedef void
     231             : (* fd_quic_cb_conn_handshake_complete_t)( fd_quic_conn_t * conn,
     232             :                                           void *           quic_ctx );
     233             : 
     234             : /* fd_quic_cb_conn_final_t: Conn termination notification.  The conn
     235             :    object is freed immediately after returning.  User should destroy any
     236             :    remaining references to conn in this callback. */
     237             : typedef void
     238             : (* fd_quic_cb_conn_final_t)( fd_quic_conn_t * conn,
     239             :                              void *           quic_ctx );
     240             : 
     241             : /* fd_quic_cb_stream_notify_t signals a notable stream event.
     242             :    stream_ctx object is the user-provided stream context set in the new
     243             :    callback.
     244             : 
     245             :    TODO will only one notify max be served?
     246             :    TODO will stream be deallocated immediately after callback?
     247             : 
     248             :    notify_type is one of FD_QUIC_NOTIFY_{...} */
     249             : typedef void
     250             : (* fd_quic_cb_stream_notify_t)( fd_quic_stream_t * stream,
     251             :                                 void *             stream_ctx,
     252             :                                 int                notify_type );
     253             : 
     254             : typedef int
     255             : (* fd_quic_cb_stream_rx_t)( fd_quic_conn_t * conn,
     256             :                             ulong            stream_id,
     257             :                             ulong            offset,
     258             :                             uchar const *    data,
     259             :                             ulong            data_sz,
     260             :                             int              fin );
     261             : 
     262             : /* fd_quic_cb_tls_keylog_t is called when a new encryption secret
     263             :    becomes available.  line is a cstr containing the secret in NSS key
     264             :    log format (intended for tests only). */
     265             : 
     266             : typedef void
     267             : (* fd_quic_cb_tls_keylog_t)( void *       quic_ctx,
     268             :                              char const * line );
     269             : 
     270             : /* fd_quic_callbacks_t defines the set of user-provided callbacks that
     271             :    are invoked by the QUIC library.  Resets on leave. */
     272             : 
     273             : struct fd_quic_callbacks {
     274             :   /* Function pointers to user callbacks */
     275             : 
     276             :   void * quic_ctx; /* user-provided context pointer
     277             :                       for instance-wide callbacks */
     278             : 
     279             :   fd_quic_cb_conn_new_t                conn_new;          /* non-NULL, with quic_ctx   */
     280             :   fd_quic_cb_conn_handshake_complete_t conn_hs_complete;  /* non-NULL, with quic_ctx   */
     281             :   fd_quic_cb_conn_final_t              conn_final;        /* non-NULL, with quic_ctx   */
     282             :   fd_quic_cb_stream_notify_t           stream_notify;     /* non-NULL, with stream_ctx */
     283             :   fd_quic_cb_stream_rx_t               stream_rx;         /* non-NULL, with stream_ctx */
     284             :   fd_quic_cb_tls_keylog_t              tls_keylog;        /* nullable, with quic_ctx   */
     285             : 
     286             :   /* Clock source */
     287             : 
     288             :   fd_quic_now_t now;     /* non-NULL */
     289             :   void *        now_ctx; /* user-provided context pointer for now_fn calls */
     290             : 
     291             : };
     292             : typedef struct fd_quic_callbacks fd_quic_callbacks_t;
     293             : 
     294             : /* fd_quic metrics ****************************************************/
     295             : 
     296             : /* TODO: evaluate performance impact of metrics */
     297             : 
     298             : union fd_quic_metrics {
     299             :   struct {
     300             :     /* Network metrics */
     301             :     ulong net_rx_pkt_cnt;  /* number of IP packets received */
     302             :     ulong net_rx_byte_cnt; /* total bytes received (including IP, UDP, QUIC headers) */
     303             :     ulong net_tx_pkt_cnt;  /* number of IP packets sent */
     304             :     ulong net_tx_byte_cnt; /* total bytes sent */
     305             : 
     306             :     /* Conn metrics */
     307             :     ulong conn_active_cnt;         /* number of active conns */
     308             :     ulong conn_created_cnt;        /* number of conns created */
     309             :     ulong conn_closed_cnt;         /* number of conns gracefully closed */
     310             :     ulong conn_aborted_cnt;        /* number of conns aborted */
     311             :     ulong conn_timeout_cnt;        /* number of conns timed out */
     312             :     ulong conn_retry_cnt;          /* number of conns established with retry */
     313             :     ulong conn_err_no_slots_cnt;   /* number of conns that failed to create due to lack of slots */
     314             :     ulong conn_err_retry_fail_cnt; /* number of conns that failed during retry (e.g. invalid token) */
     315             : 
     316             :     /* Packet metrics */
     317             :     ulong pkt_decrypt_fail_cnt[4]; /* number of packets that failed decryption due to auth tag */
     318             :     ulong pkt_no_key_cnt[4];       /* number of packets that failed decryption due to missing key */
     319             :     ulong pkt_no_conn_cnt;         /* number of packets with unknown conn ID (excl. Initial) */
     320             :     ulong pkt_tx_alloc_fail_cnt;   /* number of pkt_meta alloc fails */
     321             : 
     322             :     /* Frame metrics */
     323             :     ulong frame_rx_cnt[ 22 ];      /* number of frames received (indexed by implementation-defined IDs) */
     324             :     ulong frame_rx_err_cnt;        /* number of frames failed */
     325             : 
     326             :     /* Handshake metrics */
     327             :     ulong hs_created_cnt;          /* number of handshake flows created */
     328             :     ulong hs_err_alloc_fail_cnt;   /* number of handshakes dropped due to alloc fail */
     329             : 
     330             :     /* Stream metrics */
     331             :     ulong stream_opened_cnt;        /* number of streams opened */
     332             :     ulong stream_closed_cnt[5];     /* indexed by FD_QUIC_STREAM_NOTIFY_{...} */
     333             :     ulong stream_active_cnt;        /* number of active streams */
     334             :     ulong stream_rx_event_cnt;      /* number of stream RX events */
     335             :     ulong stream_rx_byte_cnt;       /* total stream payload bytes received */
     336             : 
     337             :     /* ACK metrics */
     338             :     ulong ack_tx[ 5 ];
     339             : 
     340             :     /* Performance metrics */
     341             :     fd_histf_t service_duration[ 1 ]; /* time spent in service */
     342             :     fd_histf_t receive_duration[ 1 ]; /* time spent in RX calls */
     343             :   };
     344             : };
     345             : typedef union fd_quic_metrics fd_quic_metrics_t;
     346             : 
     347             : /* fd_quic_t memory layout ********************************************/
     348             : 
     349             : struct fd_quic {
     350             :   ulong magic;   /* ==FD_QUIC_MAGIC */
     351             : 
     352             :   fd_quic_layout_t    layout;  /* position-independent, persistent,    read only */
     353             :   fd_quic_limits_t    limits;  /* position-independent, persistent,    read only */
     354             :   fd_quic_config_t    config;  /* position-independent, persistent,    writable pre init */
     355             :   fd_quic_callbacks_t cb;      /* position-dependent,   reset on join, writable pre init  */
     356             :   fd_quic_metrics_t   metrics; /* position-independent, persistent,    read only */
     357             : 
     358             :   fd_aio_t aio_rx; /* local AIO */
     359             :   fd_aio_t aio_tx; /* remote AIO */
     360             : 
     361             :   /* ... private variable-length structures follow ... */
     362             : };
     363             : 
     364             : FD_PROTOTYPES_BEGIN
     365             : 
     366             : /* debugging */
     367             : 
     368             : ulong
     369             : fd_quic_conn_get_pkt_meta_free_count( fd_quic_conn_t * conn );
     370             : 
     371             : 
     372             : /* Object lifecycle ***************************************************/
     373             : 
     374             : /* fd_quic_{align,footprint} return the required alignment and footprint
     375             :    of a memory region suitable for use as an fd_quic_t.  align returns
     376             :    FD_QUIC_ALIGN.  limits is a temporary reference to the requested
     377             : 
     378             :    On failure, footprint will silently return 0 (and thus can be used by
     379             :    the caller to validate fd_quic_new params) */
     380             : 
     381             : FD_QUIC_API FD_FN_CONST ulong
     382             : fd_quic_align( void );
     383             : 
     384             : FD_QUIC_API FD_FN_PURE ulong
     385             : fd_quic_footprint( fd_quic_limits_t const * limits );
     386             : 
     387             : /* fd_quic_new formats an unused memory region for use as a QUIC client
     388             :    or server.  mem is a non-NULL pointer to this region in the local
     389             :    address with the required footprint and alignment.  limits is a
     390             :    temporary reference, identical to the one given to fd_quic_footprint
     391             :    used to figure out the required footprint. */
     392             : 
     393             : FD_QUIC_API void *
     394             : fd_quic_new( void *                   mem,
     395             :              fd_quic_limits_t const * limits );
     396             : 
     397             : /* fd_quic_join joins the caller to the fd_quic.  shquic points to the
     398             :    first byte of the memory region backing the QUIC in the caller's
     399             :    address space.
     400             : 
     401             :    Returns a pointer in the local address space to the public fd_quic_t
     402             :    region on success (do not assume this to be just a cast of shquic)
     403             :    and NULL on failure (logs details).  Reasons for failure are that
     404             :    shquic is obviously not a pointer to a correctly formatted QUIC
     405             :    object.  Every successful join should have a matching leave.  The
     406             :    lifetime of the join is until the matching leave or the thread group
     407             :    is terminated. */
     408             : 
     409             : FD_QUIC_API fd_quic_t *
     410             : fd_quic_join( void * shquic );
     411             : 
     412             : /* fd_quic_leave leaves a current local join and frees all dynamically
     413             :    managed resources (heap allocs, OS handles).  Returns the given quic
     414             :    on success and NULL on failure (logs details).  Reasons for failure
     415             :    include quic is NULL or no active join */
     416             : 
     417             : FD_QUIC_API void *
     418             : fd_quic_leave( fd_quic_t * quic );
     419             : 
     420             : /* fd_quic_delete unformats a memory region used as an fd_quic_t.
     421             :    Assumes nobody is joined to the region.  Returns the given quic
     422             :    pointer on success and NULL if used obviously in error (e.g. quic is
     423             :    obviously not an fd_quic_t ... logs details).  The ownership of the
     424             :    memory region is transferred ot the caller. */
     425             : 
     426             : FD_QUIC_API void *
     427             : fd_quic_delete( fd_quic_t * quic );
     428             : 
     429             : /* Configuration ******************************************************/
     430             : 
     431             : /* fd_quic_{limits,config}_from_env populates the given QUIC limits or
     432             :    config from command-line args and env vars.  If parg{c,v} are non-
     433             :    NULL, they are updated to strip the parsed args.  The last element of
     434             :    the *argv array must be NULL.  Returns given config on success and
     435             :    NULL on failure (logs details).  It is up to the caller to properly
     436             :    initialize the given limits/config. */
     437             : 
     438             : FD_QUIC_API fd_quic_limits_t *
     439             : fd_quic_limits_from_env( int  *   pargc,
     440             :                          char *** pargv,
     441             :                          fd_quic_limits_t * limits );
     442             : 
     443             : FD_QUIC_API fd_quic_config_t *
     444             : fd_quic_config_from_env( int  *   pargc,
     445             :                          char *** pargv,
     446             :                          fd_quic_config_t * config );
     447             : 
     448             : /* fd_quic_get_aio_net_rx returns this QUIC's aio base class.  Valid
     449             :    for lifetime of QUIC.  While pointer to aio can be obtained before
     450             :    init, calls to aio may only be dispatched by the thread with
     451             :    exclusive access to QUIC that owns it. */
     452             : 
     453             : FD_QUIC_API fd_aio_t const *
     454             : fd_quic_get_aio_net_rx( fd_quic_t * quic );
     455             : 
     456             : /* fd_quic_set_aio_net_tx sets the fd_aio_t used by the fd_quic_t to
     457             :    send tx data to the network driver.  Cleared on fini. */
     458             : 
     459             : FD_QUIC_API void
     460             : fd_quic_set_aio_net_tx( fd_quic_t *      quic,
     461             :                         fd_aio_t const * aio_tx );
     462             : 
     463             : /* fd_quic_set_clock sets the clock source.  Converts all timing values
     464             :    in the config to the new time scale. */
     465             : 
     466             : FD_QUIC_API void
     467             : fd_quic_set_clock( fd_quic_t *   quic,
     468             :                    fd_quic_now_t now_fn,
     469             :                    void *        now_ctx,
     470             :                    float         tick_per_us );
     471             : 
     472             : /* fd_quic_set_clock_tickcount sets fd_tickcount as the clock source. */
     473             : 
     474             : FD_QUIC_API void
     475             : fd_quic_set_clock_tickcount( fd_quic_t * quic );
     476             : 
     477             : /* Initialization *****************************************************/
     478             : 
     479             : /* fd_quic_init initializes the QUIC such that it is ready to serve.
     480             :    permits the calling thread exclusive access during which no other
     481             :    thread may write to the QUIC.  Exclusive rights get released when the
     482             :    thread exits or calls fd_quic_fini.
     483             : 
     484             :    Requires valid configuration and external objects (aio, callbacks).
     485             :    Returns given quic on success and NULL on failure (logs details).
     486             :    Performs various heap allocations and file system accesses such
     487             :    reading certs.  Reasons for failure include invalid config or
     488             :    fd_tls error. */
     489             : 
     490             : FD_QUIC_API fd_quic_t *
     491             : fd_quic_init( fd_quic_t * quic );
     492             : 
     493             : /* fd_quic_fini releases exclusive access over a QUIC.  Zero-initializes
     494             :    references to external objects (aio, callbacks).  Frees any heap
     495             :    allocs made by fd_quic_init.  Returns quic. */
     496             : 
     497             : FD_QUIC_API fd_quic_t *
     498             : fd_quic_fini( fd_quic_t * quic );
     499             : 
     500             : /* NOTE: Calling any of the below requires valid initialization from
     501             :    this thread group. */
     502             : 
     503             : /* Connection API *****************************************************/
     504             : 
     505             : /* fd_quic_connect initiates a new client connection to a remote QUIC
     506             :    server.  On success, returns a pointer to the conn object managed by
     507             :    QUIC.  On failure, returns NULL.  Reasons for failure include quic
     508             :    not a valid join or out of free conns.  Lifetime of returned conn is
     509             :    until conn_final callback.
     510             : 
     511             :    args
     512             :      dst_ip_addr   destination ip address
     513             :      dst_udp_port  destination port number */
     514             : 
     515             : FD_QUIC_API fd_quic_conn_t *
     516             : fd_quic_connect( fd_quic_t *  quic,  /* requires exclusive access */
     517             :                  uint         dst_ip_addr,
     518             :                  ushort       dst_udp_port );
     519             : 
     520             : /* fd_quic_conn_close asynchronously initiates a shutdown of the conn.
     521             :    The given reason code is returned to the peer via a CONNECTION_CLOSE
     522             :    frame, if possible.  Causes conn_final callback to be issued
     523             :    eventually. */
     524             : 
     525             : FD_QUIC_API void
     526             : fd_quic_conn_close( fd_quic_conn_t * conn,
     527             :                     uint             reason );
     528             : 
     529             : /* Service API ********************************************************/
     530             : 
     531             : /* fd_quic_get_next_wakeup returns the next requested service time.
     532             :    This is only intended for unit tests. */
     533             : 
     534             : FD_QUIC_API ulong
     535             : fd_quic_get_next_wakeup( fd_quic_t * quic );
     536             : 
     537             : /* fd_quic_service services the next QUIC connection, including stream
     538             :    transmit ops, ACK transmit, loss timeout, and idle timeout.   The
     539             :    user should call service at high frequency.  Returns 1 if the service
     540             :    call did any work, or 0 otherwise. */
     541             : 
     542             : FD_QUIC_API int
     543             : fd_quic_service( fd_quic_t * quic );
     544             : 
     545             : /* fd_quic_svc_validate checks for violations of service queue and free
     546             :    list invariants, such as cycles in linked lists.  Prints to warning/
     547             :    error log and exits the process if checks fail.  Intended for use in
     548             :    tests. */
     549             : 
     550             : void
     551             : fd_quic_svc_validate( fd_quic_t * quic );
     552             : 
     553             : /* Stream Send API ****************************************************/
     554             : 
     555             : /* fd_quic_conn_new_stream creates a new unidirectional stream on the
     556             :    given conn.  On success, returns the newly created stream.
     557             :    On failure, returns NULL.  Reasons for failure include invalid conn
     558             :    state or out of stream quota.
     559             : 
     560             :    The user does not own the returned pointer: its lifetime is managed
     561             :    by the connection. */
     562             : 
     563             : FD_QUIC_API fd_quic_stream_t *
     564             : fd_quic_conn_new_stream( fd_quic_conn_t * conn );
     565             : 
     566             : /* fd_quic_stream_send sends a chunk on a stream in order.
     567             : 
     568             :    Use fd_quic_conn_new_stream to create a new stream for sending
     569             :    or use the new stream callback to obtain a stream for replying.
     570             : 
     571             :    args
     572             :      stream         the stream to send on
     573             :      data           points to first byte of buffer (ignored if data_sz==0)
     574             :      data_sz        number of bytes to send
     575             :      fin            final: bool
     576             :                       set to indicate the stream is finalized by the last byte
     577             :                       in the batch
     578             :                       If the last buffer in the batch was rejected, the FIN
     579             :                         flag is not set, and may be applied in a future send
     580             :                         or via the fd_quic_stream_fin(...) function
     581             : 
     582             :    returns
     583             :        0   success
     584             :       <0   one of FD_QUIC_SEND_ERR_{INVAL_STREAM,INVAL_CONN,AGAIN} */
     585             : FD_QUIC_API int
     586             : fd_quic_stream_send( fd_quic_stream_t *  stream,
     587             :                      void const *        data,
     588             :                      ulong               data_sz,
     589             :                      int                 fin );
     590             : 
     591             : /* fd_quic_stream_fin: finish sending on a stream.  Called to signal
     592             :    no more data will be sent to self-to-peer flow of stream.  Peer may
     593             :    continue sending data on their side of the stream.  Caller should
     594             :    only call stream_fin once per stream, except when fin was already
     595             :    indicated via stream_send. */
     596             : 
     597             : FD_QUIC_API void
     598             : fd_quic_stream_fin( fd_quic_stream_t * stream );
     599             : 
     600             : FD_QUIC_API void
     601             : fd_quic_process_packet( fd_quic_t * quic,
     602             :                         uchar *     data,
     603             :                         ulong       data_sz );
     604             : 
     605             : uint
     606             : fd_quic_tx_buffered_raw( fd_quic_t * quic,
     607             :                          uchar **    tx_ptr_ptr,
     608             :                          uchar *     tx_buf,
     609             :                          ulong       tx_buf_sz,
     610             :                          ulong *     tx_sz,
     611             :                          ushort *    ipv4_id,
     612             :                          uint        dst_ipv4_addr,
     613             :                          ushort      src_udp_port,
     614             :                          ushort      dst_udp_port,
     615             :                          int         flush );
     616             : 
     617             : FD_PROTOTYPES_END
     618             : 
     619             : /* Convenience exports for consumers of API */
     620             : #include "fd_quic_conn.h"
     621             : #include "fd_quic_stream.h"
     622             : 
     623             : /* FD_DEBUG_MODE: set to enable debug-only code
     624             :    TODO move to util? */
     625             : #ifdef FD_DEBUG_MODE
     626             : #define FD_DEBUG(...) __VA_ARGS__
     627             : #else
     628             : #define FD_DEBUG(...)
     629             : #endif
     630             : 
     631             : #endif /* HEADER_fd_src_waltz_quic_fd_quic_h */

Generated by: LCOV version 1.14