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