Skip to content

Commit

Permalink
Stick domains in mongoose_router and components in ejabberd_router
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jan 17, 2022
1 parent e70220c commit 6dc91ac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
22 changes: 1 addition & 21 deletions src/ejabberd_router.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
route/4,
route_error/4,
route_error_reply/4,
dirty_get_all_domains/0,
dirty_get_all_domains/1,
dirty_get_all_components/1,
register_components/2,
register_components/3,
Expand All @@ -58,8 +56,7 @@
%% debug exports for tests
-export([update_tables/0]).

-ignore_xref([dirty_get_all_domains/1,
register_component/2, register_component/3, register_component/4,
-ignore_xref([register_component/2, register_component/3, register_component/4,
register_components/2, register_components/3,
route_error/4, routes_cleanup_on_nodedown/2, start_link/0,
unregister_component/1, unregister_component/2, unregister_components/2,
Expand Down Expand Up @@ -319,23 +316,6 @@ lookup_component(Domain) ->
lookup_component(Domain, Node) ->
mnesia:dirty_read(external_component, {Domain, Node}).

-spec dirty_get_all_domains() -> [jid:lserver()].
dirty_get_all_domains() ->
dirty_get_all_domains(all).

-spec dirty_get_all_domains(return_hidden()) -> [jid:lserver()].
dirty_get_all_domains(ReturnHidden) ->
lists:usort(all_routes(ReturnHidden)).

-spec all_routes(return_hidden()) -> [jid:lserver()].
all_routes(all) ->
mongoose_router:get_all_domains() ++ mnesia:dirty_all_keys(external_component_global);
all_routes(only_public) ->
MatchNonHidden = {#external_component{ domain = '$1', is_hidden = false, _ = '_' }, [], ['$1']},
mongoose_router:get_all_domains()
++
mnesia:dirty_select(external_component_global, [MatchNonHidden]).

-spec dirty_get_all_components(return_hidden()) -> [jid:lserver()].
dirty_get_all_components(all) ->
mnesia:dirty_all_keys(external_component_global);
Expand Down
5 changes: 3 additions & 2 deletions src/ejabberd_s2s_in.erl
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ stream_established({xmlstreamelement, El}, StateData) ->
%% domain is handled by this server:
case {ejabberd_s2s:allow_host(LTo, LFrom),
mongoose_router:is_registered_route(LTo)
orelse lists:member(LTo, ejabberd_router:dirty_get_all_domains())} of
orelse lists:member(LTo, ejabberd_router:dirty_get_all_components(all))} of
{true, true} ->
ejabberd_s2s_out:terminate_if_waiting_delay(LTo, LFrom),
ejabberd_s2s_out:start(LTo, LFrom,
Expand Down Expand Up @@ -427,7 +427,8 @@ route_incoming_stanza(From, To, El, StateData) ->
is_s2s_authenticated(_, _, #state{authenticated = false}) ->
false;
is_s2s_authenticated(LFrom, LTo, #state{auth_domain = LFrom}) ->
lists:member(LTo, ejabberd_router:dirty_get_all_domains());
mongoose_router:is_registered_route(LTo)
orelse lists:member(LTo, ejabberd_router:dirty_get_all_components(all));
is_s2s_authenticated(_, _, _) ->
false.

Expand Down
2 changes: 1 addition & 1 deletion src/system_metrics/mongoose_system_metrics_collector.erl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ get_version() ->
end.

get_components() ->
Domains = mongoose_router:get_all_domains() ++ ejabberd_router:dirty_get_all_domains(),
Domains = mongoose_router:get_all_domains() ++ ejabberd_router:dirty_get_all_components(all),
Components = [ejabberd_router:lookup_component(D, node()) || D <- Domains],
LenComponents = length(lists:flatten(Components)),
#{report_name => cluster, key => number_of_components, value => LenComponents}.
Expand Down

0 comments on commit 6dc91ac

Please sign in to comment.