25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-24 17:29:28 +01:00

Define pubsub node configuration per route/host explicitly

This commit is contained in:
Evgeniy Khramtsov 2016-03-13 13:16:43 +03:00
parent 357e48fb6b
commit 5045fb584d

View File

@ -257,22 +257,26 @@ init([ServerHost, Opts]) ->
DefaultNodeCfg = gen_mod:get_opt(default_node_config, Opts, DefaultNodeCfg = gen_mod:get_opt(default_node_config, Opts,
fun(A) when is_list(A) -> filter_node_options(A) end, []), fun(A) when is_list(A) -> filter_node_options(A) end, []),
pubsub_index:init(Host, ServerHost, Opts), pubsub_index:init(Host, ServerHost, Opts),
ets:new(gen_mod:get_module_proc(ServerHost, config), [set, named_table]),
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts), {Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
mnesia:create_table(pubsub_last_item, mnesia:create_table(pubsub_last_item,
[{ram_copies, [node()]}, [{ram_copies, [node()]},
{attributes, record_info(fields, pubsub_last_item)}]), {attributes, record_info(fields, pubsub_last_item)}]),
mod_disco:register_feature(ServerHost, ?NS_PUBSUB), mod_disco:register_feature(ServerHost, ?NS_PUBSUB),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {nodetree, NodeTree}), lists:foreach(
ets:insert(gen_mod:get_module_proc(ServerHost, config), {plugins, Plugins}), fun(H) ->
ets:insert(gen_mod:get_module_proc(ServerHost, config), {last_item_cache, LastItemCache}), T = gen_mod:get_module_proc(H, config),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_items_node, MaxItemsNode}), ets:new(T, [set, named_table]),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_subscriptions_node, MaxSubsNode}), ets:insert(T, {nodetree, NodeTree}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {default_node_config, DefaultNodeCfg}), ets:insert(T, {plugins, Plugins}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}), ets:insert(T, {last_item_cache, LastItemCache}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}), ets:insert(T, {max_items_node, MaxItemsNode}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}), ets:insert(T, {max_subscriptions_node, MaxSubsNode}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {access, Access}), ets:insert(T, {default_node_config, DefaultNodeCfg}),
ets:insert(T, {pep_mapping, PepMapping}),
ets:insert(T, {ignore_pep_from_offline, PepOffline}),
ets:insert(T, {host, Host}),
ets:insert(T, {access, Access})
end, [Host, ServerHost]),
ejabberd_hooks:add(sm_remove_connection_hook, ServerHost, ejabberd_hooks:add(sm_remove_connection_hook, ServerHost,
?MODULE, on_user_offline, 75), ?MODULE, on_user_offline, 75),
ejabberd_hooks:add(disco_local_identity, ServerHost, ejabberd_hooks:add(disco_local_identity, ServerHost,
@ -3641,7 +3645,7 @@ get_option(Options, Var, Def) ->
end. end.
node_options(Host, Type) -> node_options(Host, Type) ->
case config(serverhost(Host), default_node_config) of case config(Host, default_node_config) of
undefined -> node_plugin_options(Host, Type); undefined -> node_plugin_options(Host, Type);
[] -> node_plugin_options(Host, Type); [] -> node_plugin_options(Host, Type);
Config -> Config Config -> Config
@ -3954,15 +3958,15 @@ set_xoption(Host, [_ | Opts], NewOpts) ->
set_xoption(Host, Opts, NewOpts). set_xoption(Host, Opts, NewOpts).
get_max_items_node(Host) -> get_max_items_node(Host) ->
config(serverhost(Host), max_items_node, undefined). config(Host, max_items_node, undefined).
get_max_subscriptions_node(Host) -> get_max_subscriptions_node(Host) ->
config(serverhost(Host), max_subscriptions_node, undefined). config(Host, max_subscriptions_node, undefined).
%%%% last item cache handling %%%% last item cache handling
is_last_item_cache_enabled(Host) -> is_last_item_cache_enabled(Host) ->
config(serverhost(Host), last_item_cache, false). config(Host, last_item_cache, false).
set_cached_item({_, ServerHost, _}, Nidx, ItemId, Publisher, Payload) -> set_cached_item({_, ServerHost, _}, Nidx, ItemId, Publisher, Payload) ->
set_cached_item(ServerHost, Nidx, ItemId, Publisher, Payload); set_cached_item(ServerHost, Nidx, ItemId, Publisher, Payload);
@ -4013,13 +4017,12 @@ host(ServerHost) ->
config(ServerHost, host, <<"pubsub.", ServerHost/binary>>). config(ServerHost, host, <<"pubsub.", ServerHost/binary>>).
serverhost({_U, ServerHost, _R})-> serverhost({_U, ServerHost, _R})->
ServerHost; serverhost(ServerHost);
serverhost(Host) -> serverhost(Host) ->
[_, ServerHost] = binary:split(Host, <<".">>), ejabberd_router:host_of_route(Host).
ServerHost.
tree(Host) -> tree(Host) ->
case config(serverhost(Host), nodetree) of case config(Host, nodetree) of
undefined -> tree(Host, ?STDTREE); undefined -> tree(Host, ?STDTREE);
Tree -> Tree Tree -> Tree
end. end.
@ -4041,7 +4044,7 @@ plugin(Host, Name) ->
end. end.
plugins(Host) -> plugins(Host) ->
case config(serverhost(Host), plugins) of case config(Host, plugins) of
undefined -> [?STDNODE]; undefined -> [?STDNODE];
[] -> [?STDNODE]; [] -> [?STDNODE];
Plugins -> Plugins Plugins -> Plugins
@ -4056,6 +4059,9 @@ subscription_plugin(Host) ->
config(ServerHost, Key) -> config(ServerHost, Key) ->
config(ServerHost, Key, undefined). config(ServerHost, Key, undefined).
config({_User, Host, _Resource}, Key, Default) ->
config(Host, Key, Default);
config(ServerHost, Key, Default) -> config(ServerHost, Key, Default) ->
case catch ets:lookup(gen_mod:get_module_proc(ServerHost, config), Key) of case catch ets:lookup(gen_mod:get_module_proc(ServerHost, config), Key) of
[{Key, Value}] -> Value; [{Key, Value}] -> Value;