Rabbit Slide Show

Ruby Implementation of QUIC: Progress and Challenges

2023-05-12

Description

https://rubykaigi.org/2023/presentations/yu_suke1994.html#day2

Text

Page: 1

Ruby Implementation of QUIC:
Progress and Challenges
unasuke (Yusuke Nakamura)
RubyKaigi 2023
2023-05-12

Page: 2

Self introduction
Name: unasuke (Yusuke Nakamura)
Work: freelance Web app developer @ Japan
Itamae gem maintainer, Kaigi on Rails Organizer
GitHub https://github.com/unasuke
Mastodon https://mstdn.unasuke.com/@unasuke
Twitter https://twitter.com/yu_suke1994

Page: 3

Ruby Association Grant
https://www.ruby.or.jp/en/news/20221027

Page: 4

What is QUIC?
UDP-based communication protocol
HTTP/3 uses QUIC
Faster than HTTP/2 (TCP)
image from https://github.com/quicwg/wg-materials

Page: 5

What is QUIC? - Diagram by Robin Marx
image from https://github.com/rmarx/h3-protocol-stack

Page: 6

My talks
RubyKaigi Takeout 2021
"Ruby, Ractor, QUIC"
RubyKaigi 2022 (Tsu)
"Ruby, Ractor, QUIC"
Now (2023, Matsumoto)

Page: 7

Implement QUIC from scratch
Have you ever created a Rails application?

Page: 8

Implement QUIC from scratch
Have you ever implemented the QUIC protocol?

Page: 9

Implement QUIC from scratch
It's too difficult!
When create a Rails application
learn from "Rails Guides" and "Rails Tutorial"
When create a QUIC implementation...?
RFCs are not a "implementation guide"

Page: 10

Try to implement QUIC once
To learn how to implement QUIC
Implement it once (how?)
Porting existing implementation!

Page: 11

Topics
1. Porting from Python to Ruby
2. Rubyish QUIC implementation
3. Future of my implementation

Page: 12

Porting from Python to Ruby
https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-
from-python/

Page: 13

Porting from Python to Ruby
Can you port this Python code to Ruby?

Page: 14

Porting from Python to Ruby - Code amount

Page: 15

Porting from Python to Ruby - How I ported it
Keep the same structure as Python
Carelessly changed may cause getting stuck
Avoid porting asynchronous processing parts
Difference of functionality
My lack of knowledge

Page: 16

Porting from Python to Ruby - Built-in types, bytes
https://github.com/aiortc/aioquic/blob/main/src/aioquic/_buffer.pyi

Page: 17

Porting from Python to Ruby - Built-in types, bytes
bytes in Python
immutable (bytearray is not)
String in Ruby
mutable
has Encoding (not only ASCII)

Page: 18

Porting from Python to Ruby - Built-in types, bytes
Python returns 3
Ruby returns 1 (return 3 if use String#bytesize)

Page: 19

Porting from Python to Ruby - Built-in types, enum
Python

Page: 20

Porting from Python to Ruby - Built-in types, enum
Ruby

Page: 21

Porting from Python to Ruby - Built-in types, enum
"Oh! 1025 is the SignatureAlgorithm.RSA_PKCS1_SHA256 in TLS 1.3!"

Page: 22

Porting from Python to Ruby - Built-in types, tuple
Python

Page: 23

Porting from Python to Ruby - Built-in types, tuple
Ruby

Page: 24

Porting from Python to Ruby - Code style
Python

Page: 25

Porting from Python to Ruby - Code style
Ruby

Page: 26

Porting from Python to Ruby - Code style
callback register in Python

Page: 27

Porting from Python to Ruby - Library API
Not only language themselves but also API differences.
Using OpenSSL functionality from...
Python (aioquic)
pyca/cryptography
https://github.com/pyca/cryptography
Ruby
openssl gem
https://github.com/ruby/openssl
(to implement TLS 1.3)

Page: 28

Porting from Python to Ruby - Library API
1. looked for API calls to pyca/cryptography's
2. find which C API of OpenSSL it corresponds to
3. find how it is wrapped in the openssl gem
4. port it to a Ruby API call in the openssl gem

Page: 29

Porting from Python to Ruby - Library API example

Page: 30

Porting from Python to Ruby - Library API example

Page: 31

Porting from Python to Ruby - Result

Page: 32

Porting from Python to Ruby - Demo

Page: 33

Porting from Python to Ruby - Insights
1. QUIC IS VERY DIFFICULT
2. TLS 1.3 IS ALSO VERY DIFFICULT
3. "writing once" empowers me

Page: 34

Porting from Python to Ruby - "Raioquic"
https://github.com/unasuke/raioquic

Page: 35

Rubyish QUIC implementation

Page: 36

Future of my implementation - How to make it Rubyish?
To make implementation Rubyish...
1. Use suitable features to Ruby (internal)
tuple → class or dedicated struct or data
bytes → IO::Buffer, not String
2. Adapt to existing API styles (public API)

Page: 37

Future of my implementation - TLS in Ruby
High level API (use Net::HTTP)

Page: 38

Future of my implementation - TLS in Ruby
Low level API (use OpenSSL::SSL::SSLSocket)

Page: 39

Future of my implementation - Faraday style
Very high level API

Page: 40

Future of my implementation - Net::HTTP style
Net::HTTP style API

Page: 41

Future of my implementation - Vaporware
The APIs like I've been talking about, doesn't exist yet
next year...?
um...

Page: 42

Future of my implementation - Raise your hand time!
Are you running some Rails apps on production env?

Page: 43

Future of my implementation - Raise your hand time!
Are you running some Rails apps on production without reverse
proxies or load balancers?

Page: 44

Future of my implementation - Speed!
Most Rails app is behind of web server (load balancer)
TLS termination is high cost
(asset delivery)

Page: 45

Future of my implementation - QUIC diagram (again!)
image from https://github.com/rmarx/h3-protocol-stack

Page: 46

Future of my implementation - Faster language impls
C or Rust or...
socketry/protocol-quic gem wraps ngtcp2
created by Samuel-san (ioquatix)
"Unleashing the Power of Asynchronous HTTP with Ruby" in Day 3
ngtcp2/ngtcp2 written by C

Page: 47

Future of my implementation - ngtcp2 used by curl
https://github.com/curl/curl/blob/master/docs/HTTP3.md

Page: 48

Future of my implementation - Worth of Pure Ruby
Research
Implementations that make it easy to change internal behavior
are useful
QUIC implementation itself
Helping QUIC implementation itself
e.g. Build data for test its behavior

Page: 49

Future of my implementation - Motivation
https://github.com/quicwg/base-drafts/wiki/Implementations

Page: 50

Summary
Ported aioquic (Python) to Ruby
Diffs from language features, library API makes porting hard
Ported impl could communicate other impls
Creating Rubyish implementation
Uses Ruby's built-in features
Make it can apply existing idioms
This may be where this implementation would be useful
Research
QUIC implementation itself

Page: 51

Acknowledgments
Ruby Association
For adopting my project
Koichi Sasada-san
a mentor of the porting project
Kuwayama-san
Author of tttls1.3 gem
Daisuke Aritomo a.k.a. osyoyu
Adviser of this talk

Other slides

CNDF2023 CNDF2023
2023-08-03
ruby30th-lt ruby30th-lt
2023-02-25