|
| 1 | +# `network-transport-quic` |
| 2 | + |
| 3 | +This package provides an implementation of the `network-transport` interface, where networking is done via the QUIC protocol. The primary use-case for this package is as a Cloud Haskell backend. |
| 4 | + |
| 5 | +QUIC has many advantages over TCP, including: |
| 6 | + |
| 7 | +* No head-of-line blocking. Independent streams mean packet loss on one stream doesn't stall others; |
| 8 | +* Connection migration. Connections survive IP address changes, which is important when a device switches from e.g. WIFI to 5G; |
| 9 | +* Built-in encryption via TLS 1.3; |
| 10 | + |
| 11 | +In benchmarks, `network-transport-quic` performs better than `network-transport-tcp` in dense network topologies. For example, if every `EndPoint` in your network connects to every other `EndPoint`, you might benefit greatly from switching to `network-transport-quic`! |
| 12 | + |
| 13 | +## Usage example |
| 14 | + |
| 15 | +Provided you have a TLS 1.3 certificate, you can create a `Transport` like so: |
| 16 | + |
| 17 | +```haskell |
| 18 | +import Data.List.NonEmpty qualified as NonEmpty |
| 19 | +import Network.Transport.QUIC (QUICTransportConfig(..), createTransport, credentialLoadX509) |
| 20 | + |
| 21 | +main = do |
| 22 | + let certificate = "path/to/cert.crt" |
| 23 | + key = "path/to/cert.key" |
| 24 | + |
| 25 | + creds <- credentialLoadX509 certificate key |
| 26 | + case creds of |
| 27 | + Left error_message -> error error_message |
| 28 | + Right credential -> do |
| 29 | + let config = QUICTransportConfig |
| 30 | + { hostName = "my.hostname.com" -- or some IP address |
| 31 | + , serviceName = "https" -- alternatively, some port number |
| 32 | + , credentials = NonEmpty.singleton credential |
| 33 | + , validateCredentials = True -- should be 'False' for self-signed certificate |
| 34 | + } |
| 35 | + transport <- createTransport config |
| 36 | + ... |
| 37 | +``` |
| 38 | + |
| 39 | +There are tools online to help create self-signed TLS 1.3 certificates. |
0 commit comments