@@ -24,32 +24,59 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
24
24
25
25
nil when ice_agent . state in [ :new , :checking , :connected ] ->
26
26
Logger . debug ( "Adding new candidate pair: #{ inspect ( pair ) } " )
27
+ pair = % CandidatePair { pair | requests_received: 1 }
27
28
checklist = Map . put ( ice_agent . checklist , pair . id , pair )
28
29
ice_agent = % ICEAgent { ice_agent | checklist: checklist }
29
30
ICEAgent . send_binding_success_response ( ice_agent , pair , msg )
30
31
31
32
% CandidatePair { } = checklist_pair ->
32
33
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 )
38
55
39
56
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
42
61
| state: :waiting ,
43
- last_seen: pair . last_seen
62
+ last_seen: pair . last_seen ,
63
+ requests_received: r_pair . requests_received + 1
44
64
}
45
65
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 )
48
68
49
69
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 )
53
80
end
54
81
end
55
82
end
@@ -71,15 +98,21 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
71
98
successful conn check: #{ inspect ( pair . id ) } \
72
99
""" )
73
100
74
- pair = % CandidatePair { pair | nominate?: true }
101
+ pair = % CandidatePair { pair | nominate?: true , requests_received: 1 }
75
102
checklist = Map . put ( ice_agent . checklist , pair . id , pair )
76
103
77
104
ice_agent = % ICEAgent { ice_agent | checklist: checklist }
78
105
ICEAgent . send_binding_success_response ( ice_agent , pair , msg )
79
106
80
107
% CandidatePair { state: :succeeded } = checklist_pair when ice_agent . state != :failed ->
81
108
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
+
83
116
ice_agent = put_in ( ice_agent . checklist [ discovered_pair . id ] , discovered_pair )
84
117
85
118
if ice_agent . selected_pair_id != discovered_pair . id do
@@ -92,21 +125,24 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
92
125
93
126
% CandidatePair { state: :failed } = checklist_pair
94
127
when ice_agent . state not in [ :completed , :failed ] ->
128
+ r_pair = resolve_pair ( ice_agent , checklist_pair )
129
+
95
130
Logger . debug ( """
96
131
Nomination request on failed pair. Re-scheduling pair for conn-check.
97
132
We will nominate pair once conn check passes.
98
- Pair: #{ inspect ( checklist_pair . id ) }
133
+ Pair: #{ inspect ( pair . id ) }
99
134
""" )
100
135
101
- checklist_pair = % CandidatePair {
102
- checklist_pair
136
+ r_pair = % CandidatePair {
137
+ r_pair
103
138
| nominate?: true ,
104
139
last_seen: pair . last_seen ,
105
- state: :waiting
140
+ state: :waiting ,
141
+ requests_received: r_pair . requests_received + 1
106
142
}
107
143
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 )
110
146
111
147
% CandidatePair { } = checklist_pair when ice_agent . state not in [ :completed , :failed ] ->
112
148
Logger . debug ( """
@@ -118,15 +154,23 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
118
154
checklist_pair = % CandidatePair {
119
155
checklist_pair
120
156
| nominate?: true ,
121
- last_seen: pair . last_seen
157
+ last_seen: pair . last_seen ,
158
+ requests_received: checklist_pair . requests_received + 1
122
159
}
123
160
124
161
ice_agent = put_in ( ice_agent . checklist [ checklist_pair . id ] , checklist_pair )
125
162
ICEAgent . send_binding_success_response ( ice_agent , checklist_pair , msg )
126
163
127
164
% 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 )
130
174
end
131
175
end
132
176
@@ -167,4 +211,8 @@ defmodule ExICE.Priv.ConnCheckHandler.Controlled do
167
211
ice_agent
168
212
end
169
213
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
170
218
end
0 commit comments