Skip to content

Commit

Permalink
Include related address and port in marshaled candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Sep 18, 2024
1 parent 68b734e commit dabeee8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/ex_ice/candidate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,19 @@ defmodule ExICE.Candidate do
transport = transport_to_string(transport)
address = address_to_string(address)

"#{foundation} #{component_id} #{transport} #{priority} #{address} #{port} typ #{type}"
# This is based on RFC 8839 sec. 5.1.
# Reflexive candidates MUST contain rel-addr and rel-port.
# However, for security reasons, we always use "0.0.0.0"
# (or "::" for ipv6) as rel-addr and "9" as rel-port.
related_addr =
cond do
type == :host -> ""
ExICE.Priv.Utils.family(address) == :ipv4 -> "raddr 0.0.0.0 rport 9"
ExICE.Priv.Utils.family(address) == :ipv6 -> "raddr :: rport 9"
end

"#{foundation} #{component_id} #{transport} #{priority} #{address} #{port} typ #{type} #{related_addr}"
|> String.trim()
end

@spec unmarshal(String.t()) :: {:ok, t()} | {:error, term()}
Expand Down Expand Up @@ -100,6 +112,7 @@ defmodule ExICE.Candidate do

defp address_to_string(address) when is_binary(address), do: address
defp address_to_string(address), do: :inet.ntoa(address)

defp transport_to_string(:udp), do: "UDP"

defp parse_transport("udp"), do: {:ok, :udp}
Expand Down

0 comments on commit dabeee8

Please sign in to comment.