Skip to content

Commit aa2b55c

Browse files
committed
Add Docker-based QUIC example.
1 parent 63ce73c commit aa2b55c

File tree

8 files changed

+221
-0
lines changed

8 files changed

+221
-0
lines changed

examples/docker/mqtt/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# MQTT Example
2+
3+
This example Docker compose setup shows how to use the QUIC channel to forward traffic to a remote service via the Hyper network. It defines the following services:
4+
5+
- **quic-1**: A Hyper service running the QUIC channel that is configured to forward local ports to a remote server via the **quic-2** proxy.
6+
- **quic-2**: A Hyper service running the QUIC channel that is configured as a remote proxy, forwarding connections to the **mqtt-1** container.
7+
- **sd-1**: The Hyper service directory for this setup.
8+
- **mqtt-1**: A RabbitMQ-based MQTT broker.s
9+
- **hd-1**: An admin container that initializes the service directory.
10+
11+
To run this setup, first run `make certs` in the main Hyper directory to generate all required TLS certificates. Then, simply run
12+
13+
```bash
14+
docker compose up
15+
```
16+
17+
This should create all containers and run them. You should then be able to connect to the RabbitMQ admin API via `curl` through the forwarded local port:
18+
19+
```bash
20+
curl http://localhost:6666/rabbitmqadmin
21+
# should return a JSON error response
22+
```
23+
24+
That's it! You have successfully established connectivity to a remote service through the Hyper network's QUIC channel.

examples/docker/mqtt/compose.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: mqtt-demo
2+
services:
3+
# provides a RabbitMQ test server
4+
mqtt-1:
5+
image: rabbitmq:3.12-management
6+
# provides the Redis server for the service directory
7+
redis-1:
8+
image: redis:7.2.0
9+
# loads the service directory entries
10+
sd-setup:
11+
depends_on:
12+
- sd-1
13+
environment:
14+
- HYPER_SETTINGS=/app/settings
15+
volumes:
16+
# we mount the HD-1 settings
17+
- ./hd-1:/app/settings:ro
18+
# we mount the
19+
- ../../../settings/dev/directory:/directory:ro
20+
# we mount the certificates from the regular directory
21+
- ../../../settings/dev/certs:/certs:ro
22+
# we overwrite the QUIC config service directory
23+
- ./directory:/directory/quic:ro
24+
image: kiprotect/hyper:0.3.16
25+
# we load the directory entries
26+
entrypoint: "/app/settings/setup.sh"
27+
# runs the service directory
28+
sd-1:
29+
command: run
30+
depends_on:
31+
- redis-1
32+
environment:
33+
- SD_SETTINGS=/app/settings
34+
volumes:
35+
- ./sd-1:/app/settings:ro
36+
- ../../../settings/dev/certs:/certs:ro
37+
image: kiprotect/hyper-sd:0.3.16
38+
# runs the QUIC-1 service (used to run TCP sessions through the QUIC-2 service)
39+
quic-1:
40+
command: server run
41+
ports:
42+
- 5555:5555
43+
- 6666:6666
44+
depends_on:
45+
- sd-1
46+
- mqtt-1
47+
environment:
48+
- HYPER_SETTINGS=/app/settings
49+
volumes:
50+
- ./quic-1:/app/settings:ro
51+
- ../../../settings/dev/certs:/certs:ro
52+
image: kiprotect/hyper:0.3.16
53+
# runs the QUIC-2 service (used to connect to the RabbitMQ service)
54+
quic-2:
55+
command: server run
56+
depends_on:
57+
- sd-1
58+
- mqtt-1
59+
environment:
60+
- HYPER_SETTINGS=/app/settings
61+
volumes:
62+
- ./quic-2:/app/settings:ro
63+
- ../../../settings/dev/certs:/certs:ro
64+
image: kiprotect/hyper:0.3.16
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"records": [
3+
{
4+
"name": "quic-1",
5+
"created_at": "2021-05-17T10:00:00Z",
6+
"section": "channels",
7+
"data" : [
8+
{
9+
"type" : "quic",
10+
"settings" : {
11+
"address" : "quic-1:7771"
12+
}
13+
}
14+
]
15+
},
16+
{
17+
"name": "quic-2",
18+
"created_at": "2021-05-17T10:00:00Z",
19+
"section": "channels",
20+
"data" : [
21+
{
22+
"type" : "quic",
23+
"settings" : {
24+
"address" : "quic-2:7772"
25+
}
26+
}
27+
]
28+
}
29+
]
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: hd-1
2+
directory:
3+
type: api
4+
settings:
5+
jsonrpc_client:
6+
tls:
7+
certificate_file: "/certs/hd-1.crt"
8+
key_file: "/certs/hd-1.key"
9+
ca_certificate_files: ["/certs/root.crt"]
10+
ca_certificate_files: ["/certs/root.crt"]
11+
ca_intermediate_certificate_files: ["/certs/intermediate.crt"]
12+
endpoints: ["https://sd-1:3322/jsonrpc"]
13+
server_names: ["sd-1"]
14+
channels: []
15+
signing:
16+
certificate_file: "/certs/hd-1-sign.crt"
17+
key_file: "/certs/hd-1-sign.key"
18+
ca_certificate_file: "/certs/root.crt"
19+
ca_intermediate_certificate_files: ["/certs/intermediate.crt"]

