Skip to content

Commit 127b5c4

Browse files
committed
Improve Ta timer
1 parent 0175dd8 commit 127b5c4

File tree

4 files changed

+225
-184
lines changed

4 files changed

+225
-184
lines changed

lib/conn_check_handler.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ defmodule ExICE.ConnCheckHandler do
44
alias ExICE.CandidatePair
55
alias ExICE.Attribute.UseCandidate
66

7-
@doc """
8-
Called when timer Ta fires and a new checklist transaction can be performed.
9-
"""
10-
@callback handle_checklist(ice_agent :: map()) :: map()
11-
127
@doc """
138
Called when conn check request arrives.
149
"""

lib/controlled_handler.ex

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,6 @@ defmodule ExICE.ControlledHandler do
88
alias ExICE.{CandidatePair, Checklist, ICEAgent}
99
alias ExICE.Attribute.UseCandidate
1010

11-
@impl true
12-
def handle_checklist(state) do
13-
case Checklist.get_next_pair(state.checklist) do
14-
%CandidatePair{} = pair ->
15-
Logger.debug("Sending conn check on pair: #{inspect(pair.id)}")
16-
{pair, state} = ICEAgent.send_conn_check(pair, state)
17-
put_in(state, [:checklist, pair.id], pair)
18-
19-
nil ->
20-
cond do
21-
# if we knew, the other side uses regular nomination
22-
# we would move to the completed state as soon as we
23-
# received nomination request but because we don't
24-
# know wheter the other side uses regular or aggressive
25-
# nomination we have to be prepared for the case
26-
# where there is selected pair and we are not in the completed
27-
Checklist.finished?(state.checklist) and state.gathering_state == :complete and
28-
state.selected_pair != nil and state.eoc == true ->
29-
Logger.debug("""
30-
Finished all conn checks, there won't be any further local or remote candidates
31-
and we have selected pair. Changing connection state to completed.
32-
""")
33-
34-
ICEAgent.change_connection_state(:completed, state)
35-
36-
# if we know, there are won't be any remote (eoc==true) and
37-
# local (gathering_state==complete) candidates, we finished
38-
# performing all conn checks and there is no selected or valid pair
39-
# (state.state==checking), move to the failed state
40-
Checklist.finished?(state.checklist) and state.gathering_state == :complete and
41-
state.eoc == true and state.state == :checking ->
42-
Logger.debug("""
43-
Finished all conn checks, there won't be any further local or remote candidates
44-
and we don't have any valid or selected pair. Changing connection state to failed.
45-
""")
46-
47-
ICEAgent.change_connection_state(:failed, state)
48-
49-
true ->
50-
state
51-
end
52-
end
53-
end
54-
5511
@impl true
5612
def handle_conn_check_request(state, pair, msg, nil, key) do
5713
ICEAgent.send_binding_success_response(pair, msg, key)
@@ -139,27 +95,6 @@ defmodule ExICE.ControlledHandler do
13995
state
14096
end
14197

142-
checklist_finished? =
143-
not (Checklist.in_progress?(state.checklist) or Checklist.waiting?(state.checklist))
144-
145-
state =
146-
if state.eoc and checklist_finished? and state.gathering_state == :complete and
147-
state.state != :completed do
148-
# Assuming the controlling side uses regulard nomination,
149-
# the controlled side could move to the completed
150-
# state as soon as it receives nomination request (or after
151-
# successful triggered check caused by nomination request).
152-
# However, to be compatible with the older RFC's aggresive
153-
# nomination, we wait for the end-of-candidates indication
154-
# and checklist to be finished.
155-
# This also means, that if the other side never sets eoc,
156-
# we will never move to the completed state.
157-
# This seems to be compliant with libwebrtc.
158-
ICEAgent.change_connection_state(:completed, state)
159-
else
160-
state
161-
end
162-
16398
checklist =
16499
Map.update!(state.checklist, pair_id, fn pair ->
165100
%CandidatePair{pair | nominate?: false, nominated?: true}

lib/controlling_handler.ex

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,6 @@ defmodule ExICE.ControllingHandler do
77
alias ExICE.{CandidatePair, Checklist, ICEAgent}
88
alias ExICE.Attribute.UseCandidate
99

10-
@impl true
11-
def handle_checklist(%{nominating?: {true, pair_id}} = state) do
12-
case Map.fetch!(state.checklist, pair_id) do
13-
%CandidatePair{valid?: false, state: :failed} ->
14-
# pair that we tried to nominate timed out
15-
Logger.debug("""
16-
Pair we tried to nominate failed. Changing connection state to failed. Pair id: #{pair_id}.\
17-
""")
18-
19-
ICEAgent.change_connection_state(:failed, state)
20-
21-
_ ->
22-
state
23-
end
24-
end
25-
26-
@impl true
27-
def handle_checklist(state) do
28-
case Checklist.get_next_pair(state.checklist) do
29-
%CandidatePair{} = pair ->
30-
Logger.debug("Sending conn check on pair: #{inspect(pair.id)}")
31-
{pair, state} = ICEAgent.send_conn_check(pair, state)
32-
put_in(state, [:checklist, pair.id], pair)
33-
34-
nil ->
35-
if ICEAgent.time_to_nominate?(state) do
36-
Logger.debug("Time to nominate a pair! Looking for a best valid pair...")
37-
ICEAgent.try_nominate(state)
38-
else
39-
state
40-
end
41-
end
42-
end
43-
4410
@impl true
4511
def handle_conn_check_request(state, pair, msg, %UseCandidate{}, _key) do
4612
Logger.debug("""
@@ -96,7 +62,6 @@ defmodule ExICE.ControllingHandler do
9662
state
9763
| checklist: checklist,
9864
nominating?: {false, nil},
99-
state: :completed,
10065
selected_pair: Map.fetch!(checklist, pair_id)
10166
}
10267
end

0 commit comments

Comments
 (0)