raiha 0.1.0 → 0.2.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 (347) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/LICENSE +202 -0
  4. data/README.md +94 -22
  5. data/docs/configuration.md +227 -0
  6. data/docs/development.md +99 -0
  7. data/docs/fiber-scheduler.md +591 -0
  8. data/docs/getting-started.md +190 -0
  9. data/docs/http3-client.md +303 -0
  10. data/docs/http3-server.md +301 -0
  11. data/docs/platforms.md +98 -0
  12. data/docs/qlog.md +86 -0
  13. data/docs/quic.md +268 -0
  14. data/docs/threads.md +127 -0
  15. data/examples/_certificate.rb +55 -0
  16. data/examples/high_level_loopback.rb +59 -0
  17. data/examples/http3_get_public.rb +68 -0
  18. data/examples/in_memory_handshake.rb +38 -0
  19. data/examples/qlog_output.rb +58 -0
  20. data/examples/qlog_roundtrips.rb +66 -0
  21. data/examples/quic_gem_loopback.rb +62 -0
  22. data/examples/stream_echo.rb +68 -0
  23. data/examples/udp_handshake.rb +76 -0
  24. data/lib/raiha/http3/action.rb +21 -0
  25. data/lib/raiha/http3/capsule.rb +86 -0
  26. data/lib/raiha/http3/connection.rb +983 -0
  27. data/lib/raiha/http3/error.rb +24 -0
  28. data/lib/raiha/http3/error_code.rb +27 -0
  29. data/lib/raiha/http3/event.rb +63 -0
  30. data/lib/raiha/http3/frame.rb +148 -0
  31. data/lib/raiha/http3/frame_reader.rb +114 -0
  32. data/lib/raiha/http3/message.rb +137 -0
  33. data/lib/raiha/http3/output.rb +61 -0
  34. data/lib/raiha/http3/priority.rb +52 -0
  35. data/lib/raiha/http3/qlog.rb +145 -0
  36. data/lib/raiha/http3/qpack/decoder.rb +302 -0
  37. data/lib/raiha/http3/qpack/dynamic_table.rb +83 -0
  38. data/lib/raiha/http3/qpack/encoder.rb +94 -0
  39. data/lib/raiha/http3/qpack/error.rb +39 -0
  40. data/lib/raiha/http3/qpack/error_code.rb +13 -0
  41. data/lib/raiha/http3/qpack/field.rb +15 -0
  42. data/lib/raiha/http3/qpack/huffman.rb +397 -0
  43. data/lib/raiha/http3/qpack/reader.rb +82 -0
  44. data/lib/raiha/http3/qpack/result.rb +26 -0
  45. data/lib/raiha/http3/qpack/static_table.rb +139 -0
  46. data/lib/raiha/http3/qpack/writer.rb +44 -0
  47. data/lib/raiha/http3/qpack.rb +26 -0
  48. data/lib/raiha/http3/receiving.rb +46 -0
  49. data/lib/raiha/http3/sending.rb +23 -0
  50. data/lib/raiha/http3/session.rb +31 -0
  51. data/lib/raiha/http3/settings.rb +81 -0
  52. data/lib/raiha/http3/structured_field.rb +120 -0
  53. data/lib/raiha/http3/tracer.rb +26 -0
  54. data/lib/raiha/http3/varint.rb +45 -0
  55. data/lib/raiha/http3.rb +19 -0
  56. data/lib/raiha/http3_binding.rb +139 -0
  57. data/lib/raiha/namespace.rb +11 -0
  58. data/lib/raiha/quic/config.rb +229 -0
  59. data/lib/raiha/quic/congestion/algorithms.rb +17 -0
  60. data/lib/raiha/quic/congestion/cubic.rb +258 -0
  61. data/lib/raiha/quic/congestion/new_reno.rb +161 -0
  62. data/lib/raiha/quic/congestion/pacing.rb +21 -0
  63. data/lib/raiha/quic/congestion/startup/rapid_start.rb +249 -0
  64. data/lib/raiha/quic/congestion/startup.rb +13 -0
  65. data/lib/raiha/quic/congestion.rb +15 -0
  66. data/lib/raiha/quic/connection.rb +2022 -0
  67. data/lib/raiha/quic/connection_ids.rb +62 -0
  68. data/lib/raiha/quic/crypto/aead.rb +68 -0
  69. data/lib/raiha/quic/crypto/header_protection.rb +42 -0
  70. data/lib/raiha/quic/crypto/initial.rb +23 -0
  71. data/lib/raiha/quic/crypto/keys.rb +32 -0
  72. data/lib/raiha/quic/crypto/mac.rb +15 -0
  73. data/lib/raiha/quic/crypto/random.rb +13 -0
  74. data/lib/raiha/quic/crypto.rb +18 -0
  75. data/lib/raiha/quic/crypto_stream.rb +161 -0
  76. data/lib/raiha/quic/datagrams.rb +91 -0
  77. data/lib/raiha/quic/endpoint.rb +785 -0
  78. data/lib/raiha/quic/error.rb +61 -0
  79. data/lib/raiha/quic/error_code.rb +34 -0
  80. data/lib/raiha/quic/event.rb +59 -0
  81. data/lib/raiha/quic/issued_connection_ids.rb +137 -0
  82. data/lib/raiha/quic/kept_packets.rb +41 -0
  83. data/lib/raiha/quic/mtu_search.rb +75 -0
  84. data/lib/raiha/quic/negotiation.rb +143 -0
  85. data/lib/raiha/quic/new_token.rb +55 -0
  86. data/lib/raiha/quic/pacer.rb +52 -0
  87. data/lib/raiha/quic/packet_protection.rb +310 -0
  88. data/lib/raiha/quic/path.rb +473 -0
  89. data/lib/raiha/quic/peer_connection_ids.rb +160 -0
  90. data/lib/raiha/quic/qlog.rb +260 -0
  91. data/lib/raiha/quic/ranges.rb +32 -0
  92. data/lib/raiha/quic/recovery/duty.rb +102 -0
  93. data/lib/raiha/quic/recovery/packet_number_space.rb +420 -0
  94. data/lib/raiha/quic/recovery/rate_meter.rb +95 -0
  95. data/lib/raiha/quic/recovery/rtt_estimator.rb +57 -0
  96. data/lib/raiha/quic/recovery/sent_packet.rb +16 -0
  97. data/lib/raiha/quic/recovery.rb +641 -0
  98. data/lib/raiha/quic/remembered_transport_parameters.rb +29 -0
  99. data/lib/raiha/quic/retry_token.rb +54 -0
  100. data/lib/raiha/quic/route.rb +37 -0
  101. data/lib/raiha/quic/scheduler.rb +112 -0
  102. data/lib/raiha/quic/session.rb +47 -0
  103. data/lib/raiha/quic/stateless_reset.rb +38 -0
  104. data/lib/raiha/quic/stats.rb +24 -0
  105. data/lib/raiha/quic/streams/receive_window.rb +119 -0
  106. data/lib/raiha/quic/streams/receiver.rb +217 -0
  107. data/lib/raiha/quic/streams/sender.rb +200 -0
  108. data/lib/raiha/quic/streams.rb +687 -0
  109. data/lib/raiha/quic/test/bottleneck.rb +55 -0
  110. data/lib/raiha/quic/test/congestion_contract.rb +106 -0
  111. data/lib/raiha/quic/test/network.rb +244 -0
  112. data/lib/raiha/quic/test/random_loss.rb +34 -0
  113. data/lib/raiha/quic/test/reorder.rb +51 -0
  114. data/lib/raiha/quic/test/server.rb +54 -0
  115. data/lib/raiha/quic/test/vectors.rb +337 -0
  116. data/lib/raiha/quic/test/virtual_clock.rb +21 -0
  117. data/lib/raiha/quic/test.rb +17 -0
  118. data/lib/raiha/quic/tls_binding.rb +179 -0
  119. data/lib/raiha/quic/token.rb +28 -0
  120. data/lib/raiha/quic/tracer.rb +127 -0
  121. data/lib/raiha/quic/transmit.rb +14 -0
  122. data/lib/raiha/quic/transport_parameters.rb +244 -0
  123. data/lib/raiha/quic/version.rb +63 -0
  124. data/lib/raiha/quic/wire/codec.rb +136 -0
  125. data/lib/raiha/quic/wire/frame.rb +521 -0
  126. data/lib/raiha/quic/wire/header.rb +90 -0
  127. data/lib/raiha/quic/wire/packet.rb +130 -0
  128. data/lib/raiha/quic/wire/packet_number.rb +47 -0
  129. data/lib/raiha/quic/wire/retry.rb +62 -0
  130. data/lib/raiha/quic/wire/version_negotiation.rb +53 -0
  131. data/lib/raiha/quic/wire.rb +9 -0
  132. data/lib/raiha/quic.rb +46 -0
  133. data/lib/raiha/runtime/addresses.rb +35 -0
  134. data/lib/raiha/runtime/admission.rb +37 -0
  135. data/lib/raiha/runtime/client.rb +190 -0
  136. data/lib/raiha/runtime/driver.rb +165 -0
  137. data/lib/raiha/runtime/error.rb +16 -0
  138. data/lib/raiha/runtime/http3.rb +363 -0
  139. data/lib/raiha/runtime/http3_fields.rb +38 -0
  140. data/lib/raiha/runtime/http3_server.rb +416 -0
  141. data/lib/raiha/runtime/kept.rb +36 -0
  142. data/lib/raiha/runtime/qlog.rb +204 -0
  143. data/lib/raiha/runtime/rack.rb +180 -0
  144. data/lib/raiha/runtime/server.rb +334 -0
  145. data/lib/raiha/runtime/session.rb +447 -0
  146. data/lib/raiha/runtime/threaded/client.rb +161 -0
  147. data/lib/raiha/runtime/threaded/driver.rb +230 -0
  148. data/lib/raiha/runtime/threaded/http3.rb +287 -0
  149. data/lib/raiha/runtime/threaded/http3_server.rb +432 -0
  150. data/lib/raiha/runtime/threaded/server.rb +290 -0
  151. data/lib/raiha/runtime/threaded/session.rb +604 -0
  152. data/lib/raiha/runtime/threaded.rb +45 -0
  153. data/lib/raiha/runtime/udp.rb +410 -0
  154. data/lib/raiha/runtime/worker.rb +138 -0
  155. data/lib/raiha/runtime/workers.rb +248 -0
  156. data/lib/raiha/runtime.rb +37 -0
  157. data/lib/raiha/tls/anti_replay.rb +139 -0
  158. data/lib/raiha/tls/cipher_suite.rb +62 -0
  159. data/lib/raiha/tls/codec/error.rb +43 -0
  160. data/lib/raiha/tls/codec/reader.rb +95 -0
  161. data/lib/raiha/tls/codec/writer.rb +81 -0
  162. data/lib/raiha/tls/codec.rb +5 -0
  163. data/lib/raiha/tls/config.rb +318 -0
  164. data/lib/raiha/tls/crypto/aead.rb +64 -0
  165. data/lib/raiha/tls/crypto/certificate.rb +28 -0
  166. data/lib/raiha/tls/crypto/digest.rb +30 -0
  167. data/lib/raiha/tls/crypto/ecdh.rb +74 -0
  168. data/lib/raiha/tls/crypto/hash.rb +22 -0
  169. data/lib/raiha/tls/crypto/hkdf.rb +28 -0
  170. data/lib/raiha/tls/crypto/signature.rb +87 -0
  171. data/lib/raiha/tls/crypto.rb +19 -0
  172. data/lib/raiha/tls/error.rb +36 -0
  173. data/lib/raiha/tls/event.rb +45 -0
  174. data/lib/raiha/tls/extension/alpn.rb +35 -0
  175. data/lib/raiha/tls/extension/certificate_authorities.rb +35 -0
  176. data/lib/raiha/tls/extension/compress_certificate.rb +33 -0
  177. data/lib/raiha/tls/extension/cookie.rb +27 -0
  178. data/lib/raiha/tls/extension/early_data.rb +54 -0
  179. data/lib/raiha/tls/extension/key_share.rb +90 -0
  180. data/lib/raiha/tls/extension/list.rb +49 -0
  181. data/lib/raiha/tls/extension/opaque.rb +21 -0
  182. data/lib/raiha/tls/extension/placement.rb +55 -0
  183. data/lib/raiha/tls/extension/post_handshake_auth.rb +22 -0
  184. data/lib/raiha/tls/extension/pre_shared_key.rb +81 -0
  185. data/lib/raiha/tls/extension/psk_key_exchange_modes.rb +32 -0
  186. data/lib/raiha/tls/extension/record_size_limit.rb +30 -0
  187. data/lib/raiha/tls/extension/registry.rb +50 -0
  188. data/lib/raiha/tls/extension/server_name.rb +63 -0
  189. data/lib/raiha/tls/extension/signature_algorithms.rb +39 -0
  190. data/lib/raiha/tls/extension/signature_algorithms_cert.rb +21 -0
  191. data/lib/raiha/tls/extension/supported_groups.rb +32 -0
  192. data/lib/raiha/tls/extension/supported_versions.rb +53 -0
  193. data/lib/raiha/tls/extension.rb +32 -0
  194. data/lib/raiha/tls/handshake/acceptor.rb +164 -0
  195. data/lib/raiha/tls/handshake/authentication_messages.rb +127 -0
  196. data/lib/raiha/tls/handshake/certificate.rb +56 -0
  197. data/lib/raiha/tls/handshake/certificate_request.rb +39 -0
  198. data/lib/raiha/tls/handshake/certificate_verify.rb +40 -0
  199. data/lib/raiha/tls/handshake/client_hello.rb +208 -0
  200. data/lib/raiha/tls/handshake/client_hello_builder.rb +144 -0
  201. data/lib/raiha/tls/handshake/client_side.rb +578 -0
  202. data/lib/raiha/tls/handshake/conductor.rb +390 -0
  203. data/lib/raiha/tls/handshake/encrypted_extensions.rb +33 -0
  204. data/lib/raiha/tls/handshake/end_of_early_data.rb +28 -0
  205. data/lib/raiha/tls/handshake/finished.rb +36 -0
  206. data/lib/raiha/tls/handshake/key_update.rb +38 -0
  207. data/lib/raiha/tls/handshake/key_update_handling.rb +88 -0
  208. data/lib/raiha/tls/handshake/machine.rb +238 -0
  209. data/lib/raiha/tls/handshake/message.rb +25 -0
  210. data/lib/raiha/tls/handshake/new_session_ticket.rb +48 -0
  211. data/lib/raiha/tls/handshake/reassembler.rb +88 -0
  212. data/lib/raiha/tls/handshake/server_hello.rb +98 -0
  213. data/lib/raiha/tls/handshake/server_side.rb +672 -0
  214. data/lib/raiha/tls/handshake/violation.rb +12 -0
  215. data/lib/raiha/tls/handshake.rb +62 -0
  216. data/lib/raiha/tls/iana.rb +113 -0
  217. data/lib/raiha/tls/key_exchange.rb +58 -0
  218. data/lib/raiha/tls/key_schedule.rb +269 -0
  219. data/lib/raiha/tls/keylog.rb +40 -0
  220. data/lib/raiha/tls/keyring.rb +180 -0
  221. data/lib/raiha/tls/masked_inspect.rb +33 -0
  222. data/lib/raiha/tls/output.rb +32 -0
  223. data/lib/raiha/tls/profile.rb +82 -0
  224. data/lib/raiha/tls/record/layer.rb +228 -0
  225. data/lib/raiha/tls/record/protection.rb +67 -0
  226. data/lib/raiha/tls/record.rb +11 -0
  227. data/lib/raiha/tls/server_name.rb +42 -0
  228. data/lib/raiha/tls/session.rb +106 -0
  229. data/lib/raiha/tls/signature_scheme.rb +35 -0
  230. data/lib/raiha/tls/tcp/acceptor.rb +121 -0
  231. data/lib/raiha/tls/tcp/connection.rb +371 -0
  232. data/lib/raiha/tls/tcp/event.rb +15 -0
  233. data/lib/raiha/tls/tcp/socket.rb +161 -0
  234. data/lib/raiha/tls/tcp.rb +14 -0
  235. data/lib/raiha/tls/test/fixed_kem.rb +30 -0
  236. data/lib/raiha/tls/test/fixed_random.rb +18 -0
  237. data/lib/raiha/tls/test/rfc8448.rb +923 -0
  238. data/lib/raiha/tls/test/rfc8448_handshakes.rb +118 -0
  239. data/lib/raiha/tls/test.rb +13 -0
  240. data/lib/raiha/tls/ticket.rb +184 -0
  241. data/lib/raiha/tls/ticket_keys.rb +206 -0
  242. data/lib/raiha/tls/trace.rb +58 -0
  243. data/lib/raiha/tls/transcript.rb +94 -0
  244. data/lib/raiha/tls/verifier/default.rb +72 -0
  245. data/lib/raiha/tls/verifier/host_name.rb +75 -0
  246. data/lib/raiha/tls/verifier/none.rb +14 -0
  247. data/lib/raiha/tls/verifier.rb +24 -0
  248. data/lib/raiha/tls.rb +34 -0
  249. data/lib/raiha/version.rb +3 -1
  250. data/lib/raiha.rb +8 -5
  251. data/sig/patches/array.rbs +9 -0
  252. data/sig/patches/io_buffer.rbs +13 -0
  253. data/sig/patches/openssl.rbs +25 -0
  254. data/sig/patches/socket.rbs +29 -0
  255. data/sig/patches/string.rbs +26 -0
  256. data/sig/patches/strscan.rbs +12 -0
  257. data/sig/raiha/http3/capsule.rbs +32 -0
  258. data/sig/raiha/http3/connection.rbs +324 -0
  259. data/sig/raiha/http3/frame.rbs +138 -0
  260. data/sig/raiha/http3/frame_reader.rbs +39 -0
  261. data/sig/raiha/http3/message.rbs +23 -0
  262. data/sig/raiha/http3/priority.rbs +40 -0
  263. data/sig/raiha/http3/qlog.rbs +54 -0
  264. data/sig/raiha/http3/qpack.rbs +246 -0
  265. data/sig/raiha/http3/session.rbs +11 -0
  266. data/sig/raiha/http3/settings.rbs +26 -0
  267. data/sig/raiha/http3.rbs +2 -0
  268. data/sig/raiha/http3_binding.rbs +26 -0
  269. data/sig/raiha/namespace.rbs +2 -0
  270. data/sig/raiha/quic/config.rbs +89 -0
  271. data/sig/raiha/quic/congestion.rbs +213 -0
  272. data/sig/raiha/quic/connection.rbs +249 -0
  273. data/sig/raiha/quic/connection_ids.rbs +34 -0
  274. data/sig/raiha/quic/crypto.rbs +78 -0
  275. data/sig/raiha/quic/crypto_stream.rbs +34 -0
  276. data/sig/raiha/quic/datagrams.rbs +32 -0
  277. data/sig/raiha/quic/endpoint.rbs +179 -0
  278. data/sig/raiha/quic/frame.rbs +387 -0
  279. data/sig/raiha/quic/issued_connection_ids.rbs +47 -0
  280. data/sig/raiha/quic/kept_packets.rbs +25 -0
  281. data/sig/raiha/quic/mtu_search.rbs +21 -0
  282. data/sig/raiha/quic/negotiation.rbs +33 -0
  283. data/sig/raiha/quic/new_token.rbs +14 -0
  284. data/sig/raiha/quic/pacer.rbs +16 -0
  285. data/sig/raiha/quic/packet_protection.rbs +63 -0
  286. data/sig/raiha/quic/path.rbs +106 -0
  287. data/sig/raiha/quic/peer_connection_ids.rbs +42 -0
  288. data/sig/raiha/quic/qlog.rbs +74 -0
  289. data/sig/raiha/quic/ranges.rbs +7 -0
  290. data/sig/raiha/quic/recovery.rbs +376 -0
  291. data/sig/raiha/quic/retry_token.rbs +21 -0
  292. data/sig/raiha/quic/route.rbs +51 -0
  293. data/sig/raiha/quic/scheduler.rbs +36 -0
  294. data/sig/raiha/quic/session.rbs +17 -0
  295. data/sig/raiha/quic/stateless_reset.rbs +10 -0
  296. data/sig/raiha/quic/streams.rbs +244 -0
  297. data/sig/raiha/quic/test.rbs +354 -0
  298. data/sig/raiha/quic/tls_binding.rbs +58 -0
  299. data/sig/raiha/quic/token.rbs +11 -0
  300. data/sig/raiha/quic/tracer.rbs +71 -0
  301. data/sig/raiha/quic/transport_parameters.rbs +113 -0
  302. data/sig/raiha/quic/values.rbs +200 -0
  303. data/sig/raiha/quic/version.rbs +30 -0
  304. data/sig/raiha/quic/wire.rbs +199 -0
  305. data/sig/raiha/quic.rbs +2 -0
  306. data/sig/raiha/runtime/threaded.rbs +616 -0
  307. data/sig/raiha/runtime.rbs +982 -0
  308. data/sig/raiha/tls/anti_replay.rbs +41 -0
  309. data/sig/raiha/tls/cipher_suite.rbs +41 -0
  310. data/sig/raiha/tls/codec.rbs +66 -0
  311. data/sig/raiha/tls/config.rbs +122 -0
  312. data/sig/raiha/tls/crypto.rbs +86 -0
  313. data/sig/raiha/tls/error.rbs +21 -0
  314. data/sig/raiha/tls/event.rbs +61 -0
  315. data/sig/raiha/tls/extension.rbs +331 -0
  316. data/sig/raiha/tls/handshake.rbs +311 -0
  317. data/sig/raiha/tls/iana.rbs +13 -0
  318. data/sig/raiha/tls/key_exchange.rbs +33 -0
  319. data/sig/raiha/tls/key_schedule.rbs +58 -0
  320. data/sig/raiha/tls/keylog.rbs +20 -0
  321. data/sig/raiha/tls/keyring.rbs +64 -0
  322. data/sig/raiha/tls/machine.rbs +429 -0
  323. data/sig/raiha/tls/masked_inspect.rbs +12 -0
  324. data/sig/raiha/tls/output.rbs +37 -0
  325. data/sig/raiha/tls/profile.rbs +26 -0
  326. data/sig/raiha/tls/record.rbs +79 -0
  327. data/sig/raiha/tls/server_name.rbs +10 -0
  328. data/sig/raiha/tls/session.rbs +48 -0
  329. data/sig/raiha/tls/signature_scheme.rbs +20 -0
  330. data/sig/raiha/tls/tcp.rbs +134 -0
  331. data/sig/raiha/tls/test.rbs +143 -0
  332. data/sig/raiha/tls/ticket.rbs +68 -0
  333. data/sig/raiha/tls/ticket_keys.rbs +67 -0
  334. data/sig/raiha/tls/trace.rbs +99 -0
  335. data/sig/raiha/tls/transcript.rbs +22 -0
  336. data/sig/raiha/tls/verifier.rbs +54 -0
  337. data/sig/raiha/tls.rbs +5 -0
  338. data/sig/raiha.rbs +3 -0
  339. metadata +355 -57
  340. data/.gitignore +0 -10
  341. data/CODE_OF_CONDUCT.md +0 -74
  342. data/Gemfile +0 -4
  343. data/Gemfile.lock +0 -22
  344. data/Rakefile +0 -10
  345. data/bin/console +0 -14
  346. data/bin/setup +0 -8
  347. data/raiha.gemspec +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da2de00d584d396a7bd4e431048c15ee3fdc626d5ca27d525e2bd17cc418d6de
