Skip to content
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
name: lint OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
otp: ['26']
elixir: ['1.15']
otp: ['29']
elixir: ['1.20']
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
Expand All @@ -24,8 +24,8 @@ jobs:
name: test OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
strategy:
matrix:
otp: ['26']
elixir: ['1.15']
otp: ['29']
elixir: ['1.20']
env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -39,4 +39,4 @@ jobs:
- run: mix coveralls.json
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion lib/ex_ice/ice_agent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ defmodule ExICE.ICEAgent do
@doc """
Gets agent's role.
"""
@spec get_role(pid()) :: ExICE.Agent.t() | nil
@spec get_role(pid()) :: role() | nil
def get_role(ice_agent) do
GenServer.call(ice_agent, :get_role)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/ex_ice/priv/candidate_pair.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule ExICE.Priv.CandidatePair do
@moduledoc false
require Logger

alias ExICE.Priv.{Candidate, Utils}

Expand Down Expand Up @@ -62,8 +61,9 @@ defmodule ExICE.Priv.CandidatePair do
]

@doc false
@spec new(Candidate.t(), Candidate.t(), ExICE.ICEAgent.role(), state(), valid?: boolean()) ::
t()
@spec new(Candidate.t(), Candidate.t(), ExICE.ICEAgent.role(), state(), [
{:valid?, boolean()} | {:last_seen, integer()}
]) :: t()
def new(local_cand, remote_cand, agent_role, state, opts \\ []) do
priority = priority(agent_role, local_cand.base.priority, remote_cand.priority)

Expand Down Expand Up @@ -94,8 +94,8 @@ defmodule ExICE.Priv.CandidatePair do

@doc false
@spec recompute_priority(t(), integer(), integer(), ExICE.ICEAgent.role()) :: t()
def recompute_priority(pair, local_cand_prio, remote_cand_prio, role) do
%__MODULE__{pair | priority: priority(role, local_cand_prio, remote_cand_prio)}
def recompute_priority(%__MODULE__{} = pair, local_cand_prio, remote_cand_prio, role) do
%{pair | priority: priority(role, local_cand_prio, remote_cand_prio)}
end

@doc false
Expand Down
4 changes: 2 additions & 2 deletions lib/ex_ice/priv/checklist.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ defmodule ExICE.Priv.Checklist do

@spec timeout_pairs(t(), [integer()]) :: t()
def timeout_pairs(checklist, ids) do
for {_id, pair} <- checklist, into: %{} do
for {_id, %CandidatePair{} = pair} <- checklist, into: %{} do
if pair.id in ids do
{pair.id, %CandidatePair{pair | valid?: false, state: :failed}}
{pair.id, %{pair | valid?: false, state: :failed}}
else
{pair.id, pair}
end
Expand Down
34 changes: 17 additions & 17 deletions lib/ex_ice/priv/conn_check_handler/controlled.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do

nil when ice_agent.state in [:new, :checking, :connected] ->
Logger.debug("Adding new candidate pair: #{inspect(pair)}")
pair = %CandidatePair{pair | requests_received: 1}
pair = %{pair | requests_received: 1}
checklist = Map.put(ice_agent.checklist, pair.id, pair)
ice_agent = %ICEAgent{ice_agent | checklist: checklist}
ice_agent = %{ice_agent | checklist: checklist}
ICEAgent.send_binding_success_response(ice_agent, pair, msg)

%CandidatePair{} = checklist_pair ->
cond do
ice_agent.state == :failed ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| last_seen: pair.last_seen,
requests_received: r_pair.requests_received + 1
Expand All @@ -45,7 +45,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
checklist_pair.state == :failed and ice_agent.state == :completed ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| last_seen: pair.last_seen,
requests_received: r_pair.requests_received + 1
Expand All @@ -56,7 +56,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
checklist_pair.state == :failed ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| state: :waiting,
last_seen: pair.last_seen,
Expand All @@ -69,7 +69,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
true ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| last_seen: pair.last_seen,
requests_received: r_pair.requests_received + 1
Expand Down Expand Up @@ -98,16 +98,16 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
successful conn check: #{inspect(pair.id)}\
""")

pair = %CandidatePair{pair | nominate?: true, requests_received: 1}
pair = %{pair | nominate?: true, requests_received: 1}
checklist = Map.put(ice_agent.checklist, pair.id, pair)

ice_agent = %ICEAgent{ice_agent | checklist: checklist}
ice_agent = %{ice_agent | checklist: checklist}
ICEAgent.send_binding_success_response(ice_agent, pair, msg)

%CandidatePair{state: :succeeded} = checklist_pair when ice_agent.state != :failed ->
discovered_pair = Map.fetch!(ice_agent.checklist, checklist_pair.discovered_pair_id)

discovered_pair = %CandidatePair{
discovered_pair = %{
discovered_pair
| last_seen: pair.last_seen,
requests_received: discovered_pair.requests_received + 1
Expand All @@ -133,7 +133,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
Pair: #{inspect(pair.id)}
""")

