LiteSpeed QUIC Library
lsquic.h
Go to the documentation of this file.
1 /* Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. */
2 #ifndef __LSQUIC_H__
3 #define __LSQUIC_H__
4 
11 #include <stdarg.h>
12 #include <lsquic_types.h>
13 #include <sys/uio.h>
14 #include <sys/types.h>
15 #include <time.h>
16 
17 struct iovec;
18 struct sockaddr;
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
29 #define LSENG_SERVER (1 << 0)
30 
34 #define LSENG_HTTP (1 << 1)
35 
36 #define LSENG_HTTP_SERVER (LSENG_SERVER|LSENG_HTTP)
37 
43 {
44 
47 
55 
61 
68 
73 
74  N_LSQVER
75 };
76 
81 #define LSQUIC_SUPPORTED_VERSIONS ((1 << LSQVER_035) | (1 << LSQVER_037) | \
82  (1 << LSQVER_038) | (1 << LSQVER_039) | (1 << LSQVER_041))
83 
84 #define LSQUIC_EXPERIMENTAL_VERSIONS ((1 << LSQVER_041))
85 
93 
98  lsquic_conn_ctx_t *(*on_new_conn)(void *stream_if_ctx,
99  lsquic_conn_t *c);
100 
105  void (*on_conn_closed)(lsquic_conn_t *c);
106 
115  (*on_new_stream)(void *stream_if_ctx, lsquic_stream_t *s);
116 
117  void (*on_read) (lsquic_stream_t *s, lsquic_stream_ctx_t *h);
118  void (*on_write) (lsquic_stream_t *s, lsquic_stream_ctx_t *h);
119  void (*on_close) (lsquic_stream_t *s, lsquic_stream_ctx_t *h);
120 };
121 
127 #define LSQUIC_MIN_FCW (16 * 1024)
128 
129 /* Each LSQUIC_DF_* value corresponds to es_* entry in
130  * lsquic_engine_settings below.
131  */
132 
136 #define LSQUIC_DF_VERSIONS (LSQUIC_SUPPORTED_VERSIONS & \
137  ~LSQUIC_EXPERIMENTAL_VERSIONS)
138 
139 #define LSQUIC_DF_CFCW_SERVER (3 * 1024 * 1024 / 2)
140 #define LSQUIC_DF_CFCW_CLIENT (15 * 1024 * 1024)
141 #define LSQUIC_DF_SFCW_SERVER (1 * 1024 * 1024)
142 #define LSQUIC_DF_SFCW_CLIENT (6 * 1024 * 1024)
143 #define LSQUIC_DF_MAX_STREAMS_IN 100
144 
148 #define LSQUIC_DF_HANDSHAKE_TO (10 * 1000 * 1000)
149 
150 #define LSQUIC_DF_IDLE_CONN_TO (30 * 1000 * 1000)
151 #define LSQUIC_DF_SILENT_CLOSE 1
152 
157 #define LSQUIC_DF_MAX_HEADER_LIST_SIZE 0
158 
160 #define LSQUIC_DF_UA "LSQUIC"
161 
162 #define LSQUIC_DF_STTL 86400
163 #define LSQUIC_DF_MAX_INCHOATE (1 * 1000 * 1000)
164 #define LSQUIC_DF_SUPPORT_SREJ_SERVER 1
165 #define LSQUIC_DF_SUPPORT_SREJ_CLIENT 0 /* TODO: client support */
166 
167 #define LSQUIC_DF_SUPPORT_NSTP 0
168 #define LSQUIC_DF_SUPPORT_PUSH 1
169 #define LSQUIC_DF_SUPPORT_TCID0 1
170 
171 #define LSQUIC_DF_HONOR_PRST 0
172 
174 #define LSQUIC_DF_PROGRESS_CHECK 1000
175 
177 #define LSQUIC_DF_PENDRW_CHECK 10
178 
180 #define LSQUIC_DF_RW_ONCE 0
181 
183 #define LSQUIC_DF_PROC_TIME_THRESH 0
184 
186 #define LSQUIC_DF_PACE_PACKETS 1
187 
197  unsigned es_versions;
198 
209  unsigned es_cfcw;
210 
221  unsigned es_sfcw;
222 
231  unsigned es_max_cfcw;
232 
233  unsigned es_max_sfcw;
234 
237 
245  unsigned long es_handshake_to;
246 
248  unsigned long es_idle_conn_to;
249 
252 
259 
261  const char *es_ua;
262 
263  uint32_t es_pdmd; /* One fixed value X509 */
264  uint32_t es_aead; /* One fixed value AESG */
265  uint32_t es_kexs; /* One fixed value C255 */
266 
273 
285 
294 
306 
313 
328 
344  unsigned es_pendrw_check;
345 
359 
379 
386 
387 };
388 
389 /* Initialize `settings' to default values */
390 void
391 lsquic_engine_init_settings (struct lsquic_engine_settings *,
392  unsigned lsquic_engine_flags);
393 
410 int
412  unsigned lsquic_engine_flags,
413  char *err_buf, size_t err_buf_sz);
414 
416 {
417  const unsigned char *buf;
418  size_t sz;
419  const struct sockaddr *local_sa;
420  const struct sockaddr *dest_sa;
421  void *peer_ctx;
422 };
423 
428 typedef int (*lsquic_packets_out_f)(
429  void *packets_out_ctx,
430  const struct lsquic_out_spec *out_spec,
431  unsigned n_packets_out
432 );
433 
444 {
445  void * (*pmi_allocate) (void *pmi_ctx, size_t sz);
446  void (*pmi_release) (void *pmi_ctx, void *obj);
447 };
448 
449 /* TODO: describe this important data structure */
450 typedef struct lsquic_engine_api
451 {
452  const struct lsquic_engine_settings *ea_settings; /* Optional */
453  const struct lsquic_stream_if *ea_stream_if;
454  void *ea_stream_if_ctx;
455  lsquic_packets_out_f ea_packets_out;
456  void *ea_packets_out_ctx;
461  void *ea_pmi_ctx;
463 
471 lsquic_engine_new (unsigned lsquic_engine_flags,
472  const struct lsquic_engine_api *);
473 
479 int
480 lsquic_engine_connect (lsquic_engine_t *, const struct sockaddr *peer_sa,
481  void *peer_ctx, const char *hostname,
482  unsigned short max_packet_size);
483 
494 int
496  const unsigned char *packet_in_data, size_t packet_in_size,
497  const struct sockaddr *sa_local, const struct sockaddr *sa_peer,
498  void *peer_ctx);
499 
504 void
506 
511 void
513 
518 void
520 
536 int
538 
543 void
545 
550 int
552 
557 void
559 
560 void
561 lsquic_engine_destroy (lsquic_engine_t *);
562 
563 void lsquic_conn_make_stream(lsquic_conn_t *);
564 
566 unsigned
568 
570 unsigned
572 
577 void
579 
584 void lsquic_conn_close(lsquic_conn_t *conn);
585 
586 int lsquic_stream_wantread(lsquic_stream_t *s, int is_want);
587 ssize_t lsquic_stream_read(lsquic_stream_t *s, void *buf, size_t len);
588 ssize_t lsquic_stream_readv(lsquic_stream_t *s, const struct iovec *,
589  int iovcnt);
590 
591 int lsquic_stream_wantwrite(lsquic_stream_t *s, int is_want);
592 
597 ssize_t lsquic_stream_write(lsquic_stream_t *s, const void *buf, size_t len);
598 
599 ssize_t lsquic_stream_writev(lsquic_stream_t *s, const struct iovec *vec, int count);
600 
605 {
612  size_t (*lsqr_read) (void *lsqr_ctx, void *buf, size_t count);
616  size_t (*lsqr_size) (void *lsqr_ctx);
617  void *lsqr_ctx;
618 };
619 
627 ssize_t
629 
637 int
639 
645 typedef struct lsquic_http_header
646 {
647  struct iovec name;
648  struct iovec value;
650 
657 {
658  int count;
659  lsquic_http_header_t *headers;
660 };
661 
662 int lsquic_stream_send_headers(lsquic_stream_t *s,
663  const lsquic_http_headers_t *h, int eos);
664 
665 int lsquic_conn_is_push_enabled(lsquic_conn_t *c);
666 
668 int lsquic_stream_shutdown(lsquic_stream_t *s, int how);
669 
670 int lsquic_stream_close(lsquic_stream_t *s);
671 
673 uint32_t
675 
682 
684 int
686 
694 int
696 
709 int
710 lsquic_stream_push_info (const lsquic_stream_t *, uint32_t *ref_stream_id,
711  const char **headers, size_t *headers_sz);
712 
714 unsigned lsquic_stream_priority (const lsquic_stream_t *s);
715 
722 int lsquic_stream_set_priority (lsquic_stream_t *s, unsigned priority);
723 
729 
731 lsquic_conn_get_stream_by_id (lsquic_conn_t *c, uint32_t stream_id);
732 
735 lsquic_conn_id (const lsquic_conn_t *c);
736 
737 int lsquic_conn_get_sockaddr(const lsquic_conn_t *c,
738  const struct sockaddr **local, const struct sockaddr **peer);
739 
741  int (*vprintf)(void *logger_ctx, const char *fmt, va_list args);
742 };
743 
752 
758 
763 
773 
779 
780  N_LLTS
781 };
782 
787 void lsquic_logger_init(const struct lsquic_logger_if *, void *logger_ctx,
789 
797 int
798 lsquic_set_log_level (const char *log_level);
799 
803 int
804 lsquic_logger_lopt (const char *optarg);
805 
811 
816 #define LSQUIC_GLOBAL_CLIENT (1 << 0)
817 
822 #define LSQUIC_GLOBAL_SERVER (1 << 1)
823 
838 int
839 lsquic_global_init (int flags);
840 
845 void
846 lsquic_global_cleanup (void);
847 
853 enum lsquic_version
855 
857 enum lsquic_version
858 lsquic_str2ver (const char *str, size_t len);
859 
865 
869 void *lsquic_conn_get_peer_ctx( const lsquic_conn_t *lconn);
870 
874 void
876 
883 int
885 
890 unsigned
891 lsquic_engine_count_attq (lsquic_engine_t *engine, int from_now);
892 
893 #ifdef __cplusplus
894 }
895 #endif
896 
897 #endif //__LSQUIC_H__
898 
int lsquic_engine_has_pend_rw(lsquic_engine_t *)
void lsquic_global_cleanup(void)
unsigned es_max_cfcw
Definition: lsquic.h:231
unsigned lsquic_engine_quic_versions(const lsquic_engine_t *)
Definition: lsquic.h:751
const char * es_ua
Definition: lsquic.h:261
Definition: lsquic.h:757
void lsquic_engine_send_unsent_packets(lsquic_engine_t *engine)
Definition: lsquic.h:54
unsigned es_pendrw_check
Definition: lsquic.h:344
int lsquic_engine_earliest_adv_tick(lsquic_engine_t *engine, int *diff)
Definition: lsquic.h:415
Definition: lsquic.h:762
int es_support_tcid0
Definition: lsquic.h:293
Definition: lsquic.h:450
int lsquic_stream_is_pushed(const lsquic_stream_t *s)
unsigned long es_handshake_to
Definition: lsquic.h:245
ssize_t lsquic_stream_write(lsquic_stream_t *s, const void *buf, size_t len)
unsigned es_max_streams_in
Definition: lsquic.h:236
int lsquic_set_log_level(const char *log_level)
The definition of callback functions call by lsquic_stream to process events.
Definition: lsquic.h:92
void lsquic_engine_process_conns_with_incoming(lsquic_engine_t *)
unsigned lsquic_engine_count_attq(lsquic_engine_t *engine, int from_now)
unsigned es_cfcw
Definition: lsquic.h:209
uint64_t lsquic_cid_t
Definition: lsquic_types.h:15
Definition: lsquic.h:772
lsquic_stream_ctx_t * lsquic_stream_get_ctx(const lsquic_stream_t *s)
unsigned es_versions
Definition: lsquic.h:197
unsigned lsquic_conn_cancel_pending_streams(lsquic_conn_t *, unsigned n)
Definition: lsquic.h:778
Definition: lsquic.h:645
unsigned long es_idle_conn_to
Definition: lsquic.h:248
Definition: lsquic.h:604
enum lsquic_version lsquic_str2ver(const char *str, size_t len)
struct lsquic_conn lsquic_conn_t
Definition: lsquic_types.h:21
int es_support_nstp
Definition: lsquic.h:305
int lsquic_stream_push_info(const lsquic_stream_t *, uint32_t *ref_stream_id, const char **headers, size_t *headers_sz)
lsquic_logger_timestamp_style
Definition: lsquic.h:747
int lsquic_engine_packet_in(lsquic_engine_t *, const unsigned char *packet_in_data, size_t packet_in_size, const struct sockaddr *sa_local, const struct sockaddr *sa_peer, void *peer_ctx)
unsigned es_proc_time_thresh
Definition: lsquic.h:378
void lsquic_engine_proc_all(lsquic_engine_t *engine)
int lsquic_stream_set_priority(lsquic_stream_t *s, unsigned priority)
Definition: lsquic.h:67
Definition: lsquic.h:740
Definition: lsquic.h:46
int es_silent_close
Definition: lsquic.h:251
int es_honor_prst
Definition: lsquic.h:312
void lsquic_engine_process_conns_to_tick(lsquic_engine_t *)
unsigned es_max_header_list_size
Definition: lsquic.h:258
int lsquic_engine_check_settings(const struct lsquic_engine_settings *settings, unsigned lsquic_engine_flags, char *err_buf, size_t err_buf_sz)
int es_rw_once
Definition: lsquic.h:358
lsquic_version
Definition: lsquic.h:42
int lsquic_global_init(int flags)
int lsquic_engine_connect(lsquic_engine_t *, const struct sockaddr *peer_sa, void *peer_ctx, const char *hostname, unsigned short max_packet_size)
struct lsquic_engine lsquic_engine_t
Definition: lsquic_types.h:18
int lsquic_stream_refuse_push(lsquic_stream_t *s)
Definition: lsquic.h:443
int es_support_srej
Definition: lsquic.h:272
lsquic_conn_ctx_t * lsquic_conn_get_ctx(const lsquic_conn_t *c)
void lsquic_logger_init(const struct lsquic_logger_if *, void *logger_ctx, enum lsquic_logger_timestamp_style)
int(* lsquic_packets_out_f)(void *packets_out_ctx, const struct lsquic_out_spec *out_spec, unsigned n_packets_out)
Definition: lsquic.h:428
ssize_t lsquic_stream_writef(lsquic_stream_t *, struct lsquic_reader *)
unsigned es_sfcw
Definition: lsquic.h:221
int es_pace_packets
Definition: lsquic.h:385
int lsquic_stream_shutdown(lsquic_stream_t *s, int how)
lsquic_engine_t * lsquic_engine_new(unsigned lsquic_engine_flags, const struct lsquic_engine_api *)
int lsquic_stream_flush(lsquic_stream_t *s)
lsquic_cid_t lsquic_conn_id(const lsquic_conn_t *c)
Definition: lsquic.h:656
void * lsquic_conn_get_peer_ctx(const lsquic_conn_t *lconn)
unsigned lsquic_stream_priority(const lsquic_stream_t *s)
struct lsquic_http_header lsquic_http_header_t
HTTP header structure. Contains header name and value.
int lsquic_logger_lopt(const char *optarg)
const struct lsquic_packout_mem_if * ea_pmi
Definition: lsquic.h:460
struct lsquic_conn_ctx lsquic_conn_ctx_t
Definition: lsquic_types.h:24
struct lsquic_stream_ctx lsquic_stream_ctx_t
Definition: lsquic_types.h:30
void lsquic_engine_process_conns_with_pend_rw(lsquic_engine_t *)
struct lsquic_stream lsquic_stream_t
Definition: lsquic_types.h:27
lsquic_conn_t * lsquic_stream_conn(const lsquic_stream_t *s)
int lsquic_engine_has_unsent_packets(lsquic_engine_t *engine)
void lsquic_conn_going_away(lsquic_conn_t *conn)
Definition: lsquic.h:188
enum lsquic_version lsquic_conn_quic_version(const lsquic_conn_t *c)
void lsquic_conn_close(lsquic_conn_t *conn)
Definition: lsquic.h:60
uint32_t lsquic_stream_id(const lsquic_stream_t *s)
void(* on_goaway_received)(lsquic_conn_t *c)
Definition: lsquic.h:104
Definition: lsquic.h:72
unsigned es_progress_check
Definition: lsquic.h:327
int es_support_push
Definition: lsquic.h:284
unsigned lsquic_conn_n_pending_streams(const lsquic_conn_t *)
void lsquic_conn_abort(lsquic_conn_t *c)