Skip to content

Commit 2a70e07

Browse files
committed
Review fixes
1 parent 22fe54f commit 2a70e07

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

lib/ex_ice/ice_agent.ex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,9 @@ defmodule ExICE.ICEAgent do
496496
end
497497

498498
@impl true
499-
def handle_info({:tcp, _socket, _packet}, state) do
500-
# TODO: consider receiving TCP data in the ICE Agent process
501-
# ice_agent = ExICE.Priv.ICEAgent.handle_tcp(state.ice_agent, socket, packet)
502-
# {:noreply, %{state | ice_agent: ice_agent}}
503-
{:noreply, state}
499+
def handle_info({:tcp, socket, src_ip, src_port, packet}, state) do
500+
ice_agent = ExICE.Priv.ICEAgent.handle_tcp(state.ice_agent, socket, src_ip, src_port, packet)
501+
{:noreply, %{state | ice_agent: ice_agent}}
504502
end
505503

506504
@impl true

lib/ex_ice/priv/ice_agent.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,18 @@ defmodule ExICE.Priv.ICEAgent do
920920
end
921921
end
922922

923+
@spex handle_tcp(
924+
t(),
925+
ExICE.Priv.Transport.socket(),
926+
:inet.ip_address(),
927+
:inet.port_number(),
928+
binary()
929+
) :: t()
930+
def handle_tcp(ice_agent, socket, src_ip, src_port, packet) do
931+
# This is the same because framing and mapping the sockets is handled in the TCP Client
932+
handle_udp(ice_agent, socket, src_ip, src_port, packet)
933+
end
934+
923935
@spec handle_ex_turn_msg(t(), reference(), ExTURN.Client.notification_message()) :: t()
924936
def handle_ex_turn_msg(%__MODULE__{state: :closed} = ice_agent, _, _) do
925937
Logger.debug("Received ex_turn message in closed state. Ignoring.")

lib/ex_ice/priv/transport/tcp.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ defmodule ExICE.Priv.Transport.TCP do
3737
defdelegate sockname(socket), to: :inet
3838

3939
# HACK: using listen sockets here is ugly, but was easier to fit into the existing ICE Agent implementation.
40+
# At the moment, `listen_socket` is used to access the specific socket connected to `dest`.
4041
# This should be changed, especially because we're going to want to close the listen sockets
4142
# after the connection is successfully established.
4243
@impl true
4344
def send(listen_socket, dest, packet, tp_opts \\ []) do
4445
with {:ok, local} <- sockname(listen_socket),
4546
[{pid, _}] <- Registry.lookup(ExICE.Priv.Registry, local) do
46-
GenServer.call(pid, {:send, listen_socket, dest, packet, tp_opts})
47+
Client.send(pid, listen_socket, dest, packet, tp_opts)
4748
else
4849
_ -> {:error, :no_client_process}
4950
end
@@ -53,7 +54,7 @@ defmodule ExICE.Priv.Transport.TCP do
5354
def close(listen_socket) do
5455
with {:ok, local} <- sockname(listen_socket),
5556
[{pid, _}] <- Registry.lookup(ExICE.Priv.Registry, local) do
56-
GenServer.call(pid, {:close, listen_socket})
57+
Client.close(pid, listen_socket)
5758
else
5859
_ -> {:error, :no_client_process}
5960
end

lib/ex_ice/priv/transport/tcp_client.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ defmodule ExICE.Priv.Transport.TCP.Client do
133133

134134
@impl true
135135
def handle_call({:close, listen_socket}, _from, state) do
136-
# TODO: revisit the closing logic
136+
# TODO: revisit the closing logic. Listen sockets should be closed after the connection is established
137137
:gen_tcp.close(listen_socket)
138138
Enum.each(state.connections, fn {_, %{socket: socket}} -> :gen_tcp.close(socket) end)
139139

@@ -179,7 +179,7 @@ defmodule ExICE.Priv.Transport.TCP.Client do
179179
<<length::unsigned-big-16, data::binary-size(length), rest::binary>> ->
180180
# HACK: this is dirty and means that, with framing, we're miscalculating
181181
# the bytes_sent and bytes_received counters
182-
send(state.ice_agent, {:udp, state.listen_socket, src_ip, src_port, data})
182+
send(state.ice_agent, {:tcp, state.listen_socket, src_ip, src_port, data})
183183
state = put_in(state, [:connections, remote, :recv_buffer], <<>>)
184184

185185
if rest != <<>> do
@@ -194,7 +194,7 @@ defmodule ExICE.Priv.Transport.TCP.Client do
194194
end
195195

196196
true ->
197-
send(state.ice_agent, {:udp, state.listen_socket, src_ip, src_port, packet})
197+
send(state.ice_agent, {:tcp, state.listen_socket, src_ip, src_port, packet})
198198
{:noreply, state}
199199
end
200200
end

0 commit comments

Comments
 (0)