@@ -18,9 +18,10 @@ defmodule ExICE.ControlledHandler do
18
18
Logger . debug ( "Adding new candidate pair: #{ inspect ( pair ) } " )
19
19
put_in ( state , [ :checklist , pair . id ] , pair )
20
20
21
- % CandidatePair { } = pair when pair == state . selected_pair ->
21
+ % CandidatePair { } = pair
22
+ when state . selected_pair != nil and pair . discovered_pair_id == state . selected_pair . id ->
22
23
# to be honest this might also be a retransmission
23
- Logger . debug ( "Keepalive on selected pair: #{ pair . id } " )
24
+ Logger . debug ( "Keepalive on selected pair: #{ pair . discovered_pair_id } " )
24
25
state
25
26
26
27
% CandidatePair { } ->
@@ -44,25 +45,23 @@ defmodule ExICE.ControlledHandler do
44
45
pair = % CandidatePair { pair | nominate?: true }
45
46
put_in ( state , [ :checklist , pair . id ] , pair )
46
47
47
- % CandidatePair { } = pair when pair == state . selected_pair ->
48
+ % CandidatePair { } = pair
49
+ when state . selected_pair != nil and pair . discovered_pair_id == state . selected_pair . id ->
48
50
Logger . debug ( "Keepalive on selected pair: #{ pair . id } " )
49
51
state
50
52
51
53
% CandidatePair { } = pair ->
52
54
if pair . state == :succeeded do
53
- # FIXME we should check against valid? flag
54
- # it's possible to have to pairs: one with state succeeded
55
- # and flag valid? set to false, and the other one with state
56
- # succeeded and flag valid? set to true
57
- # TODO should we call this selected or nominated pair
58
- Logger . debug ( "Nomination request on valid pair: #{ pair . id } ." )
59
- update_nominated_flag ( state , pair . id , true )
55
+ Logger . debug ( "Nomination request on pair: #{ pair . id } ." )
56
+ update_nominated_flag ( state , pair . discovered_pair_id , true )
60
57
else
61
58
# TODO should we check if this pair is not in failed?
62
59
Logger . debug ( """
63
60
Nomination request on pair that hasn't been verified yet.
64
61
We will nominate pair once conn check passes.
65
62
Pair: #{ inspect ( pair . id ) }
63
+ pair: #{ inspect ( pair ) }
64
+ selected_pair: #{ inspect ( state . selected_pair ) }
66
65
""" )
67
66
68
67
pair = % CandidatePair { pair | nominate?: true }
@@ -79,31 +78,26 @@ defmodule ExICE.ControlledHandler do
79
78
Logger . debug ( "Nomination succeeded, pair: #{ pair_id } " )
80
79
81
80
pair = Map . fetch! ( state . checklist , pair_id )
81
+ pair = % CandidatePair { pair | nominate?: false , nominated?: true }
82
82
83
- state =
84
- cond do
85
- state . selected_pair == nil ->
86
- Logger . debug ( "Selecting pair: #{ pair_id } " )
87
- % { state | selected_pair: pair }
88
-
89
- state . selected_pair != nil and pair . priority >= state . selected_pair . priority ->
90
- Logger . debug ( """
91
- Selecting new pair with higher priority. \
92
- New pair: #{ pair_id } , old pair: #{ state . selected_pair . id } .\
93
- """ )
83
+ state = put_in ( state , [ :checklist , pair . id ] , pair )
94
84
95
- % { state | selected_pair: pair }
85
+ cond do
86
+ state . selected_pair == nil ->
87
+ Logger . debug ( "Selecting pair: #{ pair_id } " )
88
+ % { state | selected_pair: pair }
96
89
97
- true ->
98
- Logger . debug ( "Not selecting a new pair as it has lower priority" )
99
- state
100
- end
90
+ state . selected_pair != nil and pair . priority >= state . selected_pair . priority ->
91
+ Logger . debug ( """
92
+ Selecting new pair with higher priority. \
93
+ New pair: #{ pair_id } , old pair: #{ state . selected_pair . id } .\
94
+ """ )
101
95
102
- checklist =
103
- Map . update! ( state . checklist , pair_id , fn pair ->
104
- % CandidatePair { pair | nominate?: false , nominated?: true }
105
- end )
96
+ % { state | selected_pair: pair }
106
97
107
- % { state | checklist: checklist , selected_pair: Map . fetch! ( checklist , pair_id ) }
98
+ true ->
99
+ Logger . debug ( "Not selecting a new pair as it has lower priority" )
100
+ state
101
+ end
108
102
end
109
103
end
0 commit comments