Updated to fix traffic stats

This commit is contained in:
Badlop 2018-01-12 11:57:30 +01:00
parent 4d3acc1637
commit aa6519209e
1 changed files with 21 additions and 19 deletions

View File

@ -24,7 +24,7 @@
web_menu_host/3, web_page_host/3, web_menu_host/3, web_page_host/3,
%% Hooks %% Hooks
register_user/2, remove_user/2, user_send_packet/1, register_user/2, remove_user/2, user_send_packet/1,
user_send_packet_traffic/4, user_receive_packet_traffic/5, user_send_packet_traffic/1, user_receive_packet_traffic/1,
%%user_logout_sm/3, %%user_logout_sm/3,
user_login/1, user_logout/4]). user_login/1, user_logout/4]).
@ -240,33 +240,35 @@ user_send_packet({NewEl, C2SState}) ->
end, end,
{NewEl, C2SState}. {NewEl, C2SState}.
user_send_packet_traffic(NewEl, _C2SState, FromJID, ToJID) -> %% Only required for traffic stats
%% Only required for traffic stats user_send_packet_traffic({NewEl, _C2SState} = Acc) ->
Host = FromJID#jid.lserver, From = xmpp:get_from(NewEl),
HostTo = ToJID#jid.lserver, To = xmpp:get_from(NewEl),
{xmlel, Type, _, _} = NewEl, Host = From#jid.lserver,
Type2 = case Type of HostTo = To#jid.lserver,
<<"iq">> -> iq; Type2 = case NewEl of
<<"message">> -> message; #iq{} -> iq;
<<"presence">> -> presence #message{} -> message;
end, #presence{} -> presence
end,
Dest = case is_host(HostTo, Host) of Dest = case is_host(HostTo, Host) of
true -> in; true -> in;
false -> out false -> out
end, end,
Table = table_name(Host), Table = table_name(Host),
ets:update_counter(Table, {send, Host, Type2, Dest}, 1), ets:update_counter(Table, {send, Host, Type2, Dest}, 1),
NewEl. Acc.
%% Only required for traffic stats %% Only required for traffic stats
user_receive_packet_traffic(FixedPacket, _C2SState, _JID, From, To) -> user_receive_packet_traffic({NewEl, _C2SState} = Acc) ->
From = xmpp:get_from(NewEl),
To = xmpp:get_from(NewEl),
HostFrom = From#jid.lserver, HostFrom = From#jid.lserver,
Host = To#jid.lserver, Host = To#jid.lserver,
{xmlel, Type, _, _} = FixedPacket, Type2 = case NewEl of
Type2 = case Type of #iq{} -> iq;
<<"iq">> -> iq; #message{} -> message;
<<"message">> -> message; #presence{} -> presence
<<"presence">> -> presence
end, end,
Dest = case is_host(HostFrom, Host) of Dest = case is_host(HostFrom, Host) of
true -> in; true -> in;
@ -274,7 +276,7 @@ user_receive_packet_traffic(FixedPacket, _C2SState, _JID, From, To) ->
end, end,
Table = table_name(Host), Table = table_name(Host),
ets:update_counter(Table, {recv, Host, Type2, Dest}, 1), ets:update_counter(Table, {recv, Host, Type2, Dest}, 1),
FixedPacket. Acc.
%%%================================== %%%==================================