Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CETS backend for mod_jingle_sip #4076

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions big_tests/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
{s2s_backend, "\"cets\""},
{stream_management_backend, cets},
{muc_online_backend, cets},
{jingle_sip_backend, cets},
{auth_method, "rdbms"},
{internal_databases, "[internal_databases.cets]
cluster_name = \"{{cluster_name}}\"
Expand Down
13 changes: 7 additions & 6 deletions big_tests/tests/jingle_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ init_per_suite(Config) ->
case rpc(mim(), application, get_application, [nksip]) of
{ok, nksip} ->
distributed_helper:add_node_to_cluster(mim2(), Config),
start_nksip_in_mim_nodes(),
start_nksip_in_mim_nodes(Config),
application:ensure_all_started(esip),
spawn(fun() -> ets:new(jingle_sip_translator, [public, named_table]),
ets:new(jingle_sip_translator_bindings, [public, named_table]),
Expand All @@ -71,9 +71,9 @@ init_per_suite(Config) ->
{skip, build_was_not_configured_with_jingle_sip}
end.

start_nksip_in_mim_nodes() ->
Pid1 = start_nskip_in_parallel(mim(), #{}),
Pid2 = start_nskip_in_parallel(mim2(), #{listen_port => 12346}),
start_nksip_in_mim_nodes(Config) ->
Pid1 = start_nskip_in_parallel(Config, mim(), #{}),
Pid2 = start_nskip_in_parallel(Config, mim2(), #{listen_port => 12346}),
wait_for_process_to_stop(Pid1),
wait_for_process_to_stop(Pid2).

Expand All @@ -85,10 +85,11 @@ wait_for_process_to_stop(Pid) ->
ct:fail(wait_for_process_to_stop_timeout)
end.

start_nskip_in_parallel(NodeSpec, ExtraOpts) ->
start_nskip_in_parallel(Config, NodeSpec, ExtraOpts) ->
Domain = domain(),
Opts = #{proxy_host => <<"localhost">>,
proxy_port => 12345},
proxy_port => 12345,
backend => ct_helper:get_preset_var(Config, jingle_sip_backend, mnesia)},
OptsWithExtra = maps:merge(Opts, ExtraOpts),
AllOpts = config_parser_helper:mod_config(mod_jingle_sip, OptsWithExtra),
RPCSpec = NodeSpec#{timeout => timer:seconds(60)},
Expand Down
7 changes: 7 additions & 0 deletions doc/modules/mod_jingle_sip.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ MongooseIM packages are built with Jingle/SIP support.

## Options

### `modules.mod_jingle_sip.backend`
* **Syntax:** string, `"mnesia"`, `"cets"`
* **Default:** `"mnesia"`
* **Example:** `backend = "cets"`

Backend for in-memory data for this module.

### `modules.mod_jingle_sip.proxy_host`
* **Syntax:** string
* **Default:** `"localhost"`
Expand Down
15 changes: 15 additions & 0 deletions include/mod_jingle_sip_session.hrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%% Defineds record to store SIP session information
%% Type is in mod_jingle_sip_session:session()
-record(jingle_sip_session, {
%% SIP CallID
sid,
dialog,
state,
direction,
request,
node,
owner,
from,
to,
now,
meta}).
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.9.0">>},1},
{<<"cets">>,
{git,"https://github.com/esl/cets.git",
{ref,"7d4876fe5285118f5349970ffb20080ea62293db"}},
{ref,"b4fefc99af7e5a729e47e1edf6453426941da766"}},
0},
{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.9.0">>},0},
{<<"cowboy_swagger">>,{pkg,<<"cowboy_swagger">>,<<"2.5.1">>},0},
Expand Down
13 changes: 7 additions & 6 deletions src/jingle_sip/jingle_sip_callbacks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ translate_and_deliver_invite(Req, FromJID, FromBinary, ToJID, ToBinary) ->

JingleEl = jingle_sip_helper:jingle_element(CallID, <<"session-initiate">>, ContentEls ++ OtherEls),

ok = mod_jingle_sip_backend:set_incoming_request(CallID, ReqID, FromJID, ToJID, JingleEl),
ok = mod_jingle_sip_session:set_incoming_request(CallID, ReqID, FromJID, ToJID, JingleEl),

?LOG_INFO(#{what => sip_invite, text => <<"Got SIP INVITE from NkSIP">>,
from_jid => FromBinary, to_jid => ToBinary,
Expand Down Expand Up @@ -176,7 +176,7 @@ sip_bye(Req, _Call) ->
from_jid => FromJID,
to_jid => ToJID }),
maybe_route_to_all_sessions(FromJID, ToJID, Acc, IQEl),

ok = mod_jingle_sip_session:remove_session(CallID),
{reply, ok}.

sip_cancel(_InviteReq, Req, _Call) ->
Expand All @@ -194,7 +194,7 @@ sip_cancel(_InviteReq, Req, _Call) ->
from_jid => FromJID,
to_jid => ToJID }),
maybe_route_to_all_sessions(FromJID, ToJID, Acc, IQEl),

ok = mod_jingle_sip_session:remove_session(CallID),
{reply, ok}.

sip_dialog_update(start, Dialog, Call) ->
Expand All @@ -203,7 +203,7 @@ sip_dialog_update(start, Dialog, Call) ->
case Transaction#trans.class of
uas ->
{ok, CallID} = nksip_dialog:call_id(Dialog),
mod_jingle_sip_backend:set_incoming_handle(CallID, DialogHandle);
mod_jingle_sip_session:set_incoming_handle(CallID, DialogHandle);

_ ->
ok
Expand Down Expand Up @@ -247,7 +247,7 @@ invite_resp_callback({resp, 200, SIPMsg, _Call}) ->
element => IQEl,
from_jid => FromJID,
to_jid => ToJID }),
ok = mod_jingle_sip_backend:set_outgoing_accepted(CallID),
ok = mod_jingle_sip_session:set_outgoing_accepted(CallID),
maybe_route_to_all_sessions(FromJID, ToJID, Acc, IQEl),
ok;
invite_resp_callback({resp, 487, _SIPMsg, _Call}) ->
Expand Down Expand Up @@ -286,6 +286,7 @@ invite_resp_callback({resp, ErrorCode, SIPMsg, _Call})
from_jid => FromJID,
to_jid => ToJID }),
maybe_route_to_all_sessions(FromJID, ToJID, Acc, IQEl),
ok = mod_jingle_sip_session:remove_session(CallID),
ok;
invite_resp_callback(Data) ->
?LOG_ERROR(#{what => sip_unknown_response, sip_data => Data}).
Expand All @@ -303,7 +304,7 @@ send_ringing_session_info(SIPMsg, ErrorCode) ->
dialog_id => DialogId, server_id => SrvId,
from_jid => FromBinary, to_binary => ToBinary}),

