pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/erlang/osmo-epdg/+/35887?usp=email )
Change subject: Fix all sets() lookup functions ......................................................................
Fix all sets() lookup functions
Previous logic was wrong, since the accumulator function was not really matching properly as the parameter was shadowed and didn't include the value from the outer function. The lookup is fixed here by passing the input lookup key (eg Imsi) as part of the default/initial value of the fold() function.
Change-Id: I3a4a473b45fa54e857c2092d8d2b1e68ff9535e1 --- M src/aaa_diameter_swm.erl M src/epdg_diameter_swm.erl M src/epdg_gtpc_s2b.erl M src/gsup_server.erl 4 files changed, 47 insertions(+), 27 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-epdg refs/changes/87/35887/1
diff --git a/src/aaa_diameter_swm.erl b/src/aaa_diameter_swm.erl index 9458383..d425ed6 100644 --- a/src/aaa_diameter_swm.erl +++ b/src/aaa_diameter_swm.erl @@ -148,12 +148,13 @@
% returns swm_session if found, undefined if not find_swm_session_by_imsi(Imsi, State) -> - sets:fold( - fun(UEsIt = #swm_session{imsi = Imsi}, _AccIn) -> UEsIt; - (_, AccIn) -> AccIn - end, - undefined, - State#swm_state.ues). + {Imsi, Res} = sets:fold( + fun(UEsIt = #swm_session{imsi = LookupImsi}, {LookupImsi, _AccIn}) -> {LookupImsi, UEsIt}; + (_, AccIn) -> AccIn + end, + {Imsi, undefined}, + State#swm_state.ues), + Res.
find_or_new_swm_session(Imsi, State) -> UE = find_swm_session_by_imsi(Imsi, State), diff --git a/src/epdg_diameter_swm.erl b/src/epdg_diameter_swm.erl index bfb8f2d..2e4d738 100644 --- a/src/epdg_diameter_swm.erl +++ b/src/epdg_diameter_swm.erl @@ -163,12 +163,13 @@
% returns Sess if found, undefined it not find_swm_session_by_imsi(Imsi, State) -> - sets:fold( - fun(SessIt = #swm_session{imsi = Imsi}, _AccIn) -> SessIt; + {Imsi, Res} = sets:fold( + fun(SessIt = #swm_session{imsi = LookupImsi}, {LookupImsi, _AccIn}) -> {LookupImsi, SessIt}; (_, AccIn) -> AccIn end, - undefined, - State#swm_state.sessions). + {Imsi, undefined}, + State#swm_state.sessions), + Res.
find_or_new_swm_session(Imsi, Pid, State) -> Sess = find_swm_session_by_imsi(Imsi, State), diff --git a/src/epdg_gtpc_s2b.erl b/src/epdg_gtpc_s2b.erl index 712e484..bc1a076 100644 --- a/src/epdg_gtpc_s2b.erl +++ b/src/epdg_gtpc_s2b.erl @@ -219,12 +219,13 @@
% returns Sess if found, undefined it not find_gtp_session_by_imsi(Imsi, State) -> - sets:fold( - fun(SessIt = #gtp_session{imsi = Imsi}, _AccIn) -> SessIt; - (_, AccIn) -> AccIn - end, - undefined, - State#gtp_state.sessions). + {Imsi, Res} = sets:fold( + fun(SessIt = #gtp_session{imsi = LookupImsi}, {LookupImsi, _AccIn}) -> {LookupImsi, SessIt}; + (_, AccIn) -> AccIn + end, + {Imsi, undefined}, + State#gtp_state.sessions), + Res.
find_or_new_gtp_session(Imsi, Pid, State) -> Sess = find_gtp_session_by_imsi(Imsi, State), @@ -289,12 +290,13 @@
% returns Sess if found, undefined it not find_gtp_session_by_local_teic(LocalControlTei, State) -> - sets:fold( - fun(SessIt = #gtp_session{local_control_tei = LocalControlTei}, _AccIn) -> SessIt; - (_, AccIn) -> AccIn + {LocalControlTei, Res} = sets:fold( + fun(SessIt = #gtp_session{local_control_tei = LookupLTEIC}, {LookupLTEIC, _AccIn}) -> {LookupLTEIC, SessIt}; + (_, AccIn) -> AccIn end, - undefined, - State#gtp_state.sessions). + {LocalControlTei, undefined}, + State#gtp_state.sessions), + Res.
%% connect/2 connect(Name, {Socket, RemoteAddr, RemotePort}) -> diff --git a/src/gsup_server.erl b/src/gsup_server.erl index 8659c95..5c536fc 100644 --- a/src/gsup_server.erl +++ b/src/gsup_server.erl @@ -381,12 +381,13 @@
% returns gsups_ue if found, undefined it not find_gsups_ue_by_imsi(Imsi, State) -> - sets:fold( - fun(UEsIt = #gsups_ue{imsi = Imsi}, _AccIn) -> UEsIt; - (_, AccIn) -> AccIn - end, - undefined, - State#gsups_state.ues). + {Imsi, Res} = sets:fold( + fun(SessIt = #gsups_ue{imsi = LookupImsi}, {LookupImsi, _AccIn}) -> {LookupImsi, SessIt}; + (_, AccIn) -> AccIn + end, + {Imsi, undefined}, + State#gsups_state.ues), + Res.
find_or_new_gsups_ue(Imsi, State) -> UE = find_gsups_ue_by_imsi(Imsi, State),