4
- data.tar.gz: 5298216aa651e05ed45fad19719ee8ae5563b50b0caf9df7a84bdf7ea569ba89
3
+ metadata.gz: f8c0ec9b7426cd991d1b0877a73eac689bddaf1c12a30a553140ec07fa686167
4
+ data.tar.gz: 5382fb52df57298479fecb5116b9bc96e3abd29b3be2331c726546fcd348442d
5
5
  SHA512:
6
- metadata.gz: ec7a6fcbd1bee25bcba31eee841bbf222ccc1f4a52cdae284fae294b9cb98cbcbfbe7ebb84917ab27ecf26199cc33476f198283ca77be26d12da5113f55f290a
7
- data.tar.gz: 7b8fa8e99796bf6ea314ce8842e90fe6264ef1d60366701df85d4719ac3b84f46722532ac5919b3e907164aafd179d6010f194ae1ca81bde8d65bec5b9b34bc8
6
+ metadata.gz: ed47bdda97aa7e820b058b113af437b6d9e02a5366f3eb3987849321dc7ef43f7c5dfa887aa0eb5fd4983ebd877648bf2f6a8ef93f4ffeff6463b3e01cec348f
7
+ data.tar.gz: 390546238081eb77446f0dee87577a432c6720e7c590490ac1e386243ec0fd82c5c37557f4e72d8ea23f1f9c54b62d3703ecb4ddd317e5106feb92154dbd22af
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [0.2.0] - 2026-12-03
8
+
9
+ ### Added
10
+
11
+ - QUIC version 1 (RFC 9000, RFC 9001, RFC 9002): streams, DATAGRAM frames (RFC 9221), 0-RTT and resumption, Retry, connection migration and preferred addresses, path MTU discovery, ECN, NewReno and CUBIC
12
+ - QUIC version 2 (RFC 9369) and version negotiation (RFC 9368), compatible and incompatible: a client starts in version 2 and falls back to version 1, and a server can roll a version out in steps with `offered_versions` and `deployed_versions` ([#11](https://github.com/unasuke/raiha/pull/11))
13
+ - HTTP/3 (RFC 9114) with QPACK (RFC 9204) and extensible priorities (RFC 9218)
14
+ - TLS 1.3, for QUIC and over TCP
15
+ - A sans-I/O core: the protocols do no I/O, and you drive them from your own socket loop
16
+ - `Raiha::Runtime`, a runtime that serves and connects over UDP sockets under a Fiber scheduler, with Ractor workers (`Raiha::Runtime::Workers`), a Rack 3 adapter (`Raiha::Runtime::Rack`) and qlog
17
+ - `Raiha::Runtime::Threaded`, a runtime on threads that needs no Fiber scheduler
18
+ - RBS signatures under `sig/`
19
+ - Documentation under `docs/` and examples under `examples/`
20
+
21
+ ### Changed
22
+
23
+ - Require Ruby 4.0 or later and the `openssl` gem 4.0 or later
24
+ - License under the Apache License 2.0
25
+
26
+ ## [0.1.0] - 2021-08-04
27
+
28
+ ### Added
29
+
30
+ - The skeleton of the gem, with nothing implemented
31
+
32
+ [0.2.0]: https://github.com/unasuke/raiha/compare/v0.1.0...v0.2.0
33
+ [0.1.0]: https://github.com/unasuke/raiha/releases/tag/v0.1.0
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md CHANGED
@@ -1,43 +1,115 @@
1
1
  # Raiha
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/raiha`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Raiha is QUIC, HTTP/3 and TLS 1.3 written in Ruby. The protocols are implemented in Ruby itself; the `openssl` gem provides only the cryptographic primitives.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ - QUIC version 1 (RFC 9000, RFC 9001, RFC 9002) and version 2 (RFC 9369), with Compatible Version Negotiation (RFC 9368): streams, DATAGRAM frames (RFC 9221), 0-RTT and resumption, Retry, connection migration and preferred addresses, path MTU discovery, ECN, NewReno and CUBIC
6
+ - HTTP/3 (RFC 9114) with QPACK (RFC 9204) and extensible priorities (RFC 9218)
7
+ - TLS 1.3, for QUIC and over TCP
8
+ - A sans-I/O core: the protocols do no I/O, and you drive them from your own socket loop
9
+ - A runtime that serves and connects over UDP sockets under a Fiber scheduler, with Ractor workers, a Rack 3 adapter and qlog, and one on threads that needs no scheduler
10
+
11
+ ## Requirements
12
+
13
+ - Ruby 4.0 or later
14
+ - The `openssl` gem 4.0 or later, with OpenSSL or LibreSSL
15
+ - Linux or OpenBSD
6
16
 
7
17
  ## Installation
8
18
 
9
- Add this line to your application's Gemfile:
19
+ Add Raiha to your Gemfile:
10
20
 
11
21
  ```ruby
12
- gem 'raiha'
22
+ gem "raiha"
13
23
  ```
14
24
 
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install raiha
25
+ The runtime also needs a Fiber scheduler, such as the `async` gem; see [Fiber scheduler](docs/fiber-scheduler.md). The runtime on threads needs none; see [Threads](docs/threads.md).
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ An HTTP/3 server that answers every request, blocking on its socket:
26
30
 
27
- ## Development
31
+ ```ruby
32
+ require "raiha"
33
+ require "socket"
34
+
35
+ def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
36
+
37
+ chain = OpenSSL::X509::Certificate.load(File.read("cert.pem")).map(&:to_der)
38
+ key = OpenSSL::PKey.read(File.read("key.pem")).private_to_der
39
+ identity = Raiha::TLS::Keyring::Identity.new(cert_der: chain, key_der: key)
40
+
41
+ tls_config = Raiha::TLS::Config.server(
42
+ profile: Raiha::TLS::Profile::QUIC,
43
+ alpn: ["h3"],
44
+ registry: Raiha::TLS::Extension::Registry::BUILTIN.with(Raiha::QUIC::TransportParameters::Extension)
45
+ )
46
+ keyring = Raiha::TLS::Keyring.server(config: tls_config, identities: [identity])
47
+
48
+ socket = UDPSocket.new
49
+ socket.bind("127.0.0.1", 4433)
50
+ endpoint = Raiha::QUIC::Endpoint.server(config: Raiha::QUIC::Config.new(ecn_address_families: [], enable_pmtud: false), random: SecureRandom, time: Time.now, now:)
51
+ # Each QUIC connection with its HTTP/3 connection and the binding between them.
52
+ connections = {}
53
+
54
+ def respond(http3, event)
55
+ return unless event.is_a?(Raiha::HTTP3::Event::Headers)
56
+ path = event.headers.to_h[":path"]
57
+ http3.send_headers(event.stream_id, [[":status", "200"], ["content-type", "text/plain"]])
58
+ http3.send_data(event.stream_id, "hello from #{path}\n", fin: true)
59
+ end
60
+
61
+ begin
62
+ loop do
63
+ endpoint.each_transmit(now:) { |transmit| socket.send(transmit.payload, 0, *transmit.destination) }
64
+
65
+ deadline = endpoint.next_timeout
66
+ if IO.select([socket], nil, nil, deadline && [deadline - now, 0].max)
67
+ data, address = socket.recvfrom(65535)
68
+ route = endpoint.receive(data, from: [address[3], address[1]], now:)
69
+ route = endpoint.admit(route.handle, now:) if route.is_a?(Raiha::QUIC::Route::Incoming)
70
+ case route
71
+ when Raiha::QUIC::Route::ClientHello
72
+ quic = endpoint.accept(route.handle, tls_config:, keyring:, now:)
73
+ http3 = Raiha::HTTP3::Connection.server
74
+ connections[quic] = [http3, Raiha::HTTP3Binding.new(quic, http3)]
75
+ when Raiha::QUIC::Route::Respond
76
+ socket.send(route.transmit.payload, 0, *route.transmit.destination)
77
+ end
78
+ end
79
+ deadline = endpoint.next_timeout
80
+ endpoint.handle_timeout(now:) if deadline && now >= deadline
81
+
82
+ connections.each do |quic, (http3, binding)|
83
+ quic.each_event { |event| binding.receive(event, now:) }
84
+ binding.flush(now:)
85
+ http3.each_event { |event| respond(http3, event) }
86
+ binding.flush(now:)
87
+ end
88
+ connections.delete_if { |quic, _| quic.closed? }
89
+ end
90
+ rescue Interrupt
91
+ connections.each_key { |quic| quic.close(error_code: Raiha::HTTP3::ErrorCode::NO_ERROR, now:) }
92
+ endpoint.each_transmit(now:) { |transmit| socket.send(transmit.payload, 0, *transmit.destination) }
93
+ end
94
+ ```
28
95
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96
+ [Getting started](docs/getting-started.md) walks through this server and a client for it.
30
97
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
98
+ ## Documentation
32
99
 
33
- ## Contributing
100
+ - [Getting started](docs/getting-started.md)
101
+ - [HTTP/3 server](docs/http3-server.md): the loop, requests and responses, stopping, 0-RTT
102
+ - [HTTP/3 client](docs/http3-client.md): requests, several requests on one connection, resumption and 0-RTT
103
+ - [QUIC](docs/quic.md): the QUIC core without HTTP/3, DATAGRAM frames
104
+ - [Fiber scheduler](docs/fiber-scheduler.md): the runtime, Rack and Ractor workers
105
+ - [Threads](docs/threads.md): the runtime on threads, with no Fiber scheduler
106
+ - [Configuration](docs/configuration.md): QUIC and TLS settings, certificates
107
+ - [qlog](docs/qlog.md)
108
+ - [Platforms](docs/platforms.md): what differs between Linux and OpenBSD
109
+ - [Development](docs/development.md): tests, type checks and interop testing
34
110
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/unasuke/raiha. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
111
+ The [examples](examples/) directory has scripts that run on their own.
36
112
 
37
113
  ## License
38
114
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the Raiha project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unasuke/raiha/blob/master/CODE_OF_CONDUCT.md).
115
+ Raiha is licensed under the [Apache License, Version 2.0](LICENSE).
@@ -0,0 +1,227 @@
1
+ # Configuration
2
+
3
+ A connection is set up from three objects:
4
+
5
+ - `Raiha::QUIC::Config` holds the transport parameters this end sends, and settings of this implementation that never go on the wire. It is frozen and can be shared between Ractors.
6
+ - `Raiha::TLS::Config` holds the TLS settings: ALPN, cipher suites, trust anchors, session tickets and 0-RTT. It is also frozen and shareable. Build one with `TLS::Config.server` or `TLS::Config.client`.
7
+ - `Raiha::TLS::Keyring` holds what cannot be shared: certificates and private keys, the trust store, and the random source. Build one per process or Ractor, not per connection, since it parses its certificates once.
8
+
9
+ A setting that cannot work raises `ArgumentError` when the object is built, not later during a handshake.
10
+
11
+ ```ruby
12
+ registry = Raiha::TLS::Extension::Registry::BUILTIN.with(Raiha::QUIC::TransportParameters::Extension)
13
+
14
+ server_tls = Raiha::TLS::Config.server(profile: Raiha::TLS::Profile::QUIC, alpn: ["echo"], registry:)
15
+ server_keyring = Raiha::TLS::Keyring.server(config: server_tls, identities: [identity])
16
+
17
+ client_tls = Raiha::TLS::Config.client(profile: Raiha::TLS::Profile::QUIC, alpn: ["echo"], registry:, trust_anchors: [ca_der])
18
+ client_keyring = Raiha::TLS::Keyring.client(config: client_tls)
19
+
20
+ quic = Raiha::QUIC::Config.new(max_idle_timeout: 10.0)
21
+ ```
22
+
23
+ ## TLS for QUIC
24
+
25
+ QUIC needs two settings that TLS over TCP does not:
26
+
27
+ - `profile: TLS::Profile::QUIC`. The default is `TLS::Profile::TCP`, and a connection whose TLS config has another profile raises `ArgumentError` ("the TLS Config of a QUIC connection has the QUIC profile"). The profile gathers what RFC 9001 changes in TLS: handshake messages travel in CRYPTO frames, middlebox compatibility mode and EndOfEarlyData are dropped, a KeyUpdate message is an error, and ALPN must be agreed.
28
+ - `registry: TLS::Extension::Registry::BUILTIN.with(QUIC::TransportParameters::Extension)`. This registers the `quic_transport_parameters` extension with the TLS layer, so TLS refuses the extension in any message other than ClientHello and EncryptedExtensions. Without it a handshake still completes, because the TLS layer passes the extension's bytes through untouched, but that check is skipped. The QUIC layer decodes the parameters either way.
29
+
30
+ `alpn` is required in practice: QUIC endpoints must agree on a protocol, and the handshake fails with `no_application_protocol` if they do not. HTTP/3 uses `"h3"` (`Raiha::Runtime::HTTP3::Client::ALPN`).
31
+
32
+ ## Certificates and keys
33
+
34
+ A `TLS::Keyring::Identity` is a certificate chain, leaf first, as an Array of DER Strings, together with the leaf's private key in DER or PEM. A server needs at least one identity. The keyring checks that each key matches its certificate.
35
+
36
+ ```ruby
37
+ require "openssl"
38
+
39
+ # fullchain.pem holds the leaf certificate followed by its intermediates.
40
+ chain = OpenSSL::X509::Certificate.load(File.read("fullchain.pem")).map(&:to_der)
41
+ key = OpenSSL::PKey.read(File.read("server.key")).private_to_der
42
+ identity = Raiha::TLS::Keyring::Identity.new(cert_der: chain, key_der: key)
43
+
44
+ keyring = Raiha::TLS::Keyring.server(config: server_tls, identities: [identity])
45
+ ```
46
+
47
+ `OpenSSL::X509::Certificate.load` reads every certificate in the file; `OpenSSL::X509::Certificate.new` would read only the first.
48
+
49
+ With several identities, the server picks for each handshake an identity whose key can sign with a scheme the client offers. Among those, it prefers one valid for the requested server name, then one whose whole chain the client accepts, then one issued by a CA the client names. Ties go to the order of `identities`.
50
+
51
+ ### Trust anchors
52
+
53
+ A client verifies the server against `trust_anchors:`, an Array of DER certificates in its `TLS::Config`. To trust the system's store, read all of its certificates:
54
+
55
+ ```ruby
56
+ trust_anchors = OpenSSL::X509::Certificate.load(File.read(OpenSSL::X509::DEFAULT_CERT_FILE)).map(&:to_der)
57
+ ```
58
+
59
+ A client keyring built without trust anchors raises `ArgumentError` ("the default verifier needs trust_anchors in the Config (or pass verifier:)"). `TLS::Verifier::None.new` accepts any chain and is for tests only: a keyring built with it answers `peer_verified?` with `false`.
60
+
61
+ ### Client certificates
62
+
63
+ A server asks for client certificates with `client_auth: :optional` or `:required`, and needs `trust_anchors` to verify them. A client gives its own with `TLS::Keyring.client(config:, identities: [...])`. It sends the first identity whose key signs with a scheme the server lists and, when the server names CAs, whose chain has an issuer among them.
64
+
65
+ ## `TLS::Config` settings
66
+
67
+ `TLS::Config.server(**options)` and `TLS::Config.client(**options)` take the same keywords. Some are only for one role; giving one to the other role raises `ArgumentError`. `config.with(...)` returns a copy with some settings changed.
68
+
69
+ | Setting | Default | Meaning |
70
+ | --- | --- | --- |
71
+ | `profile` | `TLS::Profile::TCP` | `TLS::Profile::QUIC` for QUIC. |
72
+ | `alpn` | `[]` | The ALPN protocol names, in order of preference. |
73
+ | `registry` | `Extension::Registry::BUILTIN` | The extensions TLS can parse. See above. |
74
+ | `cipher_suites` | AES-128-GCM, AES-256-GCM, ChaCha20-Poly1305 | Symbols such as `:TLS_AES_128_GCM_SHA256`. |
75
+ | `groups` | `x25519`, `secp256r1`, `secp384r1` | Key exchange groups. |
76
+ | `signature_algorithms` | ECDSA P-256, RSA-PSS, Ed25519, ... | Schemes for CertificateVerify, in order of preference. |
77
+ | `signature_algorithms_cert` | the above plus RSA PKCS#1 and ECDSA P-521 | Schemes accepted in certificate chains. |
78
+ | `trust_anchors` | `[]` | DER certificates to verify the peer against. |
79
+ | `verify_flags` | `0` | Flags for `OpenSSL::X509::Store`. |
80
+ | `client_auth` | `:none` | Server only: `:none`, `:optional` or `:required`. |
81
+ | `require_server_name` | `false` | Server only: refuse a ClientHello without SNI. |
82
+ | `resumption` | `true` | Client only: whether to resume with a ticket it is given. |
83
+ | `ticket_keys` / `ticket_key` | `nil` | Server only: the keys that seal session tickets. See below. |
84
+ | `ticket_lifetime` | `7200` | Seconds a ticket lives, at most 604800. |
85
+ | `ticket_count` | `2` with keys, else `0` | Server only: tickets issued per connection. |
86
+ | `max_early_data_size` | `0` | Server only: more than 0 allows 0-RTT. With the QUIC profile, any positive value becomes `0xffffffff`, as RFC 9001 asks. |
87
+ | `resumption_scope` | `""` | Server only: bound into tickets, so that a ticket of another scope does not resume. |
88
+ | `grease`, `permute_extensions` | `true`, `true` | GREASE values and a shuffled extension order in the ClientHello. |
89
+
90
+ The rest (`extensions`, `exporter_labels`, `record_size_limit`, `certificate_authorities`, `max_ticket_size` and the message size limits) are documented in [lib/raiha/tls/config.rb](../lib/raiha/tls/config.rb).
91
+
92
+ ## Tickets and 0-RTT
93
+
94
+ A server issues session tickets only when it has keys to seal them, and takes 0-RTT only then:
95
+
96
+ ```ruby
97
+ server_tls = Raiha::TLS::Config.server(
98
+ profile: Raiha::TLS::Profile::QUIC,
99
+ alpn: ["echo"],
100
+ registry:,
101
+ ticket_keys: Raiha::TLS::TicketKeys.static(current: SecureRandom.bytes(32)),
102
+ max_early_data_size: 1 # any positive value allows 0-RTT
103
+ )
104
+ ```
105
+
106
+ `max_early_data_size` without ticket keys raises `ArgumentError`. `ticket_key: seed` is short for `ticket_keys: TLS::TicketKeys.static(current: seed)`. Each seed is 32 bytes.
107
+
108
+ There are two kinds of ticket keys.
109
+
110
+ - `TLS::TicketKeys.static(current:, previous: [])` seals with `current` and opens tickets sealed with `current` or any of `previous`. To turn the keys over, build a new `TLS::Config` and `TLS::Keyring` and hand them to `Server#reconfigure`.
111
+ - `TLS::TicketKeys.ratchet(base:, base_epoch:, origin:, now:, epoch: 3600, retain: nil, horizon: 24)` gives each `epoch` seconds of the wall clock since `origin` a key of its own. Each epoch's seed is derived from the one before. Servers given the same `base`, `base_epoch`, `origin` and `epoch` compute the same keys without talking to each other. A `Runtime::Server` moves to the next epoch's keys by itself. `base` is the seed of epoch `base_epoch`, which must be no later than the first epoch kept: the current epoch less `retain`, where `retain` defaults to the ticket lifetime in epochs plus one. A base too far behind (more than 4096 epochs) is refused; hand out the `base` and `base_epoch` of `keys.advance(now:)` instead.
112
+
113
+ ```ruby
114
+ origin = Time.utc(2026, 1, 1)
115
+ now = Time.now
116
+ keys = Raiha::TLS::TicketKeys.ratchet(base: seed, base_epoch: ((now - origin) / 3600).floor - 24, origin:, now:)
117
+ ```
118
+
119
+ In the runtime, a client resumes by passing a ticket from `Session#tickets` to `Client.connect(session:)`, and sends 0-RTT with `early_data: true`; see [fiber-scheduler.md](fiber-scheduler.md#resuming-a-connection). In the sans-I/O core, tickets come as `Raiha::QUIC::Event::SessionTicket` and go to `Raiha::QUIC::Connection.client(session:)` or `Raiha::QUIC::Endpoint#connect(session:)`; see [quic.md](quic.md#resumption-and-0-rtt) and, for HTTP/3, [http3-client.md](http3-client.md#several-requests-resumption-and-0-rtt).
120
+
121
+ ### Replay protection
122
+
123
+ An attacker can replay 0-RTT. A server records the ClientHello of each 0-RTT it takes, in its `anti_replay:`, so that it takes each at most once. By default, `Runtime::Server` makes a `TLS::AntiReplay::Memory.new(now: Time.now)`. For its first 11 seconds, that record takes no 0-RTT, so a ClientHello taken before a restart is not taken again. `TLS::AntiReplay::Memory.new(now:, warmup: false)` skips the warm-up. That is safe only when every ticket key is newer than the record, as with keys made at random at start-up.
124
+
125
+ Servers in other processes that open the same tickets keep separate records, so each of them may take a ClientHello's 0-RTT once. `Runtime::Workers` gives its Ractors one shared record.
126
+
127
+ `app_early_data_context:` on `Runtime::Server` names what your 0-RTT depends on, such as the application's settings. A ticket issued under another context has its 0-RTT rejected. The connection still resumes.
128
+
129
+ ## `QUIC::Config` settings
130
+
131
+ `QUIC::Config.new(**options)` takes these keywords; `config.with(...)` returns a copy with some changed. Times are Float seconds, sizes are bytes. `inspect` masks the two keys.
132
+
133
+ ### Transport parameters
134
+
135
+ These are sent to the peer, named as RFC 9000 names them.
136
+
137
+ | Setting | Default | Meaning |
138
+ | --- | --- | --- |
139
+ | `max_idle_timeout` | `30.0` | Seconds of silence before the connection closes. |
140
+ | `max_udp_payload_size` | `65527` | The largest UDP payload this end can receive. |
141
+ | `initial_max_data` | `768 KiB` | The connection's initial flow control window. |
142
+ | `initial_max_stream_data_bidi_local` | `512 KiB` | The initial window of a bidirectional stream this end opened. |
143
+ | `initial_max_stream_data_bidi_remote` | `512 KiB` | The initial window of a bidirectional stream the peer opened. |
144
+ | `initial_max_stream_data_uni` | `512 KiB` | The initial window of a unidirectional stream the peer opened. |
145
+ | `initial_max_streams_bidi` | `100` | How many bidirectional streams the peer may open. |
146
+ | `initial_max_streams_uni` | `100` | How many unidirectional streams the peer may open. HTTP/3 needs three. |
147
+ | `max_ack_delay` | `0.025` | The longest this end delays an acknowledgement. |
148
+ | `ack_delay_exponent` | `3` | The exponent of the ACK Delay field. |
149
+ | `active_connection_id_limit` | `8` | How many of the peer's connection IDs this end keeps. |
150
+ | `disable_active_migration` | `false` | Tells the peer not to migrate. |
151
+ | `max_datagram_frame_size` | `nil` | `nil` or `0` for no DATAGRAM frames; RFC 9221 suggests `65535` to have them. |
152
+
153
+ ### This implementation
154
+
155
+ | Setting | Default | Meaning |
156
+ | --- | --- | --- |
157
+ | `versions` | `[QUIC::Version::V2, QUIC::Version::V1]` | The QUIC versions spoken, in order of preference: a client starts in the first, and a server switches each client to the first of them that the client offers and `deployed_versions` holds. Versions 1 and 2 (RFC 9369) are supported. See [Versions](#versions). |
158
+ | `offered_versions` | `nil` | Server only: the versions a Version Negotiation packet lists, some of `versions`. `nil` lists `versions`. |
159
+ | `deployed_versions` | `nil` | Server only: the versions every server of the deployment supports, some of `offered_versions`. The server switches clients only to these, and tells clients of them. `nil` means `offered_versions`. |
160
+ | `connection_id_length` | `8` | Bytes of the connection IDs this end issues, 0 to 20. |
161
+ | `initial_max_datagram_size` | `1200` | The datagram size before a path is probed. At least 1200. |
162
+ | `enable_pmtud` | `true` | Probe each path for larger datagrams (RFC 8899). |
163
+ | `max_stream_receive_window` | `6 MiB` | How far a stream's receive window can grow. |
164
+ | `max_receive_window` | `15 MiB` | How far the connection's receive window can grow. |
165
+ | `max_send_buffer` | `15 MiB` | The most unacknowledged data kept for sending. |
166
+ | `congestion_control` | `QUIC::Congestion::Cubic` | `:cubic`, `:new_reno`, or a class of your own. |
167
+ | `initial_window` | `min(10 × size, max(14720, 2 × size))` | A lambda from the datagram size to the initial window, as RFC 9002 gives it. Make your own with `Ractor.shareable_lambda`. |
168
+ | `startup` | `nil` | A class that wraps the controller while the connection starts, such as `QUIC::Congestion::Startup::RapidStart`. `nil` keeps the controller's own slow start. |
169
+ | `pacing_granularity` | `0.001` | Seconds between the wake-ups of pacing. |
170
+ | `max_transmit_size` | `nil` | The most bytes one send carries, cut into datagrams of one size (but the last) for GSO. `nil` means one datagram per send. The runtime fills it in; see below. |
171
+ | `fast_convergence` | `true` | CUBIC's fast convergence (RFC 9438). |
172
+ | `beta_ecn` | `nil` | The factor the window is multiplied by when an ECN-CE mark alone starts recovery. `nil` uses the algorithm's own loss factor. |
173
+ | `retry_token_key` | `nil` | The secret Retry tokens are made with, 32 bytes at least. |
174
+ | `stateless_reset_key` | `nil` | The secret stateless reset tokens are made with, 32 bytes at least. |
175
+ | `preferred_address` | `nil` | Server only: `{ipv4: [host, port], ipv6: [host, port]}`, either or both. Needs `connection_id_length` above 0. |
176
+ | `address_families` | `[:ipv4, :ipv6]` | The families this end can send to. A client picks the server's preferred address from these. |
177
+ | `ecn_address_families` | `[:ipv4, :ipv6]` | The families whose paths use ECN. A path of another family sends Not-ECT. |
178
+
179
+ When `retry_token_key` and `stateless_reset_key` are left `nil`, each endpoint draws its own, which only that process can use. Every process serving the same connections must be given the same keys. `Runtime::Workers` draws one pair and shares it among its Ractors.
180
+
181
+ The settings are checked against each other as well:
182
+
183
+ - Each receive window must be able to grow past its initial value: `max_stream_receive_window` at least each initial stream limit, and `max_receive_window` at least `initial_max_data` and at least 1.5 × `max_stream_receive_window`.
184
+ - The initial window must be at least two datagrams.
185
+
186
+ For example, raising `initial_max_data` alone to 32 MiB raises `ArgumentError` ("max_receive_window 15728640 is under initial_max_data").
187
+
188
+ ### Versions
189
+
190
+ A client starts in the first of `versions`, and offers the others that are compatible with it in its `version_information` transport parameter (RFC 9368). Versions 1 and 2 are compatible with each other. A server takes a client in any of `versions`, and switches it, within the handshake, to the first of its `versions` that the client offers and `deployed_versions` holds, which by default is all of them. A client whose version the server does not take gets a Version Negotiation packet, and starts again in the first of its `versions` that the packet lists. [quic.md](quic.md#versions) tells what a connection does on the way.
191
+
192
+ With the default, a client starts in version 2. A server of version 1 alone that answers with a Version Negotiation packet costs it a round trip. Some servers do not answer: quiche's example server, quiche-server, reads the packet type of a version 2 Initial as version 1's and drops it, so a client with the default never connects to it. A client that has to reach such servers can start in version 1 and offer version 2, which a server of both versions switches it to:
193
+
194
+ ```ruby
195
+ Raiha::QUIC::Config.new(versions: [Raiha::QUIC::Version::V1, Raiha::QUIC::Version::V2])
196
+ ```
197
+
198
+ The servers behind one address may not all have the same versions while you add or remove one, and a client that is told of a version a server cannot take fails to connect (RFC 9368 "Server Deployments of QUIC"). Add a version in three steps, each given to every server before the next. Between steps, wait as long as a packet may live in the network (the MSL; a minute is enough):
199
+
200
+ ```ruby
201
+ # 1. Every server takes a client that starts in version 2, and neither lists version 2 nor switches clients to it.
202
+ Raiha::QUIC::Config.new(versions: [Raiha::QUIC::Version::V2, Raiha::QUIC::Version::V1], offered_versions: [Raiha::QUIC::Version::V1])
203
+ # 2. Version Negotiation packets list it too.
204
+ Raiha::QUIC::Config.new(versions: [Raiha::QUIC::Version::V2, Raiha::QUIC::Version::V1], deployed_versions: [Raiha::QUIC::Version::V1])
205
+ # 3. Servers switch clients to it and tell clients of it.
206
+ Raiha::QUIC::Config.new(versions: [Raiha::QUIC::Version::V2, Raiha::QUIC::Version::V1])
207
+ ```
208
+
209
+ Remove a version with the same steps in reverse: first take it out of `deployed_versions`, then out of `offered_versions`, then out of `versions`.
210
+
211
+ ### What the runtime changes
212
+
213
+ `Runtime::Server` and `Runtime::Client` adjust the config to their socket:
214
+
215
+ - A config without `max_transmit_size` gets `Runtime::UDP::MAX_TRANSMIT` (65507). The socket cuts each send into datagrams itself, with GSO where the OS has it.
216
+ - `enable_pmtud` is set to `false` where the socket cannot keep IP from fragmenting. Today that means everywhere but Linux.
217
+ - `:ipv4` is dropped from `ecn_address_families` where the OS has no `IP_RECVTOS`, as on OpenBSD.
218
+
219
+ See [platforms.md](platforms.md).
220
+
221
+ ## Changing settings on a running server
222
+
223
+ `Runtime::Server#reconfigure(tls_config:, keyring:)` switches the TLS config and keyring for the connections that come after the call, for a renewed certificate or new static ticket keys. Connections already taken keep their own. The `QUIC::Config` cannot be changed on a running server, because its keys and connection ID length are part of the endpoint. `Runtime::Workers#reconfigure` does the same across all workers; see [fiber-scheduler.md](fiber-scheduler.md#several-ractors-with-workers).
224
+
225
+ ```ruby
226
+ server.reconfigure(tls_config: server_tls, keyring: Raiha::TLS::Keyring.server(config: server_tls, identities: [renewed_identity]))
227
+ ```