./ct_report/coverage/mongoose_s2s_info.COVER.html

1 %% Get information about S2S connections on this node.
2 -module(mongoose_s2s_info).
3
4 %% ejabberd API
5 -export([get_connections/1]).
6 -ignore_xref([get_connections/1]).
7
8 -include("mongoose_logger.hrl").
9
10 -type direction() :: in | out.
11 -type supervisor_child_spec() :: { undefined, pid(), worker, [module()] }.
12 -type connection_info() :: ejabberd_s2s_in:connection_info() | ejabberd_s2s_out:connection_info().
13
14 %% @doc Get information about S2S connections of the specified type.
15 -spec get_connections(direction()) -> [connection_info()].
16 get_connections(Type) ->
17
:-(
Specs = supervisor:which_children(type_to_supervisor(Type)),
18
:-(
[Conn || Spec <- Specs, Conn <- get_state_info(child_to_pid(Spec))].
19
20 %% Both supervisors are simple_one_for_one with temporary children processes.
21 -spec type_to_supervisor(direction()) -> atom().
22
:-(
type_to_supervisor(in) -> ejabberd_s2s_in_sup;
23
:-(
type_to_supervisor(out) -> ejabberd_s2s_out_sup.
24
25 -spec child_to_pid(supervisor_child_spec()) -> pid().
26
:-(
child_to_pid({_, Pid, _, _}) -> Pid.
27
28 -spec get_state_info(pid()) -> [connection_info()].
29 get_state_info(Pid) when is_pid(Pid) ->
30
:-(
case gen_fsm_compat:sync_send_all_state_event(Pid, get_state_info) of
31 Info when is_map(Info) ->
32
:-(
[Info];
33 Other ->
34
:-(
?LOG_ERROR(#{what => s2s_get_state_info_failed, pid => Pid, reason => Other}),
35
:-(
[]
36 end.
Line Hits Source