@@ -600,20 +600,7 @@ defmodule ExICE.Priv.ICEAgent do
600
600
% CandidatePair { } =
601
601
pair = Checklist . find_pair ( ice_agent . checklist , local_cand . base . id , remote_cand . id )
602
602
603
- case pair . state do
604
- :succeeded ->
605
- pair = Map . fetch! ( ice_agent . checklist , pair . discovered_pair_id )
606
- handle_data_message ( ice_agent , pair , packet )
607
-
608
- :failed ->
609
- Logger . error ( "Received data on failed pair! Ignoring. Pair id: #{ pair . id } " )
610
- ice_agent
611
-
612
- _other ->
613
- # We might receive data on a pair that we haven't checked
614
- # on our side yet.
615
- handle_data_message ( ice_agent , pair , packet )
616
- end
603
+ handle_data_message ( ice_agent , pair , packet )
617
604
end
618
605
end
619
606
@@ -972,7 +959,39 @@ defmodule ExICE.Priv.ICEAgent do
972
959
end
973
960
end
974
961
962
+ defp handle_data_message ( ice_agent , % { state: :succeeded } = pair , packet ) do
963
+ # take final pair as local candidate might be srflx
964
+ pair = Map . fetch! ( ice_agent . checklist , pair . discovered_pair_id )
965
+ do_handle_data_message ( ice_agent , pair , packet )
966
+ end
967
+
968
+ defp handle_data_message ( ice_agent , % { state: :failed } = pair , packet )
969
+ when ice_agent . state in [ :checking , :connected ] do
970
+ Logger . debug ( """
971
+ Received data on failed pair. Rescheduling pair for conn check. Pair id: #{ pair . id } \
972
+ """ )
973
+
974
+ ice_agent = do_handle_data_message ( ice_agent , pair , packet )
975
+
976
+ # re-schedule pair
977
+ pair = % { pair | state: :waiting }
978
+ ice_agent = put_in ( ice_agent . checklist [ pair . id ] , pair )
979
+ update_ta_timer ( ice_agent )
980
+ end
981
+
982
+ defp handle_data_message ( ice_agent , % { state: :failed } = pair , _packet ) do
983
+ raise """
984
+ Received data on failed pair in state: #{ ice_agent . state } . Pair id: #{ pair . id } .
985
+ This should never happen.
986
+ """
987
+ end
988
+
989
+ # We might receive data on a pair that we haven't check on our side yet.
975
990
defp handle_data_message ( ice_agent , pair , packet ) do
991
+ do_handle_data_message ( ice_agent , pair , packet )
992
+ end
993
+
994
+ defp do_handle_data_message ( ice_agent , pair , packet ) do
976
995
pair = % CandidatePair { pair | last_seen: now ( ) }
977
996
ice_agent = put_in ( ice_agent . checklist [ pair . id ] , pair )
978
997
0 commit comments