raioquic 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.containerignore +4 -0
  3. data/.rubocop.yml +93 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +84 -0
  6. data/Containerfile +6 -0
  7. data/Gemfile +24 -0
  8. data/Gemfile.lock +113 -0
  9. data/LICENSE +28 -0
  10. data/README.md +48 -0
  11. data/Rakefile +16 -0
  12. data/Steepfile +8 -0
  13. data/example/curlcatcher.rb +18 -0
  14. data/example/interoperability/README.md +9 -0
  15. data/example/interoperability/aioquic/aioquic_client.py +47 -0
  16. data/example/interoperability/aioquic/aioquic_server.py +34 -0
  17. data/example/interoperability/key.pem +28 -0
  18. data/example/interoperability/localhost-unasuke-dev.crt +21 -0
  19. data/example/interoperability/quic-go/sample_server.go +61 -0
  20. data/example/interoperability/raioquic_client.rb +42 -0
  21. data/example/interoperability/raioquic_server.rb +43 -0
  22. data/example/parse_curl_example.rb +108 -0
  23. data/lib/raioquic/buffer.rb +202 -0
  24. data/lib/raioquic/core_ext.rb +54 -0
  25. data/lib/raioquic/crypto/README.md +5 -0
  26. data/lib/raioquic/crypto/aesgcm.rb +52 -0
  27. data/lib/raioquic/crypto/backend/aead.rb +52 -0
  28. data/lib/raioquic/crypto/backend.rb +12 -0
  29. data/lib/raioquic/crypto.rb +10 -0
  30. data/lib/raioquic/quic/configuration.rb +81 -0
  31. data/lib/raioquic/quic/connection.rb +2776 -0
  32. data/lib/raioquic/quic/crypto.rb +317 -0
  33. data/lib/raioquic/quic/event.rb +69 -0
  34. data/lib/raioquic/quic/logger.rb +272 -0
  35. data/lib/raioquic/quic/packet.rb +471 -0
  36. data/lib/raioquic/quic/packet_builder.rb +301 -0
  37. data/lib/raioquic/quic/rangeset.rb +113 -0
  38. data/lib/raioquic/quic/recovery.rb +528 -0
  39. data/lib/raioquic/quic/stream.rb +343 -0
  40. data/lib/raioquic/quic.rb +20 -0
  41. data/lib/raioquic/tls.rb +1659 -0
  42. data/lib/raioquic/version.rb +5 -0
  43. data/lib/raioquic.rb +12 -0
  44. data/misc/export_x25519.py +43 -0
  45. data/misc/gen_rfc8448_keypair.rb +90 -0
  46. data/raioquic.gemspec +37 -0
  47. data/sig/raioquic/buffer.rbs +37 -0
  48. data/sig/raioquic/core_ext.rbs +7 -0
  49. data/sig/raioquic/crypto/aesgcm.rbs +20 -0
  50. data/sig/raioquic/crypto/backend/aead.rbs +11 -0
  51. data/sig/raioquic/quic/configuration.rbs +34 -0
  52. data/sig/raioquic/quic/connection.rbs +277 -0
  53. data/sig/raioquic/quic/crypto.rbs +88 -0
  54. data/sig/raioquic/quic/event.rbs +51 -0
  55. data/sig/raioquic/quic/logger.rbs +57 -0
  56. data/sig/raioquic/quic/packet.rbs +157 -0
  57. data/sig/raioquic/quic/packet_builder.rbs +76 -0
  58. data/sig/raioquic/quic/rangeset.rbs +17 -0
  59. data/sig/raioquic/quic/recovery.rbs +142 -0
  60. data/sig/raioquic/quic/stream.rbs +87 -0
  61. data/sig/raioquic/tls.rbs +444 -0
  62. data/sig/raioquic.rbs +9 -0
  63. metadata +121 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 92aad15cb2cf63573a3a87147da73231c0021d2840bb693cc21bc4227cfaa0f7
