Skip to content

Commit 930eee6

Browse files
committed
Requested changes
1 parent fd84d92 commit 930eee6

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

lib/ex_ice/priv/ice_agent.ex

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,13 +2231,20 @@ defmodule ExICE.Priv.ICEAgent do
22312231

22322232
# 1. L opens socket on interface 1 (I1), port 5000 - first local candidate (LC1)
22332233
# 2. L opens socket on interface 2 (I2), port 5000 - second local candidate (LC2)
2234-
# 3. L sends a connection check from LC1 to RC1. Given LC1 operates via I1, which is a bridge interface, its source address is rewritten to I2
2234+
# 3. L sends a connectivity check from LC1 to RC1.
2235+
# Given LC1 operates via I1, which is a bridge interface, its source address is rewritten to I2.
2236+
# This also creates a mapping in host's NAT from I1:5000 to I2:5000.
22352237
# 4. R perceives the request from L as originating from I2, port 5000, and responds successfully to I2, port 5000
2236-
# 5. This response arrives to the I1 port 5000. L notices that R recognized it as coming from I2, port 5000
2238+
# 5. This response arrives to the I1 port 5000 (because of the mapping in host's NAT).
2239+
# L notices that R recognized its check as one coming from I2, port 5000.
22372240

2238-
# Consequently, LC2 cannot be used to establish a discovered pair
2239-
# As this would lead to a mismatch between the successful and discovered pair sockets.
2240-
# In this case we choose to use LC1 as we are aware that this is bridge interface.
2241+
# At this moment, sending anything from I2:5000 would require OS to create another mapping in its NAT table from I2:5000 to I2:5000.
2242+
# However, because there is already an existing NAT mapping from I1:5000 to I2:5000 this send operation will fail and return an EPERM error.
2243+
2244+
# We consistently use the discovered pair socket for sending.
2245+
# Therefore, we cannot use LC2-RC1 as a valid pair discovered through a check on LC1-RC1.
2246+
# Attempting to send anything from LC1-RC1 would actually involve using the LC2 socket.
2247+
# This action is not possible while the mapping from I1:5000 to I2:5000 exists.
22412248
{conn_check_local_cand, ice_agent}
22422249

22432250
true ->

test/priv/ice_agent_test.exs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,21 +1372,9 @@ defmodule ExICE.Priv.ICEAgentTest do
13721372
end
13731373

13741374
test "success response with the xor address of a local candidate with a different socket." do
1375-
# This test checks a specific scenario where one of the local candidates uses a socket opened on a bridge interface:
1376-
1377-
# L - local side
1378-
# R - remote side
1379-
# RC1 - remote candidate
1380-
1381-
# 1. L opens socket on interface 1 (I1), port 5000 - first local candidate (LC1)
1382-
# 2. L opens socket on interface 2 (I2), port 5000 - second local candidate (LC2)
1383-
# 3. L sends a connection check from LC1 to RC1. Given LC1 operates via I1, which is a bridge interface, its source address is rewritten to I2
1384-
# 4. R perceives the request from L as originating from I2, port 5000, and responds successfully to I2, port 5000
1385-
# 5. This response arrives to the I1 port 5000. L notices that R recognized it as coming from I2, port 5000
1386-
# 6. L chooses to use LC1 and RC1 as the discovered pair because we know that I1 is a bridge interface.
1387-
1388-
# Note: If we were to use LC2 and RC1 as the discovered pair
1389-
# we would have different sockets between the succeeded and discovered pairs, which would cause a runtime error.
1375+
# 1. L sends a binding request using the {LC1, RC1} pair.
1376+
# 2. L receives a binding response with an XOR address LC2, which utilizes a different socket.
1377+
# 3. L selects the {LC1, RC2} pair as the discovered pair.
13901378

13911379
# Setup ice_agent to have two local candidates
13921380
ice_agent =
@@ -1406,7 +1394,7 @@ defmodule ExICE.Priv.ICEAgentTest do
14061394

14071395
# find candidate pair on which connectivity check was sent
14081396
{_pair_id, pair} =
1409-
Enum.find(ice_agent.checklist, fn {_pair_id, pair} -> pair.state == :in_progress end)
1397+
Enum.filter(ice_agent.checklist, fn {_pair_id, pair} -> pair.state == :in_progress end)
14101398

14111399
local_cand = Map.fetch!(ice_agent.local_cands, pair.local_cand_id)
14121400
req = read_binding_request(local_cand.base.socket, ice_agent.remote_pwd)
@@ -1434,7 +1422,8 @@ defmodule ExICE.Priv.ICEAgentTest do
14341422
|> Map.values()
14351423
|> Enum.sort(&(&1.priority > &2.priority))
14361424

1437-
# verify that discovered pair is the same as succeeded
1425+
# verify that because these two paris use local candidates with different sockets,
1426+
# they are not linked together via succeeded/discovered pair ids
14381427
assert pair_1.state == :succeeded
14391428
assert pair_1.id == pair_1.succeeded_pair_id
14401429
assert pair_1.succeeded_pair_id == pair_1.discovered_pair_id

0 commit comments

Comments
 (0)