lsquic_conn.h revision e8bd737d
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 int 78 (*ci_user_wants_read) (struct lsquic_conn *); 79 80 void 81 (*ci_destroy) (struct lsquic_conn *); 82 83 int 84 (*ci_is_tickable) (struct lsquic_conn *); 85 86 lsquic_time_t 87 (*ci_next_tick_time) (struct lsquic_conn *); 88}; 89 90struct lsquic_conn 91{ 92 void *cn_peer_ctx; 93 struct lsquic_enc_session *cn_enc_session; 94 const struct enc_session_funcs 95 *cn_esf; 96 lsquic_cid_t cn_cid; 97 STAILQ_ENTRY(lsquic_conn) cn_next_closed_conn; 98 STAILQ_ENTRY(lsquic_conn) cn_next_ticked; 99 TAILQ_ENTRY(lsquic_conn) cn_next_out, 100 cn_next_hash; 101 const struct conn_iface *cn_if; 102 const struct parse_funcs *cn_pf; 103 struct attq_elem *cn_attq_elem; 104 lsquic_time_t cn_last_sent; 105 lsquic_time_t cn_last_ticked; 106 enum lsquic_conn_flags cn_flags; 107 enum lsquic_version cn_version; 108 unsigned cn_hash; 109 unsigned short cn_pack_size; 110 unsigned char cn_peer_addr[sizeof(struct sockaddr_in6)], 111 cn_local_addr[sizeof(struct sockaddr_in6)]; 112}; 113 114void 115lsquic_conn_record_sockaddr (lsquic_conn_t *lconn, const struct sockaddr *local, 116 const struct sockaddr *peer); 117 118void 119lsquic_conn_record_peer_sa (lsquic_conn_t *lconn, const struct sockaddr *peer); 120 121int 122lsquic_conn_decrypt_packet (lsquic_conn_t *lconn, 123 struct lsquic_engine_public *, struct lsquic_packet_in *); 124 125int 126lsquic_conn_copy_and_release_pi_data (const lsquic_conn_t *conn, 127 struct lsquic_engine_public *, struct lsquic_packet_in *); 128 129#define lsquic_conn_adv_time(c) ((c)->cn_attq_elem->ae_adv_time) 130 131#endif 132