@encharm/cws 4.5.2 → 4.6.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 (284) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/CLAUDE.md +81 -0
  3. package/README.md +10 -5
  4. package/dist/bindings/cws_darwin_arm64_node115.node +0 -0
  5. package/dist/bindings/cws_darwin_arm64_node127.node +0 -0
  6. package/dist/bindings/cws_darwin_arm64_node137.node +0 -0
  7. package/dist/bindings/cws_darwin_arm64_node147.node +0 -0
  8. package/dist/bindings/cws_linux_arm64_node115.node +0 -0
  9. package/dist/bindings/cws_linux_arm64_node127.node +0 -0
  10. package/dist/bindings/cws_linux_arm64_node137.node +0 -0
  11. package/dist/bindings/cws_linux_arm64_node147.node +0 -0
  12. package/dist/bindings/cws_linux_x64_node115.node +0 -0
  13. package/dist/bindings/cws_linux_x64_node127.node +0 -0
  14. package/dist/bindings/cws_linux_x64_node137.node +0 -0
  15. package/dist/bindings/cws_linux_x64_node147.node +0 -0
  16. package/dist/bindings/cws_win32_x64_node115.node +0 -0
  17. package/dist/bindings/cws_win32_x64_node127.node +0 -0
  18. package/dist/bindings/cws_win32_x64_node137.node +0 -0
  19. package/dist/bindings/cws_win32_x64_node147.node +0 -0
  20. package/package.json +1 -1
  21. package/src/Addon.cpp +2 -1
  22. package/src/Addon.h +70 -14
  23. package/src/Hub.h +1 -0
  24. package/src/Networking.h +11 -0
  25. package/src/Socket.h +201 -6
  26. package/src/WebSocket.cpp +4 -1
  27. package/src/cSNode.cpp +2 -0
  28. package/src/cSNode.h +4 -0
  29. package/src/headers/24/tracing/agent.h +195 -0
  30. package/src/headers/24/tracing/trace_event.h +722 -0
  31. package/src/headers/26/acorn_version.h +6 -0
  32. package/src/headers/26/aliased_buffer-inl.h +264 -0
  33. package/src/headers/26/aliased_buffer.h +205 -0
  34. package/src/headers/26/aliased_struct-inl.h +143 -0
  35. package/src/headers/26/aliased_struct.h +248 -0
  36. package/src/headers/26/amaro_version.h +6 -0
  37. package/src/headers/26/async_context_frame.h +33 -0
  38. package/src/headers/26/async_wrap-inl.h +123 -0
  39. package/src/headers/26/async_wrap.h +254 -0
  40. package/src/headers/26/base_object-inl.h +333 -0
  41. package/src/headers/26/base_object.h +339 -0
  42. package/src/headers/26/base_object_types.h +76 -0
  43. package/src/headers/26/blob_serializer_deserializer-inl.h +385 -0
  44. package/src/headers/26/blob_serializer_deserializer.h +142 -0
  45. package/src/headers/26/builtin_info.h +57 -0
  46. package/src/headers/26/callback_queue-inl.h +97 -0
  47. package/src/headers/26/callback_queue.h +79 -0
  48. package/src/headers/26/cares_wrap.h +475 -0
  49. package/src/headers/26/cleanup_queue-inl.h +36 -0
  50. package/src/headers/26/cleanup_queue.h +79 -0
  51. package/src/headers/26/compile_cache.h +134 -0
  52. package/src/headers/26/connect_wrap.h +26 -0
  53. package/src/headers/26/connection_wrap.h +30 -0
  54. package/src/headers/26/cppgc_helpers-inl.h +69 -0
  55. package/src/headers/26/cppgc_helpers.h +162 -0
  56. package/src/headers/26/crypto/crypto_aes.h +107 -0
  57. package/src/headers/26/crypto/crypto_argon2.h +88 -0
  58. package/src/headers/26/crypto/crypto_bio.h +193 -0
  59. package/src/headers/26/crypto/crypto_chacha20_poly1305.h +62 -0
  60. package/src/headers/26/crypto/crypto_cipher.h +291 -0
  61. package/src/headers/26/crypto/crypto_common.h +48 -0
  62. package/src/headers/26/crypto/crypto_context.h +219 -0
  63. package/src/headers/26/crypto/crypto_dh.h +104 -0
  64. package/src/headers/26/crypto/crypto_dsa.h +50 -0
  65. package/src/headers/26/crypto/crypto_ec.h +102 -0
  66. package/src/headers/26/crypto/crypto_hash.h +157 -0
  67. package/src/headers/26/crypto/crypto_hkdf.h +62 -0
  68. package/src/headers/26/crypto/crypto_hmac.h +92 -0
  69. package/src/headers/26/crypto/crypto_kem.h +131 -0
  70. package/src/headers/26/crypto/crypto_keygen.h +382 -0
  71. package/src/headers/26/crypto/crypto_keys.h +366 -0
  72. package/src/headers/26/crypto/crypto_kmac.h +79 -0
  73. package/src/headers/26/crypto/crypto_pbkdf2.h +76 -0
  74. package/src/headers/26/crypto/crypto_pqc.h +39 -0
  75. package/src/headers/26/crypto/crypto_random.h +127 -0
  76. package/src/headers/26/crypto/crypto_rsa.h +108 -0
  77. package/src/headers/26/crypto/crypto_scrypt.h +85 -0
  78. package/src/headers/26/crypto/crypto_sig.h +159 -0
  79. package/src/headers/26/crypto/crypto_spkac.h +21 -0
  80. package/src/headers/26/crypto/crypto_timing.h +20 -0
  81. package/src/headers/26/crypto/crypto_tls.h +342 -0
  82. package/src/headers/26/crypto/crypto_turboshake.h +105 -0
  83. package/src/headers/26/crypto/crypto_util.h +775 -0
  84. package/src/headers/26/crypto/crypto_x509.h +140 -0
  85. package/src/headers/26/dataqueue/queue.h +311 -0
  86. package/src/headers/26/debug_utils-inl.h +291 -0
  87. package/src/headers/26/debug_utils.h +200 -0
  88. package/src/headers/26/diagnosticfilename-inl.h +33 -0
  89. package/src/headers/26/embedded_data.h +17 -0
  90. package/src/headers/26/encoding_binding.h +59 -0
  91. package/src/headers/26/env-inl.h +956 -0
  92. package/src/headers/26/env.h +1294 -0
  93. package/src/headers/26/env_properties.h +562 -0
  94. package/src/headers/26/ffi/data.h +30 -0
  95. package/src/headers/26/ffi/fast.h +96 -0
  96. package/src/headers/26/ffi/jit_memory.h +26 -0
  97. package/src/headers/26/ffi/types.h +99 -0
  98. package/src/headers/26/handle_wrap.h +123 -0
  99. package/src/headers/26/histogram-inl.h +211 -0
  100. package/src/headers/26/histogram.h +474 -0
  101. package/src/headers/26/inspector/dom_storage_agent.h +68 -0
  102. package/src/headers/26/inspector/inspector_object_utils.h +38 -0
  103. package/src/headers/26/inspector/io_agent.h +30 -0
  104. package/src/headers/26/inspector/main_thread_interface.h +116 -0
  105. package/src/headers/26/inspector/network_agent.h +110 -0
  106. package/src/headers/26/inspector/network_inspector.h +45 -0
  107. package/src/headers/26/inspector/network_requests_buffer.h +195 -0
  108. package/src/headers/26/inspector/network_resource_manager.h +29 -0
  109. package/src/headers/26/inspector/node_json.h +24 -0
  110. package/src/headers/26/inspector/node_string.h +101 -0
  111. package/src/headers/26/inspector/notification_emitter.h +38 -0
  112. package/src/headers/26/inspector/protocol_helper.h +27 -0
  113. package/src/headers/26/inspector/runtime_agent.h +41 -0
  114. package/src/headers/26/inspector/storage_agent.h +33 -0
  115. package/src/headers/26/inspector/target_agent.h +59 -0
  116. package/src/headers/26/inspector/target_manager.h +70 -0
  117. package/src/headers/26/inspector/tracing_agent.h +43 -0
  118. package/src/headers/26/inspector/worker_agent.h +40 -0
  119. package/src/headers/26/inspector/worker_inspector.h +124 -0
  120. package/src/headers/26/inspector_agent.h +168 -0
  121. package/src/headers/26/inspector_io.h +78 -0
  122. package/src/headers/26/inspector_profiler.h +149 -0
  123. package/src/headers/26/inspector_socket.h +60 -0
  124. package/src/headers/26/inspector_socket_server.h +110 -0
  125. package/src/headers/26/js_native_api.h +634 -0
  126. package/src/headers/26/js_native_api_types.h +244 -0
  127. package/src/headers/26/js_native_api_v8.h +485 -0
  128. package/src/headers/26/js_native_api_v8_internals.h +45 -0
  129. package/src/headers/26/js_stream.h +57 -0
  130. package/src/headers/26/json_utils.h +172 -0
  131. package/src/headers/26/large_pages/node_large_page.h +34 -0
  132. package/src/headers/26/lru_cache-inl.h +69 -0
  133. package/src/headers/26/memory_tracker-inl.h +461 -0
  134. package/src/headers/26/memory_tracker.h +341 -0
  135. package/src/headers/26/module_wrap.h +231 -0
  136. package/src/headers/26/ncrypto.h +2008 -0
  137. package/src/headers/26/node.h +1693 -0
  138. package/src/headers/26/node_api.h +265 -0
  139. package/src/headers/26/node_api_internals.h +48 -0
  140. package/src/headers/26/node_api_types.h +58 -0
  141. package/src/headers/26/node_binding.h +170 -0
  142. package/src/headers/26/node_blob.h +160 -0
  143. package/src/headers/26/node_bob-inl.h +36 -0
  144. package/src/headers/26/node_bob.h +107 -0
  145. package/src/headers/26/node_buffer.h +92 -0
  146. package/src/headers/26/node_builtins.h +239 -0
  147. package/src/headers/26/node_concepts.h +46 -0
  148. package/src/headers/26/node_config_file.h +77 -0
  149. package/src/headers/26/node_constants.h +82 -0
  150. package/src/headers/26/node_context_data.h +171 -0
  151. package/src/headers/26/node_contextify.h +261 -0
  152. package/src/headers/26/node_crypto.h +66 -0
  153. package/src/headers/26/node_debug.h +30 -0
  154. package/src/headers/26/node_diagnostics_channel.h +121 -0
  155. package/src/headers/26/node_dir.h +52 -0
  156. package/src/headers/26/node_dotenv.h +45 -0
  157. package/src/headers/26/node_errors.h +378 -0
  158. package/src/headers/26/node_exit_code.h +54 -0
  159. package/src/headers/26/node_external_reference.h +171 -0
  160. package/src/headers/26/node_ffi.h +212 -0
  161. package/src/headers/26/node_file-inl.h +421 -0
  162. package/src/headers/26/node_file.h +561 -0
  163. package/src/headers/26/node_file_utils.h +39 -0
  164. package/src/headers/26/node_hash.h +212 -0
  165. package/src/headers/26/node_http2.h +1202 -0
  166. package/src/headers/26/node_http2_state.h +159 -0
  167. package/src/headers/26/node_http_common-inl.h +199 -0
  168. package/src/headers/26/node_http_common.h +535 -0
  169. package/src/headers/26/node_i18n.h +132 -0
  170. package/src/headers/26/node_internals.h +485 -0
  171. package/src/headers/26/node_locks.h +184 -0
  172. package/src/headers/26/node_main_instance.h +67 -0
  173. package/src/headers/26/node_mem-inl.h +113 -0
  174. package/src/headers/26/node_mem.h +45 -0
  175. package/src/headers/26/node_messaging.h +389 -0
  176. package/src/headers/26/node_metadata.h +172 -0
  177. package/src/headers/26/node_modules.h +102 -0
  178. package/src/headers/26/node_mutex.h +323 -0
  179. package/src/headers/26/node_object_wrap.h +145 -0
  180. package/src/headers/26/node_options-inl.h +524 -0
  181. package/src/headers/26/node_options.h +710 -0
  182. package/src/headers/26/node_perf.h +167 -0
  183. package/src/headers/26/node_perf_common.h +103 -0
  184. package/src/headers/26/node_platform.h +290 -0
  185. package/src/headers/26/node_process-inl.h +26 -0
  186. package/src/headers/26/node_process.h +112 -0
  187. package/src/headers/26/node_profiling.h +38 -0
  188. package/src/headers/26/node_realm-inl.h +156 -0
  189. package/src/headers/26/node_realm.h +236 -0
  190. package/src/headers/26/node_report.h +43 -0
  191. package/src/headers/26/node_revert.h +82 -0
  192. package/src/headers/26/node_root_certs.h +2937 -0
  193. package/src/headers/26/node_sea.h +101 -0
  194. package/src/headers/26/node_shadow_realm.h +46 -0
  195. package/src/headers/26/node_snapshot_builder.h +57 -0
  196. package/src/headers/26/node_snapshotable.h +167 -0
  197. package/src/headers/26/node_sockaddr-inl.h +248 -0
  198. package/src/headers/26/node_sockaddr.h +459 -0
  199. package/src/headers/26/node_sqlite.h +607 -0
  200. package/src/headers/26/node_stat_watcher.h +73 -0
  201. package/src/headers/26/node_task_runner.h +92 -0
  202. package/src/headers/26/node_threadsafe_cow-inl.h +54 -0
  203. package/src/headers/26/node_threadsafe_cow.h +105 -0
  204. package/src/headers/26/node_union_bytes.h +81 -0
  205. package/src/headers/26/node_url.h +101 -0
  206. package/src/headers/26/node_url_pattern.h +118 -0
  207. package/src/headers/26/node_v8.h +78 -0
  208. package/src/headers/26/node_v8_embedder.h +26 -0
  209. package/src/headers/26/node_v8_platform-inl.h +96 -0
  210. package/src/headers/26/node_version.h +116 -0
  211. package/src/headers/26/node_wasi.h +184 -0
  212. package/src/headers/26/node_wasm_web_api.h +55 -0
  213. package/src/headers/26/node_watchdog.h +164 -0
  214. package/src/headers/26/node_webstorage.h +62 -0
  215. package/src/headers/26/node_worker.h +162 -0
  216. package/src/headers/26/path.h +36 -0
  217. package/src/headers/26/permission/boolean_permission.h +50 -0
  218. package/src/headers/26/permission/fs_permission.h +192 -0
  219. package/src/headers/26/permission/permission.h +155 -0
  220. package/src/headers/26/permission/permission_base.h +79 -0
  221. package/src/headers/26/pipe_wrap.h +80 -0
  222. package/src/headers/26/quic/application.h +279 -0
  223. package/src/headers/26/quic/arena.h +373 -0
  224. package/src/headers/26/quic/bindingdata.h +440 -0
  225. package/src/headers/26/quic/cid.h +127 -0
  226. package/src/headers/26/quic/data.h +358 -0
  227. package/src/headers/26/quic/defs.h +417 -0
  228. package/src/headers/26/quic/endpoint.h +519 -0
  229. package/src/headers/26/quic/guard.h +5 -0
  230. package/src/headers/26/quic/http3.h +25 -0
  231. package/src/headers/26/quic/packet.h +166 -0
  232. package/src/headers/26/quic/preferredaddress.h +72 -0
  233. package/src/headers/26/quic/session.h +770 -0
  234. package/src/headers/26/quic/session_manager.h +107 -0
  235. package/src/headers/26/quic/sessionticket.h +110 -0
  236. package/src/headers/26/quic/streams.h +518 -0
  237. package/src/headers/26/quic/tlscontext.h +353 -0
  238. package/src/headers/26/quic/tokens.h +263 -0
  239. package/src/headers/26/quic/transportparams.h +184 -0
  240. package/src/headers/26/req_wrap-inl.h +175 -0
  241. package/src/headers/26/req_wrap.h +79 -0
  242. package/src/headers/26/spawn_sync.h +243 -0
  243. package/src/headers/26/stream_base-inl.h +170 -0
  244. package/src/headers/26/stream_base.h +487 -0
  245. package/src/headers/26/stream_pipe.h +76 -0
  246. package/src/headers/26/stream_wrap.h +137 -0
  247. package/src/headers/26/string_bytes.h +114 -0
  248. package/src/headers/26/string_decoder-inl.h +31 -0
  249. package/src/headers/26/string_decoder.h +49 -0
  250. package/src/headers/26/tcp_wrap.h +138 -0
  251. package/src/headers/26/threadpoolwork-inl.h +70 -0
  252. package/src/headers/26/timer_wrap-inl.h +32 -0
  253. package/src/headers/26/timer_wrap.h +87 -0
  254. package/src/headers/26/timers.h +70 -0
  255. package/src/headers/26/tracing/agent.h +125 -0
  256. package/src/headers/26/tracing/agent_legacy.h +146 -0
  257. package/src/headers/26/tracing/agent_perfetto.h +145 -0
  258. package/src/headers/26/tracing/node_trace_buffer.h +91 -0
  259. package/src/headers/26/tracing/node_trace_writer.h +79 -0
  260. package/src/headers/26/tracing/trace_event.h +27 -0
  261. package/src/headers/26/tracing/trace_event_helper.h +40 -0
  262. package/src/headers/26/tracing/trace_event_legacy.h +1113 -0
  263. package/src/headers/26/tracing/trace_event_legacy_inl.h +711 -0
  264. package/src/headers/26/tracing/trace_event_perfetto.h +47 -0
  265. package/src/headers/26/tracing/traced_value.h +167 -0
  266. package/src/headers/26/tty_wrap.h +65 -0
  267. package/src/headers/26/udp_wrap.h +231 -0
  268. package/src/headers/26/undici_version.h +6 -0
  269. package/src/headers/26/util-inl.h +788 -0
  270. package/src/headers/26/util.h +1207 -0
  271. package/src/headers/26/v8-cpp-heap-external.h +56 -0
  272. package/src/headers/26/v8-external-memory-accounter.h +60 -0
  273. package/src/headers/26/v8-fast-api-calls.h +784 -0
  274. package/src/headers/26/v8-inspector-protocol.h +13 -0
  275. package/src/headers/26/v8-inspector.h +458 -0
  276. package/src/headers/26/v8-metrics.h +273 -0
  277. package/src/headers/26/v8-trace-categories.h +28 -0
  278. package/src/headers/26/v8-unwinder-state.h +30 -0
  279. package/src/headers/26/v8-util.h +549 -0
  280. package/src/headers/26/v8-value-serializer-version.h +24 -0
  281. package/src/headers/26/v8-version-string.h +38 -0
  282. package/src/headers/26/v8-wasm-trap-handler-posix.h +31 -0
  283. package/src/headers/26/v8-wasm-trap-handler-win.h +28 -0
  284. package/src/headers/26/zlib_version.h +6 -0
