protocol-quic 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/ngtcp2/AUTHORS +44 -0
  4. data/ext/ngtcp2/CMakeLists.txt +431 -0
  5. data/ext/ngtcp2/CMakeOptions.txt +17 -0
  6. data/ext/ngtcp2/COPYING +22 -0
  7. data/ext/ngtcp2/ChangeLog +0 -0
  8. data/ext/ngtcp2/Makefile.am +60 -0
  9. data/ext/ngtcp2/NEWS +0 -0
  10. data/ext/ngtcp2/README +1 -0
  11. data/ext/ngtcp2/README.rst +258 -0
  12. data/ext/ngtcp2/ci/build_boringssl.sh +10 -0
  13. data/ext/ngtcp2/ci/build_nghttp3.sh +9 -0
  14. data/ext/ngtcp2/ci/build_openssl1.sh +8 -0
  15. data/ext/ngtcp2/ci/build_openssl1_cross.sh +9 -0
  16. data/ext/ngtcp2/ci/build_openssl3.sh +8 -0
  17. data/ext/ngtcp2/ci/build_picotls.sh +26 -0
  18. data/ext/ngtcp2/ci/build_wolfssl.sh +9 -0
  19. data/ext/ngtcp2/ci/gen-certificate.sh +8 -0
  20. data/ext/ngtcp2/cmake/ExtractValidFlags.cmake +31 -0
  21. data/ext/ngtcp2/cmake/FindCUnit.cmake +40 -0
  22. data/ext/ngtcp2/cmake/FindJemalloc.cmake +40 -0
  23. data/ext/ngtcp2/cmake/FindLibev.cmake +38 -0
  24. data/ext/ngtcp2/cmake/FindLibnghttp3.cmake +41 -0
  25. data/ext/ngtcp2/cmake/Findwolfssl.cmake +41 -0
  26. data/ext/ngtcp2/cmake/Version.cmake +11 -0
  27. data/ext/ngtcp2/cmakeconfig.h.in +36 -0
  28. data/ext/ngtcp2/configure.ac +755 -0
  29. data/ext/ngtcp2/crypto/CMakeLists.txt +56 -0
  30. data/ext/ngtcp2/crypto/Makefile.am +49 -0
  31. data/ext/ngtcp2/crypto/boringssl/CMakeLists.txt +64 -0
  32. data/ext/ngtcp2/crypto/boringssl/Makefile.am +39 -0
  33. data/ext/ngtcp2/crypto/boringssl/boringssl.c +630 -0
  34. data/ext/ngtcp2/crypto/boringssl/libngtcp2_crypto_boringssl.pc.in +33 -0
  35. data/ext/ngtcp2/crypto/gnutls/CMakeLists.txt +86 -0
  36. data/ext/ngtcp2/crypto/gnutls/Makefile.am +43 -0
  37. data/ext/ngtcp2/crypto/gnutls/gnutls.c +644 -0
  38. data/ext/ngtcp2/crypto/gnutls/libngtcp2_crypto_gnutls.pc.in +33 -0
  39. data/ext/ngtcp2/crypto/includes/CMakeLists.txt +56 -0
  40. data/ext/ngtcp2/crypto/includes/Makefile.am +45 -0
  41. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h +893 -0
  42. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_boringssl.h +104 -0
  43. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_gnutls.h +107 -0
  44. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h +132 -0
  45. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_picotls.h +246 -0
  46. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
  47. data/ext/ngtcp2/crypto/openssl/CMakeLists.txt +86 -0
  48. data/ext/ngtcp2/crypto/openssl/Makefile.am +43 -0
  49. data/ext/ngtcp2/crypto/openssl/libngtcp2_crypto_openssl.pc.in +33 -0
  50. data/ext/ngtcp2/crypto/openssl/openssl.c +807 -0
  51. data/ext/ngtcp2/crypto/picotls/CMakeLists.txt +65 -0
  52. data/ext/ngtcp2/crypto/picotls/Makefile.am +39 -0
  53. data/ext/ngtcp2/crypto/picotls/libngtcp2_crypto_picotls.pc.in +33 -0
  54. data/ext/ngtcp2/crypto/picotls/picotls.c +707 -0
  55. data/ext/ngtcp2/crypto/shared.c +1431 -0
  56. data/ext/ngtcp2/crypto/shared.h +350 -0
  57. data/ext/ngtcp2/crypto/wolfssl/CMakeLists.txt +84 -0
  58. data/ext/ngtcp2/crypto/wolfssl/Makefile.am +43 -0
  59. data/ext/ngtcp2/crypto/wolfssl/libngtcp2_crypto_wolfssl.pc.in +33 -0
  60. data/ext/ngtcp2/crypto/wolfssl/wolfssl.c +534 -0
  61. data/ext/ngtcp2/doc/Makefile.am +65 -0
  62. data/ext/ngtcp2/doc/make.bat +35 -0
  63. data/ext/ngtcp2/doc/mkapiref.py +356 -0
  64. data/ext/ngtcp2/doc/source/conf.py.in +94 -0
  65. data/ext/ngtcp2/doc/source/index.rst +22 -0
  66. data/ext/ngtcp2/doc/source/programmers-guide.rst +476 -0
  67. data/ext/ngtcp2/docker/Dockerfile +39 -0
  68. data/ext/ngtcp2/examples/CMakeLists.txt +361 -0
  69. data/ext/ngtcp2/examples/Makefile.am +228 -0
  70. data/ext/ngtcp2/examples/client.cc +3049 -0
  71. data/ext/ngtcp2/examples/client.h +192 -0
  72. data/ext/ngtcp2/examples/client_base.cc +202 -0
  73. data/ext/ngtcp2/examples/client_base.h +213 -0
  74. data/ext/ngtcp2/examples/debug.cc +298 -0
  75. data/ext/ngtcp2/examples/debug.h +124 -0
  76. data/ext/ngtcp2/examples/examplestest.cc +84 -0
  77. data/ext/ngtcp2/examples/gtlssimpleclient.c +720 -0
  78. data/ext/ngtcp2/examples/h09client.cc +2601 -0
  79. data/ext/ngtcp2/examples/h09client.h +196 -0
  80. data/ext/ngtcp2/examples/h09server.cc +3024 -0
  81. data/ext/ngtcp2/examples/h09server.h +237 -0
  82. data/ext/ngtcp2/examples/http.cc +138 -0
  83. data/ext/ngtcp2/examples/http.h +44 -0
  84. data/ext/ngtcp2/examples/network.h +80 -0
  85. data/ext/ngtcp2/examples/server.cc +3731 -0
  86. data/ext/ngtcp2/examples/server.h +256 -0
  87. data/ext/ngtcp2/examples/server_base.cc +58 -0
  88. data/ext/ngtcp2/examples/server_base.h +195 -0
  89. data/ext/ngtcp2/examples/shared.cc +385 -0
  90. data/ext/ngtcp2/examples/shared.h +96 -0
  91. data/ext/ngtcp2/examples/simpleclient.c +683 -0
  92. data/ext/ngtcp2/examples/template.h +71 -0
  93. data/ext/ngtcp2/examples/tests/README.rst +60 -0
  94. data/ext/ngtcp2/examples/tests/__init__.py +0 -0
  95. data/ext/ngtcp2/examples/tests/config.ini.in +32 -0
  96. data/ext/ngtcp2/examples/tests/conftest.py +28 -0
  97. data/ext/ngtcp2/examples/tests/ngtcp2test/__init__.py +6 -0
  98. data/ext/ngtcp2/examples/tests/ngtcp2test/certs.py +476 -0
  99. data/ext/ngtcp2/examples/tests/ngtcp2test/client.py +187 -0
  100. data/ext/ngtcp2/examples/tests/ngtcp2test/env.py +191 -0
  101. data/ext/ngtcp2/examples/tests/ngtcp2test/log.py +101 -0
  102. data/ext/ngtcp2/examples/tests/ngtcp2test/server.py +137 -0
  103. data/ext/ngtcp2/examples/tests/ngtcp2test/tls.py +983 -0
  104. data/ext/ngtcp2/examples/tests/test_01_handshake.py +30 -0
  105. data/ext/ngtcp2/examples/tests/test_02_resume.py +46 -0
  106. data/ext/ngtcp2/examples/tests/test_03_earlydata.py +56 -0
  107. data/ext/ngtcp2/examples/tests/test_04_clientcert.py +57 -0
  108. data/ext/ngtcp2/examples/tests/test_05_ciphers.py +46 -0
  109. data/ext/ngtcp2/examples/tls_client_context.h +52 -0
  110. data/ext/ngtcp2/examples/tls_client_context_boringssl.cc +126 -0
  111. data/ext/ngtcp2/examples/tls_client_context_boringssl.h +49 -0
  112. data/ext/ngtcp2/examples/tls_client_context_gnutls.cc +74 -0
  113. data/ext/ngtcp2/examples/tls_client_context_gnutls.h +50 -0
  114. data/ext/ngtcp2/examples/tls_client_context_openssl.cc +137 -0
  115. data/ext/ngtcp2/examples/tls_client_context_openssl.h +49 -0
  116. data/ext/ngtcp2/examples/tls_client_context_picotls.cc +158 -0
  117. data/ext/ngtcp2/examples/tls_client_context_picotls.h +53 -0
  118. data/ext/ngtcp2/examples/tls_client_context_wolfssl.cc +177 -0
  119. data/ext/ngtcp2/examples/tls_client_context_wolfssl.h +51 -0
  120. data/ext/ngtcp2/examples/tls_client_session.h +52 -0
  121. data/ext/ngtcp2/examples/tls_client_session_boringssl.cc +110 -0
  122. data/ext/ngtcp2/examples/tls_client_session_boringssl.h +52 -0
  123. data/ext/ngtcp2/examples/tls_client_session_gnutls.cc +190 -0
  124. data/ext/ngtcp2/examples/tls_client_session_gnutls.h +52 -0
  125. data/ext/ngtcp2/examples/tls_client_session_openssl.cc +113 -0
  126. data/ext/ngtcp2/examples/tls_client_session_openssl.h +52 -0
  127. data/ext/ngtcp2/examples/tls_client_session_picotls.cc +147 -0
  128. data/ext/ngtcp2/examples/tls_client_session_picotls.h +52 -0
  129. data/ext/ngtcp2/examples/tls_client_session_wolfssl.cc +160 -0
  130. data/ext/ngtcp2/examples/tls_client_session_wolfssl.h +52 -0
  131. data/ext/ngtcp2/examples/tls_server_context.h +52 -0
  132. data/ext/ngtcp2/examples/tls_server_context_boringssl.cc +257 -0
  133. data/ext/ngtcp2/examples/tls_server_context_boringssl.h +54 -0
  134. data/ext/ngtcp2/examples/tls_server_context_gnutls.cc +99 -0
  135. data/ext/ngtcp2/examples/tls_server_context_gnutls.h +59 -0
  136. data/ext/ngtcp2/examples/tls_server_context_openssl.cc +338 -0
  137. data/ext/ngtcp2/examples/tls_server_context_openssl.h +54 -0
  138. data/ext/ngtcp2/examples/tls_server_context_picotls.cc +321 -0
  139. data/ext/ngtcp2/examples/tls_server_context_picotls.h +58 -0
  140. data/ext/ngtcp2/examples/tls_server_context_wolfssl.cc +284 -0
  141. data/ext/ngtcp2/examples/tls_server_context_wolfssl.h +55 -0
  142. data/ext/ngtcp2/examples/tls_server_session.h +52 -0
  143. data/ext/ngtcp2/examples/tls_server_session_boringssl.cc +84 -0
  144. data/ext/ngtcp2/examples/tls_server_session_boringssl.h +47 -0
  145. data/ext/ngtcp2/examples/tls_server_session_gnutls.cc +155 -0
  146. data/ext/ngtcp2/examples/tls_server_session_gnutls.h +46 -0
  147. data/ext/ngtcp2/examples/tls_server_session_openssl.cc +54 -0
  148. data/ext/ngtcp2/examples/tls_server_session_openssl.h +47 -0
  149. data/ext/ngtcp2/examples/tls_server_session_picotls.cc +70 -0
  150. data/ext/ngtcp2/examples/tls_server_session_picotls.h +47 -0
  151. data/ext/ngtcp2/examples/tls_server_session_wolfssl.cc +55 -0
  152. data/ext/ngtcp2/examples/tls_server_session_wolfssl.h +47 -0
  153. data/ext/ngtcp2/examples/tls_session_base_gnutls.cc +87 -0
  154. data/ext/ngtcp2/examples/tls_session_base_gnutls.h +51 -0
  155. data/ext/ngtcp2/examples/tls_session_base_openssl.cc +54 -0
  156. data/ext/ngtcp2/examples/tls_session_base_openssl.h +52 -0
  157. data/ext/ngtcp2/examples/tls_session_base_picotls.cc +56 -0
  158. data/ext/ngtcp2/examples/tls_session_base_picotls.h +54 -0
  159. data/ext/ngtcp2/examples/tls_session_base_wolfssl.cc +54 -0
  160. data/ext/ngtcp2/examples/tls_session_base_wolfssl.h +54 -0
  161. data/ext/ngtcp2/examples/tls_shared_picotls.cc +59 -0
  162. data/ext/ngtcp2/examples/tls_shared_picotls.h +36 -0
  163. data/ext/ngtcp2/examples/util.cc +646 -0
  164. data/ext/ngtcp2/examples/util.h +361 -0
  165. data/ext/ngtcp2/examples/util_gnutls.cc +136 -0
  166. data/ext/ngtcp2/examples/util_openssl.cc +131 -0
  167. data/ext/ngtcp2/examples/util_test.cc +237 -0
  168. data/ext/ngtcp2/examples/util_test.h +45 -0
  169. data/ext/ngtcp2/examples/util_wolfssl.cc +130 -0
  170. data/ext/ngtcp2/fuzz/corpus/decode_frame/ack +0 -0
  171. data/ext/ngtcp2/fuzz/corpus/decode_frame/ack_ecn +0 -0
  172. data/ext/ngtcp2/fuzz/corpus/decode_frame/connection_close +0 -0
  173. data/ext/ngtcp2/fuzz/corpus/decode_frame/crypto +1 -0
  174. data/ext/ngtcp2/fuzz/corpus/decode_frame/data_blocked +1 -0
  175. data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram +1 -0
  176. data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram_len +1 -0
  177. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_data +1 -0
  178. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_stream_data +0 -0
  179. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_streams +0 -0
  180. data/ext/ngtcp2/fuzz/corpus/decode_frame/new_connection_id +1 -0
  181. data/ext/ngtcp2/fuzz/corpus/decode_frame/new_token +1 -0
  182. data/ext/ngtcp2/fuzz/corpus/decode_frame/path_challenge +1 -0
  183. data/ext/ngtcp2/fuzz/corpus/decode_frame/path_response +1 -0
  184. data/ext/ngtcp2/fuzz/corpus/decode_frame/reset_stream +0 -0
  185. data/ext/ngtcp2/fuzz/corpus/decode_frame/retire_connection_id +1 -0
  186. data/ext/ngtcp2/fuzz/corpus/decode_frame/stop_sending +0 -0
  187. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream +0 -0
  188. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_data_blocked +0 -0
  189. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_len +0 -0
  190. data/ext/ngtcp2/fuzz/corpus/decode_frame/streams_blocked +0 -0
  191. data/ext/ngtcp2/fuzz/corpus/ksl/random +0 -0
  192. data/ext/ngtcp2/fuzz/decode_frame.cc +25 -0
  193. data/ext/ngtcp2/fuzz/ksl.cc +77 -0
  194. data/ext/ngtcp2/interop/Dockerfile +39 -0
  195. data/ext/ngtcp2/interop/run_endpoint.sh +93 -0
  196. data/ext/ngtcp2/lib/CMakeLists.txt +110 -0
  197. data/ext/ngtcp2/lib/Makefile.am +122 -0
  198. data/ext/ngtcp2/lib/includes/CMakeLists.txt +4 -0
  199. data/ext/ngtcp2/lib/includes/Makefile.am +25 -0
  200. data/ext/ngtcp2/lib/includes/ngtcp2/ngtcp2.h +5843 -0
  201. data/ext/ngtcp2/lib/includes/ngtcp2/version.h.in +51 -0
  202. data/ext/ngtcp2/lib/libngtcp2.pc.in +33 -0
  203. data/ext/ngtcp2/lib/ngtcp2_acktr.c +335 -0
  204. data/ext/ngtcp2/lib/ngtcp2_acktr.h +221 -0
  205. data/ext/ngtcp2/lib/ngtcp2_addr.c +117 -0
  206. data/ext/ngtcp2/lib/ngtcp2_addr.h +69 -0
  207. data/ext/ngtcp2/lib/ngtcp2_balloc.c +90 -0
  208. data/ext/ngtcp2/lib/ngtcp2_balloc.h +91 -0
  209. data/ext/ngtcp2/lib/ngtcp2_bbr.c +693 -0
  210. data/ext/ngtcp2/lib/ngtcp2_bbr.h +157 -0
  211. data/ext/ngtcp2/lib/ngtcp2_bbr2.c +1490 -0
  212. data/ext/ngtcp2/lib/ngtcp2_bbr2.h +149 -0
  213. data/ext/ngtcp2/lib/ngtcp2_buf.c +56 -0
  214. data/ext/ngtcp2/lib/ngtcp2_buf.h +108 -0
  215. data/ext/ngtcp2/lib/ngtcp2_cc.c +616 -0
  216. data/ext/ngtcp2/lib/ngtcp2_cc.h +422 -0
  217. data/ext/ngtcp2/lib/ngtcp2_cid.c +147 -0
  218. data/ext/ngtcp2/lib/ngtcp2_cid.h +175 -0
  219. data/ext/ngtcp2/lib/ngtcp2_conn.c +13731 -0
  220. data/ext/ngtcp2/lib/ngtcp2_conn.h +1119 -0
  221. data/ext/ngtcp2/lib/ngtcp2_conn_stat.h +131 -0
  222. data/ext/ngtcp2/lib/ngtcp2_conv.c +291 -0
  223. data/ext/ngtcp2/lib/ngtcp2_conv.h +208 -0
  224. data/ext/ngtcp2/lib/ngtcp2_crypto.c +895 -0
  225. data/ext/ngtcp2/lib/ngtcp2_crypto.h +148 -0
  226. data/ext/ngtcp2/lib/ngtcp2_err.c +154 -0
  227. data/ext/ngtcp2/lib/ngtcp2_err.h +34 -0
  228. data/ext/ngtcp2/lib/ngtcp2_gaptr.c +167 -0
  229. data/ext/ngtcp2/lib/ngtcp2_gaptr.h +98 -0
  230. data/ext/ngtcp2/lib/ngtcp2_idtr.c +79 -0
  231. data/ext/ngtcp2/lib/ngtcp2_idtr.h +89 -0
  232. data/ext/ngtcp2/lib/ngtcp2_ksl.c +819 -0
  233. data/ext/ngtcp2/lib/ngtcp2_ksl.h +345 -0
  234. data/ext/ngtcp2/lib/ngtcp2_log.c +822 -0
  235. data/ext/ngtcp2/lib/ngtcp2_log.h +123 -0
  236. data/ext/ngtcp2/lib/ngtcp2_macro.h +58 -0
  237. data/ext/ngtcp2/lib/ngtcp2_map.c +336 -0
  238. data/ext/ngtcp2/lib/ngtcp2_map.h +136 -0
  239. data/ext/ngtcp2/lib/ngtcp2_mem.c +113 -0
  240. data/ext/ngtcp2/lib/ngtcp2_mem.h +72 -0
  241. data/ext/ngtcp2/lib/ngtcp2_net.h +136 -0
  242. data/ext/ngtcp2/lib/ngtcp2_objalloc.c +40 -0
  243. data/ext/ngtcp2/lib/ngtcp2_objalloc.h +140 -0
  244. data/ext/ngtcp2/lib/ngtcp2_opl.c +46 -0
  245. data/ext/ngtcp2/lib/ngtcp2_opl.h +65 -0
  246. data/ext/ngtcp2/lib/ngtcp2_path.c +77 -0
  247. data/ext/ngtcp2/lib/ngtcp2_path.h +49 -0
  248. data/ext/ngtcp2/lib/ngtcp2_pkt.c +2527 -0
  249. data/ext/ngtcp2/lib/ngtcp2_pkt.h +1235 -0
  250. data/ext/ngtcp2/lib/ngtcp2_pmtud.c +160 -0
  251. data/ext/ngtcp2/lib/ngtcp2_pmtud.h +123 -0
  252. data/ext/ngtcp2/lib/ngtcp2_ppe.c +230 -0
  253. data/ext/ngtcp2/lib/ngtcp2_ppe.h +153 -0
  254. data/ext/ngtcp2/lib/ngtcp2_pq.c +164 -0
  255. data/ext/ngtcp2/lib/ngtcp2_pq.h +126 -0
  256. data/ext/ngtcp2/lib/ngtcp2_pv.c +172 -0
  257. data/ext/ngtcp2/lib/ngtcp2_pv.h +194 -0
  258. data/ext/ngtcp2/lib/ngtcp2_qlog.c +1219 -0
  259. data/ext/ngtcp2/lib/ngtcp2_qlog.h +161 -0
  260. data/ext/ngtcp2/lib/ngtcp2_range.c +61 -0
  261. data/ext/ngtcp2/lib/ngtcp2_range.h +80 -0
  262. data/ext/ngtcp2/lib/ngtcp2_rcvry.h +40 -0
  263. data/ext/ngtcp2/lib/ngtcp2_ringbuf.c +121 -0
  264. data/ext/ngtcp2/lib/ngtcp2_ringbuf.h +132 -0
  265. data/ext/ngtcp2/lib/ngtcp2_rob.c +319 -0
  266. data/ext/ngtcp2/lib/ngtcp2_rob.h +197 -0
  267. data/ext/ngtcp2/lib/ngtcp2_rst.c +138 -0
  268. data/ext/ngtcp2/lib/ngtcp2_rst.h +86 -0
  269. data/ext/ngtcp2/lib/ngtcp2_rtb.c +1676 -0
  270. data/ext/ngtcp2/lib/ngtcp2_rtb.h +468 -0
  271. data/ext/ngtcp2/lib/ngtcp2_str.c +233 -0
  272. data/ext/ngtcp2/lib/ngtcp2_str.h +94 -0
  273. data/ext/ngtcp2/lib/ngtcp2_strm.c +698 -0
  274. data/ext/ngtcp2/lib/ngtcp2_strm.h +310 -0
  275. data/ext/ngtcp2/lib/ngtcp2_unreachable.c +71 -0
  276. data/ext/ngtcp2/lib/ngtcp2_unreachable.h +46 -0
  277. data/ext/ngtcp2/lib/ngtcp2_vec.c +243 -0
  278. data/ext/ngtcp2/lib/ngtcp2_vec.h +120 -0
  279. data/ext/ngtcp2/lib/ngtcp2_version.c +39 -0
  280. data/ext/ngtcp2/lib/ngtcp2_window_filter.c +99 -0
  281. data/ext/ngtcp2/lib/ngtcp2_window_filter.h +65 -0
  282. data/ext/ngtcp2/m4/ax_check_compile_flag.m4 +74 -0
  283. data/ext/ngtcp2/m4/ax_cxx_compile_stdcxx.m4 +1009 -0
  284. data/ext/ngtcp2/tests/CMakeLists.txt +68 -0
  285. data/ext/ngtcp2/tests/Makefile.am +94 -0
  286. data/ext/ngtcp2/tests/main.c +358 -0
  287. data/ext/ngtcp2/tests/ngtcp2_acktr_test.c +367 -0
  288. data/ext/ngtcp2/tests/ngtcp2_acktr_test.h +37 -0
  289. data/ext/ngtcp2/tests/ngtcp2_conn_test.c +9821 -0
  290. data/ext/ngtcp2/tests/ngtcp2_conn_test.h +104 -0
  291. data/ext/ngtcp2/tests/ngtcp2_conv_test.c +430 -0
  292. data/ext/ngtcp2/tests/ngtcp2_conv_test.h +46 -0
  293. data/ext/ngtcp2/tests/ngtcp2_crypto_test.c +667 -0
  294. data/ext/ngtcp2/tests/ngtcp2_crypto_test.h +35 -0
  295. data/ext/ngtcp2/tests/ngtcp2_gaptr_test.c +127 -0
  296. data/ext/ngtcp2/tests/ngtcp2_gaptr_test.h +36 -0
  297. data/ext/ngtcp2/tests/ngtcp2_idtr_test.c +79 -0
  298. data/ext/ngtcp2/tests/ngtcp2_idtr_test.h +34 -0
  299. data/ext/ngtcp2/tests/ngtcp2_ksl_test.c +502 -0
  300. data/ext/ngtcp2/tests/ngtcp2_ksl_test.h +39 -0
  301. data/ext/ngtcp2/tests/ngtcp2_map_test.c +206 -0
  302. data/ext/ngtcp2/tests/ngtcp2_map_test.h +38 -0
  303. data/ext/ngtcp2/tests/ngtcp2_pkt_test.c +1645 -0
  304. data/ext/ngtcp2/tests/ngtcp2_pkt_test.h +68 -0
  305. data/ext/ngtcp2/tests/ngtcp2_pmtud_test.c +153 -0
  306. data/ext/ngtcp2/tests/ngtcp2_pmtud_test.h +34 -0
  307. data/ext/ngtcp2/tests/ngtcp2_pv_test.c +129 -0
  308. data/ext/ngtcp2/tests/ngtcp2_pv_test.h +35 -0
  309. data/ext/ngtcp2/tests/ngtcp2_range_test.c +105 -0
  310. data/ext/ngtcp2/tests/ngtcp2_range_test.h +36 -0
  311. data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.c +91 -0
  312. data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.h +35 -0
  313. data/ext/ngtcp2/tests/ngtcp2_rob_test.c +552 -0
  314. data/ext/ngtcp2/tests/ngtcp2_rob_test.h +37 -0
  315. data/ext/ngtcp2/tests/ngtcp2_rtb_test.c +470 -0
  316. data/ext/ngtcp2/tests/ngtcp2_rtb_test.h +38 -0
  317. data/ext/ngtcp2/tests/ngtcp2_str_test.c +96 -0
  318. data/ext/ngtcp2/tests/ngtcp2_str_test.h +36 -0
  319. data/ext/ngtcp2/tests/ngtcp2_strm_test.c +575 -0
  320. data/ext/ngtcp2/tests/ngtcp2_strm_test.h +36 -0
  321. data/ext/ngtcp2/tests/ngtcp2_test_helper.c +404 -0
  322. data/ext/ngtcp2/tests/ngtcp2_test_helper.h +191 -0
  323. data/ext/ngtcp2/tests/ngtcp2_vec_test.c +426 -0
  324. data/ext/ngtcp2/tests/ngtcp2_vec_test.h +36 -0
  325. data/ext/ngtcp2/third-party/CMakeLists.txt +34 -0
  326. data/ext/ngtcp2/third-party/Makefile.am +31 -0
  327. data/ext/ngtcp2/third-party/http-parser/AUTHORS +68 -0
  328. data/ext/ngtcp2/third-party/http-parser/LICENSE-MIT +23 -0
  329. data/ext/ngtcp2/third-party/http-parser/Makefile +157 -0
  330. data/ext/ngtcp2/third-party/http-parser/README.md +246 -0
  331. data/ext/ngtcp2/third-party/http-parser/bench.c +111 -0
  332. data/ext/ngtcp2/third-party/http-parser/contrib/parsertrace.c +160 -0
  333. data/ext/ngtcp2/third-party/http-parser/contrib/url_parser.c +47 -0
  334. data/ext/ngtcp2/third-party/http-parser/http_parser.c +2419 -0
  335. data/ext/ngtcp2/third-party/http-parser/http_parser.gyp +111 -0
  336. data/ext/ngtcp2/third-party/http-parser/http_parser.h +431 -0
  337. data/ext/ngtcp2/third-party/http-parser/test.c +4411 -0
  338. data/lib/protocol/quic/version.rb +10 -0
  339. data/lib/protocol/quic.rb +9 -0
  340. data/license.md +21 -0
  341. data.tar.gz.sig +1 -0
  342. metadata +424 -0
  343. metadata.gz.sig +1 -0
