lsquic_rechist.h revision b62ec17f
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_rechist.h -- History of received packets. 4 * 5 * The purpose of received packet history is to generate ACK frames. 6 */ 7 8#ifndef LSQUIC_RECHIST_H 9#define LSQUIC_RECHIST_H 1 10 11 12/* Structure is exposed to facilitate some manipulations in unit tests. */ 13struct rechist_elem { 14 lsquic_packno_t re_low; 15 unsigned re_count; 16 unsigned re_next; /* UINT_MAX means no next element */ 17}; 18 19 20struct lsquic_rechist { 21 /* elems and masks are allocated in contiguous memory */ 22 struct rechist_elem *rh_elems; 23 uintptr_t *rh_masks; 24 lsquic_packno_t rh_cutoff; 25 lsquic_time_t rh_largest_acked_received; 26 unsigned rh_n_masks; 27 unsigned rh_n_alloced; 28 unsigned rh_n_used; 29 unsigned rh_head; 30 enum { 31 RH_CUTOFF_SET = (1 << 0), 32 } rh_flags; 33 struct 34 { 35 struct lsquic_packno_range range; 36 unsigned next; 37 } rh_iter; 38#if LSQUIC_TEST 39 unsigned rh_n_ops; 40#endif 41}; 42 43typedef struct lsquic_rechist lsquic_rechist_t; 44 45void 46lsquic_rechist_init (struct lsquic_rechist *, int is_ietf); 47 48void 49lsquic_rechist_cleanup (struct lsquic_rechist *); 50 51enum received_st { 52 REC_ST_OK, 53 REC_ST_DUP, 54 REC_ST_ERR, 55}; 56 57enum received_st 58lsquic_rechist_received (lsquic_rechist_t *, lsquic_packno_t, 59 lsquic_time_t now); 60 61void 62lsquic_rechist_stop_wait (lsquic_rechist_t *, lsquic_packno_t); 63 64const struct lsquic_packno_range * 65lsquic_rechist_first (lsquic_rechist_t *); 66 67const struct lsquic_packno_range * 68lsquic_rechist_next (lsquic_rechist_t *); 69 70lsquic_packno_t 71lsquic_rechist_largest_packno (const lsquic_rechist_t *); 72 73lsquic_packno_t 74lsquic_rechist_cutoff (const lsquic_rechist_t *); 75 76lsquic_time_t 77lsquic_rechist_largest_recv (const lsquic_rechist_t *); 78 79size_t 80lsquic_rechist_mem_used (const struct lsquic_rechist *); 81 82const struct lsquic_packno_range * 83lsquic_rechist_peek (struct lsquic_rechist *); 84 85#define lsquic_rechist_is_empty(rechist_) ((rechist_)->rh_n_used == 0) 86 87#endif 88