Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebRTC support with Coturn #16

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
!files/dev-perms.pub.pem
!files/dev-reticulum-jwk.json
!files/dev-reticulum.conf
!files/coturn/entrypoint.sh
!files/coturn/certs/cert.pem
!files/coturn/certs/key.pem
!services/reticulum/priv/dev-ssl.cert
!services/reticulum/priv/dev-ssl.key
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ means visiting these links in your web browser and following the prompts:
* [Hubs Admin](https://hubs.local:8989)
* [Hubs Client](https://hubs.local:8080)
* [Reticulum](https://hubs.local:4000)
* [Coturn](https://hubs.local:5349)

### Admin panel access

Expand Down
54 changes: 53 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
version: "3.9"
services:
coturn:
environment:
REALM: ret
PSQL: host=db dbname=ret_dev user=postgres password=postgres options='-c search_path=coturn' connect_timeout=30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need access to Reticulum’s database? If not, it should get its own and probably its own host too since the version of Postgres Reticulum needs may differ from that of coturn.

TLS_PORT: 5349
MIN_PORT: 50000
MAX_PORT: 50050
build:
context: .
dockerfile: dockerfiles/coturn.Dockerfile
volumes:
- coturn:/var/lib/coturn
ports:
- "5349:5349"
# This should be the same as MIN_PORT MAX_PORT.
# You might neeed to increase this number depending on how many clients you are connecting.
# (Keep the ports range small to improve container startup time)
- "50000-50050:50000-50050"
- "50000-50050:50000-50050/udp"
networks:
hubs_network:
db:
environment:
POSTGRES_PASSWORD: postgres
Expand All @@ -9,6 +30,10 @@ services:
user: postgres
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a smell. Why do we need to expose the database to the host OS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coturn needs to access the database. Is there another better way of inter container communication?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Containers on the same network can reach one another. The ports configuration maps the container port to the port on the host OS. So in this case, that’s HOST:CONTAINER which maps port 5432 from the container to the same port on the host OS. Will software on your local machine need to access the database directly?

networks:
hubs_network:
dialog:
build:
context: .
Expand All @@ -18,11 +43,22 @@ services:
HTTPS_CERT_FULLCHAIN: /etc/ssl/fullchain.pem
HTTPS_CERT_PRIVKEY: /etc/ssl/privkey.pem
INTERACTIVE: "false"
MEDIASOUP_MIN_PORT: 40000
MEDIASOUP_MAX_PORT: 40050
MEDIASOUP_ANNOUNCED_IP: 10.20.30.12
ports:
- "4443:4443"
# This should be the same as MEDIASOUP_MIN_PORT and MEDIASOUP_MAX_PORT
# You might neeed to increase this number depending on how many clients you are connecting.
# (Keep the ports range small to improve container startup time)
- "40000-40050:40000-40050"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these ports need to be exposed to the host OS? If so, does the user need to accept proxy certificates in the browser for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This are used for Coturn <-> Dialog communication but again this is the only way I found to communicate two containers. Open to hear alternatives.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ports config shouldn’t affect communication between two services on the same network. They are able to communicate directly without the intervention of the host OS.

- "40000-40050:40000-40050/udp"
volumes:
- dialog:/code
working_dir: /code
networks:
hubs_network:
ipv4_address: 10.20.30.12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to fix the address to a static IP?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to listen in a specific IP address, you can't listen in all interfaces. Is there a better way to assign the current container IP without making it static?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t follow. Does it need to be the same between orchestrations? Who is listening?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we just need to know the current container IP, then # hostname -i should do the trick.

hubs-admin:
build:
context: .
Expand All @@ -38,6 +74,8 @@ services:
volumes:
- hubs:/code
working_dir: /code/admin
networks:
hubs_network:
hubs-client:
build:
context: .
Expand All @@ -54,6 +92,8 @@ services:
volumes:
- hubs:/code
working_dir: /code
networks:
hubs_network:
hubs-storybook:
build:
context: .
Expand All @@ -67,10 +107,14 @@ services:
volumes:
- hubs:/code
working_dir: /code
networks:
hubs_network:
postgrest:
build:
context: .
dockerfile: dockerfiles/postgrest.Dockerfile
networks:
hubs_network:
reticulum:
build:
context: ./services/reticulum
Expand All @@ -92,6 +136,8 @@ services:
volumes:
- reticulum:/code
- retstorage:/code/storage/dev
networks:
hubs_network:
spoke:
build:
context: .
Expand All @@ -104,10 +150,16 @@ services:
- "9090:9090"
volumes:
- spoke:/code
networks:
hubs_network:
networks:
default:
hubs_network:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default applies the custom network (mozilla-hubs) to all the services. When you remove default you then have to specify the network for each service. That makes sense when you are divvying up the services between multiple networks, but we aren’t doing that. What’s the benefit in ditching the default here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC it was required to assigning a static ip address.

name: mozilla-hubs
ipam:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Today I learned that ipam stands for IP address management.

config:
- subnet: 10.20.30.0/24
volumes:
coturn:
dialog:
hubs:
pgdata:
Expand Down
8 changes: 8 additions & 0 deletions dockerfiles/coturn.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM coturn/coturn:alpine AS dev
USER root:root
RUN apk add curl netcat-openbsd
COPY files/coturn/certs/key.pem /certs/key.pem
COPY files/coturn/certs/cert.pem /certs/cert.pem
COPY files/coturn/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/bin/sh", "entrypoint.sh"]
27 changes: 27 additions & 0 deletions files/coturn/certs/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-----BEGIN CERTIFICATE-----
MIIEqDCCApACCQD9yAV5B4xV9jANBgkqhkiG9w0BAQsFADAVMRMwEQYDVQQDDApo
dWJzLmxvY2FsMCAXDTIyMTExMDE0MjQ0OFoYDzIxMjIxMDE3MTQyNDQ4WjAVMRMw
EQYDVQQDDApodWJzLmxvY2FsMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKC
AgEA6uga2VrfqURqckX+dGwJzxXrzrOVxnAJw1sszl/IFgedhbYvrdcEbKjjl335
7i5pK6JRIslU0VscYLmCjr4ru9KOlJQFfpeix3ZjNR3djuh/bO62hZPS9LHqDDcv
AsrKV+pTmttfs4C7XSr4hVK5e/nbuOPVOCU+HsvxubV5OxlVQjRiU/XrzJluAyaA
e5xGG5eeUdUMgVX38qOynxzRGFTTJswMzOLxoIkVB1iTfoY/tCKI4t3z+45SICzg
gEUtv1mYn2s31tG+4jqRrZZB09NSaf+vvRlvv17hyhzIWUQnNtxU5A1CWy4Hsl+K
00kPYEQFIOKF9rrZbo/58cipLYl0h03OlsVgmDbFQz3zDQJK5VxdxUsSH8Hg8Y2C
L0yfehnCO+B4P3KkJ8UME4YyzFWpUeAGFELvJowG5HGAC2DVyaVoVrC6MbX+ZwZH
IT6BBLCyaygd3E1MS3nrNygsV6SUMGX5AiNxlpgBYg+uthykvlqDlBvN6rhK6rEI
3+Lx2Fcu5SzHCni1Y7m316T20xHYXpnZF3/OmIPHpFL2dS+hy7hds6SNye5I0TQE
zSCPD7kQpqh50V7feZ0T4iF5Xb2K7AnPRGbYTxqs/0RPRyR7ffEgNCGuenU333at
gsvvxzYbiw3PUK31uhZ6PRXmC7AVje6CffBXBmjlrI4iRMcCAwEAATANBgkqhkiG
9w0BAQsFAAOCAgEAn4WKLyZw1n1MP1XKEfVIuFD2j3nxCXIfFqSBoufmUiYJ0qbT
nGqWp5WqyQRcoboiz7jJFRu54f3OJjCxQ3EY/5ylyKLEPoRUFQlt1EA0MAJEZs8n
afB37RAsWIqANH/mgRqgSriKx4EVVZqeHhRvlx1CwdtQO5kPW5g1cKuym/Kw0MT/
Dw7sNBizsBUMaaPfR1QLN6R3WWysSRFLDMtK25LTJTYlm8veQSlmTVp2cAOjWYAF
xEAoOw3cnZcLKi2q1FiCeSf08VfvqyORiBkzohMJlV7xUy8c/sOgFVRLaFh05baX
GJdXs10sqOJr4HLWMUhYzpDdm5ZPmyb27TA3m5Z45E2Kq9S40BhWSYZgRIumJV5W
NVsGmnwqvyDD7pWfPLA7jXKQ8u+yrGBcyZchRoS+ltXgnDpP7HR980Rm6E8Jg3dT
YNhvKCKgyWr5g78omNXJtez9EwjpnxTqTf5xmjcLxuCI65oHs0xBzgIjQpWSoMc/
JVt7FpWXNxSirThMSeUSL7lAbYsm71Dsr/Av+jZKlSR0fSOD0Ee1ga9upbjyJYV3
2YglvaHSIyjtdf0qrvk5ABWZwzqM4fc2snAZKaP0wnuR13dujzWlRAIUdDETXldC
FFxYNVWYKzfxkGCb1GXUerAYidBlCRwxHlfp9+SYIARSNSa0/x0jJq6+fUQ=
-----END CERTIFICATE-----
52 changes: 52 additions & 0 deletions files/coturn/certs/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJRAI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oint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

echo "realm=${REALM}" > /etc/turnserver.conf
echo "min-port=${MIN_PORT}" >> /etc/turnserver.conf
echo "max-port=${MAX_PORT}" >> /etc/turnserver.conf
echo "tls-listening-port=${TLS_PORT}" >> /etc/turnserver.conf
echo "psql-userdb=${PSQL}" >> /etc/turnserver.conf
echo "lt-cred-mech=true" >> /etc/turnserver.conf
echo "use-auth-secret=true" >> /etc/turnserver.conf
echo "cert=/certs/cert.pem" >> /etc/turnserver.conf
echo "pkey=/certs/key.pem" >> /etc/turnserver.conf
echo "verbose" >> /etc/turnserver.conf

echo "####################################################"
cat /etc/turnserver.conf
echo "####################################################"

turnserver --log-file=stdout