lsquic_rechist.h revision f198a02d
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    enum {
34        RH_CUTOFF_SET   = (1 << 0),
35    }                               rh_flags;
36    struct
37    {
38        struct lsquic_packno_range      range;
39        unsigned                        next;
40    }                               rh_iter;
41#if LSQUIC_TEST
42    unsigned                        rh_n_ops;
43#endif
44};
45
46typedef struct lsquic_rechist lsquic_rechist_t;
47
48void
49lsquic_rechist_init (struct lsquic_rechist *, int is_ietf);
50
51void
52lsquic_rechist_cleanup (struct lsquic_rechist *);
53
54enum received_st {
55    REC_ST_OK,
56    REC_ST_DUP,
57    REC_ST_ERR,
58};
59
60enum received_st
61lsquic_rechist_received (lsquic_rechist_t *, lsquic_packno_t,
62                         lsquic_time_t now);
63
64void
65lsquic_rechist_stop_wait (lsquic_rechist_t *, lsquic_packno_t);
66
67const struct lsquic_packno_range *
68lsquic_rechist_first (lsquic_rechist_t *);
69
70const struct lsquic_packno_range *
71lsquic_rechist_next (lsquic_rechist_t *);
72
73lsquic_packno_t
74lsquic_rechist_largest_packno (const lsquic_rechist_t *);
75
76lsquic_packno_t
77lsquic_rechist_cutoff (const lsquic_rechist_t *);
78
79lsquic_time_t
80lsquic_rechist_largest_recv (const lsquic_rechist_t *);
81
82size_t
83lsquic_rechist_mem_used (const struct lsquic_rechist *);
84
85const struct lsquic_packno_range *
86lsquic_rechist_peek (struct lsquic_rechist *);
87
88#define lsquic_rechist_is_empty(rechist_) ((rechist_)->rh_n_used == 0)
89
90int
91lsquic_rechist_copy_ranges (struct lsquic_rechist *, void *rechist_ctx,
92    const struct lsquic_packno_range * (*first) (void *),
93    const struct lsquic_packno_range * (*next) (void *));
94
95#endif
96