Skip to content

Commit 2d44376

Browse files
committed
Don't close candidate on eperm
1 parent 4854d81 commit 2d44376

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

lib/ex_ice/priv/checklist.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ defmodule ExICE.Priv.Checklist do
2929
def get_valid_pair(checklist) do
3030
checklist
3131
|> Stream.map(fn {_id, pair} -> pair end)
32-
# pair might have been marked as failed if the associated
33-
# local candidate has been closed
34-
|> Stream.filter(fn pair -> pair.state == :succeeded end)
3532
|> Stream.filter(fn pair -> pair.valid? end)
3633
|> Enum.sort_by(fn pair -> pair.priority end, :desc)
3734
|> Enum.at(0)
@@ -89,7 +86,7 @@ defmodule ExICE.Priv.Checklist do
8986
def close_candidate(checklist, local_cand) do
9087
Enum.reduce(checklist, {[], checklist}, fn {pair_id, pair}, {failed_pair_ids, checklist} ->
9188
if pair.local_cand_id == local_cand.base.id and pair.state != :failed do
92-
checklist = Map.put(checklist, pair_id, %{pair | state: :failed})
89+
checklist = Map.put(checklist, pair_id, %{pair | state: :failed, valid?: false})
9390
{[pair_id | failed_pair_ids], checklist}
9491
else
9592
{failed_pair_ids, checklist}

lib/ex_ice/priv/ice_agent.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3085,7 +3085,7 @@ defmodule ExICE.Priv.ICEAgent do
30853085
""")
30863086

30873087
ice_agent = put_in(ice_agent.local_cands[local_cand.base.id], local_cand)
3088-
ice_agent = close_candidate(ice_agent, local_cand)
3088+
30893089
{:error, ice_agent}
30903090
end
30913091
end

test/priv/ice_agent_test.exs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,8 +2492,8 @@ defmodule ExICE.Priv.ICEAgentTest do
24922492
test "candidate fails to send data when ice is connected" do
24932493
# 1. make ice agent connected
24942494
# 2. replace candidate with the mock one that always fails to send data
2495-
# 3. assert that after unsuccessful data sending, ice_agent moves to the failed state
2496-
# as there are no other pairs
2495+
# 3. assert that after unsuccessful data sending, ice_agent doesn't move to the failed state
2496+
# even when there is only one pair
24972497

24982498
ice_agent =
24992499
ICEAgent.new(
@@ -2519,10 +2519,18 @@ defmodule ExICE.Priv.ICEAgentTest do
25192519
# try to send some data
25202520
ice_agent = ICEAgent.send_data(ice_agent, "somedata")
25212521

2522-
# assert that local cand has been closed and the agent moved to the failed state
2523-
assert [%{base: %{closed?: true}}] = Map.values(ice_agent.local_cands)
2524-
assert ice_agent.state == :failed
2525-
assert [%{state: :failed}] = Map.values(ice_agent.checklist)
2522+
# assert that the local candidate hasn't been closed and that the agent hasn't moved to a failed state
2523+
assert [%{base: %{closed?: false}}] = Map.values(ice_agent.local_cands)
2524+
assert ice_agent.state == :connected
2525+
2526+
# assert that the local candidate's state was updated after the packet was discarded
2527+
assert [
2528+
%{
2529+
state: :succeeded,
2530+
packets_discarded_on_send: 1,
2531+
bytes_discarded_on_send: 8
2532+
}
2533+
] = Map.values(ice_agent.checklist)
25262534
end
25272535

25282536
test "relay connection" do

0 commit comments

Comments
 (0)