File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -108,15 +108,19 @@ defmodule ExICE.Priv.ICEAgent do
108108 defp resolve_address ( remote_cand ) when is_binary ( remote_cand . address ) do
109109 Logger . debug ( "Trying to resolve addr: #{ remote_cand . address } " )
110110
111- case ExICE.Priv.MDNS.Resolver . gethostbyname ( remote_cand . address ) do
112- { :ok , addr } ->
113- Logger . debug ( "Successfully resolved #{ remote_cand . address } to #{ inspect ( addr ) } " )
114- remote_cand = % ExICE.Candidate { remote_cand | address: addr }
115- { :ok , remote_cand }
116-
111+ with pid when is_pid ( pid ) <- Process . whereis ( ExICE.Priv.MDNS.Resolver ) ,
112+ { :ok , addr } <- ExICE.Priv.MDNS.Resolver . gethostbyname ( remote_cand . address ) do
113+ Logger . debug ( "Successfully resolved #{ remote_cand . address } to #{ inspect ( addr ) } " )
114+ remote_cand = % ExICE.Candidate { remote_cand | address: addr }
115+ { :ok , remote_cand }
116+ else
117117 { :error , reason } = err ->
118118 Logger . debug ( "Couldn't resolve #{ remote_cand . address } , reason: #{ reason } " )
119119 err
120+
121+ nil ->
122+ Logger . debug ( "Couldn't resolve #{ remote_cand . address } , reason: MDNS reslover not alive." )
123+ { :error , :mdns_resolver_not_alive }
120124 end
121125 end
122126
Original file line number Diff line number Diff line change @@ -76,6 +76,21 @@ defmodule ExICE.Priv.ICEAgentTest do
7676 cand = "1 1 UDP 1686052863 someincalidmdnsadddress 57940 typ srflx raddr 0.0.0.0 rport 0"
7777 assert { :error , _reason } = ICEAgent . unmarshal_remote_candidate ( cand )
7878 end
79+
80+ test "with MDNS resolver not started" do
81+ # this test checks what happens when MDNS resolver has not been started due to too old Erlang version
82+
83+ # stop MDNS resolver
84+ pid = Process . whereis ( ExICE.Priv.MDNS.Resolver )
85+ assert :ok == GenServer . stop ( pid )
86+ assert nil == Process . whereis ( ExICE.Priv.MDNS.Resolver )
87+
88+ # try to resolve some address
89+ cand = "1 1 UDP 1686052863 example.local 57940 typ srflx raddr 0.0.0.0 rport 0"
90+
91+ assert { :error , { :resolve_address , :mdns_resolver_not_alive } } =
92+ ICEAgent . unmarshal_remote_candidate ( cand )
93+ end
7994 end
8095
8196 describe "add_remote_candidate/2" do
You can’t perform that action at this time.
0 commit comments