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
108
108
defp resolve_address ( remote_cand ) when is_binary ( remote_cand . address ) do
109
109
Logger . debug ( "Trying to resolve addr: #{ remote_cand . address } " )
110
110
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
117
117
{ :error , reason } = err ->
118
118
Logger . debug ( "Couldn't resolve #{ remote_cand . address } , reason: #{ reason } " )
119
119
err
120
+
121
+ nil ->
122
+ Logger . debug ( "Couldn't resolve #{ remote_cand . address } , reason: MDNS reslover not alive." )
123
+ { :error , :mdns_resolver_not_alive }
120
124
end
121
125
end
122
126
Original file line number Diff line number Diff line change @@ -76,6 +76,21 @@ defmodule ExICE.Priv.ICEAgentTest do
76
76
cand = "1 1 UDP 1686052863 someincalidmdnsadddress 57940 typ srflx raddr 0.0.0.0 rport 0"
77
77
assert { :error , _reason } = ICEAgent . unmarshal_remote_candidate ( cand )
78
78
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
79
94
end
80
95
81
96
describe "add_remote_candidate/2" do
You can’t perform that action at this time.
0 commit comments