lsquic_rechist.h revision f38b395a
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#ifndef LSQUIC_TEST 12#define LSQUIC_TEST 0 13#endif 14 15/* Structure is exposed to facilitate some manipulations in unit tests. */ 16struct rechist_elem { 17 lsquic_packno_t re_low; 18 unsigned re_count; 19 unsigned re_next; /* UINT_MAX means no next element */ 20}; 21 22 23struct lsquic_rechist { 24 /* elems and masks are allocated in contiguous memory */ 25 struct rechist_elem *rh_elems; 26 uintptr_t *rh_masks; 27 lsquic_packno_t rh_cutoff; 28 lsquic_time_t rh_largest_acked_received; 29 unsigned rh_n_masks; 30 unsigned rh_n_alloced; 31 unsigned rh_n_used; 32 unsigned rh_head; 33 unsigned rh_max_ranges; 34 enum { 35 RH_CUTOFF_SET = (1 << 0), 36 } rh_flags; 37 struct 38 { 39 struct lsquic_packno_range range; 40 unsigned next; 41 } rh_iter; 42#if LSQUIC_TEST 43 unsigned rh_n_ops; 44#endif 45}; 46 47typedef struct lsquic_rechist lsquic_rechist_t; 48 49void 50lsquic_rechist_init (struct lsquic_rechist *, int is_ietf, unsigned max_ranges); 51 52void 53lsquic_rechist_cleanup (struct lsquic_rechist *); 54 55enum received_st { 56 REC_ST_OK, 57 REC_ST_DUP, 58 REC_ST_ERR, 59}; 60 61enum received_st 62lsquic_rechist_received (lsquic_rechist_t *, lsquic_packno_t, 63 lsquic_time_t now); 64 65void 66lsquic_rechist_stop_wait (lsquic_rechist_t *, lsquic_packno_t); 67 68const struct lsquic_packno_range * 69lsquic_rechist_first (lsquic_rechist_t *); 70 71const struct lsquic_packno_range * 72lsquic_rechist_next (lsquic_rechist_t *); 73 74lsquic_packno_t 75lsquic_rechist_largest_packno (const lsquic_rechist_t *); 76 77lsquic_packno_t 78lsquic_rechist_cutoff (const lsquic_rechist_t *); 79 80lsquic_time_t 81lsquic_rechist_largest_recv (const lsquic_rechist_t *); 82 83size_t 84lsquic_rechist_mem_used (const struct lsquic_rechist *); 85 86const struct lsquic_packno_range * 87lsquic_rechist_peek (struct lsquic_rechist *); 88 89#define lsquic_rechist_is_empty(rechist_) ((rechist_)->rh_n_used == 0) 90 91int 92lsquic_rechist_copy_ranges (struct lsquic_rechist *, void *rechist_ctx, 93 const struct lsquic_packno_range * (*first) (void *), 94 const struct lsquic_packno_range * (*next) (void *)); 95 96#endif 97