@@ -12,30 +12,60 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
12
12
def handle_conn_check_request ( ice_agent , pair , msg , nil ) do
13
13
# TODO use triggered check queue
14
14
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 ] ->
16
26
Logger . debug ( "Adding new candidate pair: #{ inspect ( pair ) } " )
17
27
checklist = Map . put ( ice_agent . checklist , pair . id , pair )
18
28
ice_agent = % ICEAgent { ice_agent | checklist: checklist }
19
29
ICEAgent . send_binding_success_response ( ice_agent , pair , msg )
20
30
21
31
% 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
31
54
end
32
55
end
33
56
34
57
@ impl true
35
58
def handle_conn_check_request ( ice_agent , pair , msg , % UseCandidate { } ) do
36
59
# TODO use triggered check queue
37
60
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 ] ->
39
69
Logger . debug ( """
40
70
Adding new candidate pair that will be nominated after \
41
71
successful conn check: #{ inspect ( pair . id ) } \
@@ -47,20 +77,21 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
47
77
ice_agent = % ICEAgent { ice_agent | checklist: checklist }
48
78
ICEAgent . send_binding_success_response ( ice_agent , pair , msg )
49
79
50
- % CandidatePair { state: :succeeded } = checklist_pair ->
80
+ % CandidatePair { state: :succeeded } = checklist_pair when ice_agent . state != :failed ->
51
81
discovered_pair = Map . fetch! ( ice_agent . checklist , checklist_pair . discovered_pair_id )
52
82
discovered_pair = % CandidatePair { discovered_pair | last_seen: pair . last_seen }
53
83
ice_agent = put_in ( ice_agent . checklist [ discovered_pair . id ] , discovered_pair )
54
84
55
- if ice_agent . selected_pair_id == nil do
85
+ if ice_agent . selected_pair_id != discovered_pair . id do
56
86
Logger . debug ( "Nomination request on pair: #{ discovered_pair . id } ." )
57
87
update_nominated_flag ( ice_agent , discovered_pair . id , true )
58
88
else
59
89
ice_agent
60
90
end
61
91
|> ICEAgent . send_binding_success_response ( discovered_pair , msg )
62
92
63
- % CandidatePair { state: :failed } = checklist_pair ->
93
+ % CandidatePair { state: :failed } = checklist_pair
94
+ when ice_agent . state not in [ :completed , :failed ] ->
64
95
Logger . debug ( """
65
96
Nomination request on failed pair. Re-scheduling pair for conn-check.
66
97
We will nominate pair once conn check passes.
@@ -77,7 +108,7 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
77
108
ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
78
109
ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
79
110
80
- % CandidatePair { } = checklist_pair ->
111
+ % CandidatePair { } = checklist_pair when ice_agent . state not in [ :completed , :failed ] ->
81
112
Logger . debug ( """
82
113
Nomination request on pair that hasn't been verified yet.
83
114
We will nominate pair once conn check passes.
@@ -92,6 +123,10 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
92
123
93
124
ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
94
125
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 )
95
130
end
96
131
end
97
132
0 commit comments