r_pair = %CandidatePair{
r_pair = %{
r_pair
| nominate?: true,
last_seen: pair.last_seen,
Expand All @@ -151,7 +151,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
Pair: #{inspect(checklist_pair.id)}
""")

checklist_pair = %CandidatePair{
checklist_pair = %{
checklist_pair
| nominate?: true,
last_seen: pair.last_seen,
Expand All @@ -164,7 +164,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
%CandidatePair{} = checklist_pair ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| last_seen: pair.last_seen,
requests_received: r_pair.requests_received + 1
Expand All @@ -182,22 +182,22 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
Logger.debug("Nomination succeeded, pair: #{pair_id}")

pair = Map.fetch!(ice_agent.checklist, pair_id)
pair = %CandidatePair{pair | nominate?: false, nominated?: true}
pair = %{pair | nominate?: false, nominated?: true}

checklist = Map.put(ice_agent.checklist, pair.id, pair)
ice_agent = %ICEAgent{ice_agent | checklist: checklist}
ice_agent = %{ice_agent | checklist: checklist}

cond do
ice_agent.selected_pair_id == nil ->
Logger.debug("Selecting pair: #{pair_id}")

%ICEAgent{
%{
ice_agent
| selected_pair_id: pair.id,
selected_candidate_pair_changes: ice_agent.selected_candidate_pair_changes + 1
}

ice_agent.selected_pair_id != nil and pair.id != ice_agent.selected_pair_id ->
pair.id != ice_agent.selected_pair_id ->
selected_pair = Map.fetch!(ice_agent.checklist, ice_agent.selected_pair_id)

if pair.priority >= selected_pair.priority do
Expand All @@ -206,7 +206,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
New pair: #{pair_id}, old pair: #{ice_agent.selected_pair_id}.\
""")

%ICEAgent{
%{
ice_agent
| selected_pair_id: pair.id,
selected_candidate_pair_changes: ice_agent.selected_candidate_pair_changes + 1
Expand Down
22 changes: 11 additions & 11 deletions lib/ex_ice/priv/conn_check_handler/controlling.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlling do

nil when ice_agent.state in [:new, :checking, :connected] ->
Logger.debug("Adding new candidate pair: #{inspect(pair)}")
pair = %CandidatePair{pair | requests_received: 1}
pair = %{pair | requests_received: 1}
checklist = Map.put(ice_agent.checklist, pair.id, pair)
ice_agent = %ICEAgent{ice_agent | checklist: checklist}
ice_agent = %{ice_agent | checklist: checklist}
ICEAgent.send_binding_success_response(ice_agent, pair, msg)

%CandidatePair{} = checklist_pair ->
cond do
ice_agent.state == :failed ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| last_seen: pair.last_seen,
requests_received: r_pair.requests_received + 1
Expand All @@ -57,7 +57,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlling do
checklist_pair.state == :failed and ice_agent.state == :completed ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| last_seen: pair.last_seen,
requests_received: r_pair.requests_received + 1
Expand All @@ -68,7 +68,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlling do
checklist_pair.state == :failed ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| state: :waiting,
last_seen: pair.last_seen,
Expand All @@ -81,7 +81,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlling do
true ->
r_pair = resolve_pair(ice_agent, checklist_pair)

r_pair = %CandidatePair{
r_pair = %{
r_pair
| last_seen: pair.last_seen,
requests_received: r_pair.requests_received + 1
Expand All @@ -106,21 +106,21 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlling do
Logger.debug("Nomination succeeded. Selecting pair: #{inspect(pair_id)}")

pair = Map.fetch!(ice_agent.checklist, pair_id)
pair = %CandidatePair{pair | nominate?: false, nominated?: true}
pair = %{pair | nominate?: false, nominated?: true}
ice_agent = put_in(ice_agent.checklist[pair.id], pair)

ice_agent =
cond do
ice_agent.selected_pair_id == nil ->
Logger.debug("Selecting pair: #{pair_id}")

%ICEAgent{
%{
ice_agent
| selected_pair_id: pair.id,
selected_candidate_pair_changes: ice_agent.selected_candidate_pair_changes + 1
}

ice_agent.selected_pair_id != nil and pair.id != ice_agent.selected_pair_id ->
pair.id != ice_agent.selected_pair_id ->
selected_pair = Map.fetch!(ice_agent.checklist, ice_agent.selected_pair_id)

if pair.priority >= selected_pair.priority do
Expand All @@ -129,7 +129,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlling do
New pair: #{pair_id}, old pair: #{ice_agent.selected_pair_id}.\
""")

%ICEAgent{
%{
ice_agent
| selected_pair_id: pair.id,
selected_candidate_pair_changes: ice_agent.selected_candidate_pair_changes + 1
Expand All @@ -150,7 +150,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlling do
Logger.warning("Nomination succeeded but checklist hasn't finished.")
end

%ICEAgent{ice_agent | nominating?: {false, nil}}
%{ice_agent | nominating?: {false, nil}}
end

defp resolve_pair(ice_agent, pair) do
Expand Down
7 changes: 4 additions & 3 deletions lib/ex_ice/priv/gatherer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defmodule ExICE.Priv.Gatherer do

require Logger

@type local_preferences :: %{:inet.ip_address() => non_neg_integer()}

@type t() :: %__MODULE__{
if_discovery_module: module(),
transport_module: module(),
Expand Down Expand Up @@ -95,9 +97,8 @@ defmodule ExICE.Priv.Gatherer do
end)
end

@spec gather_host_candidates(t(), %{:inet.ip_address() => non_neg_integer()}, [
{Transport.socket(), map()}
]) :: [Candidate.t()]
@spec gather_host_candidates(t(), local_preferences(), [{Transport.socket(), map()}]) ::
{local_preferences(), [Candidate.t()]}
def gather_host_candidates(gatherer, local_preferences, sockets) do
{local_preferences, cands} =
Enum.reduce(sockets, {local_preferences, []}, fn socket, {local_preferences, cands} ->
Expand Down
Loading
Loading