Skip to content

Commit

Permalink
Merge pull request #4181 from esl/document-muc-online-backend
Browse files Browse the repository at this point in the history
Document muc online backend / move files
  • Loading branch information
chrzaszcz authored Dec 5, 2023
2 parents 216342f + 4e94945 commit c5ff950
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion big_tests/tests/mongoose_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ stop_online_rooms() ->
end,
rpc(mim(), erlang, exit, [SupervisorPid, kill]),
%% That's a pretty dirty way
rpc(mim(), mongoose_muc_online_backend, clear_table, [HostType]),
rpc(mim(), mod_muc_online_backend, clear_table, [HostType]),
ok.

forget_persistent_rooms() ->
Expand Down
2 changes: 1 addition & 1 deletion big_tests/tests/muc_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ destroy_room(Config) ->
destroy_room(Host, Room) when is_binary(Host), is_binary(Room) ->
HostType = domain_helper:host_type(),
Room1 = jid:nodeprep(Room),
case rpc(mim(), mongoose_muc_online_backend, find_room_pid, [HostType, Host, Room1]) of
case rpc(mim(), mod_muc_online_backend, find_room_pid, [HostType, Host, Room1]) of
{ok, Pid} ->
%% @TODO related to gen_fsm_compat: after migration to gen_statem
%% should be replaced to - gen_statem:call(Pid, destroy).
Expand Down
2 changes: 1 addition & 1 deletion doc/configuration/internal-databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The following example enables only CETS with the default RDBMS discovery backend
When switching to CETS, you need to configure particular backends to actually use it:

* general backends: [`sm_backend`](general.md#generalsm_backend), [`s2s_backend`](general.md#generals2s_backend), [`component_backend`](general.md#generalcomponent_backend)
* module backends: [`mod_bosh`](../modules/mod_bosh.md#modulesmod_boshbackend), [`mod_stream_management`](../modules/mod_stream_management.md#modulesmod_stream_managementbackend), [`mod_jingle_sip`](../modules/mod_jingle_sip.md#modulesmod_jingle_sipbackend)
* module backends: [`mod_bosh`](../modules/mod_bosh.md#modulesmod_boshbackend), [`mod_stream_management`](../modules/mod_stream_management.md#modulesmod_stream_managementbackend), [`mod_jingle_sip`](../modules/mod_jingle_sip.md#modulesmod_jingle_sipbackend), [`mod_muc`](../modules/mod_muc.md#modulesmod_muconline_backend)

Sometimes you might want to have both databases enabled and choose which backends use a particular DB:

Expand Down
14 changes: 12 additions & 2 deletions doc/modules/mod_muc.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ Subdomain for MUC service to reside under. `@HOST@` is replaced with each served
* **Syntax:** string, one of `"mnesia"` or `"rdbms"`
* **Default:** `"mnesia"`
* **Example:** `backend = "rdbms"`

Storage backend.

Storage backend to store rooms and settings persistently.

### `modules.mod_muc.online_backend`
* **Syntax:** string, one of `"mnesia"` or `"cets"`
* **Default:** `"mnesia"`
* **Example:** `online_backend = "cets"`

Backend to use to register and find online rooms. Queried when routing stanzas to the rooms.

!!! Warning
The corresponding [internal database](../configuration/internal-databases.md) has to be enabled.

### `modules.mod_muc.access`
* **Syntax:** non-empty string
Expand Down
16 changes: 8 additions & 8 deletions src/mod_muc.erl → src/muc/mod_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ start_link(HostType, Opts) ->

-spec start(host_type(), _) -> ok.
start(HostType, Opts) when is_map(Opts) ->
mongoose_muc_online_backend:start(HostType, Opts),
mod_muc_online_backend:start(HostType, Opts),
ensure_metrics(HostType),
start_supervisor(HostType),
start_server(HostType, Opts),
Expand All @@ -175,7 +175,7 @@ start(HostType, Opts) when is_map(Opts) ->
stop(HostType) ->
stop_supervisor(HostType),
stop_gen_server(HostType),
mongoose_muc_online_backend:stop(HostType),
mod_muc_online_backend:stop(HostType),
ok.

-spec supported_features() -> [atom()].
Expand All @@ -202,7 +202,7 @@ config_spec() ->
items = #{<<"backend">> => #option{type = atom,
validate = {module, mod_muc}},
<<"online_backend">> => #option{type = atom,
validate = {module, mongoose_muc_online}},
validate = {module, mod_muc_online}},
<<"host">> => #option{type = string,
validate = subdomain_template,
process = fun mongoose_subdomain_utils:make_subdomain_pattern/1},
Expand Down Expand Up @@ -371,7 +371,7 @@ stop_gen_server(HostType) ->
%% So the message sending must be catched
-spec room_destroyed(host_type(), jid:server(), room(), pid()) -> 'ok'.
room_destroyed(HostType, MucHost, Room, Pid) ->
mongoose_muc_online_backend:room_destroyed(HostType, MucHost, Room, Pid).
mod_muc_online_backend:room_destroyed(HostType, MucHost, Room, Pid).

