lsquic_alarmset.h revision 06b2a236
1/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc.  See LICENSE. */
2/*
3 * lsquic_alarmset.h -- A set of alarms
4 */
5
6#ifndef LSQUIC_ALARM_H
7#define LSQUIC_ALARM_H 1
8
9#include "lsquic_int_types.h"
10
11enum alarm_id;
12struct lsquic_conn;
13
14typedef void (*lsquic_alarm_cb_f)(enum alarm_id, void *cb_ctx,
15                                  lsquic_time_t expiry, lsquic_time_t now);
16
17typedef struct lsquic_alarm {
18    lsquic_alarm_cb_f           callback;
19    void                       *cb_ctx;
20} lsquic_alarm_t;
21
22
23enum alarm_id {
24    AL_HANDSHAKE,
25    AL_RETX_INIT,
26    AL_RETX_HSK = AL_RETX_INIT + PNS_HSK,
27    AL_RETX_APP = AL_RETX_INIT + PNS_APP,
28    AL_PING,
29    AL_MTU_PROBE,
30    AL_IDLE,
31    AL_ACK_APP,
32    AL_RET_CIDS,
33    AL_CID_THROT,
34    AL_PATH_CHAL,
35    AL_PATH_CHAL_0 = AL_PATH_CHAL,
36    AL_PATH_CHAL_1,
37    AL_PATH_CHAL_2,
38    AL_PATH_CHAL_3,
39    AL_SESS_TICKET,
40    AL_BLOCKED_KA,      /* Blocked Keep-Alive */
41    AL_PACK_TOL,        /* Calculate packet tolerance */
42    MAX_LSQUIC_ALARMS
43};
44
45
46enum alarm_id_bit {
47    ALBIT_HANDSHAKE = 1 << AL_HANDSHAKE,
48    ALBIT_RETX_INIT = 1 << AL_RETX_INIT,
49    ALBIT_RETX_HSK  = 1 << AL_RETX_HSK,
50    ALBIT_RETX_APP  = 1 << AL_RETX_APP,
51    ALBIT_ACK_APP   = 1 << AL_ACK_APP,
52    ALBIT_PING      = 1 << AL_PING,
53    ALBIT_IDLE      = 1 << AL_IDLE,
54    ALBIT_RET_CIDS  = 1 << AL_RET_CIDS,
55    ALBIT_CID_THROT = 1 << AL_CID_THROT,
56    ALBIT_PATH_CHAL_0 = 1 << AL_PATH_CHAL_0,
57    ALBIT_PATH_CHAL_1 = 1 << AL_PATH_CHAL_1,
58    ALBIT_PATH_CHAL_2 = 1 << AL_PATH_CHAL_2,
59    ALBIT_PATH_CHAL_3 = 1 << AL_PATH_CHAL_3,
60    ALBIT_SESS_TICKET = 1 << AL_SESS_TICKET,
61    ALBIT_BLOCKED_KA  = 1 << AL_BLOCKED_KA,
62    ALBIT_MTU_PROBE = 1 << AL_MTU_PROBE,
63    ALBIT_PACK_TOL = 1 << AL_PACK_TOL,
64};
65
66
67typedef struct lsquic_alarmset {
68    enum alarm_id_bit           as_armed_set;
69    lsquic_time_t               as_expiry[MAX_LSQUIC_ALARMS];
70    const struct lsquic_conn   *as_conn;    /* Used for logging */
71    struct lsquic_alarm         as_alarms[MAX_LSQUIC_ALARMS];
72} lsquic_alarmset_t;
73
74
75void
76lsquic_alarmset_init (lsquic_alarmset_t *, const struct lsquic_conn *);
77
78void
79lsquic_alarmset_init_alarm (lsquic_alarmset_t *, enum alarm_id,
80                            lsquic_alarm_cb_f, void *cb_ctx);
81
82#define lsquic_alarmset_set(alarmset, al_id, exp) do {                  \
83    (alarmset)->as_armed_set |= 1 << (al_id);                           \
84    (alarmset)->as_expiry[al_id] = exp;                                 \
85} while (0)
86
87#define lsquic_alarmset_unset(alarmset, al_id) do {                     \
88    (alarmset)->as_armed_set &= ~(1 << (al_id));                        \
89} while (0)
90
91#define lsquic_alarmset_is_set(alarmset, al_id) \
92                            ((alarmset)->as_armed_set & (1 << (al_id)))
93
94#define lsquic_alarmset_are_set(alarmset, flags) \
95                            ((alarmset)->as_armed_set & (flags))
96
97#define lsquic_alarmset_is_inited(alarmset_, al_id_) (                  \
98    (alarmset_)->as_alarms[al_id_].callback)
99
100/* Timers "fire," alarms "ring." */
101void
102lsquic_alarmset_ring_expired (lsquic_alarmset_t *, lsquic_time_t now);
103
104lsquic_time_t
105lsquic_alarmset_mintime (const lsquic_alarmset_t *, enum alarm_id *);
106
107extern const char *const lsquic_alid2str[];
108
109#endif
110