|
2 | 2 |
|
3 | 3 | QUIC library for TypeScript/JavaScript applications.
|
4 | 4 |
|
5 |
| -This is built on top of Cloudflare's [quiche](https://github.com/cloudflare/quiche) library. It is intended to support Linux, Windows MacOS, Android and iOS. Mobile support is still pending. |
| 5 | +This is built on top of Cloudflare's |
| 6 | +[quiche](https://github.com/cloudflare/quiche) library. It is intended to |
| 7 | +support Linux, Windows MacOS, Android and iOS. Mobile support is still pending. |
6 | 8 |
|
7 |
| -Since Cloudflare's quiche is written in Rust. This uses the [napi-rs](https://github.com/napi-rs/napi-rs) binding system compile the native objects for Node.js. |
| 9 | +Since Cloudflare's quiche is written in Rust. This uses the |
| 10 | +[napi-rs](https://github.com/napi-rs/napi-rs) binding system compile the native |
| 11 | +objects for Node.js. |
8 | 12 |
|
9 |
| -This library focuses only on the QUIC protocol. It does not support HTTP3. You can build HTTP3 on top of this. |
| 13 | +This library focuses only on the QUIC protocol. It does not support HTTP3. You |
| 14 | +can build HTTP3 on top of this. |
10 | 15 |
|
11 | 16 | ## Installation
|
12 | 17 |
|
@@ -62,9 +67,11 @@ git push --tags
|
62 | 67 |
|
63 | 68 | ### Quiche
|
64 | 69 |
|
65 |
| -To understand how to develop this, it is important to understand how quiche works. |
| 70 | +To understand how to develop this, it is important to understand how quiche |
| 71 | +works. |
66 | 72 |
|
67 |
| -Clone the https://github.com/cloudflare/quiche project. It's multi-workspace Cargo project. |
| 73 | +Clone the https://github.com/cloudflare/quiche project. It's multi-workspace |
| 74 | +Cargo project. |
68 | 75 |
|
69 | 76 | You can build and run their examples located in `/quiche/examples/`:
|
70 | 77 |
|
@@ -128,55 +135,96 @@ The available target list is in `rustc --print target-list`.
|
128 | 135 |
|
129 | 136 | ### Structure
|
130 | 137 |
|
131 |
| -It is possible to structure the QUIC system in the encapsulated way or the injected way. |
| 138 | +It is possible to structure the QUIC system in the encapsulated way or the |
| 139 | +injected way. |
132 | 140 |
|
133 |
| -When using the encapsulated way, the `QUICSocket` is separated between client and server. |
| 141 | +When using the encapsulated way, the `QUICSocket` is separated between client |
| 142 | +and server. |
134 | 143 |
|
135 |
| -When using the injected way, the `QUICSocket` is shared between client and server. |
| 144 | +When using the injected way, the `QUICSocket` is shared between client and |
| 145 | +server. |
136 | 146 |
|
137 | 147 | 
|
138 | 148 |
|
139 |
| -If you are building a peer to peer network, you must use the injected way. This is the only way to ensure that hole-punching works because both the client and server for any given peer must share the same UDP socket and thus share the `QUICSocket`. When done in this way, the `QUICSocket` lifecycle is managed outside of both the `QUICClient` and `QUICServer`. |
| 149 | +If you are building a peer to peer network, you must use the injected way. This |
| 150 | +is the only way to ensure that hole-punching works because both the client and |
| 151 | +server for any given peer must share the same UDP socket and thus share the |
| 152 | +`QUICSocket`. When done in this way, the `QUICSocket` lifecycle is managed |
| 153 | +outside of both the `QUICClient` and `QUICServer`. |
140 | 154 |
|
141 | 155 | 
|
142 | 156 |
|
143 |
| -This also means both `QUICClient` and `QUICServer` must share the same connection map. In order to allow the `QUICSocket` to dispatch data into the correct connection, the connection map is constructed in the `QUICSocket`, however setting and unsetting connections is managed by `QUICClient` and `QUICServer`. |
| 157 | +This also means both `QUICClient` and `QUICServer` must share the same |
| 158 | +connection map. In order to allow the `QUICSocket` to dispatch data into the |
| 159 | +correct connection, the connection map is constructed in the `QUICSocket`, |
| 160 | +however setting and unsetting connections is managed by `QUICClient` and |
| 161 | +`QUICServer`. |
144 | 162 |
|
145 | 163 | ### Dataflow
|
146 | 164 |
|
147 | 165 | The data flow of the QUIC system is a bidirectional graph.
|
148 | 166 |
|
149 |
| -Data received from the outside world is received on the UDP socket. It is parsed and then dispatched to each `QUICConnection`. Each connection further parses the data and then dispatches to the `QUICStream`. Each `QUICStream` presents the data on the `ReadableStream` interface, which can be read by a caller. |
| 167 | +Data received from the outside world is received on the UDP socket. It is parsed |
| 168 | +and then dispatched to each `QUICConnection`. Each connection further parses the |
| 169 | +data and then dispatches to the `QUICStream`. Each `QUICStream` presents the |
| 170 | +data on the `ReadableStream` interface, which can be read by a caller. |
150 | 171 |
|
151 |
| -Data sent to the outside world is written to a `WritableStream` interface of a `QUICStream`. This data is buffered up in the underlying Quiche stream. A send procedure is triggered on the associated `QUICConnection` which takes all the buffered data to be sent for that connection, and sends it to the `QUICSocket`, which then sends it to the underlying UDP socket. |
| 172 | +Data sent to the outside world is written to a `WritableStream` interface of a |
| 173 | +`QUICStream`. This data is buffered up in the underlying Quiche stream. A send |
| 174 | +procedure is triggered on the associated `QUICConnection` which takes all the |
| 175 | +buffered data to be sent for that connection, and sends it to the `QUICSocket`, |
| 176 | +which then sends it to the underlying UDP socket. |
152 | 177 |
|
153 | 178 | 
|
154 | 179 |
|
155 |
| -Buffering occurs at the connection level and at the stream level. Each connection has a global buffer for all streams, and each stream has its own buffer. Note that connection buffering and stream buffering all occur within the Quiche library. The web streams `ReadableStream` and `WritableStream` do not do any buffering at all. |
| 180 | +Buffering occurs at the connection level and at the stream level. Each |
| 181 | +connection has a global buffer for all streams, and each stream has its own |
| 182 | +buffer. Note that connection buffering and stream buffering all occur within the |
| 183 | +Quiche library. The web streams `ReadableStream` and `WritableStream` do not do |
| 184 | +any buffering at all. |
156 | 185 |
|
157 | 186 | ### Connection Negotiation
|
158 | 187 |
|
159 |
| -The connection negotiation process involves several exchanges of QUIC packets before the `QUICConnection` is constructed. |
| 188 | +The connection negotiation process involves several exchanges of QUIC packets |
| 189 | +before the `QUICConnection` is constructed. |
160 | 190 |
|
161 |
| -The primary reason to do this is for both sides to determine their respective connection IDs. |
| 191 | +The primary reason to do this is for both sides to determine their respective |
| 192 | +connection IDs. |
162 | 193 |
|
163 | 194 | 
|
164 | 195 |
|
165 | 196 | ### Push & Pull
|
166 | 197 |
|
167 |
| -The `QUICSocket`, `QUICClient`, `QUICServer`, `QUICConnection` and `QUICStream` are independent state machines that exposes methods that can be called as well as events that may be emitted between them. |
| 198 | +The `QUICSocket`, `QUICClient`, `QUICServer`, `QUICConnection` and `QUICStream` |
| 199 | +are independent state machines that exposes methods that can be called as well |
| 200 | +as events that may be emitted between them. |
168 | 201 |
|
169 |
| -This creates a concurrent decentralised state machine system where there are multiple entrypoints of change. |
| 202 | +This creates a concurrent decentralised state machine system where there are |
| 203 | +multiple entrypoints of change. |
170 | 204 |
|
171 |
| -Users may call methods which causes state transitions internally that trigger event emissions. However some methods are considered internal to the library, this means these methods are not intended to be called by the end user. They are however public relative to the other components in the system. These methods should be marked with `@internal` documentation annotation. |
| 205 | +Users may call methods which causes state transitions internally that trigger |
| 206 | +event emissions. However some methods are considered internal to the library, |
| 207 | +this means these methods are not intended to be called by the end user. They are |
| 208 | +however public relative to the other components in the system. These methods |
| 209 | +should be marked with `@internal` documentation annotation. |
172 | 210 |
|
173 |
| -External events may also trigger event handlers that will call methods which perform state transitions and event emission. |
| 211 | +External events may also trigger event handlers that will call methods which |
| 212 | +perform state transitions and event emission. |
174 | 213 |
|
175 |
| -Keeping track of how the system works is therefore quite complex and must follow a set of rules. |
| 214 | +Keeping track of how the system works is therefore quite complex and must follow |
| 215 | +a set of rules. |
176 | 216 |
|
177 |
| -- Pull methods - these are either synchronous or asynchronous methods that may throw exceptions. |
178 |
| -- Push handlers - these are event handlers that can initiate pull methods, if these pull handlers throw exceptions, these exceptions must be caught, and expected runtime exceptions are to be converted to error events, all other exceptions will be considered to be software bugs and will be bubbled up to the program boundary as unhandled exceptions or unhandled promise rejections. Generally the only exceptions that are expected runtime exceptions are those that arise from perform IO with the operating system. |
| 217 | +- Pull methods - these are either synchronous or asynchronous methods that may |
| 218 | + throw exceptions. |
| 219 | +- Push handlers - these are event handlers that can initiate pull methods, if |
| 220 | + these pull handlers throw exceptions, these exceptions must be caught, and |
| 221 | + expected runtime exceptions are to be converted to error events, all other |
| 222 | + exceptions will be considered to be software bugs and will be bubbled up to |
| 223 | + the program boundary as unhandled exceptions or unhandled promise rejections. |
| 224 | + Generally the only exceptions that are expected runtime exceptions are those |
| 225 | + that arise from perform IO with the operating system. |
179 | 226 |
|
180 | 227 | ## License
|
181 | 228 |
|
182 |
| -js-quic is licensed under Apache-2.0, you may read the terms of the license [here](LICENSE). |
| 229 | +js-quic is licensed under Apache-2.0, you may read the terms of the license |
| 230 | +[here](LICENSE). |
0 commit comments