%% @doc Create a room.
%% If Opts = default, the default room options are used.
Expand Down Expand Up @@ -914,7 +914,7 @@ register_room_or_stop_if_duplicate(HostType, MucHost, Room, Pid) ->
-spec register_room(HostType :: host_type(), jid:server(), room(),
pid()) -> ok | {exists, pid()} | {error, term()}.
register_room(HostType, MucHost, Room, Pid) ->
mongoose_muc_online_backend:register_room(HostType, MucHost, Room, Pid).
mod_muc_online_backend:register_room(HostType, MucHost, Room, Pid).

-spec room_jid_to_pid(RoomJID :: jid:jid()) -> {ok, pid()} | {error, not_found}.
room_jid_to_pid(#jid{luser = Room, lserver = MucHost}) ->
Expand All @@ -926,7 +926,7 @@ room_jid_to_pid(#jid{luser = Room, lserver = MucHost}) ->
end.

find_room_pid(HostType, MucHost, Room) ->
mongoose_muc_online_backend:find_room_pid(HostType, MucHost, Room).
mod_muc_online_backend:find_room_pid(HostType, MucHost, Room).

-spec default_host() -> mongoose_subdomain_utils:subdomain_pattern().
default_host() ->
Expand Down Expand Up @@ -1162,7 +1162,7 @@ broadcast_service_message(MucHost, Msg) ->
-spec get_vh_rooms(muc_host()) -> [muc_online_room()].
get_vh_rooms(MucHost) ->
{ok, HostType} = mongoose_domain_api:get_subdomain_host_type(MucHost),
mongoose_muc_online_backend:get_online_rooms(HostType, MucHost).
mod_muc_online_backend:get_online_rooms(HostType, MucHost).

-spec get_persistent_vh_rooms(muc_host()) -> [muc_room()].
get_persistent_vh_rooms(MucHost) ->
Expand All @@ -1176,7 +1176,7 @@ get_persistent_vh_rooms(MucHost) ->

-spec node_cleanup(host_type(), node()) -> ok.
node_cleanup(HostType, Node) ->
mongoose_muc_online_backend:node_cleanup(HostType, Node).
mod_muc_online_backend:node_cleanup(HostType, Node).

%%====================================================================
%% Hooks handlers
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(mongoose_muc_online_backend).
-module(mod_muc_online_backend).

-export([start/2,
stop/1,
Expand All @@ -12,7 +12,7 @@
%% Used in tests
-ignore_xref([clear_table/1]).

-define(MAIN_MODULE, mongoose_muc_online).
-define(MAIN_MODULE, mod_muc_online).

%% Callbacks

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-module(mongoose_muc_online_cets).
-behaviour(mongoose_muc_online_backend).
-module(mod_muc_online_cets).
-behaviour(mod_muc_online_backend).

-export([start/2,
stop/1,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-module(mongoose_muc_online_mnesia).
-behaviour(mongoose_muc_online_backend).
-module(mod_muc_online_mnesia).
-behaviour(mod_muc_online_backend).

-export([start/2,
stop/1,
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions test/mongoose_cleanup_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -264,19 +264,19 @@ muc_room(_Config) ->
Pid = remote_pid(),
Node = node(Pid),
Room = <<"remote_room">>,
ok = mongoose_muc_online_backend:register_room(HostType, MucHost, Room, Pid),
ok = mongoose_muc_online_backend:node_cleanup(HostType, Node),
{error, not_found} = mongoose_muc_online_backend:find_room_pid(HostType, MucHost, Room).
ok = mod_muc_online_backend:register_room(HostType, MucHost, Room, Pid),
ok = mod_muc_online_backend:node_cleanup(HostType, Node),
{error, not_found} = mod_muc_online_backend:find_room_pid(HostType, MucHost, Room).

muc_room_from_other_node_remains(_Config) ->
HostType = ?HOST,
MucHost = <<"muc.localhost">>,
Pid = self(),
RemoteNode = node(remote_pid()),
Room = <<"room_on_other_node">>,
ok = mongoose_muc_online_backend:register_room(HostType, MucHost, Room, Pid),
ok = mongoose_muc_online_backend:node_cleanup(HostType, RemoteNode),
{ok, Pid} = mongoose_muc_online_backend:find_room_pid(HostType, MucHost, Room).
ok = mod_muc_online_backend:register_room(HostType, MucHost, Room, Pid),
ok = mod_muc_online_backend:node_cleanup(HostType, RemoteNode),
{ok, Pid} = mod_muc_online_backend:find_room_pid(HostType, MucHost, Room).

%% -----------------------------------------------------
%% Internal
Expand Down Expand Up @@ -376,7 +376,7 @@ start_muc(TestCase, Config) ->
end.

start_muc_backend(Backend) ->
mongoose_muc_online_backend:start(?HOST, #{online_backend => Backend}).
mod_muc_online_backend:start(?HOST, #{online_backend => Backend}).

start_muc_module(Backend) ->
ExtraOpts = #{online_backend => Backend, backend => mnesia},
Expand Down

0 comments on commit c5ff950

Please sign in to comment.