• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ngtcp2
3  *
4  * Copyright (c) 2018 ngtcp2 contributors
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #ifndef NGTCP2_LOG_H
26 #define NGTCP2_LOG_H
27 
28 #ifdef HAVE_CONFIG_H
29 #  include <config.h>
30 #endif /* HAVE_CONFIG_H */
31 
32 #include <ngtcp2/ngtcp2.h>
33 
34 #include "ngtcp2_pkt.h"
35 
36 typedef struct ngtcp2_log {
37   /* log_printf is a sink to write log.  NULL means no logging
38      output. */
39   ngtcp2_printf log_printf;
40   /* ts is the time point used to write time delta in the log. */
41   ngtcp2_tstamp ts;
42   /* last_ts is the most recent time point that this object is
43      told. */
44   ngtcp2_tstamp last_ts;
45   /* user_data is user-defined opaque data which is passed to
46      log_pritnf. */
47   void *user_data;
48   /* scid is SCID encoded as NULL-terminated hex string. */
49   uint8_t scid[NGTCP2_MAX_CIDLEN * 2 + 1];
50 } ngtcp2_log;
51 
52 /**
53  * @enum
54  *
55  * :type:`ngtcp2_log_event` defines an event of ngtcp2 library
56  * internal logger.
57  */
58 typedef enum ngtcp2_log_event {
59   /**
60    * :enum:`NGTCP2_LOG_EVENT_NONE` represents no event.
61    */
62   NGTCP2_LOG_EVENT_NONE,
63   /**
64    * :enum:`NGTCP2_LOG_EVENT_CON` is a connection (catch-all) event
65    */
66   NGTCP2_LOG_EVENT_CON,
67   /**
68    * :enum:`NGTCP2_LOG_EVENT_PKT` is a packet event.
69    */
70   NGTCP2_LOG_EVENT_PKT,
71   /**
72    * :enum:`NGTCP2_LOG_EVENT_FRM` is a QUIC frame event.
73    */
74   NGTCP2_LOG_EVENT_FRM,
75   /**
76    * :enum:`NGTCP2_LOG_EVENT_RCV` is a congestion and recovery event.
77    */
78   NGTCP2_LOG_EVENT_RCV,
79   /**
80    * :enum:`NGTCP2_LOG_EVENT_CRY` is a crypto event.
81    */
82   NGTCP2_LOG_EVENT_CRY,
83   /**
84    * :enum:`NGTCP2_LOG_EVENT_PTV` is a path validation event.
85    */
86   NGTCP2_LOG_EVENT_PTV,
87 } ngtcp2_log_event;
88 
89 void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid,
90                      ngtcp2_printf log_printf, ngtcp2_tstamp ts,
91                      void *user_data);
92 
93 void ngtcp2_log_rx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
94                       const ngtcp2_frame *fr);
95 void ngtcp2_log_tx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
96                       const ngtcp2_frame *fr);
97 
98 void ngtcp2_log_rx_vn(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
99                       const uint32_t *sv, size_t nsv);
100 
101 void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset *sr);
102 
103 void ngtcp2_log_remote_tp(ngtcp2_log *log, uint8_t exttype,
104                           const ngtcp2_transport_params *params);
105 
106 void ngtcp2_log_pkt_lost(ngtcp2_log *log, int64_t pkt_num, uint8_t type,
107                          uint8_t flags, ngtcp2_tstamp sent_ts);
108 
109 void ngtcp2_log_rx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd);
110 
111 void ngtcp2_log_tx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd);
112 
113 void ngtcp2_log_tx_cancel(ngtcp2_log *log, const ngtcp2_pkt_hd *hd);
114 
115 /**
116  * @function
117  *
118  * `ngtcp2_log_info` writes info level log.
119  */
120 void ngtcp2_log_info(ngtcp2_log *log, ngtcp2_log_event ev, const char *fmt,
121                      ...);
122 
123 #endif /* NGTCP2_LOG_H */
124