lsquic_conn.h revision 50aadb33
1/* Copyright (c) 2017 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_conn.h -- Connection interface 4 * 5 */ 6#ifndef LSQUIC_CONN_H 7#define LSQUIC_CONN_H 8 9#include <sys/queue.h> 10#include <sys/socket.h> 11#include <netinet/in.h> 12 13struct lsquic_conn; 14struct lsquic_enc_session; 15struct lsquic_engine_public; 16struct lsquic_packet_out; 17struct lsquic_packet_in; 18struct sockaddr; 19struct parse_funcs; 20struct attq_elem; 21 22enum lsquic_conn_flags { 23 LSCONN_HAS_INCOMING = (1 << 0), 24 LSCONN_HAS_OUTGOING = (1 << 1), 25 LSCONN_HASHED = (1 << 2), 26 LSCONN_HAS_PEER_SA = (1 << 4), 27 LSCONN_HAS_LOCAL_SA = (1 << 5), 28 LSCONN_HANDSHAKE_DONE = (1 << 6), 29 LSCONN_CLOSING = (1 << 7), 30 LSCONN_PEER_GOING_AWAY= (1 << 8), 31 LSCONN_TCID0 = (1 << 9), 32 LSCONN_VER_SET = (1 <<10), /* cn_version is set */ 33 LSCONN_EVANESCENT = (1 <<11), /* evanescent connection */ 34 LSCONN_RW_PENDING = (1 <<12), 35 LSCONN_COI_ACTIVE = (1 <<13), 36 LSCONN_COI_INACTIVE = (1 <<14), 37 LSCONN_SEND_BLOCKED = (1 <<15), /* Send connection blocked frame */ 38 LSCONN_NEVER_PEND_RW = (1 <<17), /* Do not put onto Pending RW queue */ 39 LSCONN_ATTQ = (1 <<19), 40}; 41 42#define TICK_BIT_PROGRESS 3 43 44/* A connection may have things to send and be closed at the same time. 45 */ 46enum tick_st { 47 TICK_SEND = (1 << 0), 48 TICK_CLOSE = (1 << 1), 49 /* Progress was made (see @ref es_pendrw_check for definition of 50 * "progress.") 51 */ 52 TICK_PROGRESS= (1 << TICK_BIT_PROGRESS), 53}; 54 55#define TICK_QUIET 0 56 57struct conn_iface 58{ 59 enum tick_st 60 (*ci_tick) (struct lsquic_conn *, lsquic_time_t now); 61 62 void 63 (*ci_packet_in) (struct lsquic_conn *, struct lsquic_packet_in *); 64 65 struct lsquic_packet_out * 66 (*ci_next_packet_to_send) (struct lsquic_conn *); 67 68 void 69 (*ci_packet_sent) (struct lsquic_conn *, struct lsquic_packet_out *); 70 71 void 72 (*ci_packet_not_sent) (struct lsquic_conn *, struct lsquic_packet_out *); 73 74 void 75 (*ci_handshake_done) (struct lsquic_conn *); 76 77 int 78 (*ci_user_wants_read) (struct lsquic_conn *); 79 80 void 81 (*ci_destroy) (struct lsquic_conn *); 82}; 83 84#define RW_HIST_BITS 6 85typedef unsigned char rw_hist_idx_t; 86 87struct lsquic_conn 88{ 89 void *cn_peer_ctx; 90 struct lsquic_enc_session *cn_enc_session; 91 lsquic_cid_t cn_cid; 92 STAILQ_ENTRY(lsquic_conn) cn_next_closed_conn; 93 TAILQ_ENTRY(lsquic_conn) cn_next_all, 94 cn_next_in, 95 cn_next_pend_rw, 96 cn_next_out, 97 cn_next_hash; 98 const struct conn_iface *cn_if; 99 const struct parse_funcs *cn_pf; 100 struct attq_elem *cn_attq_elem; 101 lsquic_time_t cn_last_sent; 102 enum lsquic_conn_flags cn_flags; 103 enum lsquic_version cn_version; 104 unsigned cn_noprogress_count; 105 unsigned cn_hash; 106 unsigned short cn_pack_size; 107 rw_hist_idx_t cn_rw_hist_idx; 108 unsigned char cn_rw_hist_buf[ 1 << RW_HIST_BITS ]; 109 unsigned char cn_peer_addr[sizeof(struct sockaddr_in6)], 110 cn_local_addr[sizeof(struct sockaddr_in6)]; 111}; 112 113void 114lsquic_conn_record_sockaddr (lsquic_conn_t *lconn, const struct sockaddr *local, 115 const struct sockaddr *peer); 116 117void 118lsquic_conn_record_peer_sa (lsquic_conn_t *lconn, const struct sockaddr *peer); 119 120int 121lsquic_conn_decrypt_packet (lsquic_conn_t *lconn, 122 struct lsquic_engine_public *, struct lsquic_packet_in *); 123 124int 125lsquic_conn_copy_and_release_pi_data (const lsquic_conn_t *conn, 126 struct lsquic_engine_public *, struct lsquic_packet_in *); 127 128#define lsquic_conn_adv_time(c) ((c)->cn_attq_elem->ae_adv_time) 129 130#endif 131