lsquic_senhist.h revision 50aadb33
1/* Copyright (c) 2017 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_senhist.h -- History sent packets.
4 *
5 * We only keep track of packet numbers in order to verify ACKs.
6 */
7
8#ifndef LSQUIC_SENHIST_H
9#define LSQUIC_SENHIST_H 1
10
11#include "lsquic_packints.h"
12
13typedef struct lsquic_senhist {
14    /* These ranges are ordered from high to low.  While searching this
15     * structure is O(n), I expect that in practice, a very long search
16     * could only happen once before the connection is terminated,
17     * because:
18     *  a) either the packet number far away is real, but it was so long
19     *     ago that it would have timed out by now (RTO); or
20     *  b) the peer sends an invalid ACK.
21     */
22    struct packints             sh_pints;
23#ifndef NDEBUG
24    enum {
25        SH_REORDER  = (1 << 0),
26    }                           sh_flags;
27#endif
28} lsquic_senhist_t;
29
30void
31lsquic_senhist_init (lsquic_senhist_t *);
32
33void
34lsquic_senhist_cleanup (lsquic_senhist_t *);
35
36int
37lsquic_senhist_add (lsquic_senhist_t *, lsquic_packno_t);
38
39/* Returns true if history contains all packets numbers in this range.
40 */
41int
42lsquic_senhist_sent_range (lsquic_senhist_t *, lsquic_packno_t low,
43                                               lsquic_packno_t high);
44
45/* Returns 0 if no packets have been sent yet */
46lsquic_packno_t
47lsquic_senhist_largest (lsquic_senhist_t *hist);
48
49void
50lsquic_senhist_tostr (lsquic_senhist_t *hist, char *buf, size_t bufsz);
51
52#endif
53