@@ -12,30 +12,60 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
1212 def handle_conn_check_request ( ice_agent , pair , msg , nil ) do
1313 # TODO use triggered check queue
1414 case Checklist . find_pair ( ice_agent . checklist , pair ) do
15- nil ->
15+ nil when ice_agent . state in [ :completed , :failed ] ->
16+ # This is to make sure we won't add a new pair with prflx candidate
17+ # after we have moved to the completed or failed state.
18+ # Alternatively, we could answer with error message.
19+ Logger . warning ( """
20+ Received conn check request for non-existing pair in unexpected state: #{ ice_agent . state } . Ignoring\
21+ """ )
22+
23+ ice_agent
24+
25+ nil when ice_agent . state in [ :new , :checking , :connected ] ->
1626 Logger . debug ( "Adding new candidate pair: #{ inspect ( pair ) } " )
1727 checklist = Map . put ( ice_agent . checklist , pair . id , pair )
1828 ice_agent = % ICEAgent { ice_agent | checklist: checklist }
1929 ICEAgent . send_binding_success_response ( ice_agent , pair , msg )
2030
2131 % CandidatePair { } = checklist_pair ->
22- checklist_pair =
23- if checklist_pair . state == :failed do
24- % CandidatePair { checklist_pair | state: :waiting , last_seen: pair . last_seen }
25- else
26- % CandidatePair { checklist_pair | last_seen: pair . last_seen }
27- end
28-
29- ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
30- ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
32+ cond do
33+ checklist_pair . state == :failed and ice_agent . state in [ :failed , :completed ] ->
34+ # update last seen so we can observe that something is received but don't reply
35+ # as we are in the failed state
36+ checklist_pair = % CandidatePair { checklist_pair | last_seen: pair . last_seen }
37+ put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
38+
39+ checklist_pair . state == :failed ->
40+ checklist_pair = % CandidatePair {
41+ checklist_pair
42+ | state: :waiting ,
43+ last_seen: pair . last_seen
44+ }
45+
46+ ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
47+ ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
48+
49+ true ->
50+ checklist_pair = % CandidatePair { checklist_pair | last_seen: pair . last_seen }
51+ ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
52+ ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
53+ end
3154 end
3255 end
3356
3457 @ impl true
3558 def handle_conn_check_request ( ice_agent , pair , msg , % UseCandidate { } ) do
3659 # TODO use triggered check queue
3760 case Checklist . find_pair ( ice_agent . checklist , pair ) do
38- nil ->
61+ nil when ice_agent . state in [ :completed , :failed ] ->
62+ Logger . warning ( """
63+ Received conn check request for non-existing pair in unexpected state: #{ ice_agent . state } . Ignoring\
64+ """ )
65+
66+ ice_agent
67+
68+ nil when ice_agent . state in [ :new , :checking , :connected ] ->
3969 Logger . debug ( """
4070 Adding new candidate pair that will be nominated after \
4171 successful conn check: #{ inspect ( pair . id ) } \
@@ -47,20 +77,21 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
4777 ice_agent = % ICEAgent { ice_agent | checklist: checklist }
4878 ICEAgent . send_binding_success_response ( ice_agent , pair , msg )
4979
50- % CandidatePair { state: :succeeded } = checklist_pair ->
80+ % CandidatePair { state: :succeeded } = checklist_pair when ice_agent . state != :failed ->
5181 discovered_pair = Map . fetch! ( ice_agent . checklist , checklist_pair . discovered_pair_id )
5282 discovered_pair = % CandidatePair { discovered_pair | last_seen: pair . last_seen }
5383 ice_agent = put_in ( ice_agent . checklist [ discovered_pair . id ] , discovered_pair )
5484
55- if ice_agent . selected_pair_id == nil do
85+ if ice_agent . selected_pair_id != discovered_pair . id do
5686 Logger . debug ( "Nomination request on pair: #{ discovered_pair . id } ." )
5787 update_nominated_flag ( ice_agent , discovered_pair . id , true )
5888 else
5989 ice_agent
6090 end
6191 |> ICEAgent . send_binding_success_response ( discovered_pair , msg )
6292
63- % CandidatePair { state: :failed } = checklist_pair ->
93+ % CandidatePair { state: :failed } = checklist_pair
94+ when ice_agent . state not in [ :completed , :failed ] ->
6495 Logger . debug ( """
6596 Nomination request on failed pair. Re-scheduling pair for conn-check.
6697 We will nominate pair once conn check passes.
@@ -77,7 +108,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
77108 ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
78109 ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
79110
80- % CandidatePair { } = checklist_pair ->
111+ % CandidatePair { } = checklist_pair when ice_agent . state not in [ :completed , :failed ] ->
81112 Logger . debug ( """
82113 Nomination request on pair that hasn't been verified yet.
83114 We will nominate pair once conn check passes.
@@ -92,6 +123,10 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
92123
93124 ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
94125 ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
126+
127+ % CandidatePair { } = checklist_pair ->
128+ checklist_pair = % CandidatePair { checklist_pair | last_seen: pair . last_seen }
129+ put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
95130 end
96131 end
97132
0 commit comments