@@ -0,0 +1,1219 @@
1
+ /*
2
+ * ngtcp2
3
+ *
4
+ * Copyright (c) 2019 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
+ #include "ngtcp2_qlog.h"
26
+
27
+ #include <assert.h>
28
+
29
+ #include "ngtcp2_str.h"
30
+ #include "ngtcp2_vec.h"
31
+ #include "ngtcp2_conv.h"
32
+ #include "ngtcp2_net.h"
33
+ #include "ngtcp2_unreachable.h"
34
+ #include "ngtcp2_conn_stat.h"
35
+
36
+ void ngtcp2_qlog_init(ngtcp2_qlog *qlog, ngtcp2_qlog_write write,
37
+ ngtcp2_tstamp ts, void *user_data) {
38
+ qlog->write = write;
39
+ qlog->ts = qlog->last_ts = ts;
40
+ qlog->user_data = user_data;
41
+ }
42
+
43
+ #define write_verbatim(DEST, S) ngtcp2_cpymem((DEST), (S), sizeof(S) - 1)
44
+
45
+ static uint8_t *write_string_impl(uint8_t *p, const uint8_t *data,
46
+ size_t datalen) {
47
+ *p++ = '"';
48
+ if (datalen) {
49
+ p = ngtcp2_cpymem(p, data, datalen);
50
+ }
51
+ *p++ = '"';
52
+ return p;
53
+ }
54
+
55
+ #define write_string(DEST, S) \
56
+ write_string_impl((DEST), (const uint8_t *)(S), sizeof(S) - 1)
57
+
58
+ #define NGTCP2_LOWER_XDIGITS "0123456789abcdef"
59
+
60
+ static uint8_t *write_hex(uint8_t *p, const uint8_t *data, size_t datalen) {
61
+ const uint8_t *b = data, *end = data + datalen;
62
+ *p++ = '"';
63
+ for (; b != end; ++b) {
64
+ *p++ = (uint8_t)NGTCP2_LOWER_XDIGITS[*b >> 4];
65
+ *p++ = (uint8_t)NGTCP2_LOWER_XDIGITS[*b & 0xf];
66
+ }
67
+ *p++ = '"';
68
+ return p;
69
+ }
70
+
71
+ static uint8_t *write_cid(uint8_t *p, const ngtcp2_cid *cid) {
72
+ return write_hex(p, cid->data, cid->datalen);
73
+ }
74
+
75
+ static uint8_t *write_number(uint8_t *p, uint64_t n) {
76
+ size_t nlen = 0;
77
+ uint64_t t;
78
+ uint8_t *res;
79
+
80
+ if (n == 0) {
81
+ *p++ = '0';
82
+ return p;
83
+ }
84
+ for (t = n; t; t /= 10, ++nlen)
85
+ ;
86
+ p += nlen;
87
+ res = p;
88
+ for (; n; n /= 10) {
89
+ *--p = (uint8_t)((n % 10) + '0');
90
+ }
91
+ return res;
92
+ }
93
+
94
+ static uint8_t *write_tstamp(uint8_t *p, ngtcp2_tstamp ts) {
95
+ return write_number(p, ts / NGTCP2_MILLISECONDS);
96
+ }
97
+
98
+ static uint8_t *write_duration(uint8_t *p, ngtcp2_duration duration) {
99
+ return write_number(p, duration / NGTCP2_MILLISECONDS);
100
+ }
101
+
102
+ static uint8_t *write_bool(uint8_t *p, int b) {
103
+ if (b) {
104
+ return ngtcp2_cpymem(p, "true", sizeof("true") - 1);
105
+ }
106
+ return ngtcp2_cpymem(p, "false", sizeof("false") - 1);
107
+ }
108
+
109
+ static uint8_t *write_pair_impl(uint8_t *p, const uint8_t *name, size_t namelen,
110
+ const ngtcp2_vec *value) {
111
+ p = write_string_impl(p, name, namelen);
112
+ *p++ = ':';
113
+ return write_string_impl(p, value->base, value->len);
114
+ }
115
+
116
+ #define write_pair(DEST, NAME, VALUE) \
117
+ write_pair_impl((DEST), (const uint8_t *)(NAME), sizeof(NAME) - 1, (VALUE))
118
+
119
+ static uint8_t *write_pair_hex_impl(uint8_t *p, const uint8_t *name,
120
+ size_t namelen, const uint8_t *value,
121
+ size_t valuelen) {
122
+ p = write_string_impl(p, name, namelen);
123
+ *p++ = ':';
124
+ return write_hex(p, value, valuelen);
125
+ }
126
+
127
+ #define write_pair_hex(DEST, NAME, VALUE, VALUELEN) \
128
+ write_pair_hex_impl((DEST), (const uint8_t *)(NAME), sizeof(NAME) - 1, \
129
+ (VALUE), (VALUELEN))
130
+
131
+ static uint8_t *write_pair_number_impl(uint8_t *p, const uint8_t *name,
132
+ size_t namelen, uint64_t value) {
133
+ p = write_string_impl(p, name, namelen);
134
+ *p++ = ':';
135
+ return write_number(p, value);
136
+ }
137
+
138
+ #define write_pair_number(DEST, NAME, VALUE) \
139
+ write_pair_number_impl((DEST), (const uint8_t *)(NAME), sizeof(NAME) - 1, \
140
+ (VALUE))
141
+
142
+ static uint8_t *write_pair_duration_impl(uint8_t *p, const uint8_t *name,
143
+ size_t namelen,
144
+ ngtcp2_duration duration) {
145
+ p = write_string_impl(p, name, namelen);
146
+ *p++ = ':';
147
+ return write_duration(p, duration);
148
+ }
149
+
150
+ #define write_pair_duration(DEST, NAME, VALUE) \
151
+ write_pair_duration_impl((DEST), (const uint8_t *)(NAME), sizeof(NAME) - 1, \
152
+ (VALUE))
153
+
154
+ static uint8_t *write_pair_tstamp_impl(uint8_t *p, const uint8_t *name,
155
+ size_t namelen, ngtcp2_tstamp ts) {
156
+ p = write_string_impl(p, name, namelen);
157
+ *p++ = ':';
158
+ return write_tstamp(p, ts);
159
+ }
160
+
161
+ #define write_pair_tstamp(DEST, NAME, VALUE) \
162
+ write_pair_tstamp_impl((DEST), (const uint8_t *)(NAME), sizeof(NAME) - 1, \
163
+ (VALUE))
164
+
165
+ static uint8_t *write_pair_bool_impl(uint8_t *p, const uint8_t *name,
166
+ size_t namelen, int b) {
167
+ p = write_string_impl(p, name, namelen);
168
+ *p++ = ':';
169
+ return write_bool(p, b);
170
+ }
171
+
172
+ #define write_pair_bool(DEST, NAME, VALUE) \
173
+ write_pair_bool_impl((DEST), (const uint8_t *)(NAME), sizeof(NAME) - 1, \
174
+ (VALUE))
175
+
176
+ static uint8_t *write_pair_cid_impl(uint8_t *p, const uint8_t *name,
177
+ size_t namelen, const ngtcp2_cid *cid) {
178
+ p = write_string_impl(p, name, namelen);
179
+ *p++ = ':';
180
+ return write_cid(p, cid);
181
+ }
182
+
183
+ #define write_pair_cid(DEST, NAME, VALUE) \
184
+ write_pair_cid_impl((DEST), (const uint8_t *)(NAME), sizeof(NAME) - 1, \
185
+ (VALUE))
186
+
187
+ #define ngtcp2_make_vec_lit(S) \
188
+ { (uint8_t *)(S), sizeof((S)) - 1 }
189
+
190
+ static uint8_t *write_common_fields(uint8_t *p, const ngtcp2_cid *odcid) {
191
+ p = write_verbatim(
192
+ p, "\"common_fields\":{\"protocol_type\":[\"QUIC\"],\"time_format\":"
193
+ "\"relative\",\"reference_time\":0,\"group_id\":");
194
+ p = write_cid(p, odcid);
195
+ *p++ = '}';
196
+ return p;
197
+ }
198
+
199
+ static uint8_t *write_trace(uint8_t *p, int server, const ngtcp2_cid *odcid) {
200
+ p = write_verbatim(
201
+ p, "\"trace\":{\"vantage_point\":{\"name\":\"ngtcp2\",\"type\":");
202
+ if (server) {
203
+ p = write_string(p, "server");
204
+ } else {
205
+ p = write_string(p, "client");
206
+ }
207
+ p = write_verbatim(p, "},");
208
+ p = write_common_fields(p, odcid);
209
+ *p++ = '}';
210
+ return p;
211
+ }
212
+
213
+ void ngtcp2_qlog_start(ngtcp2_qlog *qlog, const ngtcp2_cid *odcid, int server) {
214
+ uint8_t buf[1024];
215
+ uint8_t *p = buf;
216
+
217
+ if (!qlog->write) {
218
+ return;
219
+ }
220
+
221
+ p = write_verbatim(
222
+ p, "\x1e{\"qlog_format\":\"JSON-SEQ\",\"qlog_version\":\"0.3\",");
223
+ p = write_trace(p, server, odcid);
224
+ p = write_verbatim(p, "}\n");
225
+
226
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf,
227
+ (size_t)(p - buf));
228
+ }
229
+
230
+ void ngtcp2_qlog_end(ngtcp2_qlog *qlog) {
231
+ uint8_t buf[1] = {0};
232
+
233
+ if (!qlog->write) {
234
+ return;
235
+ }
236
+
237
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_FIN, &buf, 0);
238
+ }
239
+
240
+ static ngtcp2_vec vec_pkt_type_initial = ngtcp2_make_vec_lit("initial");
241
+ static ngtcp2_vec vec_pkt_type_handshake = ngtcp2_make_vec_lit("handshake");
242
+ static ngtcp2_vec vec_pkt_type_0rtt = ngtcp2_make_vec_lit("0RTT");
243
+ static ngtcp2_vec vec_pkt_type_1rtt = ngtcp2_make_vec_lit("1RTT");
244
+ static ngtcp2_vec vec_pkt_type_retry = ngtcp2_make_vec_lit("retry");
245
+ static ngtcp2_vec vec_pkt_type_version_negotiation =
246
+ ngtcp2_make_vec_lit("version_negotiation");
247
+ static ngtcp2_vec vec_pkt_type_stateless_reset =
248
+ ngtcp2_make_vec_lit("stateless_reset");
249
+ static ngtcp2_vec vec_pkt_type_unknown = ngtcp2_make_vec_lit("unknown");
250
+
251
+ static const ngtcp2_vec *qlog_pkt_type(const ngtcp2_pkt_hd *hd) {
252
+ if (hd->flags & NGTCP2_PKT_FLAG_LONG_FORM) {
253
+ switch (hd->type) {
254
+ case NGTCP2_PKT_INITIAL:
255
+ return &vec_pkt_type_initial;
256
+ case NGTCP2_PKT_HANDSHAKE:
257
+ return &vec_pkt_type_handshake;
258
+ case NGTCP2_PKT_0RTT:
259
+ return &vec_pkt_type_0rtt;
260
+ case NGTCP2_PKT_RETRY:
261
+ return &vec_pkt_type_retry;
262
+ default:
263
+ return &vec_pkt_type_unknown;
264
+ }
265
+ }
266
+
267
+ switch (hd->type) {
268
+ case NGTCP2_PKT_VERSION_NEGOTIATION:
269
+ return &vec_pkt_type_version_negotiation;
270
+ case NGTCP2_PKT_STATELESS_RESET:
271
+ return &vec_pkt_type_stateless_reset;
272
+ case NGTCP2_PKT_1RTT:
273
+ return &vec_pkt_type_1rtt;
274
+ default:
275
+ return &vec_pkt_type_unknown;
276
+ }
277
+ }
278
+
279
+ static uint8_t *write_pkt_hd(uint8_t *p, const ngtcp2_pkt_hd *hd) {
280
+ /*
281
+ * {"packet_type":"version_negotiation","packet_number":"0000000000000000000","token":{"data":""}}
282
+ */
283
+ #define NGTCP2_QLOG_PKT_HD_OVERHEAD 95
284
+
285
+ *p++ = '{';
286
+ p = write_pair(p, "packet_type", qlog_pkt_type(hd));
287
+ *p++ = ',';
288
+ p = write_pair_number(p, "packet_number", (uint64_t)hd->pkt_num);
289
+ if (hd->type == NGTCP2_PKT_INITIAL && hd->tokenlen) {
290
+ p = write_verbatim(p, ",\"token\":{");
291
+ p = write_pair_hex(p, "data", hd->token, hd->tokenlen);
292
+ *p++ = '}';
293
+ }
294
+ /* TODO Write DCIL and DCID */
295
+ /* TODO Write SCIL and SCID */
296
+ *p++ = '}';
297
+ return p;
298
+ }
299
+
300
+ static uint8_t *write_padding_frame(uint8_t *p, const ngtcp2_padding *fr) {
301
+ (void)fr;
302
+
303
+ /* {"frame_type":"padding"} */
304
+ #define NGTCP2_QLOG_PADDING_FRAME_OVERHEAD 24
305
+
306
+ return write_verbatim(p, "{\"frame_type\":\"padding\"}");
307
+ }
308
+
309
+ static uint8_t *write_ping_frame(uint8_t *p, const ngtcp2_ping *fr) {
310
+ (void)fr;
311
+
312
+ /* {"frame_type":"ping"} */
313
+ #define NGTCP2_QLOG_PING_FRAME_OVERHEAD 21
314
+
315
+ return write_verbatim(p, "{\"frame_type\":\"ping\"}");
316
+ }
317
+
318
+ static uint8_t *write_ack_frame(uint8_t *p, const ngtcp2_ack *fr) {
319
+ int64_t largest_ack, min_ack;
320
+ size_t i;
321
+ const ngtcp2_ack_range *range;
322
+
323
+ /*
324
+ * {"frame_type":"ack","ack_delay":0000000000000000000,"acked_ranges":[]}
325
+ *
326
+ * each range:
327
+ * [0000000000000000000,0000000000000000000],
328
+ *
329
+ * ecn:
330
+ * ,"ect1":0000000000000000000,"ect0":0000000000000000000,"ce":0000000000000000000
331
+ */
332
+ #define NGTCP2_QLOG_ACK_FRAME_BASE_OVERHEAD 70
333
+ #define NGTCP2_QLOG_ACK_FRAME_RANGE_OVERHEAD 42
334
+ #define NGTCP2_QLOG_ACK_FRAME_ECN_OVERHEAD 79
335
+
336
+ p = write_verbatim(p, "{\"frame_type\":\"ack\",");
337
+ p = write_pair_duration(p, "ack_delay", fr->ack_delay_unscaled);
338
+ p = write_verbatim(p, ",\"acked_ranges\":[");
339
+
340
+ largest_ack = fr->largest_ack;
341
+ min_ack = fr->largest_ack - (int64_t)fr->first_ack_range;
342
+
343
+ *p++ = '[';
344
+ p = write_number(p, (uint64_t)min_ack);
345
+ if (largest_ack != min_ack) {
346
+ *p++ = ',';
347
+ p = write_number(p, (uint64_t)largest_ack);
348
+ }
349
+ *p++ = ']';
350
+
351
+ for (i = 0; i < fr->rangecnt; ++i) {
352
+ range = &fr->ranges[i];
353
+ largest_ack = min_ack - (int64_t)range->gap - 2;
354
+ min_ack = largest_ack - (int64_t)range->len;
355
+ *p++ = ',';
356
+ *p++ = '[';
357
+ p = write_number(p, (uint64_t)min_ack);
358
+ if (largest_ack != min_ack) {
359
+ *p++ = ',';
360
+ p = write_number(p, (uint64_t)largest_ack);
361
+ }
362
+ *p++ = ']';
363
+ }
364
+
365
+ *p++ = ']';
366
+
367
+ if (fr->type == NGTCP2_FRAME_ACK_ECN) {
368
+ *p++ = ',';
369
+ p = write_pair_number(p, "ect1", fr->ecn.ect1);
370
+ *p++ = ',';
371
+ p = write_pair_number(p, "ect0", fr->ecn.ect0);
372
+ *p++ = ',';
373
+ p = write_pair_number(p, "ce", fr->ecn.ce);
374
+ }
375
+
376
+ *p++ = '}';
377
+
378
+ return p;
379
+ }
380
+
381
+ static uint8_t *write_reset_stream_frame(uint8_t *p,
382
+ const ngtcp2_reset_stream *fr) {
383
+ /*
384
+ * {"frame_type":"reset_stream","stream_id":0000000000000000000,"error_code":0000000000000000000,"final_size":0000000000000000000}
385
+ */
386
+ #define NGTCP2_QLOG_RESET_STREAM_FRAME_OVERHEAD 127
387
+
388
+ p = write_verbatim(p, "{\"frame_type\":\"reset_stream\",");
389
+ p = write_pair_number(p, "stream_id", (uint64_t)fr->stream_id);
390
+ *p++ = ',';
391
+ p = write_pair_number(p, "error_code", fr->app_error_code);
392
+ *p++ = ',';
393
+ p = write_pair_number(p, "final_size", fr->final_size);
394
+ *p++ = '}';
395
+
396
+ return p;
397
+ }
398
+
399
+ static uint8_t *write_stop_sending_frame(uint8_t *p,
400
+ const ngtcp2_stop_sending *fr) {
401
+ /*
402
+ * {"frame_type":"stop_sending","stream_id":0000000000000000000,"error_code":0000000000000000000}
403
+ */
404
+ #define NGTCP2_QLOG_STOP_SENDING_FRAME_OVERHEAD 94
405
+
406
+ p = write_verbatim(p, "{\"frame_type\":\"stop_sending\",");
407
+ p = write_pair_number(p, "stream_id", (uint64_t)fr->stream_id);
408
+ *p++ = ',';
409
+ p = write_pair_number(p, "error_code", fr->app_error_code);
410
+ *p++ = '}';
411
+
412
+ return p;
413
+ }
414
+
415
+ static uint8_t *write_crypto_frame(uint8_t *p, const ngtcp2_crypto *fr) {
416
+ /*
417
+ * {"frame_type":"crypto","offset":0000000000000000000,"length":0000000000000000000}
418
+ */
419
+ #define NGTCP2_QLOG_CRYPTO_FRAME_OVERHEAD 81
420
+
421
+ p = write_verbatim(p, "{\"frame_type\":\"crypto\",");
422
+ p = write_pair_number(p, "offset", fr->offset);
423
+ *p++ = ',';
424
+ p = write_pair_number(p, "length", ngtcp2_vec_len(fr->data, fr->datacnt));
425
+ *p++ = '}';
426
+
427
+ return p;
428
+ }
429
+
430
+ static uint8_t *write_new_token_frame(uint8_t *p, const ngtcp2_new_token *fr) {
431
+ /*
432
+ * {"frame_type":"new_token","length":0000000000000000000,"token":{"data":""}}
433
+ */
434
+ #define NGTCP2_QLOG_NEW_TOKEN_FRAME_OVERHEAD 75
435
+
436
+ p = write_verbatim(p, "{\"frame_type\":\"new_token\",");
437
+ p = write_pair_number(p, "length", fr->tokenlen);
438
+ p = write_verbatim(p, ",\"token\":{");
439
+ p = write_pair_hex(p, "data", fr->token, fr->tokenlen);
440
+ *p++ = '}';
441
+ *p++ = '}';
442
+
443
+ return p;
444
+ }
445
+
446
+ static uint8_t *write_stream_frame(uint8_t *p, const ngtcp2_stream *fr) {
447
+ /*
448
+ * {"frame_type":"stream","stream_id":0000000000000000000,"offset":0000000000000000000,"length":0000000000000000000,"fin":true}
449
+ */
450
+ #define NGTCP2_QLOG_STREAM_FRAME_OVERHEAD 124
451
+
452
+ p = write_verbatim(p, "{\"frame_type\":\"stream\",");
453
+ p = write_pair_number(p, "stream_id", (uint64_t)fr->stream_id);
454
+ *p++ = ',';
455
+ p = write_pair_number(p, "offset", fr->offset);
456
+ *p++ = ',';
457
+ p = write_pair_number(p, "length", ngtcp2_vec_len(fr->data, fr->datacnt));
458
+ if (fr->fin) {
459
+ *p++ = ',';
460
+ p = write_pair_bool(p, "fin", 1);
461
+ }
462
+ *p++ = '}';
463
+
464
+ return p;
465
+ }
466
+
467
+ static uint8_t *write_max_data_frame(uint8_t *p, const ngtcp2_max_data *fr) {
468
+ /*
469
+ * {"frame_type":"max_data","maximum":0000000000000000000}
470
+ */
471
+ #define NGTCP2_QLOG_MAX_DATA_FRAME_OVERHEAD 55
472
+
473
+ p = write_verbatim(p, "{\"frame_type\":\"max_data\",");
474
+ p = write_pair_number(p, "maximum", fr->max_data);
475
+ *p++ = '}';
476
+
477
+ return p;
478
+ }
479
+
480
+ static uint8_t *write_max_stream_data_frame(uint8_t *p,
481
+ const ngtcp2_max_stream_data *fr) {
482
+ /*
483
+ * {"frame_type":"max_stream_data","stream_id":0000000000000000000,"maximum":0000000000000000000}
484
+ */
485
+ #define NGTCP2_QLOG_MAX_STREAM_DATA_FRAME_OVERHEAD 94
486
+
487
+ p = write_verbatim(p, "{\"frame_type\":\"max_stream_data\",");
488
+ p = write_pair_number(p, "stream_id", (uint64_t)fr->stream_id);
489
+ *p++ = ',';
490
+ p = write_pair_number(p, "maximum", fr->max_stream_data);
491
+ *p++ = '}';
492
+
493
+ return p;
494
+ }
495
+
496
+ static uint8_t *write_max_streams_frame(uint8_t *p,
497
+ const ngtcp2_max_streams *fr) {
498
+ /*
499
+ * {"frame_type":"max_streams","stream_type":"unidirectional","maximum":0000000000000000000}
500
+ */
501
+ #define NGTCP2_QLOG_MAX_STREAMS_FRAME_OVERHEAD 89
502
+
503
+ p = write_verbatim(p, "{\"frame_type\":\"max_streams\",\"stream_type\":");
504
+ if (fr->type == NGTCP2_FRAME_MAX_STREAMS_BIDI) {
505
+ p = write_string(p, "bidirectional");
506
+ } else {
507
+ p = write_string(p, "unidirectional");
508
+ }
509
+ *p++ = ',';
510
+ p = write_pair_number(p, "maximum", fr->max_streams);
511
+ *p++ = '}';
512
+
513
+ return p;
514
+ }
515
+
516
+ static uint8_t *write_data_blocked_frame(uint8_t *p,
517
+ const ngtcp2_data_blocked *fr) {
518
+ (void)fr;
519
+
520
+ /*
521
+ * {"frame_type":"data_blocked"}
522
+ */
523
+ #define NGTCP2_QLOG_DATA_BLOCKED_FRAME_OVERHEAD 29
524
+
525
+ /* TODO log limit */
526
+
527
+ return write_verbatim(p, "{\"frame_type\":\"data_blocked\"}");
528
+ }
529
+
530
+ static uint8_t *
531
+ write_stream_data_blocked_frame(uint8_t *p,
532
+ const ngtcp2_stream_data_blocked *fr) {
533
+ (void)fr;
534
+
535
+ /*
536
+ * {"frame_type":"stream_data_blocked"}
537
+ */
538
+ #define NGTCP2_QLOG_STREAM_DATA_BLOCKED_FRAME_OVERHEAD 36
539
+
540
+ /* TODO log limit */
541
+
542
+ return write_verbatim(p, "{\"frame_type\":\"stream_data_blocked\"}");
543
+ }
544
+
545
+ static uint8_t *write_streams_blocked_frame(uint8_t *p,
546
+ const ngtcp2_streams_blocked *fr) {
547
+ (void)fr;
548
+
549
+ /*
550
+ * {"frame_type":"streams_blocked"}
551
+ */
552
+ #define NGTCP2_QLOG_STREAMS_BLOCKED_FRAME_OVERHEAD 32
553
+
554
+ /* TODO Log stream_type and limit */
555
+
556
+ return write_verbatim(p, "{\"frame_type\":\"streams_blocked\"}");
557
+ }
558
+
559
+ static uint8_t *
560
+ write_new_connection_id_frame(uint8_t *p, const ngtcp2_new_connection_id *fr) {
561
+ /*
562
+ * {"frame_type":"new_connection_id","sequence_number":0000000000000000000,"retire_prior_to":0000000000000000000,"connection_id_length":0000000000000000000,"connection_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","stateless_reset_token":{"data":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}}
563
+ */
564
+ #define NGTCP2_QLOG_NEW_CONNECTION_ID_FRAME_OVERHEAD 280
565
+
566
+ p = write_verbatim(p, "{\"frame_type\":\"new_connection_id\",");
567
+ p = write_pair_number(p, "sequence_number", fr->seq);
568
+ *p++ = ',';
569
+ p = write_pair_number(p, "retire_prior_to", fr->retire_prior_to);
570
+ *p++ = ',';
571
+ p = write_pair_number(p, "connection_id_length", fr->cid.datalen);
572
+ *p++ = ',';
573
+ p = write_pair_cid(p, "connection_id", &fr->cid);
574
+ p = write_verbatim(p, ",\"stateless_reset_token\":{");
575
+ p = write_pair_hex(p, "data", fr->stateless_reset_token,
576
+ sizeof(fr->stateless_reset_token));
577
+ *p++ = '}';
578
+ *p++ = '}';
579
+
580
+ return p;
581
+ }
582
+
583
+ static uint8_t *
584
+ write_retire_connection_id_frame(uint8_t *p,
585
+ const ngtcp2_retire_connection_id *fr) {
586
+ /*
587
+ * {"frame_type":"retire_connection_id","sequence_number":0000000000000000000}
588
+ */
589
+ #define NGTCP2_QLOG_RETIRE_CONNECTION_ID_FRAME_OVERHEAD 75
590
+
591
+ p = write_verbatim(p, "{\"frame_type\":\"retire_connection_id\",");
592
+ p = write_pair_number(p, "sequence_number", fr->seq);
593
+ *p++ = '}';
594
+
595
+ return p;
596
+ }
597
+
598
+ static uint8_t *write_path_challenge_frame(uint8_t *p,
599
+ const ngtcp2_path_challenge *fr) {
600
+ /*
601
+ * {"frame_type":"path_challenge","data":"xxxxxxxxxxxxxxxx"}
602
+ */
603
+ #define NGTCP2_QLOG_PATH_CHALLENGE_FRAME_OVERHEAD 57
604
+
605
+ p = write_verbatim(p, "{\"frame_type\":\"path_challenge\",");
606
+ p = write_pair_hex(p, "data", fr->data, sizeof(fr->data));
607
+ *p++ = '}';
608
+
609
+ return p;
610
+ }
611
+
612
+ static uint8_t *write_path_response_frame(uint8_t *p,
613
+ const ngtcp2_path_response *fr) {
614
+ /*
615
+ * {"frame_type":"path_response","data":"xxxxxxxxxxxxxxxx"}
616
+ */
617
+ #define NGTCP2_QLOG_PATH_RESPONSE_FRAME_OVERHEAD 56
618
+
619
+ p = write_verbatim(p, "{\"frame_type\":\"path_response\",");
620
+ p = write_pair_hex(p, "data", fr->data, sizeof(fr->data));
621
+ *p++ = '}';
622
+
623
+ return p;
624
+ }
625
+
626
+ static uint8_t *
627
+ write_connection_close_frame(uint8_t *p, const ngtcp2_connection_close *fr) {
628
+ /*
629
+ * {"frame_type":"connection_close","error_space":"application","error_code":0000000000000000000,"raw_error_code":0000000000000000000}
630
+ */
631
+ #define NGTCP2_QLOG_CONNECTION_CLOSE_FRAME_OVERHEAD 131
632
+
633
+ p = write_verbatim(p,
634
+ "{\"frame_type\":\"connection_close\",\"error_space\":");
635
+ if (fr->type == NGTCP2_FRAME_CONNECTION_CLOSE) {
636
+ p = write_string(p, "transport");
637
+ } else {
638
+ p = write_string(p, "application");
639
+ }
640
+ *p++ = ',';
641
+ p = write_pair_number(p, "error_code", fr->error_code);
642
+ *p++ = ',';
643
+ p = write_pair_number(p, "raw_error_code", fr->error_code);
644
+ /* TODO Write reason by escaping non-printables */
645
+ /* TODO Write trigger_frame_type */
646
+ *p++ = '}';
647
+
648
+ return p;
649
+ }
650
+
651
+ static uint8_t *write_handshake_done_frame(uint8_t *p,
652
+ const ngtcp2_handshake_done *fr) {
653
+ (void)fr;
654
+
655
+ /*
656
+ * {"frame_type":"handshake_done"}
657
+ */
658
+ #define NGTCP2_QLOG_HANDSHAKE_DONE_FRAME_OVERHEAD 31
659
+
660
+ return write_verbatim(p, "{\"frame_type\":\"handshake_done\"}");
661
+ }
662
+
663
+ static uint8_t *write_datagram_frame(uint8_t *p, const ngtcp2_datagram *fr) {
664
+ /*
665
+ * {"frame_type":"datagram","length":0000000000000000000}
666
+ */
667
+ #define NGTCP2_QLOG_DATAGRAM_FRAME_OVERHEAD 54
668
+
669
+ p = write_verbatim(p, "{\"frame_type\":\"datagram\",");
670
+ p = write_pair_number(p, "length", ngtcp2_vec_len(fr->data, fr->datacnt));
671
+ *p++ = '}';
672
+
673
+ return p;
674
+ }
675
+
676
+ static uint8_t *qlog_write_time(ngtcp2_qlog *qlog, uint8_t *p) {
677
+ return write_pair_tstamp(p, "time", qlog->last_ts - qlog->ts);
678
+ }
679
+
680
+ static void qlog_pkt_write_start(ngtcp2_qlog *qlog, int sent) {
681
+ uint8_t *p;
682
+
683
+ if (!qlog->write) {
684
+ return;
685
+ }
686
+
687
+ ngtcp2_buf_reset(&qlog->buf);
688
+ p = qlog->buf.last;
689
+
690
+ *p++ = '\x1e';
691
+ *p++ = '{';
692
+ p = qlog_write_time(qlog, p);
693
+ p = write_verbatim(p, ",\"name\":");
694
+ if (sent) {
695
+ p = write_string(p, "transport:packet_sent");
696
+ } else {
697
+ p = write_string(p, "transport:packet_received");
698
+ }
699
+ p = write_verbatim(p, ",\"data\":{\"frames\":[");
700
+ qlog->buf.last = p;
701
+ }
702
+
703
+ static void qlog_pkt_write_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
704
+ size_t pktlen) {
705
+ uint8_t *p = qlog->buf.last;
706
+
707
+ if (!qlog->write) {
708
+ return;
709
+ }
710
+
711
+ /*
712
+ * ],"header":,"raw":{"length":0000000000000000000}}}
713
+ *
714
+ * plus, terminating LF
715
+ */
716
+ #define NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD \
717
+ (1 + 50 + NGTCP2_QLOG_PKT_HD_OVERHEAD)
718
+
719
+ if (ngtcp2_buf_left(&qlog->buf) <
720
+ NGTCP2_QLOG_PKT_WRITE_END_OVERHEAD + hd->tokenlen * 2) {
721
+ return;
722
+ }
723
+
724
+ assert(ngtcp2_buf_len(&qlog->buf));
725
+
726
+ /* Eat last ',' */
727
+ if (*(p - 1) == ',') {
728
+ --p;
729
+ }
730
+
731
+ p = write_verbatim(p, "],\"header\":");
732
+ p = write_pkt_hd(p, hd);
733
+ p = write_verbatim(p, ",\"raw\":{\"length\":");
734
+ p = write_number(p, pktlen);
735
+ p = write_verbatim(p, "}}}\n");
736
+
737
+ qlog->buf.last = p;
738
+
739
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, qlog->buf.pos,
740
+ ngtcp2_buf_len(&qlog->buf));
741
+ }
742
+
743
+ void ngtcp2_qlog_write_frame(ngtcp2_qlog *qlog, const ngtcp2_frame *fr) {
744
+ uint8_t *p = qlog->buf.last;
745
+
746
+ if (!qlog->write) {
747
+ return;
748
+ }
749
+
750
+ switch (fr->type) {
751
+ case NGTCP2_FRAME_PADDING:
752
+ if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_PADDING_FRAME_OVERHEAD + 1) {
753
+ return;
754
+ }
755
+ p = write_padding_frame(p, &fr->padding);
756
+ break;
757
+ case NGTCP2_FRAME_PING:
758
+ if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_PING_FRAME_OVERHEAD + 1) {
759
+ return;
760
+ }
761
+ p = write_ping_frame(p, &fr->ping);
762
+ break;
763
+ case NGTCP2_FRAME_ACK:
764
+ case NGTCP2_FRAME_ACK_ECN:
765
+ if (ngtcp2_buf_left(&qlog->buf) <
766
+ NGTCP2_QLOG_ACK_FRAME_BASE_OVERHEAD +
767
+ (size_t)(fr->type == NGTCP2_FRAME_ACK_ECN
768
+ ? NGTCP2_QLOG_ACK_FRAME_ECN_OVERHEAD
769
+ : 0) +
770
+ NGTCP2_QLOG_ACK_FRAME_RANGE_OVERHEAD * (1 + fr->ack.rangecnt) + 1) {
771
+ return;
772
+ }
773
+ p = write_ack_frame(p, &fr->ack);
774
+ break;
775
+ case NGTCP2_FRAME_RESET_STREAM:
776
+ if (ngtcp2_buf_left(&qlog->buf) <
777
+ NGTCP2_QLOG_RESET_STREAM_FRAME_OVERHEAD + 1) {
778
+ return;
779
+ }
780
+ p = write_reset_stream_frame(p, &fr->reset_stream);
781
+ break;
782
+ case NGTCP2_FRAME_STOP_SENDING:
783
+ if (ngtcp2_buf_left(&qlog->buf) <
784
+ NGTCP2_QLOG_STOP_SENDING_FRAME_OVERHEAD + 1) {
785
+ return;
786
+ }
787
+ p = write_stop_sending_frame(p, &fr->stop_sending);
788
+ break;
789
+ case NGTCP2_FRAME_CRYPTO:
790
+ if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_CRYPTO_FRAME_OVERHEAD + 1) {
791
+ return;
792
+ }
793
+ p = write_crypto_frame(p, &fr->crypto);
794
+ break;
795
+ case NGTCP2_FRAME_NEW_TOKEN:
796
+ if (ngtcp2_buf_left(&qlog->buf) <
797
+ NGTCP2_QLOG_NEW_TOKEN_FRAME_OVERHEAD + fr->new_token.tokenlen * 2 + 1) {
798
+ return;
799
+ }
800
+ p = write_new_token_frame(p, &fr->new_token);
801
+ break;
802
+ case NGTCP2_FRAME_STREAM:
803
+ if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_STREAM_FRAME_OVERHEAD + 1) {
804
+ return;
805
+ }
806
+ p = write_stream_frame(p, &fr->stream);
807
+ break;
808
+ case NGTCP2_FRAME_MAX_DATA:
809
+ if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_MAX_DATA_FRAME_OVERHEAD + 1) {
810
+ return;
811
+ }
812
+ p = write_max_data_frame(p, &fr->max_data);
813
+ break;
814
+ case NGTCP2_FRAME_MAX_STREAM_DATA:
815
+ if (ngtcp2_buf_left(&qlog->buf) <
816
+ NGTCP2_QLOG_MAX_STREAM_DATA_FRAME_OVERHEAD + 1) {
817
+ return;
818
+ }
819
+ p = write_max_stream_data_frame(p, &fr->max_stream_data);
820
+ break;
821
+ case NGTCP2_FRAME_MAX_STREAMS_BIDI:
822
+ case NGTCP2_FRAME_MAX_STREAMS_UNI:
823
+ if (ngtcp2_buf_left(&qlog->buf) <
824
+ NGTCP2_QLOG_MAX_STREAMS_FRAME_OVERHEAD + 1) {
825
+ return;
826
+ }
827
+ p = write_max_streams_frame(p, &fr->max_streams);
828
+ break;
829
+ case NGTCP2_FRAME_DATA_BLOCKED:
830
+ if (ngtcp2_buf_left(&qlog->buf) <
831
+ NGTCP2_QLOG_DATA_BLOCKED_FRAME_OVERHEAD + 1) {
832
+ return;
833
+ }
834
+ p = write_data_blocked_frame(p, &fr->data_blocked);
835
+ break;
836
+ case NGTCP2_FRAME_STREAM_DATA_BLOCKED:
837
+ if (ngtcp2_buf_left(&qlog->buf) <
838
+ NGTCP2_QLOG_STREAM_DATA_BLOCKED_FRAME_OVERHEAD + 1) {
839
+ return;
840
+ }
841
+ p = write_stream_data_blocked_frame(p, &fr->stream_data_blocked);
842
+ break;
843
+ case NGTCP2_FRAME_STREAMS_BLOCKED_BIDI:
844
+ case NGTCP2_FRAME_STREAMS_BLOCKED_UNI:
845
+ if (ngtcp2_buf_left(&qlog->buf) <
846
+ NGTCP2_QLOG_STREAMS_BLOCKED_FRAME_OVERHEAD + 1) {
847
+ return;
848
+ }
849
+ p = write_streams_blocked_frame(p, &fr->streams_blocked);
850
+ break;
851
+ case NGTCP2_FRAME_NEW_CONNECTION_ID:
852
+ if (ngtcp2_buf_left(&qlog->buf) <
853
+ NGTCP2_QLOG_NEW_CONNECTION_ID_FRAME_OVERHEAD + 1) {
854
+ return;
855
+ }
856
+ p = write_new_connection_id_frame(p, &fr->new_connection_id);
857
+ break;
858
+ case NGTCP2_FRAME_RETIRE_CONNECTION_ID:
859
+ if (ngtcp2_buf_left(&qlog->buf) <
860
+ NGTCP2_QLOG_RETIRE_CONNECTION_ID_FRAME_OVERHEAD + 1) {
861
+ return;
862
+ }
863
+ p = write_retire_connection_id_frame(p, &fr->retire_connection_id);
864
+ break;
865
+ case NGTCP2_FRAME_PATH_CHALLENGE:
866
+ if (ngtcp2_buf_left(&qlog->buf) <
867
+ NGTCP2_QLOG_PATH_CHALLENGE_FRAME_OVERHEAD + 1) {
868
+ return;
869
+ }
870
+ p = write_path_challenge_frame(p, &fr->path_challenge);
871
+ break;
872
+ case NGTCP2_FRAME_PATH_RESPONSE:
873
+ if (ngtcp2_buf_left(&qlog->buf) <
874
+ NGTCP2_QLOG_PATH_RESPONSE_FRAME_OVERHEAD + 1) {
875
+ return;
876
+ }
877
+ p = write_path_response_frame(p, &fr->path_response);
878
+ break;
879
+ case NGTCP2_FRAME_CONNECTION_CLOSE:
880
+ case NGTCP2_FRAME_CONNECTION_CLOSE_APP:
881
+ if (ngtcp2_buf_left(&qlog->buf) <
882
+ NGTCP2_QLOG_CONNECTION_CLOSE_FRAME_OVERHEAD + 1) {
883
+ return;
884
+ }
885
+ p = write_connection_close_frame(p, &fr->connection_close);
886
+ break;
887
+ case NGTCP2_FRAME_HANDSHAKE_DONE:
888
+ if (ngtcp2_buf_left(&qlog->buf) <
889
+ NGTCP2_QLOG_HANDSHAKE_DONE_FRAME_OVERHEAD + 1) {
890
+ return;
891
+ }
892
+ p = write_handshake_done_frame(p, &fr->handshake_done);
893
+ break;
894
+ case NGTCP2_FRAME_DATAGRAM:
895
+ case NGTCP2_FRAME_DATAGRAM_LEN:
896
+ if (ngtcp2_buf_left(&qlog->buf) < NGTCP2_QLOG_DATAGRAM_FRAME_OVERHEAD + 1) {
897
+ return;
898
+ }
899
+ p = write_datagram_frame(p, &fr->datagram);
900
+ break;
901
+ default:
902
+ ngtcp2_unreachable();
903
+ }
904
+
905
+ *p++ = ',';
906
+
907
+ qlog->buf.last = p;
908
+ }
909
+
910
+ void ngtcp2_qlog_pkt_received_start(ngtcp2_qlog *qlog) {
911
+ qlog_pkt_write_start(qlog, /* sent = */ 0);
912
+ }
913
+
914
+ void ngtcp2_qlog_pkt_received_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
915
+ size_t pktlen) {
916
+ qlog_pkt_write_end(qlog, hd, pktlen);
917
+ }
918
+
919
+ void ngtcp2_qlog_pkt_sent_start(ngtcp2_qlog *qlog) {
920
+ qlog_pkt_write_start(qlog, /* sent = */ 1);
921
+ }
922
+
923
+ void ngtcp2_qlog_pkt_sent_end(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
924
+ size_t pktlen) {
925
+ qlog_pkt_write_end(qlog, hd, pktlen);
926
+ }
927
+
928
+ void ngtcp2_qlog_parameters_set_transport_params(
929
+ ngtcp2_qlog *qlog, const ngtcp2_transport_params *params, int server,
930
+ ngtcp2_qlog_side side) {
931
+ uint8_t buf[1024];
932
+ uint8_t *p = buf;
933
+ const ngtcp2_preferred_addr *paddr;
934
+ const ngtcp2_sockaddr_in *sa_in;
935
+ const ngtcp2_sockaddr_in6 *sa_in6;
936
+
937
+ if (!qlog->write) {
938
+ return;
939
+ }
940
+
941
+ *p++ = '\x1e';
942
+ *p++ = '{';
943
+ p = qlog_write_time(qlog, p);
944
+ p = write_verbatim(
945
+ p, ",\"name\":\"transport:parameters_set\",\"data\":{\"owner\":");
946
+
947
+ if (side == NGTCP2_QLOG_SIDE_LOCAL) {
948
+ p = write_string(p, "local");
949
+ } else {
950
+ p = write_string(p, "remote");
951
+ }
952
+
953
+ *p++ = ',';
954
+ p = write_pair_cid(p, "initial_source_connection_id", &params->initial_scid);
955
+ *p++ = ',';
956
+ if (side == (server ? NGTCP2_QLOG_SIDE_LOCAL : NGTCP2_QLOG_SIDE_REMOTE)) {
957
+ p = write_pair_cid(p, "original_destination_connection_id",
958
+ &params->original_dcid);
959
+ *p++ = ',';
960
+ }
961
+ if (params->retry_scid_present) {
962
+ p = write_pair_cid(p, "retry_source_connection_id", &params->retry_scid);
963
+ *p++ = ',';
964
+ }
965
+ if (params->stateless_reset_token_present) {
966
+ p = write_verbatim(p, "\"stateless_reset_token\":{");
967
+ p = write_pair_hex(p, "data", params->stateless_reset_token,
968
+ sizeof(params->stateless_reset_token));
969
+ *p++ = '}';
970
+ *p++ = ',';
971
+ }
972
+ p = write_pair_bool(p, "disable_active_migration",
973
+ params->disable_active_migration);
974
+ *p++ = ',';
975
+ p = write_pair_duration(p, "max_idle_timeout", params->max_idle_timeout);
976
+ *p++ = ',';
977
+ p = write_pair_number(p, "max_udp_payload_size",
978
+ params->max_udp_payload_size);
979
+ *p++ = ',';
980
+ p = write_pair_number(p, "ack_delay_exponent", params->ack_delay_exponent);
981
+ *p++ = ',';
982
+ p = write_pair_duration(p, "max_ack_delay", params->max_ack_delay);
983
+ *p++ = ',';
984
+ p = write_pair_number(p, "active_connection_id_limit",
985
+ params->active_connection_id_limit);
986
+ *p++ = ',';
987
+ p = write_pair_number(p, "initial_max_data", params->initial_max_data);
988
+ *p++ = ',';
989
+ p = write_pair_number(p, "initial_max_stream_data_bidi_local",
990
+ params->initial_max_stream_data_bidi_local);
991
+ *p++ = ',';
992
+ p = write_pair_number(p, "initial_max_stream_data_bidi_remote",
993
+ params->initial_max_stream_data_bidi_remote);
994
+ *p++ = ',';
995
+ p = write_pair_number(p, "initial_max_stream_data_uni",
996
+ params->initial_max_stream_data_uni);
997
+ *p++ = ',';
998
+ p = write_pair_number(p, "initial_max_streams_bidi",
999
+ params->initial_max_streams_bidi);
1000
+ *p++ = ',';
1001
+ p = write_pair_number(p, "initial_max_streams_uni",
1002
+ params->initial_max_streams_uni);
1003
+ if (params->preferred_address_present) {
1004
+ *p++ = ',';
1005
+ paddr = &params->preferred_address;
1006
+ p = write_string(p, "preferred_address");
1007
+ *p++ = ':';
1008
+ *p++ = '{';
1009
+
1010
+ if (paddr->ipv4_present) {
1011
+ sa_in = &paddr->ipv4;
1012
+
1013
+ p = write_pair_hex(p, "ip_v4", (const uint8_t *)&sa_in->sin_addr,
1014
+ sizeof(sa_in->sin_addr));
1015
+ *p++ = ',';
1016
+ p = write_pair_number(p, "port_v4", ngtcp2_ntohs(sa_in->sin_port));
1017
+ *p++ = ',';
1018
+ }
1019
+
1020
+ if (paddr->ipv6_present) {
1021
+ sa_in6 = &paddr->ipv6;
1022
+
1023
+ p = write_pair_hex(p, "ip_v6", (const uint8_t *)&sa_in6->sin6_addr,
1024
+ sizeof(sa_in6->sin6_addr));
1025
+ *p++ = ',';
1026
+ p = write_pair_number(p, "port_v6", ngtcp2_ntohs(sa_in6->sin6_port));
1027
+ *p++ = ',';
1028
+ }
1029
+
1030
+ p = write_pair_cid(p, "connection_id", &paddr->cid);
1031
+ p = write_verbatim(p, ",\"stateless_reset_token\":{");
1032
+ p = write_pair_hex(p, "data", paddr->stateless_reset_token,
1033
+ sizeof(paddr->stateless_reset_token));
1034
+ *p++ = '}';
1035
+ *p++ = '}';
1036
+ }
1037
+ *p++ = ',';
1038
+ p = write_pair_number(p, "max_datagram_frame_size",
1039
+ params->max_datagram_frame_size);
1040
+ *p++ = ',';
1041
+ p = write_pair_bool(p, "grease_quic_bit", params->grease_quic_bit);
1042
+ p = write_verbatim(p, "}}\n");
1043
+
1044
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf,
1045
+ (size_t)(p - buf));
1046
+ }
1047
+
1048
+ void ngtcp2_qlog_metrics_updated(ngtcp2_qlog *qlog,
1049
+ const ngtcp2_conn_stat *cstat) {
1050
+ uint8_t buf[1024];
1051
+ uint8_t *p = buf;
1052
+
1053
+ if (!qlog->write) {
1054
+ return;
1055
+ }
1056
+
1057
+ *p++ = '\x1e';
1058
+ *p++ = '{';
1059
+ p = qlog_write_time(qlog, p);
1060
+ p = write_verbatim(p, ",\"name\":\"recovery:metrics_updated\",\"data\":{");
1061
+
1062
+ if (cstat->min_rtt != UINT64_MAX) {
1063
+ p = write_pair_duration(p, "min_rtt", cstat->min_rtt);
1064
+ *p++ = ',';
1065
+ }
1066
+ p = write_pair_duration(p, "smoothed_rtt", cstat->smoothed_rtt);
1067
+ *p++ = ',';
1068
+ p = write_pair_duration(p, "latest_rtt", cstat->latest_rtt);
1069
+ *p++ = ',';
1070
+ p = write_pair_duration(p, "rtt_variance", cstat->rttvar);
1071
+ *p++ = ',';
1072
+ p = write_pair_number(p, "pto_count", cstat->pto_count);
1073
+ *p++ = ',';
1074
+ p = write_pair_number(p, "congestion_window", cstat->cwnd);
1075
+ *p++ = ',';
1076
+ p = write_pair_number(p, "bytes_in_flight", cstat->bytes_in_flight);
1077
+ if (cstat->ssthresh != UINT64_MAX) {
1078
+ *p++ = ',';
1079
+ p = write_pair_number(p, "ssthresh", cstat->ssthresh);
1080
+ }
1081
+
1082
+ p = write_verbatim(p, "}}\n");
1083
+
1084
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf,
1085
+ (size_t)(p - buf));
1086
+ }
1087
+
1088
+ void ngtcp2_qlog_pkt_lost(ngtcp2_qlog *qlog, ngtcp2_rtb_entry *ent) {
1089
+ uint8_t buf[256];
1090
+ uint8_t *p = buf;
1091
+ ngtcp2_pkt_hd hd = {0};
1092
+
1093
+ if (!qlog->write) {
1094
+ return;
1095
+ }
1096
+
1097
+ *p++ = '\x1e';
1098
+ *p++ = '{';
1099
+ p = qlog_write_time(qlog, p);
1100
+ p = write_verbatim(
1101
+ p, ",\"name\":\"recovery:packet_lost\",\"data\":{\"header\":");
1102
+
1103
+ hd.type = ent->hd.type;
1104
+ hd.flags = ent->hd.flags;
1105
+ hd.pkt_num = ent->hd.pkt_num;
1106
+
1107
+ p = write_pkt_hd(p, &hd);
1108
+ p = write_verbatim(p, "}}\n");
1109
+
1110
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf,
1111
+ (size_t)(p - buf));
1112
+ }
1113
+
1114
+ void ngtcp2_qlog_retry_pkt_received(ngtcp2_qlog *qlog, const ngtcp2_pkt_hd *hd,
1115
+ const ngtcp2_pkt_retry *retry) {
1116
+ uint8_t rawbuf[1024];
1117
+ ngtcp2_buf buf;
1118
+
1119
+ if (!qlog->write) {
1120
+ return;
1121
+ }
1122
+
1123
+ ngtcp2_buf_init(&buf, rawbuf, sizeof(rawbuf));
1124
+
1125
+ *buf.last++ = '\x1e';
1126
+ *buf.last++ = '{';
1127
+ buf.last = qlog_write_time(qlog, buf.last);
1128
+ buf.last = write_verbatim(
1129
+ buf.last,
1130
+ ",\"name\":\"transport:packet_received\",\"data\":{\"header\":");
1131
+
1132
+ if (ngtcp2_buf_left(&buf) <
1133
+ NGTCP2_QLOG_PKT_HD_OVERHEAD + hd->tokenlen * 2 +
1134
+ sizeof(",\"retry_token\":{\"data\":\"\"}}}\n") - 1 +
1135
+ retry->tokenlen * 2) {
1136
+ return;
1137
+ }
1138
+
1139
+ buf.last = write_pkt_hd(buf.last, hd);
1140
+ buf.last = write_verbatim(buf.last, ",\"retry_token\":{");
1141
+ buf.last = write_pair_hex(buf.last, "data", retry->token, retry->tokenlen);
1142
+ buf.last = write_verbatim(buf.last, "}}}\n");
1143
+
1144
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf.pos,
1145
+ ngtcp2_buf_len(&buf));
1146
+ }
1147
+
1148
+ void ngtcp2_qlog_stateless_reset_pkt_received(
1149
+ ngtcp2_qlog *qlog, const ngtcp2_pkt_stateless_reset *sr) {
1150
+ uint8_t buf[256];
1151
+ uint8_t *p = buf;
1152
+ ngtcp2_pkt_hd hd = {0};
1153
+
1154
+ if (!qlog->write) {
1155
+ return;
1156
+ }
1157
+
1158
+ hd.type = NGTCP2_PKT_STATELESS_RESET;
1159
+
1160
+ *p++ = '\x1e';
1161
+ *p++ = '{';
1162
+ p = qlog_write_time(qlog, p);
1163
+ p = write_verbatim(
1164
+ p, ",\"name\":\"transport:packet_received\",\"data\":{\"header\":");
1165
+ p = write_pkt_hd(p, &hd);
1166
+ *p++ = ',';
1167
+ p = write_pair_hex(p, "stateless_reset_token", sr->stateless_reset_token,
1168
+ NGTCP2_STATELESS_RESET_TOKENLEN);
1169
+ p = write_verbatim(p, "}}\n");
1170
+
1171
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf,
1172
+ (size_t)(p - buf));
1173
+ }
1174
+
1175
+ void ngtcp2_qlog_version_negotiation_pkt_received(ngtcp2_qlog *qlog,
1176
+ const ngtcp2_pkt_hd *hd,
1177
+ const uint32_t *sv,
1178
+ size_t nsv) {
1179
+ uint8_t rawbuf[512];
1180
+ ngtcp2_buf buf;
1181
+ size_t i;
1182
+ uint32_t v;
1183
+
1184
+ if (!qlog->write) {
1185
+ return;
1186
+ }
1187
+
1188
+ ngtcp2_buf_init(&buf, rawbuf, sizeof(rawbuf));
1189
+
1190
+ *buf.last++ = '\x1e';
1191
+ *buf.last++ = '{';
1192
+ buf.last = qlog_write_time(qlog, buf.last);
1193
+ buf.last = write_verbatim(
1194
+ buf.last,
1195
+ ",\"name\":\"transport:packet_received\",\"data\":{\"header\":");
1196
+ buf.last = write_pkt_hd(buf.last, hd);
1197
+ buf.last = write_verbatim(buf.last, ",\"supported_versions\":[");
1198
+
1199
+ if (nsv) {
1200
+ if (ngtcp2_buf_left(&buf) <
1201
+ (sizeof("\"xxxxxxxx\",") - 1) * nsv - 1 + sizeof("]}}\n") - 1) {
1202
+ return;
1203
+ }
1204
+
1205
+ v = ngtcp2_htonl(sv[0]);
1206
+ buf.last = write_hex(buf.last, (const uint8_t *)&v, sizeof(v));
1207
+
1208
+ for (i = 1; i < nsv; ++i) {
1209
+ *buf.last++ = ',';
1210
+ v = ngtcp2_htonl(sv[i]);
1211
+ buf.last = write_hex(buf.last, (const uint8_t *)&v, sizeof(v));
1212
+ }
1213
+ }
1214
+
1215
+ buf.last = write_verbatim(buf.last, "]}}\n");
1216
+
1217
+ qlog->write(qlog->user_data, NGTCP2_QLOG_WRITE_FLAG_NONE, buf.pos,
1218
+ ngtcp2_buf_len(&buf));
1219
+ }