| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#ifndef NGTCP2_LOG_H |
| 26 |
#define NGTCP2_LOG_H |
| 27 |
|
| 28 |
#ifdef HAVE_CONFIG_H |
| 29 |
# include <config.h> |
| 30 |
#endif |
| 31 |
|
| 32 |
#include <ngtcp2/ngtcp2.h> |
| 33 |
|
| 34 |
#include "ngtcp2_pkt.h" |
| 35 |
|
| 36 |
typedef struct ngtcp2_log { |
| 37 |
|
| 38 |
|
| 39 |
ngtcp2_printf log_printf; |
| 40 |
|
| 41 |
|
| 42 |
uint8_t events; |
| 43 |
|
| 44 |
ngtcp2_tstamp ts; |
| 45 |
|
| 46 |
|
| 47 |
ngtcp2_tstamp last_ts; |
| 48 |
|
| 49 |
|
| 50 |
void *user_data; |
| 51 |
|
| 52 |
char scid[NGTCP2_MAX_CIDLEN * 2 + 1]; |
| 53 |
} ngtcp2_log; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
typedef enum ngtcp2_log_event { |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
NGTCP2_LOG_EVENT_NONE, |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
NGTCP2_LOG_EVENT_CON = 0x1, |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
NGTCP2_LOG_EVENT_PKT = 0x2, |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
NGTCP2_LOG_EVENT_FRM = 0x4, |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
NGTCP2_LOG_EVENT_LDC = 0x8, |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
NGTCP2_LOG_EVENT_CRY = 0x10, |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
NGTCP2_LOG_EVENT_PTV = 0x20, |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
NGTCP2_LOG_EVENT_CCA = 0x40, |
| 96 |
} ngtcp2_log_event; |
| 97 |
|
| 98 |
void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid, |
| 99 |
ngtcp2_printf log_printf, ngtcp2_tstamp ts, |
| 100 |
void *user_data); |
| 101 |
|
| 102 |
void ngtcp2_log_rx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, |
| 103 |
const ngtcp2_frame *fr); |
| 104 |
void ngtcp2_log_tx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, |
| 105 |
const ngtcp2_frame *fr); |
| 106 |
|
| 107 |
void ngtcp2_log_rx_vn(ngtcp2_log *log, const ngtcp2_pkt_hd *hd, |
| 108 |
const uint32_t *sv, size_t nsv); |
| 109 |
|
| 110 |
void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset *sr); |
| 111 |
|
| 112 |
void ngtcp2_log_remote_tp(ngtcp2_log *log, |
| 113 |
const ngtcp2_transport_params *params); |
| 114 |
|
| 115 |
void ngtcp2_log_pkt_lost(ngtcp2_log *log, int64_t pkt_num, uint8_t type, |
| 116 |
uint8_t flags, ngtcp2_tstamp sent_ts); |
| 117 |
|
| 118 |
void ngtcp2_log_rx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd); |
| 119 |
|
| 120 |
void ngtcp2_log_tx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd); |
| 121 |
|
| 122 |
void ngtcp2_log_tx_cancel(ngtcp2_log *log, const ngtcp2_pkt_hd *hd); |
| 123 |
|
| 124 |
#define NGTCP2_LOG_HD "I%08" PRIu64 " 0x%s %s" |
| 125 |
|
| 126 |
uint64_t ngtcp2_log_timestamp(const ngtcp2_log *log); |
| 127 |
|
| 128 |
static inline const char *ngtcp2_log_event_str(ngtcp2_log_event ev) { |
| 129 |
switch (ev) { |
| 130 |
case NGTCP2_LOG_EVENT_CON: |
| 131 |
return "con"; |
| 132 |
case NGTCP2_LOG_EVENT_PKT: |
| 133 |
return "pkt"; |
| 134 |
case NGTCP2_LOG_EVENT_FRM: |
| 135 |
return "frm"; |
| 136 |
case NGTCP2_LOG_EVENT_LDC: |
| 137 |
return "ldc"; |
| 138 |
case NGTCP2_LOG_EVENT_CRY: |
| 139 |
return "cry"; |
| 140 |
case NGTCP2_LOG_EVENT_PTV: |
| 141 |
return "ptv"; |
| 142 |
case NGTCP2_LOG_EVENT_CCA: |
| 143 |
return "cca"; |
| 144 |
case NGTCP2_LOG_EVENT_NONE: |
| 145 |
default: |
| 146 |
return "non"; |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
#define ngtcp2_log_infof_raw(LOG, EV, FMT, ...) \ |
| 151 |
(LOG)->log_printf((LOG)->user_data, NGTCP2_LOG_HD " " FMT, \ |
| 152 |
ngtcp2_log_timestamp(LOG), (LOG)->scid, \ |
| 153 |
ngtcp2_log_event_str(EV), __VA_ARGS__); |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
#define ngtcp2_log_infof(LOG, EV, FMT, ...) \ |
| 162 |
do { \ |
| 163 |
if (!(LOG)->log_printf || !((LOG)->events & (EV))) { \ |
| 164 |
break; \ |
| 165 |
} \ |
| 166 |
\ |
| 167 |
ngtcp2_log_infof_raw((LOG), (EV), FMT, __VA_ARGS__); \ |
| 168 |
} while (0) |
| 169 |
|
| 170 |
#define ngtcp2_log_info_raw(LOG, EV, FMT) \ |
| 171 |
(LOG)->log_printf((LOG)->user_data, NGTCP2_LOG_HD " " FMT, \ |
| 172 |
ngtcp2_log_timestamp(LOG), (LOG)->scid, \ |
| 173 |
ngtcp2_log_event_str(EV)) |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
#define ngtcp2_log_info(LOG, EV, FMT) \ |
| 183 |
do { \ |
| 184 |
if (!(LOG)->log_printf || !((LOG)->events & (EV))) { \ |
| 185 |
break; \ |
| 186 |
} \ |
| 187 |
\ |
| 188 |
ngtcp2_log_info_raw((LOG), (EV), FMT); \ |
| 189 |
} while (0) |
| 190 |
|
| 191 |
#endif |