Skip to content

Commit

Permalink
Change project name to Rel
Browse files Browse the repository at this point in the history
  • Loading branch information
LVala committed Aug 9, 2023
1 parent f8fef56 commit c20e54a
Show file tree
Hide file tree
Showing 26 changed files with 73 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ RUN apk add --no-cache --update libncursesw openssl libstdc++

WORKDIR /app

COPY --from=build /app/_build/prod/rel/ex_turn ./
COPY --from=build /app/_build/prod/rel/rel ./

CMD ["bin/ex_turn", "start"]
CMD ["bin/rel", "start"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ExTURN
# Rel

TURN server.

Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Config

config :ex_turn,
config :rel,
# 1 day in seconds, see https://datatracker.ietf.org/doc/html/draft-uberti-rtcweb-turn-rest-00#section-2.2
credentials_lifetime: 24 * 60 * 60,
# 10 minutes in seconds
Expand Down
2 changes: 1 addition & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Config

# FIXME: temporary, as `:credentials_lifetime` is a compile time variable atm
config :ex_turn, :credentials_lifetime, 3 * 24 * 24
config :rel, :credentials_lifetime, 3 * 24 * 24
8 changes: 4 additions & 4 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ external_relay_ip =
end

# AuthProvider/credentials configuration
config :ex_turn,
config :rel,
auth_provider_ip:
System.get_env("AUTH_PROVIDER_IP", "127.0.0.1") |> ConfigUtils.parse_ip_address(),
auth_provider_port: System.get_env("AUTH_PROVIDER_PORT", "4000") |> ConfigUtils.parse_port(),
Expand All @@ -110,7 +110,7 @@ config :ex_turn,
certfile: certfile

# TURN server configuration
config :ex_turn,
config :rel,
listen_ip: listen_ip,
external_listen_ip: external_listen_ip,
relay_ip: relay_ip,
Expand All @@ -119,11 +119,11 @@ config :ex_turn,
domain_name: System.get_env("DOMAIN_NAME", "example.com")

# Metrics endpoint configuration
config :ex_turn,
config :rel,
metrics_ip: System.get_env("METRICS_IP", "127.0.0.1") |> ConfigUtils.parse_ip_address(),
metrics_port: System.get_env("METRICS_PORT", "9568") |> ConfigUtils.parse_port()

# Automatically generated secrets
config :ex_turn,
config :rel,
auth_secret: :crypto.strong_rand_bytes(64),
nonce_secret: :crypto.strong_rand_bytes(64)
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.2'
services:
turn:
image: ghcr.io/elixir-webrtc/ex_turn:${TAG}
image: ghcr.io/elixir-webrtc/rel:${TAG}
container_name: turn
restart: on-failure
network_mode: host
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.AllocationHandler do
defmodule Rel.AllocationHandler do
@moduledoc false
use GenServer, restart: :transient

Expand All @@ -7,15 +7,15 @@ defmodule ExTURN.AllocationHandler do
alias ExSTUN.Message
alias ExSTUN.Message.Type

alias ExTURN.Auth
alias ExTURN.Attribute.{ChannelNumber, Data, Lifetime, XORPeerAddress}
alias ExTURN.Utils
alias Rel.Auth
alias Rel.Attribute.{ChannelNumber, Data, Lifetime, XORPeerAddress}
alias Rel.Utils

@type five_tuple() ::
{:inet.ip_address(), :inet.port_number(), :inet.ip_address(), :inet.port_number(), :udp}

@permission_lifetime Application.compile_env!(:ex_turn, :permission_lifetime)
@channel_lifetime Application.compile_env!(:ex_turn, :channel_lifetime)
@permission_lifetime Application.compile_env!(:rel, :permission_lifetime)
@channel_lifetime Application.compile_env!(:rel, :channel_lifetime)

@spec start_link(term()) :: GenServer.on_start()
def start_link([five_tuple, alloc_socket | _rest] = args) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.AdditionalAddressFamily do
defmodule Rel.Attribute.AdditionalAddressFamily do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.ChannelNumber do
defmodule Rel.Attribute.ChannelNumber do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.Data do
defmodule Rel.Attribute.Data do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.EvenPort do
defmodule Rel.Attribute.EvenPort do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.Lifetime do
defmodule Rel.Attribute.Lifetime do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.RequestedAddressFamily do
defmodule Rel.Attribute.RequestedAddressFamily do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.RequestedTransport do
defmodule Rel.Attribute.RequestedTransport do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.ReservationToken do
defmodule Rel.Attribute.ReservationToken do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.XORPeerAddress do
defmodule Rel.Attribute.XORPeerAddress do
@moduledoc """
STUN Message Attribute XOR Peer Address
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Attribute.XORRelayedAddress do
defmodule Rel.Attribute.XORRelayedAddress do
@moduledoc false
@behaviour ExSTUN.Message.Attribute

Expand Down
12 changes: 6 additions & 6 deletions lib/ex_turn/auth.ex → lib/rel/auth.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
defmodule ExTURN.Auth do
defmodule Rel.Auth do
@moduledoc false
require Logger

alias ExSTUN.Message
alias ExSTUN.Message.Attribute.{MessageIntegrity, Nonce, Realm, Username}

@nonce_lifetime Application.compile_env!(:ex_turn, :nonce_lifetime)
@credentials_lifetime Application.compile_env!(:ex_turn, :credentials_lifetime)
@nonce_lifetime Application.compile_env!(:rel, :nonce_lifetime)
@credentials_lifetime Application.compile_env!(:rel, :credentials_lifetime)

@spec authenticate(Message.t(), username: String.t()) :: {:ok, binary()} | {:error, atom()}
def authenticate(%Message{} = msg, opts \\ []) do
auth_secret = Application.fetch_env!(:ex_turn, :auth_secret)
auth_secret = Application.fetch_env!(:rel, :auth_secret)

with :ok <- verify_message_integrity(msg),
{:ok, username, nonce} <- verify_attrs_presence(msg),
Expand Down Expand Up @@ -64,7 +64,7 @@ defmodule ExTURN.Auth do
|> :base64.decode()
|> String.split(" ", parts: 2)

nonce_secret = Application.fetch_env!(:ex_turn, :nonce_secret)
nonce_secret = Application.fetch_env!(:rel, :nonce_secret)

is_hash_valid? = hash == :crypto.hash(:sha256, "#{timestamp}:#{nonce_secret}")

Expand All @@ -77,7 +77,7 @@ defmodule ExTURN.Auth do
@spec generate_credentials(String.t() | nil) ::
{username :: String.t(), password :: String.t(), ttl :: non_neg_integer()}
def generate_credentials(username \\ nil) do
auth_secret = Application.fetch_env!(:ex_turn, :auth_secret)
auth_secret = Application.fetch_env!(:rel, :auth_secret)
timestamp = System.os_time(:second) + @credentials_lifetime

username = if is_nil(username), do: "#{timestamp}", else: "#{timestamp}:#{username}"
Expand Down
8 changes: 4 additions & 4 deletions lib/ex_turn/auth_provider.ex → lib/rel/auth_provider.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
defmodule ExTURN.AuthProvider do
defmodule Rel.AuthProvider do
@moduledoc false
# REST service described in https://datatracker.ietf.org/doc/html/draft-uberti-rtcweb-turn-rest-00
use Plug.Router

require Logger

alias ExTURN.Auth
alias Rel.Auth

plug(CORSPlug)
plug(:match)
Expand All @@ -20,8 +20,8 @@ defmodule ExTURN.AuthProvider do
username = Map.get(query_params, "username")
{username, password, ttl} = Auth.generate_credentials(username)

ip_addr = Application.fetch_env!(:ex_turn, :external_listen_ip)
port = Application.fetch_env!(:ex_turn, :listen_port)
ip_addr = Application.fetch_env!(:rel, :external_listen_ip)
port = Application.fetch_env!(:rel, :listen_port)

response =
Jason.encode!(%{
Expand Down
20 changes: 10 additions & 10 deletions lib/ex_turn/listener.ex → lib/rel/listener.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule ExTURN.Listener do
defmodule Rel.Listener do
@moduledoc false
use Task, restart: :permanent

require Logger

alias ExTURN.Attribute.{
alias Rel.Attribute.{
EvenPort,
Lifetime,
RequestedAddressFamily,
Expand All @@ -13,9 +13,9 @@ defmodule ExTURN.Listener do
XORRelayedAddress
}

alias ExTURN.AllocationHandler
alias ExTURN.Auth
alias ExTURN.Utils
alias Rel.AllocationHandler
alias Rel.Auth
alias Rel.Utils

alias ExSTUN.Message
alias ExSTUN.Message.Type
Expand Down Expand Up @@ -46,7 +46,7 @@ defmodule ExTURN.Listener do
]
)

spawn(ExTURN.Monitor, :start, [self(), socket])
spawn(Rel.Monitor, :start, [self(), socket])

recv_loop(socket, %{
listener_id: listener_addr,
Expand Down Expand Up @@ -160,8 +160,8 @@ defmodule ExTURN.Listener do
:ok <- check_even_port(even_port),
{:ok, alloc_port} <- get_available_port(),
{:ok, lifetime} <- Utils.get_lifetime(msg) do
relay_ip = Application.fetch_env!(:ex_turn, :relay_ip)
external_relay_ip = Application.fetch_env!(:ex_turn, :external_relay_ip)
relay_ip = Application.fetch_env!(:rel, :relay_ip)
external_relay_ip = Application.fetch_env!(:rel, :external_relay_ip)

type = %Type{class: :success_response, method: msg.type.method}

Expand Down Expand Up @@ -192,8 +192,8 @@ defmodule ExTURN.Listener do

{:ok, alloc_pid} =
DynamicSupervisor.start_child(
ExTURN.AllocationSupervisor,
{ExTURN.AllocationHandler, [five_tuple, alloc_socket, socket, username, lifetime]}
Rel.AllocationSupervisor,
{Rel.AllocationHandler, [five_tuple, alloc_socket, socket, username, lifetime]}
)

:ok = :gen_udp.controlling_process(alloc_socket, alloc_pid)
Expand Down
2 changes: 1 addition & 1 deletion lib/ex_turn/monitor.ex → lib/rel/monitor.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Monitor do
defmodule Rel.Monitor do
@moduledoc false
require Logger

Expand Down
10 changes: 5 additions & 5 deletions lib/ex_turn/supervisor.ex → lib/rel/supervisor.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Supervisor do
defmodule Rel.Supervisor do
@moduledoc false
use Supervisor

Expand All @@ -9,13 +9,13 @@ defmodule ExTURN.Supervisor do

@impl true
def init(_arg) do
listen_ip = Application.fetch_env!(:ex_turn, :listen_ip)
listen_port = Application.fetch_env!(:ex_turn, :listen_port)
listen_ip = Application.fetch_env!(:rel, :listen_ip)
listen_port = Application.fetch_env!(:rel, :listen_port)

children = [
{DynamicSupervisor, strategy: :one_for_one, name: ExTURN.AllocationSupervisor},
{DynamicSupervisor, strategy: :one_for_one, name: Rel.AllocationSupervisor},
{Registry, keys: :unique, name: Registry.Allocations},
{ExTURN.Listener, [listen_ip, listen_port]}
{Rel.Listener, [listen_ip, listen_port]}
]

Supervisor.init(children, strategy: :one_for_all)
Expand Down
12 changes: 6 additions & 6 deletions lib/ex_turn/utils.ex → lib/rel/utils.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.Utils do
defmodule Rel.Utils do
@moduledoc false
require Logger

Expand All @@ -7,10 +7,10 @@ defmodule ExTURN.Utils do
alias ExSTUN.Message.Type
alias ExSTUN.Message.Attribute.{ErrorCode, Nonce, Realm}

alias ExTURN.Attribute.Lifetime
alias Rel.Attribute.Lifetime

@default_lifetime Application.compile_env!(:ex_turn, :default_allocation_lifetime)
@max_lifetime Application.compile_env!(:ex_turn, :max_allocation_lifetime)
@default_lifetime Application.compile_env!(:rel, :default_allocation_lifetime)
@max_lifetime Application.compile_env!(:rel, :max_allocation_lifetime)

@spec get_lifetime(Message.t()) :: {:ok, integer()} | {:error, :invalid_lifetime}
def get_lifetime(msg) do
Expand All @@ -32,7 +32,7 @@ defmodule ExTURN.Utils do
@spec build_error(atom(), integer(), Method.t()) ::
{response :: binary(), log_msg :: String.t()}
def build_error(reason, t_id, method) do
domain_name = Application.fetch_env!(:ex_turn, :domain_name)
domain_name = Application.fetch_env!(:rel, :domain_name)
{log_msg, code, with_attrs?} = translate_error(reason)
error_type = %Type{class: :error_response, method: method}

Expand All @@ -55,7 +55,7 @@ defmodule ExTURN.Utils do

defp build_nonce() do
# inspired by https://datatracker.ietf.org/doc/html/rfc7616#section-5.4
nonce_secret = Application.fetch_env!(:ex_turn, :nonce_secret)
nonce_secret = Application.fetch_env!(:rel, :nonce_secret)
timestamp = System.monotonic_time(:nanosecond)
hash = :crypto.hash(:sha256, "#{timestamp}:#{nonce_secret}")
"#{timestamp} #{hash}" |> :base64.encode()
Expand Down
22 changes: 11 additions & 11 deletions lib/ex_turn_app.ex → lib/rel_app.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTURN.App do
defmodule Rel.App do
@moduledoc false
use Application

Expand All @@ -8,16 +8,16 @@ defmodule ExTURN.App do

@impl true
def start(_, _) do
Logger.info("Starting ExTURN v#{@version}")
Logger.info("Starting Rel v#{@version}")

auth_provider_ip = Application.fetch_env!(:ex_turn, :auth_provider_ip)
auth_provider_port = Application.fetch_env!(:ex_turn, :auth_provider_port)
use_tls? = Application.fetch_env!(:ex_turn, :auth_provider_use_tls?)
keyfile = Application.fetch_env!(:ex_turn, :keyfile)
certfile = Application.fetch_env!(:ex_turn, :certfile)
auth_provider_ip = Application.fetch_env!(:rel, :auth_provider_ip)
auth_provider_port = Application.fetch_env!(:rel, :auth_provider_port)
use_tls? = Application.fetch_env!(:rel, :auth_provider_use_tls?)
keyfile = Application.fetch_env!(:rel, :keyfile)
certfile = Application.fetch_env!(:rel, :certfile)

metrics_ip = Application.fetch_env!(:ex_turn, :metrics_ip)
metrics_port = Application.fetch_env!(:ex_turn, :metrics_port)
metrics_ip = Application.fetch_env!(:rel, :metrics_ip)
metrics_port = Application.fetch_env!(:rel, :metrics_port)

scheme_opts =
if use_tls? do
Expand All @@ -31,11 +31,11 @@ defmodule ExTURN.App do
end

children = [
ExTURN.Supervisor,
Rel.Supervisor,
{TelemetryMetricsPrometheus,
metrics: metrics(), plug_cowboy_opts: [ip: metrics_ip, port: metrics_port]},
{Bandit,
[plug: ExTURN.AuthProvider, ip: auth_provider_ip, port: auth_provider_port] ++ scheme_opts}
[plug: Rel.AuthProvider, ip: auth_provider_ip, port: auth_provider_port] ++ scheme_opts}
]

Logger.info(
Expand Down
Loading

0 comments on commit c20e54a

Please sign in to comment.