Skip to content

Commit 116c61e

Browse files
committed
Fix ICE Runtime Error
1 parent 4854d81 commit 116c61e

File tree

2 files changed

+140
-52
lines changed

2 files changed

+140
-52
lines changed

lib/ex_ice/priv/ice_agent.ex

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2210,38 +2210,48 @@ defmodule ExICE.Priv.ICEAgent do
22102210
end
22112211

22122212
defp get_or_create_local_cand(ice_agent, xor_addr, conn_check_pair) do
2213+
conn_check_local_cand = Map.fetch!(ice_agent.local_cands, conn_check_pair.local_cand_id)
2214+
22132215
local_cand =
22142216
find_local_cand(Map.values(ice_agent.local_cands), xor_addr.address, xor_addr.port)
22152217

2216-
if local_cand do
2217-
{local_cand, ice_agent}
2218-
else
2219-
# prflx candidate sec 7.2.5.3.1
2220-
# TODO calculate correct prio and foundation
2221-
local_cand = Map.fetch!(ice_agent.local_cands, conn_check_pair.local_cand_id)
2218+
cond do
2219+
local_cand && local_cand.base.socket == conn_check_local_cand.base.socket ->
2220+
{local_cand, ice_agent}
22222221

2223-
priority =
2224-
Candidate.priority!(ice_agent.local_preferences, local_cand.base.base_address, :prflx)
2225-
2226-
cand =
2227-
Candidate.Prflx.new(
2228-
address: xor_addr.address,
2229-
port: xor_addr.port,
2230-
base_address: local_cand.base.base_address,
2231-
base_port: local_cand.base.base_port,
2232-
priority: priority,
2233-
transport_module: ice_agent.transport_module,
2234-
socket: local_cand.base.socket
2235-
)
2222+
local_cand ->
2223+
# If selected local candidate uses different socket than received the response
2224+
# Take local candidate from connection check
2225+
# See https://github.com/elixir-webrtc/ex_ice/issues/77
2226+
{conn_check_local_cand, ice_agent}
22362227

2237-
Logger.debug("Adding new local prflx candidate: #{inspect(cand)}")
2228+
true ->
2229+
# prflx candidate sec 7.2.5.3.1
2230+
# TODO calculate correct prio and foundation
2231+
local_cand = conn_check_local_cand
22382232

2239-
ice_agent = %__MODULE__{
2240-
ice_agent
2241-
| local_cands: Map.put(ice_agent.local_cands, cand.base.id, cand)
2242-
}
2233+
priority =
2234+
Candidate.priority!(ice_agent.local_preferences, local_cand.base.base_address, :prflx)
2235+
2236+
cand =
2237+
Candidate.Prflx.new(
2238+
address: xor_addr.address,
2239+
port: xor_addr.port,
2240+
base_address: local_cand.base.base_address,
2241+
base_port: local_cand.base.base_port,
2242+
priority: priority,
2243+
transport_module: ice_agent.transport_module,
2244+
socket: local_cand.base.socket
2245+
)
2246+
2247+
Logger.debug("Adding new local prflx candidate: #{inspect(cand)}")
22432248

2244-
{cand, ice_agent}
2249+
ice_agent = %__MODULE__{
2250+
ice_agent
2251+
| local_cands: Map.put(ice_agent.local_cands, cand.base.id, cand)
2252+
}
2253+
2254+
{cand, ice_agent}
22452255
end
22462256
end
22472257

0 commit comments

Comments
 (0)