Skip to content

Commit 6467984

Browse files
committed
Test relay candidates (#35)
1 parent 4601bbb commit 6467984

File tree

4 files changed

+465
-78
lines changed

4 files changed

+465
-78
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ jobs:
3737
elixir-version: ${{matrix.elixir}}
3838
- run: mix deps.get
3939
- run: mix coveralls.json
40-
- uses: codecov/codecov-action@v3
40+
- uses: codecov/codecov-action@v4
41+
with:
42+
token: ${{ secrets.CODECOV_TOKEN }}

lib/ex_ice/priv/candidate.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ defmodule ExICE.Priv.Candidate do
4545
2 ** 24 * type_preference + 2 ** 8 * local_preference + 2 ** 0 * (256 - 1)
4646
end
4747

48-
@spec foundation(type(), :inet.ip_address(), :inet.ip_address() | nil, atom()) :: integer()
48+
@spec foundation(type(), :inet.ip_address() | String.t(), :inet.ip_address() | nil, atom()) ::
49+
integer()
4950
def foundation(type, ip, stun_turn_ip, transport) do
5051
{type, ip, stun_turn_ip, transport}
5152
|> then(&inspect(&1))

lib/ex_ice/priv/ice_agent.ex

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ defmodule ExICE.Priv.ICEAgent do
6565
eoc: false,
6666
# {did we nominate pair, pair id}
6767
nominating?: {false, nil},
68-
sockets: MapSet.new(),
68+
sockets: [],
6969
local_cands: %{},
7070
remote_cands: %{},
7171
stun_servers: [],
@@ -213,9 +213,7 @@ defmodule ExICE.Priv.ICEAgent do
213213
def gather_candidates(
214214
%__MODULE__{gathering_state: :new, ice_transport_policy: :all} = ice_agent
215215
) do
216-
Logger.debug("Gathering state change: #{ice_agent.gathering_state} -> gathering")
217-
notify(ice_agent.on_gathering_state_change, {:gathering_state_change, :gathering})
218-
ice_agent = %{ice_agent | gathering_state: :gathering}
216+
ice_agent = change_gathering_state(ice_agent, :gathering)
219217

220218
{:ok, sockets} = Gatherer.open_sockets(ice_agent.gatherer)
221219
host_cands = Gatherer.gather_host_candidates(ice_agent.gatherer, sockets)
@@ -247,7 +245,7 @@ defmodule ExICE.Priv.ICEAgent do
247245
def gather_candidates(
248246
%__MODULE__{gathering_state: :new, ice_transport_policy: :relay} = ice_agent
249247
) do
250-
change_gathering_state(ice_agent, :gathering)
248+
ice_agent = change_gathering_state(ice_agent, :gathering)
251249

252250
{:ok, sockets} = Gatherer.open_sockets(ice_agent.gatherer)
253251

@@ -734,6 +732,10 @@ defmodule ExICE.Priv.ICEAgent do
734732
{_socket, {src_ip, src_port}} = tr_id
735733

736734
case ExTURN.Client.handle_message(tr.client, {:socket_data, src_ip, src_port, packet}) do
735+
{:ok, client} ->
736+
tr = %{tr | client: client}
737+
put_in(ice_agent.gathering_transactions[tr_id], tr)
738+
737739
{:allocation_created, {alloc_ip, alloc_port}, client} ->
738740
tr = %{tr | client: client, state: :complete}
739741

@@ -1921,14 +1923,16 @@ defmodule ExICE.Priv.ICEAgent do
19211923

19221924
defp send_keepalive(ice_agent, pair) do
19231925
type = %Type{class: :indication, method: :binding}
1926+
local_cand = Map.fetch!(ice_agent.local_cands, pair.local_cand_id)
1927+
remote_cand = Map.fetch!(ice_agent.remote_cands, pair.remote_cand_id)
19241928

19251929
req =
19261930
type
19271931
|> Message.new()
19281932
|> Message.with_fingerprint()
19291933

1930-
dst = {pair.remote_cand.address, pair.remote_cand.port}
1931-
{_result, ice_agent} = do_send(ice_agent, pair.local_cand, dst, Message.encode(req))
1934+
dst = {remote_cand.address, remote_cand.port}
1935+
{_result, ice_agent} = do_send(ice_agent, local_cand, dst, Message.encode(req))
19321936
ice_agent
19331937
end
19341938

0 commit comments

Comments
 (0)