4
+ data.tar.gz: ca8aac35548c161b03cd19ebc5d3e6eb3b74745d19e84430adc9a5e1331948ed
5
+ SHA512:
6
+ metadata.gz: 02c4ec60a02530ab48db4cb064370c4ad63a5b9b98838c255d7cbdcd2cf2497d46674d7cbb375ffd35ac231735c9d10ab9117352850024875e56018a0d04a43e
7
+ data.tar.gz: 40dd6af2a168ecc7a7fe52e48793eea39a846a284fd0944e2e24a220d7a9134f5bd36e4d0f342fa2b82403a3b3b6ec4b2dd39d13a94effd0a7f2471d774bb021
data/.containerignore ADDED
@@ -0,0 +1,4 @@
1
+ .git
2
+ .idea
3
+ .vscode
4
+ tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,93 @@
1
+ require:
2
+ - rubocop-minitest
3
+ - rubocop-rake
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.0
7
+ NewCops: enable
8
+ Exclude:
9
+ - "example/*.rb"
10
+ - "tmp/*"
11
+ - "vendor/bundle/**/*"
12
+
13
+ Metrics/AbcSize:
14
+ Enabled: false
15
+
16
+ Metrics/ClassLength:
17
+ Enabled: false
18
+
19
+ Metrics/MethodLength:
20
+ Max: 30
21
+ Exclude:
22
+ - "test/**/test_*.rb"
23
+
24
+ Metrics/ParameterLists:
25
+ Enabled: false
26
+
27
+ Naming/AccessorMethodName:
28
+ Enabled: false # for pythonic
29
+
30
+ Naming/PredicateName:
31
+ Enabled: false # for pythonic
32
+
33
+ Naming/VariableNumber:
34
+ Exclude:
35
+ - "test/**/test_*.rb"
36
+
37
+ Style/AccessorGrouping:
38
+ EnforcedStyle: separated
39
+
40
+ Style/AccessModifierDeclarations:
41
+ EnforcedStyle: inline
42
+
43
+ Style/Documentation:
44
+ Exclude:
45
+ - "test/**/test_*.rb"
46
+
47
+ Style/KeywordParametersOrder:
48
+ Enabled: false
49
+
50
+ Style/LineEndConcatenation:
51
+ Enabled: false
52
+
53
+ Style/StringLiterals:
54
+ Enabled: true
55
+ EnforcedStyle: double_quotes
56
+
57
+ Style/StringLiteralsInInterpolation:
58
+ Enabled: true
59
+ EnforcedStyle: double_quotes
60
+
61
+ Style/TrailingCommaInArguments:
62
+ Enabled: true
63
+ EnforcedStyleForMultiline: consistent_comma
64
+
65
+ Style/TrailingCommaInArrayLiteral:
66
+ Enabled: false
67
+ # EnforcedStyleForMultiline: consistent_comma
68
+
69
+ Style/TrailingCommaInHashLiteral:
70
+ Enabled: true
71
+ EnforcedStyleForMultiline: consistent_comma
72
+
73
+ Style/NumericLiterals:
74
+ Enabled: false
75
+
76
+ Style/NumericPredicate:
77
+ Enabled: false
78
+
79
+ # I need to write 'return' explicitly sometime
80
+ Style/RedundantReturn:
81
+ Enabled: false
82
+
83
+ Style/ZeroLengthPredicate:
84
+ Enabled: false
85
+
86
+ Layout/LineLength:
87
+ Max: 150
88
+
89
+ Minitest/EmptyLineBeforeAssertionMethods:
90
+ Enabled: false
91
+
92
+ Minitest/RefuteFalse:
93
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-17
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at yusuke1994525@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Containerfile ADDED
@@ -0,0 +1,6 @@
1
+ FROM docker.io/library/ruby:3.1-buster
2
+ WORKDIR /src/raioquic
3
+ COPY lib/raioquic/version.rb /src/raioquic/lib/raioquic/version.rb
4
+ COPY raioquic.gemspec Gemfile Gemfile.lock /src/raioquic
5
+ RUN bundle install
6
+ COPY . .
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in raioquic.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "minitest-reporters"
13
+
14
+ gem "rubocop", "~> 1.21"
15
+ gem "rubocop-minitest", require: false
16
+ gem "rubocop-rake", require: false
17
+
18
+ gem "steep"
19
+
20
+ gem "openssl", ">= 3.1.0"
21
+
22
+ gem "debug"
23
+
24
+ gem "certifi", git: "https://github.com/unasuke/ruby-certifi.git", branch: "update-202212"
data/Gemfile.lock ADDED
@@ -0,0 +1,113 @@
1
+ GIT
2
+ remote: https://github.com/unasuke/ruby-certifi.git
3
+ revision: f59c61a4dc0e15f35a68aca259ebbd635625a9fd
4
+ branch: update-202212
5
+ specs:
6
+ certifi (2018.09.06)
7
+
8
+ PATH
9
+ remote: .
10
+ specs:
11
+ raioquic (0.1.0)
12
+ tttls1.3
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ activesupport (7.0.4)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 1.6, < 2)
20
+ minitest (>= 5.1)
21
+ tzinfo (~> 2.0)
22
+ ansi (1.5.0)
23
+ ast (2.4.2)
24
+ builder (3.2.4)
25
+ concurrent-ruby (1.1.10)
26
+ debug (1.7.0)
27
+ irb (>= 1.5.0)
28
+ reline (>= 0.3.1)
29
+ ffi (1.15.5)
30
+ i18n (1.12.0)
31
+ concurrent-ruby (~> 1.0)
32
+ io-console (0.5.11)
33
+ irb (1.5.1)
34
+ reline (>= 0.3.0)
35
+ json (2.6.2)
36
+ language_server-protocol (3.17.0.1)
37
+ listen (3.7.1)
38
+ rb-fsevent (~> 0.10, >= 0.10.3)
39
+ rb-inotify (~> 0.9, >= 0.9.10)
40
+ logger (1.5.1)
41
+ minitest (5.16.3)
42
+ minitest-reporters (1.5.0)
43
+ ansi
44
+ builder
45
+ minitest (>= 5.0)
46
+ ruby-progressbar
47
+ openssl (3.1.0)
48
+ parallel (1.22.1)
49
+ parser (3.1.2.1)
50
+ ast (~> 2.4.1)
51
+ rainbow (3.1.1)
52
+ rake (13.0.6)
53
+ rb-fsevent (0.11.2)
54
+ rb-inotify (0.10.1)
55
+ ffi (~> 1.0)
56
+ rbs (2.6.0)
57
+ regexp_parser (2.5.0)
58
+ reline (0.3.1)
59
+ io-console (~> 0.5)
60
+ rexml (3.2.5)
61
+ rubocop (1.36.0)
62
+ json (~> 2.3)
63
+ parallel (~> 1.10)
64
+ parser (>= 3.1.2.1)
65
+ rainbow (>= 2.2.2, < 4.0)
66
+ regexp_parser (>= 1.8, < 3.0)
67
+ rexml (>= 3.2.5, < 4.0)
68
+ rubocop-ast (>= 1.20.1, < 2.0)
69
+ ruby-progressbar (~> 1.7)
70
+ unicode-display_width (>= 1.4.0, < 3.0)
71
+ rubocop-ast (1.21.0)
72
+ parser (>= 3.1.1.0)
73
+ rubocop-minitest (0.23.2)
74
+ rubocop (>= 0.90, < 2.0)
75
+ rubocop-rake (0.6.0)
76
+ rubocop (~> 1.0)
77
+ ruby-progressbar (1.11.0)
78
+ steep (1.1.1)
79
+ activesupport (>= 5.1)
80
+ language_server-protocol (>= 3.15, < 4.0)
81
+ listen (~> 3.0)
82
+ parallel (>= 1.0.0)
83
+ parser (>= 3.1)
84
+ rainbow (>= 2.2.2, < 4.0)
85
+ rbs (>= 2.3.2)
86
+ terminal-table (>= 2, < 4)
87
+ terminal-table (3.0.2)
88
+ unicode-display_width (>= 1.1.1, < 3)
89
+ tttls1.3 (0.2.18)
90
+ logger
91
+ openssl
92
+ tzinfo (2.0.5)
93
+ concurrent-ruby (~> 1.0)
94
+ unicode-display_width (2.3.0)
95
+
96
+ PLATFORMS
97
+ x86_64-linux
98
+
99
+ DEPENDENCIES
100
+ certifi!
101
+ debug
102
+ minitest (~> 5.0)
103
+ minitest-reporters
104
+ openssl (>= 3.1.0)
105
+ raioquic!
106
+ rake (~> 13.0)
107
+ rubocop (~> 1.21)
108
+ rubocop-minitest
109
+ rubocop-rake
110
+ steep
111
+
112
+ BUNDLED WITH
113
+ 2.3.7
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Yusuke Nakamura
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Raioquic
2
+
3
+ Raioquic is a ruby porting of [aiortc/aioquic](https://github.com/aiortc/aioquic), that python's async IO library.
4
+
5
+ ## :warning: **DISCLAIMER** :warning:
6
+
7
+ Porting is incomplete, and I'm not going to create complete porting. Do not use this gem in production. If you want to use this gem, you **SHOULD** deeply understand QUIC protocol.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'raioquic'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```sh
20
+ $ bundle install
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```sh
26
+ $ gem install raioquic
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ See [test](test/) and [example/](example/).
32
+
33
+ ## Development
34
+
35
+ 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.
36
+
37
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
38
+
39
+ ## Contributing
40
+
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/unasuke/raioquic. 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/raioquic/blob/main/CODE_OF_CONDUCT.md).
42
+
43
+ ## Code of Conduct
44
+
45
+ Everyone interacting in the Raioquic project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/unasuke/raioquic/blob/main/CODE_OF_CONDUCT.md).
46
+
47
+ ## Acknowledgement
48
+ * <https://github.com/aiortc/aioquic>
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/Steepfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ target :lib do
4
+ signature "sig"
5
+
6
+ check "lib"
7
+ library "ipaddr", "socket", "openssl"
8
+ end
@@ -0,0 +1,18 @@
1
+ require 'socket'
2
+
3
+ host = ENV.fetch("HOST", "0.0.0.0")
4
+ port = ENV.fetch("PORT", 8080).to_i
5
+
6
+ socket = UDPSocket.new
7
+ socket.bind(host, port)
8
+
9
+ puts "server start"
10
+ loop do
11
+ begin
12
+ raw, addr = socket.recvmsg_nonblock()
13
+ rescue IO::WaitReadable
14
+ retry
15
+ end
16
+
17
+ puts raw.unpack1("H*") + "\n=============\n" if raw
18
+ end
@@ -0,0 +1,9 @@
1
+ # interoperability example
2
+
3
+ ## Appendix: Generate self-signed certificate by OpenSSL
4
+
5
+ ```shell
6
+ $ openssl genpkey -algorithm RSA -out key.pem
7
+ $ openssl req -new -x509 -days 365 -key key.pem -out localhost-unasuke-dev.crt -subj "/C=JP/L=Tokyo/O=unasuke/CN=localhost.unasuke.dev"
8
+ $ openssl x509 -text -in localhost-unasuke-dev.crt -noout # for verify
9
+ ```
@@ -0,0 +1,47 @@
1
+ import socket
2
+ import time
3
+
4
+ from aioquic.quic.configuration import QuicConfiguration
5
+ from aioquic.quic.connection import QuicConnection
6
+ from aioquic.quic import packet
7
+ from aioquic.buffer import Buffer
8
+ from aioquic.quic.events import HandshakeCompleted
9
+
10
+ if __name__ == '__main__':
11
+ conf = QuicConfiguration(is_client=True)
12
+ conf.load_verify_locations(cafile="localhost-unasuke-dev.crt")
13
+ client = QuicConnection(configuration=conf)
14
+ client.connect(addr=("0.0.0.0", 4433), now=time.time())
15
+ with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
16
+ s.connect(("0.0.0.0", 4433))
17
+ # handshake
18
+ for i in range(3):
19
+ for data, addr in client.datagrams_to_send(now=time.time()):
20
+ s.sendall(data)
21
+ data, addr = s.recvfrom(65536)
22
+ client.receive_datagram(data=data, addr=addr, now=time.time())
23
+ print(client.next_event())
24
+
25
+ stream_id = client.get_next_available_stream_id
26
+ for i in range(2):
27
+ client.send_stream_data(0, b"hello")
28
+ for data, addr in client.datagrams_to_send(now=time.time()):
29
+ s.sendall(data)
30
+ data, addr = s.recvfrom(655536)
31
+ client.receive_datagram(data=data, addr=addr, now=time.time())
32
+ client.close()
33
+
34
+
35
+ # while True:
36
+ # event = client.next_event()
37
+ # # print(event)
38
+ # if event == None:
39
+ # # print("AAAAAAAAAAAAAAAAAAA")
40
+ # stream = client._get_or_create_stream_for_send(stream_id=0)
41
+ # client.send_stream_data(0, b"hello")
42
+ # continue
43
+ # else:
44
+ # data, addr = s.recvfrom(655536)
45
+ # client.receive_datagram(data=data, addr=addr, now=time.time())
46
+ # for data, addr in client.datagrams_to_send(now=time.time()):
47
+ # s.sendall(data)
@@ -0,0 +1,34 @@
1
+ import socket
2
+ import time
3
+
4
+ from aioquic.quic.configuration import QuicConfiguration
5
+ from aioquic.quic.connection import QuicConnection
6
+ from aioquic.quic.events import StreamDataReceived
7
+ from aioquic.quic import packet
8
+ from aioquic.buffer import Buffer
9
+
10
+ if __name__ == '__main__':
11
+ conf = QuicConfiguration(is_client=False)
12
+ conf.load_cert_chain(certfile="localhost-unasuke-dev.crt", keyfile="key.pem")
13
+ server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
14
+ server_socket.bind(("0.0.0.0", 4433))
15
+ connections = {}
16
+
17
+ while True:
18
+ data, client_addr = server_socket.recvfrom(65536)
19
+ header = packet.pull_quic_header(Buffer(data=data), conf.connection_id_length)
20
+ connection = connections.get(header.destination_cid)
21
+ if connection is None and header.packet_type == packet.PACKET_TYPE_INITIAL:
22
+ conn = QuicConnection(configuration=conf, original_destination_connection_id=header.destination_cid)
23
+ connections[conn.host_cid] = conn
24
+ if conn is not None:
25
+ conn.receive_datagram(data=data, addr=client_addr, now=time.time())
26
+ while True:
27
+ event = conn.next_event()
28
+ if event == None:
29
+ break
30
+ print(event)
31
+ if type(event) == StreamDataReceived and event.data == b"hello":
32
+ conn.send_stream_data(event.stream_id, b"hello")
33
+ for data, addr in conn.datagrams_to_send(now=time.time()):
34
+ server_socket.sendto(data, addr)
@@ -0,0 +1,28 @@
1
+ -----BEGIN PRIVATE KEY-----
2
+ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC4MD70EUmHLYQF
3
+ w+VTG7rLTB+5TuTADjNSCLwzjnRACTWkbc4YUL9f1kOflYD2Bg/zzzyLdl8tdgnl
4
+ OvwYVrm0Jh9INnQCE0k96XrceJLBmKp/nzNqm08A6KS/EjKI1g4hF4WX6WgGza02
5
+ ryzN3muL4bdZwlSXCDF4WMSPhvF7Wux5BwoNuroFSvxM/YpQenSc8zdKWCciyYXN
6
+ 7uQsa94Bz1v3hW3IE7rr+z/VvZFeCND6cbWAuwji5AVmecgTSKa0wcm5LAo7Rv5K
7
+ hsZCEUNUXZ6GvKyx11L+jOiql1CRYhv0b0M3RHHwQsNg61ckT/K5bKa4zy0tWEYd
8
+ euWQF9q3AgMBAAECggEACrMKxSTH76lONQOHK8e9lxep9BrIIPvyMT6+qAQLbrja
9
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R0OBBYEFMLQ2Y+DEsw6S5MQdlMiKS+Tnn08MB8G
14
+ A1UdIwQYMBaAFMLQ2Y+DEsw6S5MQdlMiKS+Tnn08MA8GA1UdEwEB/wQFMAMBAf8w
15
+ DQYJKoZIhvcNAQELBQADggEBABQUKRMYi0sBf0EZOhpPX4X+H+vpbePDjeLf0otz
16
+ P1h8/uO7/un+VZH1dHCLqhVmJTd/m4kNk8Z/jlOM1Q0C4vqJSwGM6/4NEKvV72UU
17
+ t8hst+GGyoOp9CEIGDXmSH0c/mFU+vsk50Eoy9tpldvPx5vojPBd5V/kbyhKA8oM
18
+ URRuavbmvFdg9G2yyr5saIX/IFK6VTWMN5B91+NF1jh8huqZpZ0fIFLpsmfG4/HE
19
+ MUcvwCtZd+UOUA/xqc5GZdZnXs6j1kSx4voXuwvcGHxt4BphmcO//ilRtqJz3fAb
20
+ 7Q0CrslPLw7snHD9AzazF/SxB8uOdYZDat7Wp1A/2du24jA=
21
+ -----END CERTIFICATE-----
@@ -0,0 +1,61 @@
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "crypto/tls"
6
+ "fmt"
7
+ "io"
8
+ "log"
9
+ "time"
10
+
11
+ "github.com/quic-go/quic-go"
12
+ )
13
+
14
+ const addr = "localhost:4433"
15
+
16
+ const message = "foobar"
17
+
18
+ func main() {
19
+ go func() { log.Fatal(echoServer()) }()
20
+
21
+ time.Sleep(1 * time.Hour)
22
+ }
23
+
24
+ func echoServer() error {
25
+ listener, err := quic.ListenAddr(addr, generateTLSConfig(), nil)
26
+ if err != nil {
27
+ return err
28
+ }
29
+ conn, err := listener.Accept(context.Background())
30
+ if err != nil {
31
+ return err
32
+ }
33
+ stream, err := conn.AcceptStream(context.Background())
34
+ if err != nil {
35
+ panic(err)
36
+ }
37
+ // Echo through the loggingWriter
38
+ _, err = io.Copy(loggingWriter{stream}, stream)
39
+ return err
40
+ }
41
+
42
+ // A wrapper for io.Writer that also logs the message.
43
+ type loggingWriter struct{ io.Writer }
44
+
45
+ func (w loggingWriter) Write(b []byte) (int, error) {
46
+ fmt.Printf("Server: Got '%s'\n", string(b))
47
+ return w.Writer.Write(b)
48
+ }
49
+
50
+ // Setup a bare-bones TLS config for the server
51
+ func generateTLSConfig() *tls.Config {
52
+ cert, err := tls.LoadX509KeyPair("localhost-unasuke-dev.crt", "key.pem")
53
+ if err != nil {
54
+ panic(err)
55
+ }
56
+
57
+ return &tls.Config{
58
+ Certificates: []tls.Certificate{cert},
59
+ // NextProtos: []string{"quic-echo-example"},
60
+ }
61
+ }