@@ -0,0 +1,440 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+
5
+ #include <base_object.h>
6
+ #include <env.h>
7
+ #include <memory_tracker.h>
8
+ #include <nghttp3/nghttp3.h>
9
+ #include <ngtcp2/ngtcp2.h>
10
+ #include <ngtcp2/ngtcp2_crypto.h>
11
+ #include <node.h>
12
+ #include <node_mem.h>
13
+ #include <uv.h>
14
+ #include <v8.h>
15
+ #include <functional>
16
+ #include <memory>
17
+ #include <unordered_map>
18
+ #include <vector>
19
+ #include "defs.h"
20
+
21
+ namespace node::quic {
22
+
23
+ class Endpoint;
24
+ class Packet;
25
+ class Session;
26
+ class SessionManager;
27
+
28
+ // ============================================================================
29
+
30
+ // The FunctionTemplates the BindingData will store for us.
31
+ #define QUIC_CONSTRUCTORS(V) \
32
+ V(endpoint) \
33
+ V(session) \
34
+ V(stream) \
35
+ V(udp)
36
+
37
+ // The callbacks are persistent v8::Function references that are set in the
38
+ // quic::BindingState used to communicate data and events back out to the JS
39
+ // environment. They are set once from the JavaScript side when the
40
+ // internalBinding('quic') is first loaded.
41
+ #define QUIC_JS_CALLBACKS(V) \
42
+ V(endpoint_close, EndpointClose) \
43
+ V(session_close, SessionClose) \
44
+ V(session_application, SessionApplication) \
45
+ V(session_early_data_rejected, SessionEarlyDataRejected) \
46
+ V(session_goaway, SessionGoaway) \
47
+ V(session_datagram, SessionDatagram) \
48
+ V(session_datagram_status, SessionDatagramStatus) \
49
+ V(session_handshake, SessionHandshake) \
50
+ V(session_keylog, SessionKeyLog) \
51
+ V(session_qlog, SessionQlog) \
52
+ V(session_new, SessionNew) \
53
+ V(session_new_token, SessionNewToken) \
54
+ V(session_origin, SessionOrigin) \
55
+ V(session_path_validation, SessionPathValidation) \
56
+ V(session_ticket, SessionTicket) \
57
+ V(session_version_negotiation, SessionVersionNegotiation) \
58
+ V(stream_blocked, StreamBlocked) \
59
+ V(stream_close, StreamClose) \
60
+ V(stream_created, StreamCreated) \
61
+ V(stream_drain, StreamDrain) \
62
+ V(stream_headers, StreamHeaders) \
63
+ V(stream_reset, StreamReset) \
64
+ V(stream_stop_sending, StreamStopSending) \
65
+ V(stream_trailers, StreamTrailers)
66
+
67
+ // The various JS strings the implementation uses.
68
+ #define QUIC_STRINGS(V) \
69
+ V(abandoned, "abandoned") \
70
+ V(aborted, "aborted") \
71
+ V(acknowledged, "acknowledged") \
72
+ V(ack_delay_exponent, "ackDelayExponent") \
73
+ V(active_connection_id_limit, "activeConnectionIDLimit") \
74
+ V(address_lru_size, "addressLRUSize") \
75
+ V(allow, "allow") \
76
+ V(application, "application") \
77
+ V(authoritative, "authoritative") \
78
+ V(bbr, "bbr") \
79
+ V(ca, "ca") \
80
+ V(cc_algorithm, "cc") \
81
+ V(certificate_compression, "certificateCompression") \
82
+ V(certs, "certs") \
83
+ V(code, "code") \
84
+ V(ciphers, "ciphers") \
85
+ V(crl, "crl") \
86
+ V(cubic, "cubic") \
87
+ V(datagram_drop_policy, "datagramDropPolicy") \
88
+ V(deny, "deny") \
89
+ V(disable_stateless_reset, "disableStatelessReset") \
90
+ V(draining_period_multiplier, "drainingPeriodMultiplier") \
91
+ V(enable_connect_protocol, "enableConnectProtocol") \
92
+ V(enable_early_data, "enableEarlyData") \
93
+ V(enable_datagrams, "enableDatagrams") \
94
+ V(enable_tls_trace, "tlsTrace") \
95
+ V(endpoint, "Endpoint") \
96
+ V(endpoint_udp, "Endpoint::UDP") \
97
+ V(failure, "failure") \
98
+ V(groups, "groups") \
99
+ V(handshake_timeout, "handshakeTimeout") \
100
+ V(http3_alpn, &NGHTTP3_ALPN_H3[1]) \
101
+ V(initial_rtt, "initialRtt") \
102
+ V(keep_alive_timeout, "keepAlive") \
103
+ V(initial_max_data, "initialMaxData") \
104
+ V(initial_max_stream_data_bidi_local, "initialMaxStreamDataBidiLocal") \
105
+ V(initial_max_stream_data_bidi_remote, "initialMaxStreamDataBidiRemote") \
106
+ V(initial_max_stream_data_uni, "initialMaxStreamDataUni") \
107
+ V(initial_max_streams_bidi, "initialMaxStreamsBidi") \
108
+ V(initial_max_streams_uni, "initialMaxStreamsUni") \
109
+ V(ipv6_only, "ipv6Only") \
110
+ V(reuse_port, "reusePort") \
111
+ V(keylog, "keylog") \
112
+ V(keys, "keys") \
113
+ V(lost, "lost") \
114
+ V(max_ack_delay, "maxAckDelay") \
115
+ V(max_connections_per_host, "maxConnectionsPerHost") \
116
+ V(max_connections_total, "maxConnectionsTotal") \
117
+ V(max_datagram_frame_size, "maxDatagramFrameSize") \
118
+ V(max_datagram_send_attempts, "maxDatagramSendAttempts") \
119
+ V(stream_idle_timeout, "streamIdleTimeout") \
120
+ V(max_field_section_size, "maxFieldSectionSize") \
121
+ V(max_header_length, "maxHeaderLength") \
122
+ V(max_header_pairs, "maxHeaderPairs") \
123
+ V(idle_timeout, "idleTimeout") \
124
+ V(max_idle_timeout, "maxIdleTimeout") \
125
+ V(max_payload_size, "maxPayloadSize") \
126
+ V(retry_rate, "retryRate") \
127
+ V(retry_burst, "retryBurst") \
128
+ V(stateless_reset_rate, "statelessResetRate") \
129
+ V(stateless_reset_burst, "statelessResetBurst") \
130
+ V(version_negotiation_rate, "versionNegotiationRate") \
131
+ V(version_negotiation_burst, "versionNegotiationBurst") \
132
+ V(immediate_close_rate, "immediateCloseRate") \
133
+ V(immediate_close_burst, "immediateCloseBurst") \
134
+ V(session_creation_rate, "sessionCreationRate") \
135
+ V(session_creation_burst, "sessionCreationBurst") \
136
+ V(block_list, "blockList") \
137
+ V(block_list_policy, "blockListPolicy") \
138
+ V(max_stream_window, "maxStreamWindow") \
139
+ V(max_window, "maxWindow") \
140
+ V(min_version, "minVersion") \
141
+ V(port, "port") \
142
+ V(preferred_address_ipv4, "preferredAddressIpv4") \
143
+ V(preferred_address_ipv6, "preferredAddressIpv6") \
144
+ V(preferred_address_strategy, "preferredAddressPolicy") \
145
+ V(alpn, "alpn") \
146
+ V(qlog, "qlog") \
147
+ V(qpack_blocked_streams, "qpackBlockedStreams") \
148
+ V(qpack_encoder_max_dtable_capacity, "qpackEncoderMaxDTableCapacity") \
149
+ V(qpack_max_dtable_capacity, "qpackMaxDTableCapacity") \
150
+ V(reason, "reason") \
151
+ V(reject_unauthorized, "rejectUnauthorized") \
152
+ V(reno, "reno") \
153
+ V(reset_token_secret, "resetTokenSecret") \
154
+ V(retry_token_expiration, "retryTokenExpiration") \
155
+ V(rx_loss, "rxDiagnosticLoss") \
156
+ V(servername, "servername") \
157
+ V(session, "Session") \
158
+ V(sni, "sni") \
159
+ V(stream, "Stream") \
160
+ V(success, "success") \
161
+ V(tls_options, "tls") \
162
+ V(token, "token") \
163
+ V(token_expiration, "tokenExpiration") \
164
+ V(token_secret, "tokenSecret") \
165
+ V(transport, "transport") \
166
+ V(transport_params, "transportParams") \
167
+ V(type, "type") \
168
+ V(tx_loss, "txDiagnosticLoss") \
169
+ V(udp_receive_buffer_size, "udpReceiveBufferSize") \
170
+ V(udp_send_buffer_size, "udpSendBufferSize") \
171
+ V(udp_ttl, "udpTTL") \
172
+ V(unacknowledged_packet_threshold, "unacknowledgedPacketThreshold") \
173
+ V(validate_address, "validateAddress") \
174
+ V(verify_client, "verifyClient") \
175
+ V(verify_hostname, "verifyHostname") \
176
+ V(verify_peer_strict, "verifyPeerStrict") \
177
+ V(verify_private_key, "verifyPrivateKey") \
178
+ V(version, "version")
179
+
180
+ // =============================================================================
181
+ // Lightweight wrappers around uv_check_t that ensure safe handle closure.
182
+ // The check handle is embedded in a heap-allocated CheckWrap whose destruction
183
+ // is deferred until the uv_close callback fires, preventing use-after-free
184
+ // when the owning object is destroyed before libuv finishes closing the handle.
185
+ // Follows the same two-layer pattern as TimerWrap / TimerWrapHandle
186
+ // (see timer_wrap.h).
187
+ // TODO(@jasnell): Consider moving it out to a separate file like timer_wrap.h.
188
+ class CheckWrap final : public MemoryRetainer {
189
+ public:
190
+ using CheckCb = std::function<void()>;
191
+
192
+ template <typename... Args>
193
+ explicit CheckWrap(Environment* env, Args&&... args)
194
+ : env_(env), fn_(std::forward<Args>(args)...) {
195
+ uv_check_init(env->event_loop(), &check_);
196
+ check_.data = this;
197
+ }
198
+
199
+ DISALLOW_COPY_AND_MOVE(CheckWrap)
200
+
201
+ inline Environment* env() const { return env_; }
202
+
203
+ void Start();
204
+ void Stop();
205
+ void Close();
206
+ void Ref();
207
+ void Unref();
208
+
209
+ SET_NO_MEMORY_INFO()
210
+ SET_MEMORY_INFO_NAME(CheckWrap)
211
+ SET_SELF_SIZE(CheckWrap)
212
+
213
+ private:
214
+ static void OnCheck(uv_check_t* check);
215
+ static void CheckClosedCb(uv_handle_t* handle);
216
+ ~CheckWrap() = default;
217
+
218
+ Environment* env_;
219
+ CheckCb fn_;
220
+ uv_check_t check_;
221
+
222
+ friend std::unique_ptr<CheckWrap>::deleter_type;
223
+ };
224
+
225
+ class CheckWrapHandle : public MemoryRetainer {
226
+ public:
227
+ template <typename... Args>
228
+ explicit CheckWrapHandle(Environment* env, Args&&... args)
229
+ : check_(new CheckWrap(env, std::forward<Args>(args)...)) {
230
+ env->AddCleanupHook(CleanupHook, this);
231
+ }
232
+
233
+ DISALLOW_COPY_AND_MOVE(CheckWrapHandle)
234
+
235
+ ~CheckWrapHandle() { Close(); }
236
+
237
+ inline operator bool() const { return check_ != nullptr; }
238
+
239
+ void Start();
240
+ void Stop();
241
+ void Close();
242
+ void Ref();
243
+ void Unref();
244
+
245
+ void MemoryInfo(node::MemoryTracker* tracker) const override;
246
+
247
+ SET_MEMORY_INFO_NAME(CheckWrapHandle)
248
+ SET_SELF_SIZE(CheckWrapHandle)
249
+
250
+ private:
251
+ static void CleanupHook(void* data);
252
+ CheckWrap* check_;
253
+ };
254
+
255
+ // =============================================================================
256
+ // The BindingState object holds state for the internalBinding('quic') binding
257
+ // instance. It is mostly used to hold the persistent constructors, strings, and
258
+ // callback references used for the rest of the implementation.
259
+ //
260
+ // TODO(@jasnell): Make this snapshotable?
261
+ class BindingData final
262
+ : public BaseObject,
263
+ public mem::NgLibMemoryManager<BindingData, ngtcp2_mem> {
264
+ public:
265
+ SET_BINDING_ID(quic_binding_data)
266
+ static void InitPerContext(Realm* realm, v8::Local<v8::Object> target);
267
+ static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
268
+
269
+ static BindingData& Get(Environment* env);
270
+ static inline BindingData& Get(Realm* realm) { return Get(realm->env()); }
271
+
272
+ BindingData(Realm* realm, v8::Local<v8::Object> object);
273
+ ~BindingData() override;
274
+ DISALLOW_COPY_AND_MOVE(BindingData)
275
+
276
+ void MemoryInfo(MemoryTracker* tracker) const override;
277
+ SET_MEMORY_INFO_NAME(BindingData)
278
+ SET_SELF_SIZE(BindingData)
279
+
280
+ // NgLibMemoryManager — the base class provides CheckAllocatedSize,
281
+ // IncreaseAllocatedSize, DecreaseAllocatedSize, and StopTrackingMemory.
282
+ // Actual allocations go through the thread-local allocators below.
283
+ void CheckAllocatedSize(size_t previous_size) const;
284
+ void IncreaseAllocatedSize(size_t size);
285
+ void DecreaseAllocatedSize(size_t size);
286
+
287
+ // Thread-local allocators that outlive BindingData destruction.
288
+ // Both ngtcp2 and nghttp3 store the allocator pointer inside every
289
+ // object they allocate; some of those objects (e.g., nghttp3 rcbufs
290
+ // backing V8 external strings) can be freed after BindingData is gone.
291
+ ngtcp2_mem* ngtcp2_allocator();
292
+ nghttp3_mem* nghttp3_allocator();
293
+
294
+ // Installs the set of JavaScript callback functions that are used to
295
+ // bridge out to the JS API.
296
+ JS_METHOD(SetCallbacks);
297
+
298
+ // Lazily-created per-Realm SessionManager. Centralizes CID -> Session
299
+ // routing so that any endpoint can route packets to any session.
300
+ SessionManager& session_manager();
301
+
302
+ // Schedule a session for deferred SendPendingData. Sessions are accumulated
303
+ // during the I/O poll phase (via Endpoint::Receive -> Session::ReadPacket)
304
+ // and flushed in a uv_check callback immediately after poll completes.
305
+ // This batches multiple received packets before generating responses,
306
+ // allowing ngtcp2 to make better ACK coalescing decisions.
307
+ void ScheduleSessionFlush(const BaseObjectPtr<Session>& session);
308
+
309
+ std::unordered_map<Endpoint*, BaseObjectPtr<BaseObject>> listening_endpoints;
310
+
311
+ v8::Local<v8::String> error_name_string(const char* name);
312
+
313
+ size_t current_ngtcp2_memory_ = 0;
314
+
315
+ // The following set up various storage and accessors for common strings,
316
+ // construction templates, and callbacks stored on the BindingData. These
317
+ // are all defined in defs.h
318
+
319
+ #define V(name) \
320
+ void set_##name##_constructor_template( \
321
+ v8::Local<v8::FunctionTemplate> tmpl); \
322
+ v8::Local<v8::FunctionTemplate> name##_constructor_template() const;
323
+ QUIC_CONSTRUCTORS(V)
324
+ #undef V
325
+
326
+ void set_transport_params_template(v8::Local<v8::DictionaryTemplate> tmpl);
327
+ v8::Local<v8::DictionaryTemplate> transport_params_template() const;
328
+
329
+ void set_application_options_template(v8::Local<v8::DictionaryTemplate> tmpl);
330
+ v8::Local<v8::DictionaryTemplate> application_options_template() const;
331
+
332
+ #define V(name, _) \
333
+ void set_##name##_callback(v8::Local<v8::Function> fn); \
334
+ v8::Local<v8::Function> name##_callback() const;
335
+ QUIC_JS_CALLBACKS(V)
336
+ #undef V
337
+
338
+ #define V(name, _) v8::Local<v8::String> name##_string() const;
339
+ QUIC_STRINGS(V)
340
+ #undef V
341
+
342
+ #define V(name, _) v8::Local<v8::String> on_##name##_string() const;
343
+ QUIC_JS_CALLBACKS(V)
344
+ #undef V
345
+
346
+ #define V(name) v8::Global<v8::FunctionTemplate> name##_constructor_template_;
347
+ QUIC_CONSTRUCTORS(V)
348
+ #undef V
349
+
350
+ v8::Global<v8::DictionaryTemplate> transport_params_template_;
351
+ v8::Global<v8::DictionaryTemplate> application_options_template_;
352
+
353
+ #define V(name, _) v8::Global<v8::Function> name##_callback_;
354
+ QUIC_JS_CALLBACKS(V)
355
+ #undef V
356
+
357
+ #define V(name, _) mutable v8::Eternal<v8::String> name##_string_;
358
+ QUIC_STRINGS(V)
359
+ #undef V
360
+
361
+ #define V(name, _) mutable v8::Eternal<v8::String> on_##name##_string_;
362
+ QUIC_JS_CALLBACKS(V)
363
+ #undef V
364
+
365
+ // Lazy cache backing error_name_string()
366
+ std::unordered_map<const char*, v8::Eternal<v8::String>> error_name_strings_;
367
+
368
+ std::unique_ptr<SessionManager> session_manager_;
369
+
370
+ // Type-erased arena storage. The concrete AliasedStructArena<T> types
371
+ // are only complete in the .cc files where Stream::State etc. are defined.
372
+ // Each .cc file provides typed accessor methods. The deleters are set
373
+ // when the arenas are created so that ~BindingData destroys them correctly.
374
+ using ArenaDeleter = void (*)(void*);
375
+ using ArenaPtr = std::unique_ptr<void, ArenaDeleter>;
376
+ ArenaPtr stream_state_arena_{nullptr, +[](void*) {}};
377
+ ArenaPtr stream_stats_arena_{nullptr, +[](void*) {}};
378
+ ArenaPtr session_state_arena_{nullptr, +[](void*) {}};
379
+ ArenaPtr session_stats_arena_{nullptr, +[](void*) {}};
380
+ ArenaPtr endpoint_state_arena_{nullptr, +[](void*) {}};
381
+ ArenaPtr endpoint_stats_arena_{nullptr, +[](void*) {}};
382
+
383
+ // Deferred send flush state. The CheckWrapHandle fires immediately after
384
+ // the I/O poll phase in the same event loop tick, allowing batched
385
+ // receive processing: all packets are read during poll, then
386
+ // SendPendingData is called once per dirty session in the check callback.
387
+ CheckWrapHandle flush_check_;
388
+ std::vector<BaseObjectPtr<Session>> pending_flush_sessions_;
389
+ bool flush_check_started_ = false;
390
+
391
+ void OnFlushCheck();
392
+ };
393
+
394
+ JS_METHOD_IMPL(IllegalConstructor);
395
+
396
+ // The ngtcp2 and nghttp3 callbacks have certain restrictions
397
+ // that forbid re-entry. We provide the following scopes for
398
+ // use in those to help protect against it.
399
+ // These callback scopes are per-session, not per-environment. This ensures
400
+ // that one session's ngtcp2/nghttp3 callback does not block an unrelated
401
+ // session from sending packets. A BaseObjectPtr prevents the Session from
402
+ // being prematurely freed while the scope is alive on the stack.
403
+ struct NgTcp2CallbackScope final {
404
+ BaseObjectPtr<Session> session;
405
+ explicit NgTcp2CallbackScope(Session* session);
406
+ DISALLOW_COPY_AND_MOVE(NgTcp2CallbackScope)
407
+ ~NgTcp2CallbackScope();
408
+ };
409
+
410
+ struct NgHttp3CallbackScope final {
411
+ BaseObjectPtr<Session> session;
412
+ explicit NgHttp3CallbackScope(Session* session);
413
+ DISALLOW_COPY_AND_MOVE(NgHttp3CallbackScope)
414
+ ~NgHttp3CallbackScope();
415
+ };
416
+
417
+ struct CallbackScopeBase {
418
+ Environment* env;
419
+ v8::Context::Scope context_scope;
420
+ v8::TryCatch try_catch;
421
+
422
+ explicit CallbackScopeBase(Environment* env);
423
+ DISALLOW_COPY_AND_MOVE(CallbackScopeBase)
424
+ ~CallbackScopeBase();
425
+ };
426
+
427
+ // Maintains a strong reference to BaseObject type ptr to keep it alive during
428
+ // a MakeCallback during which it might be destroyed.
429
+ template <typename T>
430
+ struct CallbackScope final : public CallbackScopeBase {
431
+ BaseObjectPtr<T> ref;
432
+ explicit CallbackScope(const T* ptr)
433
+ : CallbackScopeBase(ptr->env()), ref(ptr) {}
434
+ DISALLOW_COPY_AND_MOVE(CallbackScope)
435
+ explicit CallbackScope(T* ptr) : CallbackScopeBase(ptr->env()), ref(ptr) {}
436
+ };
437
+
438
+ } // namespace node::quic
439
+
440
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
@@ -0,0 +1,127 @@
1
+ #pragma once
2
+
3
+ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
+
5
+ #include <memory_tracker.h>
6
+ #include <ngtcp2/ngtcp2.h>
7
+ #include <string>
8
+ #include "defs.h"
9
+
10
+ namespace node::quic {
11
+
12
+ // CIDS are used to identify endpoints participating in a QUIC session.
13
+ // Once created, CID instances are immutable.
14
+ //
15
+ // CIDs contain between 1 to 20 bytes. Most typically they are selected
16
+ // randomly but there is a spec for creating "routable" CIDs that encode
17
+ // a specific structure that is meaningful only to the side that creates
18
+ // the CID. For most purposes, CIDs should be treated as opaque tokens.
19
+ //
20
+ // Each peer in a QUIC session generates one or more CIDs that the *other*
21
+ // peer will use to identify the session. When a QUIC client initiates a
22
+ // brand new session, it will initially generate a CID of its own (its
23
+ // source CID) and a random placeholder CID for the server (the original
24
+ // destination CID). When the server receives the initial packet, it will
25
+ // generate its own source CID and use the client's source CID as the
26
+ // server's destination CID.
27
+ //
28
+ // Client Server
29
+ // -------------------------------------------
30
+ // Source CID <====> Destination CID
31
+ // Destination CID <====> Source CID
32
+ //
33
+ // While the connection is being established, or even while the connection
34
+ // is active, it is possible for either peer to generate additional CIDs that
35
+ // are also associated with the connection.
36
+ class CID final : public MemoryRetainer {
37
+ public:
38
+ static constexpr size_t kMinLength = NGTCP2_MIN_CIDLEN;
39
+ static constexpr size_t kMaxLength = NGTCP2_MAX_CIDLEN;
40
+
41
+ // Copy the given ngtcp2_cid.
42
+ explicit CID(const ngtcp2_cid& cid);
43
+
44
+ // Copy the given buffer as a CID. The len must be within
45
+ // kMinLength and kMaxLength.
46
+ explicit CID(const uint8_t* data, size_t len);
47
+
48
+ // Wrap the given ngtcp2_cid. The CID does not take ownership
49
+ // of the underlying ngtcp2_cid.
50
+ explicit CID(const ngtcp2_cid* cid);
51
+
52
+ CID(const CID& other);
53
+ CID& operator=(const CID& other);
54
+
55
+ struct Hash final {
56
+ size_t operator()(const CID& cid) const;
57
+ };
58
+
59
+ bool operator==(const CID& other) const noexcept;
60
+ bool operator!=(const CID& other) const noexcept;
61
+
62
+ operator const uint8_t*() const;
63
+ operator const ngtcp2_cid&() const;
64
+ operator const ngtcp2_cid*() const;
65
+
66
+ // True if the CID length is at least kMinLength;
67
+ operator bool() const;
68
+ size_t length() const;
69
+
70
+ // Returns a hex-encoded string representation of the CID useful
71
+ // for debugging.
72
+ std::string ToString() const;
73
+
74
+ SET_NO_MEMORY_INFO()
75
+ SET_MEMORY_INFO_NAME(CID)
76
+ SET_SELF_SIZE(CID)
77
+
78
+ template <typename T>
79
+ using Map = std::unordered_map<const CID, T, CID::Hash>;
80
+
81
+ // A CID::Factory, as the name suggests, is used to create new CIDs.
82
+ // Per https://datatracker.ietf.org/doc/draft-ietf-quic-load-balancers/, QUIC
83
+ // implementations MAY use the Connection ID associated with a QUIC session
84
+ // as a routing mechanism, with each CID instance securely encoding the
85
+ // routing information. By default, our implementation creates CIDs randomly
86
+ // but will allow user code to provide their own CID::Factory implementation.
87
+ class Factory;
88
+
89
+ static const CID kInvalid;
90
+
91
+ // The default constructor creates an empty, zero-length CID.
92
+ // Zero-length CIDs are not usable. We use them as a placeholder
93
+ // for a missing or empty CID value. This is public only because
94
+ // it is required for the CID::Map implementation. It should not
95
+ // be used directly. Use kInvalid instead.
96
+ CID();
97
+
98
+ private:
99
+ ngtcp2_cid cid_;
100
+ const ngtcp2_cid* ptr_;
101
+
102
+ friend struct Hash;
103
+ };
104
+
105
+ class CID::Factory {
106
+ public:
107
+ virtual ~Factory() = default;
108
+
109
+ // Generate a new CID. The length_hint must be between CID::kMinLength
110
+ // and CID::kMaxLength. The implementation can choose to ignore the length.
111
+ virtual const CID Generate(size_t length_hint = CID::kMaxLength) const = 0;
112
+
113
+ // Generate a new CID into the given ngtcp2_cid. This variation of
114
+ // Generate should be used far less commonly.
115
+ virtual const CID GenerateInto(
116
+ ngtcp2_cid* cid, size_t length_hint = CID::kMaxLength) const = 0;
117
+
118
+ // The default random CID generator instance.
119
+ static const Factory& random();
120
+
121
+ // TODO(@jasnell): This will soon also include additional implementations
122
+ // of CID::Factory that implement the QUIC Load Balancers spec.
123
+ };
124
+
125
+ } // namespace node::quic
126
+
127
+ #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS