From 3f9e627bd7394298d265bfb3c63f83f9107395a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Wala?= Date: Thu, 18 Jul 2024 09:59:03 +0200 Subject: [PATCH] Fix issue with not recognizing keepalive response --- lib/ex_ice/priv/ice_agent.ex | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/ex_ice/priv/ice_agent.ex b/lib/ex_ice/priv/ice_agent.ex index bb7a889..683e8ee 100644 --- a/lib/ex_ice/priv/ice_agent.ex +++ b/lib/ex_ice/priv/ice_agent.ex @@ -72,7 +72,7 @@ defmodule ExICE.Priv.ICEAgent do gathering_transactions: %{}, checklist: %{}, conn_checks: %{}, - keepalive_ids: MapSet.new(), + keepalives: %{}, gathering_state: :new, eoc: false, # {did we nominate pair, pair id} @@ -1051,10 +1051,15 @@ defmodule ExICE.Priv.ICEAgent do handle_stun_gathering_transaction_response(ice_agent, msg) %Type{class: class, method: :binding} - when is_response(class) and is_map_key(ice_agent.consent_checks, msg.transaction_id) -> + when is_response(class) and is_map_key(ice_agent.keepalives, msg.transaction_id) -> # TODO: this a good basis to implement consent freshness - keepalive_ids = MapSet.delete(ice_agent.keepalive_ids, msg.transaction_id) - %__MODULE__{ice_agent | keepalive_ids: keepalive_ids} + Logger.debug(""" + Received keepalive response from from #{inspect({src_ip, src_port})}, \ + on: #{inspect({local_cand.base.base_address, local_cand.base.base_port})} \ + """) + + keepalives = Map.delete(ice_agent.keepalives, msg.transaction_id) + %__MODULE__{ice_agent | keepalives: keepalives} %Type{class: class, method: :binding} when is_response(class) -> Logger.warning(""" @@ -2178,8 +2183,8 @@ defmodule ExICE.Priv.ICEAgent do case do_send(ice_agent, local_cand, dst, Message.encode(req)) do {:ok, ice_agent} -> - keepalive_ids = MapSet.put(ice_agent.keepalive_ids, req.transaction_id) - %__MODULE__{ice_agent | keepalive_ids: keepalive_ids} + keepalives = Map.put(ice_agent.keepalives, req.transaction_id, pair.id) + %__MODULE__{ice_agent | keepalives: keepalives} {:error, ice_agent} -> ice_agent