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_040))
83 
84 #define LSQUIC_EXPERIMENTAL_VERSIONS ((1 << LSQVER_040))
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 
598 
604 ssize_t lsquic_stream_write(lsquic_stream_t *s, const void *buf, size_t len);
605 
612 int lsquic_stream_write_file(lsquic_stream_t *s, const char *filename);
613 
614 ssize_t lsquic_stream_writev(lsquic_stream_t *s, const struct iovec *vec, int count);
615 
621 int lsquic_stream_sendfile(lsquic_stream_t *s, int fdSrc, off_t off, size_t size);
622 
623 int lsquic_stream_flush(lsquic_stream_t *s);
624 
630 typedef struct lsquic_http_header
631 {
632  struct iovec name;
633  struct iovec value;
635 
642 {
643  int count;
644  lsquic_http_header_t *headers;
645 };
646 
647 int lsquic_stream_send_headers(lsquic_stream_t *s,
648  const lsquic_http_headers_t *h, int eos);
649 
650 int lsquic_conn_is_push_enabled(lsquic_conn_t *c);
651 
653 int lsquic_stream_shutdown(lsquic_stream_t *s, int how);
654 
655 int lsquic_stream_close(lsquic_stream_t *s);
656 
658 uint32_t
660 
667 
669 int
671 
679 int
681 
694 int
695 lsquic_stream_push_info (const lsquic_stream_t *, uint32_t *ref_stream_id,
696  const char **headers, size_t *headers_sz);
697 
699 unsigned lsquic_stream_priority (const lsquic_stream_t *s);
700 
707 int lsquic_stream_set_priority (lsquic_stream_t *s, unsigned priority);
708 
714 
716 lsquic_conn_get_stream_by_id (lsquic_conn_t *c, uint32_t stream_id);
717 
720 lsquic_conn_id (const lsquic_conn_t *c);
721 
722 int lsquic_conn_get_sockaddr(const lsquic_conn_t *c,
723  const struct sockaddr **local, const struct sockaddr **peer);
724 
726  int (*vprintf)(void *logger_ctx, const char *fmt, va_list args);
727 };
728 
737 
743 
748 
758 
764 
765  N_LLTS
766 };
767 
772 void lsquic_logger_init(const struct lsquic_logger_if *, void *logger_ctx,
774 
782 int
783 lsquic_set_log_level (const char *log_level);
784 
788 int
789 lsquic_logger_lopt (const char *optarg);
790 
796 
801 #define LSQUIC_GLOBAL_CLIENT (1 << 0)
802 
807 #define LSQUIC_GLOBAL_SERVER (1 << 1)
808 
823 int
824 lsquic_global_init (int flags);
825 
830 void
831 lsquic_global_cleanup (void);
832 
838 enum lsquic_version
840 
842 enum lsquic_version
843 lsquic_str2ver (const char *str, size_t len);
844 
850 
854 void *lsquic_conn_get_peer_ctx( const lsquic_conn_t *lconn);
855 
859 void
861 
868 int
870 
875 unsigned
876 lsquic_engine_count_attq (lsquic_engine_t *engine, int from_now);
877 
878 #ifdef __cplusplus
879 }
880 #endif
881 
882 #endif //__LSQUIC_H__
883 
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:736
const char * es_ua
Definition: lsquic.h:261
Definition: lsquic.h:742
void lsquic_engine_send_unsent_packets(lsquic_engine_t *engine)
Definition: lsquic.h:54
unsigned es_pendrw_check
Definition: lsquic.h:344
Definition: lsquic.h:72
int lsquic_engine_earliest_adv_tick(lsquic_engine_t *engine, int *diff)
Definition: lsquic.h:415
Definition: lsquic.h:747
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
int lsquic_stream_write_file(lsquic_stream_t *s, const char *filename)
Definition: lsquic.h:757
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:763
Definition: lsquic.h:630
unsigned long es_idle_conn_to
Definition: lsquic.h:248
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:732
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)
size_t lsquic_stream_write_avail(const lsquic_stream_t *s)
int lsquic_stream_set_priority(lsquic_stream_t *s, unsigned priority)
Definition: lsquic.h:67
Definition: lsquic.h:725
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
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 *)
lsquic_cid_t lsquic_conn_id(const lsquic_conn_t *c)
Definition: lsquic.h:641
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
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 *)
int lsquic_stream_sendfile(lsquic_stream_t *s, int fdSrc, off_t off, size_t size)
void lsquic_conn_abort(lsquic_conn_t *c)