examples/docker/mqtt/hd-1/setup.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
echo "initializing service directory..."
3+
export HYPER_SETTINGS=/app/settings
4+
/app/hyper sd submit-records --reset /directory/001_certificates.json
5+
/app/hyper sd submit-records /directory/quic/001_default.json
6+
echo "Done!"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: quic-1
2+
directory:
3+
type: api
4+
settings:
5+
jsonrpc_client:
6+
tls:
7+
certificate_file: "/certs/quic-1.crt"
8+
key_file: "/certs/quic-1.key"
9+
ca_certificate_files: ["/certs/root.crt"]
10+
ca_certificate_files: ["/certs/root.crt"]
11+
ca_intermediate_certificate_files: ["/certs/intermediate.crt"]
12+
endpoints: ["https://sd-1:3322/jsonrpc"]
13+
server_names: ["sd-1"]
14+
channels: # defines all the channels that we want to open when starting the server
15+
- name: main QUIC client/server # forwards TCP streams and UDP packets via QUIC
16+
type: quic
17+
settings:
18+
bindAddress: 0.0.0.0:7771
19+
channels:
20+
- remote:
21+
host: quic-2
22+
target: "mqtt-1:5672"
23+
local:
24+
port: 5555
25+
- remote:
26+
host: quic-2
27+
target: "mqtt-1:15672"
28+
local:
29+
port: 6666
30+
tls:
31+
ca_certificate_files: ["/certs/root.crt"]
32+
certificate_file: "/certs/quic-1.crt"
33+
key_file: "/certs/quic-1.key"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: quic-2
2+
directory:
3+
type: api
4+
settings:
5+
jsonrpc_client:
6+
tls:
7+
certificate_file: "/certs/quic-2.crt"
8+
key_file: "/certs/quic-2.key"
9+
ca_certificate_files: ["/certs/root.crt"]
10+
ca_certificate_files: ["/certs/root.crt"]
11+
ca_intermediate_certificate_files: ["/certs/intermediate.crt"]
12+
endpoints: ["https://sd-1:3322/jsonrpc"]
13+
server_names: ["sd-1"]
14+
channels: # defines all the channels that we want to open when starting the server
15+
- name: main QUIC client/server # forwards TCP streams and UDP packets via QUIC
16+
type: quic
17+
settings:
18+
bindAddress: 0.0.0.0:7772
19+
channels: []
20+
tls:
21+
ca_certificate_files: ["/certs/root.crt"]
22+
certificate_file: "/certs/quic-2.crt"
23+
key_file: "/certs/quic-2.key"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
jsonrpc_server: # the JSON-RPC server that the EPS server uses for communication
2+
bind_address: "0.0.0.0:3322"
3+
tcp_rate_limits:
4+
- type: second
5+
limit: 10
6+
- type: minute
7+
limit: 1000
8+
tls:
9+
ca_certificate_files: ["/certs/root.crt"]
10+
certificate_file: "/certs/sd-1.crt"
11+
key_file: "/certs/sd-1.key"
12+
directory:
13+
datastore:
14+
type: redis
15+
settings:
16+
addresses:
17+
- redis-1:6379
18+
database: 0
19+
password: ""
20+
key: sd-entries
21+
ca_certificate_files: ["/certs/root.crt"]
22+
ca_intermediate_certificate_files: ["/certs/intermediate.crt"]

0 commit comments

Comments
 (0)