ngtcp2_log.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* defined(HAVE_CONFIG_H) */
  30. #include <ngtcp2/ngtcp2.h>
  31. #include "ngtcp2_pkt.h"
  32. typedef struct ngtcp2_log {
  33. /* log_printf is a sink to write log. NULL means no logging
  34. output. */
  35. ngtcp2_printf log_printf;
  36. /* events is an event filter. Only events set in this field are
  37. emitted. */
  38. uint8_t events;
  39. /* ts is the time point used to write time delta in the log. */
  40. ngtcp2_tstamp ts;
  41. /* last_ts is the most recent time point that this object is
  42. told. */
  43. ngtcp2_tstamp last_ts;
  44. /* user_data is user-defined opaque data which is passed to
  45. log_pritnf. */
  46. void *user_data;
  47. /* scid is SCID encoded as NULL-terminated hex string. */
  48. uint8_t scid[NGTCP2_MAX_CIDLEN * 2 + 1];
  49. } ngtcp2_log;
  50. /**
  51. * @enum
  52. *
  53. * :type:`ngtcp2_log_event` defines an event of ngtcp2 library
  54. * internal logger.
  55. */
  56. typedef enum ngtcp2_log_event {
  57. /**
  58. * :enum:`NGTCP2_LOG_EVENT_NONE` represents no event.
  59. */
  60. NGTCP2_LOG_EVENT_NONE,
  61. /**
  62. * :enum:`NGTCP2_LOG_EVENT_CON` is a connection (catch-all) event
  63. */
  64. NGTCP2_LOG_EVENT_CON = 0x1,
  65. /**
  66. * :enum:`NGTCP2_LOG_EVENT_PKT` is a packet event.
  67. */
  68. NGTCP2_LOG_EVENT_PKT = 0x2,
  69. /**
  70. * :enum:`NGTCP2_LOG_EVENT_FRM` is a QUIC frame event.
  71. */
  72. NGTCP2_LOG_EVENT_FRM = 0x4,
  73. /**
  74. * :enum:`NGTCP2_LOG_EVENT_LDC` is a loss detection and congestion
  75. * control event.
  76. */
  77. NGTCP2_LOG_EVENT_LDC = 0x8,
  78. /**
  79. * :enum:`NGTCP2_LOG_EVENT_CRY` is a crypto event.
  80. */
  81. NGTCP2_LOG_EVENT_CRY = 0x10,
  82. /**
  83. * :enum:`NGTCP2_LOG_EVENT_PTV` is a path validation event.
  84. */
  85. NGTCP2_LOG_EVENT_PTV = 0x20,
  86. /**
  87. * :enum:`NGTCP2_LOG_EVENT_CCA` is a congestion controller algorithm
  88. * event.
  89. */
  90. NGTCP2_LOG_EVENT_CCA = 0x40,
  91. } ngtcp2_log_event;
  92. void ngtcp2_log_init(ngtcp2_log *log, const ngtcp2_cid *scid,
  93. ngtcp2_printf log_printf, ngtcp2_tstamp ts,
  94. void *user_data);
  95. void ngtcp2_log_rx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
  96. const ngtcp2_frame *fr);
  97. void ngtcp2_log_tx_fr(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
  98. const ngtcp2_frame *fr);
  99. void ngtcp2_log_rx_vn(ngtcp2_log *log, const ngtcp2_pkt_hd *hd,
  100. const uint32_t *sv, size_t nsv);
  101. void ngtcp2_log_rx_sr(ngtcp2_log *log, const ngtcp2_pkt_stateless_reset *sr);
  102. void ngtcp2_log_remote_tp(ngtcp2_log *log,
  103. const ngtcp2_transport_params *params);
  104. void ngtcp2_log_pkt_lost(ngtcp2_log *log, int64_t pkt_num, uint8_t type,
  105. uint8_t flags, ngtcp2_tstamp sent_ts);
  106. void ngtcp2_log_rx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd);
  107. void ngtcp2_log_tx_pkt_hd(ngtcp2_log *log, const ngtcp2_pkt_hd *hd);
  108. void ngtcp2_log_tx_cancel(ngtcp2_log *log, const ngtcp2_pkt_hd *hd);
  109. /**
  110. * @function
  111. *
  112. * `ngtcp2_log_info` writes info level log.
  113. */
  114. void ngtcp2_log_info(ngtcp2_log *log, ngtcp2_log_event ev, const char *fmt,
  115. ...);
  116. #endif /* !defined(NGTCP2_LOG_H) */