mod_jingle_sip_backend:set_outgoing_handle(CallID, DialogHandle, FromJID, ToJID),
mod_jingle_sip_session:set_outgoing_handle(CallID, DialogHandle, FromJID, ToJID),

RingingEl = #xmlel{name = <<"ringing">>,
attrs = [{<<"xmlns">>, <<"urn:xmpp:jingle:apps:rtp:info:1">>}]},
Expand Down
21 changes: 12 additions & 9 deletions src/jingle_sip/mod_jingle_sip.erl
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,18 @@
validate = ip_address},
<<"transport">> => #option{type = string,
validate = {enum, ["udp", "tcp"]}},
<<"username_to_phone">> => #list{items = username_to_phone_spec()}
<<"username_to_phone">> => #list{items = username_to_phone_spec()},
<<"backend">> => #option{type = atom,
validate = {module, mod_jingle_sip}}
},
defaults = #{<<"proxy_host">> => "localhost",
<<"proxy_port">> => 5060,
<<"listen_port">> => 5600,
<<"local_host">> => "localhost",
<<"sdp_origin">> => "127.0.0.1",
<<"transport">> => "udp",
<<"username_to_phone">> => []}
<<"username_to_phone">> => [],
<<"backend">> => mnesia}
}.

username_to_phone_spec() ->
Expand Down Expand Up @@ -206,7 +209,7 @@
From = mongoose_acc:from_jid(Acc),
To = mongoose_acc:to_jid(Acc),
SID = exml_query:attr(Jingle, <<"sid">>),
case mod_jingle_sip_backend:get_session_info(SID, From) of
case mod_jingle_sip_session:get_session_info(SID, From) of
{ok, Session} ->
maybe_resend_session_initiate(From, To, IQ, Acc, Session);
_ ->
Expand Down Expand Up @@ -247,7 +250,7 @@
%% Internal options
async,
{callback, fun jingle_sip_callbacks:invite_resp_callback/1}]),
Result = mod_jingle_sip_backend:set_outgoing_request(SID, Handle, FromJID, ToJID),
Result = mod_jingle_sip_session:set_outgoing_request(SID, Handle, FromJID, ToJID),
{_, SrvId, DialogId, _CallId} = nksip_sipmsg:parse_handle(Handle),
?LOG_INFO(#{what => sip_session_start,
text => <<"Start SIP session with set_outgoing_request call">>,
Expand All @@ -258,7 +261,7 @@
translate_to_sip(<<"session-accept">>, Jingle, Acc) ->
LServer = mongoose_acc:lserver(Acc),
SID = exml_query:attr(Jingle, <<"sid">>),
case mod_jingle_sip_backend:get_incoming_request(SID, mongoose_acc:get(c2s, origin_jid, Acc)) of
case mod_jingle_sip_session:get_incoming_request(SID, mongoose_acc:get(c2s, origin_jid, Acc)) of
{ok, ReqID} ->
try_to_accept_session(ReqID, Jingle, Acc, LServer, SID);
_ ->
Expand All @@ -273,7 +276,7 @@
translate_to_sip(<<"transport-info">>, Jingle, Acc) ->
SID = exml_query:attr(Jingle, <<"sid">>),
SDP = make_sdp_for_ice_candidate(Jingle),
case mod_jingle_sip_backend:get_outgoing_handle(SID, mongoose_acc:get(c2s, origin_jid, Acc)) of
case mod_jingle_sip_session:get_outgoing_handle(SID, mongoose_acc:get(c2s, origin_jid, Acc)) of

Check warning on line 279 in src/jingle_sip/mod_jingle_sip.erl

View check run for this annotation

Codecov / codecov/patch

src/jingle_sip/mod_jingle_sip.erl#L279

Added line #L279 was not covered by tests
{ok, undefined} ->
?LOG_ERROR(#{what => sip_missing_dialog, sid => SID, acc => Acc}),
{error, item_not_found};
Expand All @@ -290,7 +293,7 @@
From = mongoose_acc:get(c2s, origin_jid, Acc),
FromLUS = jid:to_lus(From),
ToLUS = jid:to_lus(ToJID),
case mod_jingle_sip_backend:get_session_info(SID, From) of
case mod_jingle_sip_session:get_session_info(SID, From) of
{ok, Session} ->
try_to_terminate_the_session(FromLUS, ToLUS, Session);
_ ->
Expand All @@ -300,7 +303,7 @@
translate_source_change_to_sip(ActionName, Jingle, Acc) ->
SID = exml_query:attr(Jingle, <<"sid">>),
SDP = get_spd(ActionName, Jingle, Acc),
case mod_jingle_sip_backend:get_outgoing_handle(SID, mongoose_acc:get(c2s, origin_jid, Acc)) of
case mod_jingle_sip_session:get_outgoing_handle(SID, mongoose_acc:get(c2s, origin_jid, Acc)) of
{ok, undefined} ->
?LOG_ERROR(#{what => sip_missing_dialod, sid => SID, acc => Acc}),
{error, item_not_found};
Expand Down Expand Up @@ -342,7 +345,7 @@
LocalHost = gen_mod:get_module_opt(Server, ?MODULE, local_host),
case nksip_request_reply({ok, [{body, SDP}, {local_host, LocalHost}]}, ReqID) of
ok ->
ok = mod_jingle_sip_backend:set_incoming_accepted(SID),
ok = mod_jingle_sip_session:set_incoming_accepted(SID),
terminate_session_on_other_devices(SID, Acc),
ok;
Other ->
Expand Down
Loading