1 |
|
%% Just a proxy interface module between the main mod_keystore module and |
2 |
|
%% the backend modules (i.e. mod_keystore_mnesia...). |
3 |
|
-module(mod_keystore_backend). |
4 |
|
|
5 |
|
-export([init/2, stop/1, init_ram_key/2, get_key/1]). |
6 |
|
|
7 |
|
-define(MAIN_MODULE, mod_keystore). |
8 |
|
|
9 |
|
-callback init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. |
10 |
|
-callback stop(mongooseim:host_type()) -> ok. |
11 |
|
|
12 |
|
%% Cluster members race to decide whose key gets stored in the distributed database. |
13 |
|
%% That's why ProposedKey (the key this cluster member tries to propagate to other nodes) |
14 |
|
%% might not be the same as ActualKey (key of the member who will have won the race). |
15 |
|
-callback init_ram_key(ProposedKey) -> Result when |
16 |
|
ProposedKey :: mod_keystore:key(), |
17 |
|
Result :: {ok, ActualKey} | {error, any()}, |
18 |
|
ActualKey :: mod_keystore:key(). |
19 |
|
|
20 |
|
-callback get_key(ID :: mod_keystore:key_id()) -> mod_keystore:key_list(). |
21 |
|
|
22 |
|
-spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. |
23 |
|
init(HostType, Opts) -> |
24 |
:-( |
mongoose_backend:init(HostType, ?MAIN_MODULE, [], Opts), |
25 |
:-( |
Args = [HostType, Opts], |
26 |
:-( |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
27 |
|
|
28 |
|
-spec stop(mongooseim:host_type()) -> ok. |
29 |
|
stop(HostType) -> |
30 |
:-( |
Args = [HostType], |
31 |
:-( |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
32 |
|
|
33 |
|
%% Cluster members race to decide whose key gets stored in the distributed database. |
34 |
|
%% That's why ProposedKey (the key this cluster member tries to propagate to other nodes) |
35 |
|
%% might not be the same as ActualKey (key of the member who will have won the race). |
36 |
|
-spec init_ram_key(HostType, ProposedKey) -> Result when |
37 |
|
HostType :: mongooseim:host_type(), |
38 |
|
ProposedKey :: mod_keystore:key(), |
39 |
|
Result :: {ok, ActualKey} | {error, any()}, |
40 |
|
ActualKey :: mod_keystore:key(). |
41 |
|
init_ram_key(HostType, ProposedKey) -> |
42 |
:-( |
Args = [ProposedKey], |
43 |
:-( |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |
44 |
|
|
45 |
|
-spec get_key(ID :: mod_keystore:key_id()) -> mod_keystore:key_list(). |
46 |
|
get_key({_, HostType} = ID) -> |
47 |
:-( |
Args = [ID], |
48 |
:-( |
mongoose_backend:call(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). |