@@ -24,32 +24,59 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
2424
2525 nil when ice_agent . state in [ :new , :checking , :connected ] ->
2626 Logger . debug ( "Adding new candidate pair: #{ inspect ( pair ) } " )
27+ pair = % CandidatePair { pair | requests_received: 1 }
2728 checklist = Map . put ( ice_agent . checklist , pair . id , pair )
2829 ice_agent = % ICEAgent { ice_agent | checklist: checklist }
2930 ICEAgent . send_binding_success_response ( ice_agent , pair , msg )
3031
3132 % CandidatePair { } = checklist_pair ->
3233 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 )
34+ ice_agent . state == :failed ->
35+ r_pair = resolve_pair ( ice_agent , checklist_pair )
36+
37+ r_pair = % CandidatePair {
38+ r_pair
39+ | last_seen: pair . last_seen ,
40+ requests_received: r_pair . requests_received + 1
41+ }
42+
43+ put_in ( ice_agent . checklist [ r_pair . id ] , r_pair )
44+
45+ checklist_pair . state == :failed and ice_agent . state == :completed ->
46+ r_pair = resolve_pair ( ice_agent , checklist_pair )
47+
48+ r_pair = % CandidatePair {
49+ r_pair
50+ | last_seen: pair . last_seen ,
51+ requests_received: r_pair . requests_received + 1
52+ }
53+
54+ put_in ( ice_agent . checklist [ r_pair . id ] , r_pair )
3855
3956 checklist_pair . state == :failed ->
40- checklist_pair = % CandidatePair {
41- checklist_pair
57+ r_pair = resolve_pair ( ice_agent , checklist_pair )
58+
59+ r_pair = % CandidatePair {
60+ r_pair
4261 | state: :waiting ,
43- last_seen: pair . last_seen
62+ last_seen: pair . last_seen ,
63+ requests_received: r_pair . requests_received + 1
4464 }
4565
46- ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
47- ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
66+ ice_agent = put_in ( ice_agent . checklist [ r_pair . id ] , r_pair )
67+ ICEAgent . send_binding_success_response ( ice_agent , r_pair , msg )
4868
4969 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 )
70+ r_pair = resolve_pair ( ice_agent , checklist_pair )
71+
72+ r_pair = % CandidatePair {
73+ r_pair
74+ | last_seen: pair . last_seen ,
75+ requests_received: r_pair . requests_received + 1
76+ }
77+
78+ ice_agent = put_in ( ice_agent . checklist [ r_pair . id ] , r_pair )
79+ ICEAgent . send_binding_success_response ( ice_agent , r_pair , msg )
5380 end
5481 end
5582 end
@@ -71,15 +98,21 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
7198 successful conn check: #{ inspect ( pair . id ) } \
7299 """ )
73100
74- pair = % CandidatePair { pair | nominate?: true }
101+ pair = % CandidatePair { pair | nominate?: true , requests_received: 1 }
75102 checklist = Map . put ( ice_agent . checklist , pair . id , pair )
76103
77104 ice_agent = % ICEAgent { ice_agent | checklist: checklist }
78105 ICEAgent . send_binding_success_response ( ice_agent , pair , msg )
79106
80107 % CandidatePair { state: :succeeded } = checklist_pair when ice_agent . state != :failed ->
81108 discovered_pair = Map . fetch! ( ice_agent . checklist , checklist_pair . discovered_pair_id )
82- discovered_pair = % CandidatePair { discovered_pair | last_seen: pair . last_seen }
109+
110+ discovered_pair = % CandidatePair {
111+ discovered_pair
112+ | last_seen: pair . last_seen ,
113+ requests_received: discovered_pair . requests_received + 1
114+ }
115+
83116 ice_agent = put_in ( ice_agent . checklist [ discovered_pair . id ] , discovered_pair )
84117
85118 if ice_agent . selected_pair_id != discovered_pair . id do
@@ -92,21 +125,24 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
92125
93126 % CandidatePair { state: :failed } = checklist_pair
94127 when ice_agent . state not in [ :completed , :failed ] ->
128+ r_pair = resolve_pair ( ice_agent , checklist_pair )
129+
95130 Logger . debug ( """
96131 Nomination request on failed pair. Re-scheduling pair for conn-check.
97132 We will nominate pair once conn check passes.
98- Pair: #{ inspect ( checklist_pair . id ) }
133+ Pair: #{ inspect ( pair . id ) }
99134 """ )
100135
101- checklist_pair = % CandidatePair {
102- checklist_pair
136+ r_pair = % CandidatePair {
137+ r_pair
103138 | nominate?: true ,
104139 last_seen: pair . last_seen ,
105- state: :waiting
140+ state: :waiting ,
141+ requests_received: r_pair . requests_received + 1
106142 }
107143
108- ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
109- ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
144+ ice_agent = put_in ( ice_agent . checklist [ r_pair . id ] , r_pair )
145+ ICEAgent . send_binding_success_response ( ice_agent , r_pair , msg )
110146
111147 % CandidatePair { } = checklist_pair when ice_agent . state not in [ :completed , :failed ] ->
112148 Logger . debug ( """
@@ -118,15 +154,23 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
118154 checklist_pair = % CandidatePair {
119155 checklist_pair
120156 | nominate?: true ,
121- last_seen: pair . last_seen
157+ last_seen: pair . last_seen ,
158+ requests_received: checklist_pair . requests_received + 1
122159 }
123160
124161 ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
125162 ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
126163
127164 % 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 )
165+ r_pair = resolve_pair ( ice_agent , checklist_pair )
166+
167+ r_pair = % CandidatePair {
168+ r_pair
169+ | last_seen: pair . last_seen ,
170+ requests_received: r_pair . requests_received + 1
171+ }
172+
173+ put_in ( ice_agent . checklist [ r_pair . id ] , r_pair )
130174 end
131175 end
132176
@@ -167,4 +211,8 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
167211 ice_agent
168212 end
169213 end
214+
215+ defp resolve_pair ( ice_agent , pair ) do
216+ ( pair . discovered_pair_id && Map . fetch! ( ice_agent . checklist , pair . discovered_pair_id ) ) || pair
217+ end
170218end
0 commit comments