quic 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 12a202268fc7d9b862cdc0b6577284f5ae98fc275229b129be39f03656ce6967
4
+ data.tar.gz: eef365c93fcce127f4621ac8aa244ea0b020f239c29bd56bdd5706998852449d
5
+ SHA512:
6
+ metadata.gz: a6fdb666ea56dc95b50087da5f43a14366416434029e59b4e041f4a7a5eb41a79abbf530403bb7b4505ada4da5387cf6fcba5fc29f8350bc0466bb5ad8f58dc4
7
+ data.tar.gz: 33f053db5b35c2c7dd428d5e6ad3e29b58b4624f208ebae9593b3bb160fdfd7622942c13d75311ebd854411371f09690627a1f42366d1b3fe24d06362cbe7f36
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.0.1] - 2026-05-28
4
+
5
+ - Initial release
@@ -0,0 +1,10 @@
1
+ # Code of Conduct
2
+
3
+ "quic" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
4
+
5
+ * Participants will be tolerant of opposing views.
6
+ * Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
7
+ * When interpreting the words and actions of others, participants should always assume good intentions.
8
+ * Behaviour which can be reasonably considered harassment will not be tolerated.
9
+
10
+ If you have any concerns about behaviour within this project, please contact us at ["yusuke1994525@gmail.com"](mailto:"yusuke1994525@gmail.com").
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Yusuke Nakamura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Quic
2
+
3
+ `quic` is a thin Ruby binding around [ngtcp2](https://github.com/ngtcp2/ngtcp2) for the QUIC transport protocol, with [LibreSSL](https://github.com/libressl/portable) as the TLS backend. Both dependencies are vendored at install time via [`mini_portile2`](https://github.com/flavorjones/mini_portile) (no system libraries required).
4
+
5
+ The gem is intentionally optimized for **synchronous I/O and `String`-based buffers**. It exposes ngtcp2 primitives (`#read_pkt` / `#write_pkt` / `#expiry` / `#handle_expiry`) and lets the caller own the I/O loop. If you need Fiber Scheduler / `IO::Buffer` / `async` ecosystem integration, see [`socketry/protocol-quic`](https://github.com/socketry/protocol-quic) instead.
6
+
7
+ This project is in early development; the public API is not yet stable.
8
+
9
+ ## Installation
10
+
11
+ Not yet released to RubyGems.org. To use from a Gemfile while it is in development:
12
+
13
+ ```ruby
14
+ gem "quic", github: "unasuke/quic-ruby"
15
+ ```
16
+
17
+ The native extension downloads and builds LibreSSL and ngtcp2 release tarballs during `bundle install`, so the host needs `autoconf`, `automake`, `libtool`, `pkg-config`, and a C toolchain available.
18
+
19
+ ## Development
20
+
21
+ After checking out the repo, run `bin/setup` to install dependencies. Then run `bundle exec rake` to compile the C extension and run the tests + linter. You can also run `bin/console` for an interactive prompt.
22
+
23
+ To install this gem onto your local machine, run `bundle exec rake install`.
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/unasuke/quic-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/unasuke/quic-ruby/blob/main/CODE_OF_CONDUCT.md).
28
+
29
+ ## License
30
+
31
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
32
+
33
+ ## Code of Conduct
34
+
35
+ Everyone interacting in the Quic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unasuke/quic-ruby/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "standard/rake"
9
+
10
+ require "rake/extensiontask"
11
+
12
+ task build: :compile
13
+
14
+ GEMSPEC = Gem::Specification.load("quic.gemspec")
15
+
16
+ Rake::ExtensionTask.new("quic", GEMSPEC) do |ext|
17
+ ext.lib_dir = "lib/quic"
18
+ end
19
+
20
+ task default: %i[clobber compile test standard]
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Stream API demo: open a bidirectional stream, write a small payload with
4
+ # FIN, then block on Stream#read until the peer echoes the bytes back and
5
+ # closes its side. Requires a local QUIC echo server (default: 127.0.0.1:4433
6
+ # with ALPN "perf"); ngtcp2 ships an examples/server binary that does this
7
+ # when built with --enable-examples.
8
+ #
9
+ # Override the target via env vars:
10
+ # QUIC_ECHO_HOST (default 127.0.0.1)
11
+ # QUIC_ECHO_PORT (default 4433)
12
+ # QUIC_ECHO_ALPN (default perf)
13
+ #
14
+ # Run with: bundle exec ruby examples/echo_demo.rb
15
+
16
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
17
+ require "quic"
18
+ require "socket"
19
+
20
+ TARGET_HOST = ENV.fetch("QUIC_ECHO_HOST", "127.0.0.1")
21
+ TARGET_PORT = Integer(ENV.fetch("QUIC_ECHO_PORT", "4433"))
22
+ TARGET_ALPN = ENV.fetch("QUIC_ECHO_ALPN", "perf")
23
+
24
+ addr = Addrinfo.getaddrinfo(TARGET_HOST, TARGET_PORT, Socket::AF_INET, Socket::SOCK_DGRAM).first
25
+ sock = UDPSocket.new
26
+ sock.connect(addr.ip_address, addr.ip_port)
27
+
28
+ settings = Quic::Settings.default.with(alpn: [TARGET_ALPN])
29
+ client = Quic::Connection::Client._open(
30
+ local_sockaddr: Addrinfo.udp("0.0.0.0", 0).to_sockaddr,
31
+ remote_sockaddr: addr.to_sockaddr,
32
+ server_name: TARGET_HOST,
33
+ transport_params: Quic::TransportParams.default,
34
+ settings: settings
35
+ )
36
+ client.bind(sock).run
37
+
38
+ stream = client.open_bidi_stream
39
+ puts "opened stream #{stream.id} (#{stream.initiator})"
40
+
41
+ payload = "hello quic stream\n"
42
+ stream.write(payload, fin: true)
43
+ puts "sent #{payload.bytesize} bytes + FIN"
44
+
45
+ response = stream.read
46
+ puts "received #{response.bytesize} bytes:"
47
+ puts response
48
+
49
+ sock.close
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Sample script: drive a real QUIC + TLS 1.3 handshake against a public
4
+ # HTTP/3 server (cloudflare-quic.com:443) using Client#bind + Client#run.
5
+ #
6
+ # Why _open instead of Client.new: Client.new resolves the hostname via
7
+ # Addrinfo.udp, and UDPSocket#connect resolves it independently. Cloudflare
8
+ # returns multiple A/AAAA records, so the two resolutions can disagree
9
+ # and ngtcp2 then drops every reply with "ignore packet from unknown path".
10
+ # Pre-resolving once to a single IPv4 sockaddr and feeding it to both
11
+ # _open and the socket avoids this.
12
+ #
13
+ # Run with: bundle exec ruby examples/handshake_demo.rb
14
+
15
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
16
+ require "quic"
17
+ require "socket"
18
+
19
+ TARGET_HOST = "cloudflare-quic.com"
20
+ TARGET_PORT = 443
21
+
22
+ addr = Addrinfo.getaddrinfo(TARGET_HOST, TARGET_PORT, Socket::AF_INET, Socket::SOCK_DGRAM).first
23
+ sock = UDPSocket.new
24
+ sock.connect(addr.ip_address, addr.ip_port)
25
+
26
+ settings = Quic::Settings.default.with(alpn: ["h3"])
27
+ client = Quic::Connection::Client._open(
28
+ local_sockaddr: Addrinfo.udp("0.0.0.0", 0).to_sockaddr,
29
+ remote_sockaddr: addr.to_sockaddr,
30
+ server_name: TARGET_HOST,
31
+ transport_params: Quic::TransportParams.default,
32
+ settings: settings
33
+ )
34
+
35
+ puts "ngtcp2: #{Quic.library_versions[:ngtcp2]}"
36
+ puts "TLS: #{Quic.library_versions[:openssl]}"
37
+ puts "Target: #{TARGET_HOST} (#{addr.ip_address}:#{addr.ip_port})"
38
+ puts
39
+
40
+ t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
41
+ client.bind(sock).run
42
+ elapsed_ms = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0) * 1000).round(1)
43
+
44
+ puts "handshake_completed? #{client.handshake_completed?} (#{elapsed_ms}ms)"
45
+ sock.close