lsquic_conn.h revision 82f3bcef
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_OUTGOING = (1 << 1), 28 LSCONN_HASHED = (1 << 2), 29 LSCONN_HAS_PEER_SA = (1 << 4), 30 LSCONN_HAS_LOCAL_SA = (1 << 5), 31 LSCONN_HANDSHAKE_DONE = (1 << 6), 32 LSCONN_CLOSING = (1 << 7), 33 LSCONN_PEER_GOING_AWAY= (1 << 8), 34 LSCONN_TCID0 = (1 << 9), 35 LSCONN_VER_SET = (1 <<10), /* cn_version is set */ 36 LSCONN_EVANESCENT = (1 <<11), /* evanescent connection */ 37 LSCONN_TICKABLE = (1 <<12), /* Connection is in the Tickable Queue */ 38 LSCONN_COI_ACTIVE = (1 <<13), 39 LSCONN_COI_INACTIVE = (1 <<14), 40 LSCONN_SEND_BLOCKED = (1 <<15), /* Send connection blocked frame */ 41 LSCONN_NEVER_TICKABLE = (1 <<17), /* Do not put onto the Tickable Queue */ 42 LSCONN_ATTQ = (1 <<19), 43}; 44 45/* A connection may have things to send and be closed at the same time. 46 */ 47enum tick_st { 48 TICK_SEND = (1 << 0), 49 TICK_CLOSE = (1 << 1), 50}; 51 52#define TICK_QUIET 0 53 54struct conn_iface 55{ 56 enum tick_st 57 (*ci_tick) (struct lsquic_conn *, lsquic_time_t now); 58 59 void 60 (*ci_packet_in) (struct lsquic_conn *, struct lsquic_packet_in *); 61 62 struct lsquic_packet_out * 63 (*ci_next_packet_to_send) (struct lsquic_conn *); 64 65 void 66 (*ci_packet_sent) (struct lsquic_conn *, struct lsquic_packet_out *); 67 68 void 69 (*ci_packet_not_sent) (struct lsquic_conn *, struct lsquic_packet_out *); 70 71 void 72 (*ci_handshake_ok) (struct lsquic_conn *); 73 74 void 75 (*ci_handshake_failed) (struct lsquic_conn *); 76 77 void 78 (*ci_destroy) (struct lsquic_conn *); 79 80 int 81 (*ci_is_tickable) (struct lsquic_conn *); 82 83 lsquic_time_t 84 (*ci_next_tick_time) (struct lsquic_conn *); 85}; 86 87struct lsquic_conn 88{ 89 void *cn_peer_ctx; 90 struct lsquic_enc_session *cn_enc_session; 91 const struct enc_session_funcs 92 *cn_esf; 93 lsquic_cid_t cn_cid; 94 STAILQ_ENTRY(lsquic_conn) cn_next_closed_conn; 95 STAILQ_ENTRY(lsquic_conn) cn_next_ticked; 96 TAILQ_ENTRY(lsquic_conn) 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 lsquic_time_t cn_last_ticked; 103 enum lsquic_conn_flags cn_flags; 104 enum lsquic_version cn_version; 105 unsigned cn_hash; 106 unsigned short cn_pack_size; 107 unsigned char cn_peer_addr[sizeof(struct sockaddr_in6)], 108 cn_local_addr[sizeof(struct sockaddr_in6)]; 109}; 110 111void 112lsquic_conn_record_sockaddr (lsquic_conn_t *lconn, const struct sockaddr *local, 113 const struct sockaddr *peer); 114 115void 116lsquic_conn_record_peer_sa (lsquic_conn_t *lconn, const struct sockaddr *peer); 117 118int 119lsquic_conn_decrypt_packet (lsquic_conn_t *lconn, 120 struct lsquic_engine_public *, struct lsquic_packet_in *); 121 122int 123lsquic_conn_copy_and_release_pi_data (const lsquic_conn_t *conn, 124 struct lsquic_engine_public *, struct lsquic_packet_in *); 125 126#define lsquic_conn_adv_time(c) ((c)->cn_attq_elem->ae_adv_time) 127 128#endif 129