2016-12-28 07:47:11 +01:00
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
%%% Author : Holger Weiss <holger@zedat.fu-berlin.de>
|
|
|
|
%%% Created : 25 Dec 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2021-01-27 16:55:25 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2021 ProcessOne
|
2016-12-28 07:47:11 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
%%%
|
|
|
|
%%%-------------------------------------------------------------------
|
2017-02-21 07:18:58 +01:00
|
|
|
-module(mod_stream_mgmt).
|
2016-12-28 07:47:11 +01:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
-author('holger@zedat.fu-berlin.de').
|
|
|
|
-protocol({xep, 198, '1.5.2'}).
|
|
|
|
|
|
|
|
%% gen_mod API
|
2018-01-23 08:54:52 +01:00
|
|
|
-export([start/2, stop/1, reload/3, depends/2, mod_opt_type/1, mod_options/1]).
|
2020-01-08 10:24:51 +01:00
|
|
|
-export([mod_doc/0]).
|
2016-12-28 07:47:11 +01:00
|
|
|
%% hooks
|
2019-06-14 11:33:26 +02:00
|
|
|
-export([c2s_stream_started/2, c2s_stream_features/2,
|
2016-12-28 07:47:11 +01:00
|
|
|
c2s_authenticated_packet/2, c2s_unauthenticated_packet/2,
|
2016-12-29 22:00:36 +01:00
|
|
|
c2s_unbinded_packet/2, c2s_closed/2, c2s_terminated/2,
|
2017-01-09 15:02:17 +01:00
|
|
|
c2s_handle_send/3, c2s_handle_info/2, c2s_handle_call/3,
|
|
|
|
c2s_handle_recv/3]).
|
2018-04-17 00:27:07 +02:00
|
|
|
%% adjust pending session timeout / access queue
|
|
|
|
-export([get_resume_timeout/1, set_resume_timeout/2, queue_find/2]).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("xmpp/include/xmpp.hrl").
|
2016-12-28 07:47:11 +01:00
|
|
|
-include("logger.hrl").
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("p1_utils/include/p1_queue.hrl").
|
2019-06-22 16:08:45 +02:00
|
|
|
-include("translate.hrl").
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2018-11-30 14:18:49 +01:00
|
|
|
-define(STREAM_MGMT_CACHE, stream_mgmt_cache).
|
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
-define(is_sm_packet(Pkt),
|
|
|
|
is_record(Pkt, sm_enable) or
|
|
|
|
is_record(Pkt, sm_resume) or
|
|
|
|
is_record(Pkt, sm_a) or
|
|
|
|
is_record(Pkt, sm_r)).
|
|
|
|
|
|
|
|
-type state() :: ejabberd_c2s:state().
|
2019-06-28 21:16:29 +02:00
|
|
|
-type queue() :: p1_queue:queue({non_neg_integer(), erlang:timestamp(), xmpp_element() | xmlel()}).
|
2020-06-01 21:33:55 +02:00
|
|
|
-type id() :: binary().
|
2019-06-25 19:42:54 +02:00
|
|
|
-type error_reason() :: session_not_found | session_timed_out |
|
|
|
|
session_is_dead | session_has_exited |
|
|
|
|
session_was_killed | session_copy_timed_out |
|
|
|
|
invalid_previd.
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% API
|
|
|
|
%%%===================================================================
|
2018-11-30 14:18:49 +01:00
|
|
|
start(Host, Opts) ->
|
|
|
|
init_cache(Opts),
|
2016-12-28 07:47:11 +01:00
|
|
|
ejabberd_hooks:add(c2s_stream_started, Host, ?MODULE,
|
|
|
|
c2s_stream_started, 50),
|
|
|
|
ejabberd_hooks:add(c2s_post_auth_features, Host, ?MODULE,
|
|
|
|
c2s_stream_features, 50),
|
|
|
|
ejabberd_hooks:add(c2s_unauthenticated_packet, Host, ?MODULE,
|
|
|
|
c2s_unauthenticated_packet, 50),
|
|
|
|
ejabberd_hooks:add(c2s_unbinded_packet, Host, ?MODULE,
|
|
|
|
c2s_unbinded_packet, 50),
|
|
|
|
ejabberd_hooks:add(c2s_authenticated_packet, Host, ?MODULE,
|
|
|
|
c2s_authenticated_packet, 50),
|
2016-12-29 22:00:36 +01:00
|
|
|
ejabberd_hooks:add(c2s_handle_send, Host, ?MODULE, c2s_handle_send, 50),
|
|
|
|
ejabberd_hooks:add(c2s_handle_recv, Host, ?MODULE, c2s_handle_recv, 50),
|
|
|
|
ejabberd_hooks:add(c2s_handle_info, Host, ?MODULE, c2s_handle_info, 50),
|
|
|
|
ejabberd_hooks:add(c2s_handle_call, Host, ?MODULE, c2s_handle_call, 50),
|
|
|
|
ejabberd_hooks:add(c2s_closed, Host, ?MODULE, c2s_closed, 50),
|
|
|
|
ejabberd_hooks:add(c2s_terminated, Host, ?MODULE, c2s_terminated, 50).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
stop(Host) ->
|
|
|
|
ejabberd_hooks:delete(c2s_stream_started, Host, ?MODULE,
|
|
|
|
c2s_stream_started, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_post_auth_features, Host, ?MODULE,
|
|
|
|
c2s_stream_features, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_unauthenticated_packet, Host, ?MODULE,
|
|
|
|
c2s_unauthenticated_packet, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_unbinded_packet, Host, ?MODULE,
|
|
|
|
c2s_unbinded_packet, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_authenticated_packet, Host, ?MODULE,
|
|
|
|
c2s_authenticated_packet, 50),
|
2016-12-29 22:00:36 +01:00
|
|
|
ejabberd_hooks:delete(c2s_handle_send, Host, ?MODULE, c2s_handle_send, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_handle_recv, Host, ?MODULE, c2s_handle_recv, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_handle_info, Host, ?MODULE, c2s_handle_info, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_handle_call, Host, ?MODULE, c2s_handle_call, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_closed, Host, ?MODULE, c2s_closed, 50),
|
|
|
|
ejabberd_hooks:delete(c2s_terminated, Host, ?MODULE, c2s_terminated, 50).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2018-11-30 16:12:27 +01:00
|
|
|
reload(_Host, NewOpts, _OldOpts) ->
|
|
|
|
init_cache(NewOpts),
|
2019-09-23 14:17:20 +02:00
|
|
|
?WARNING_MSG("Module ~ts is reloaded, but new configuration will take "
|
2017-02-26 14:27:26 +01:00
|
|
|
"effect for newly created client connections only", [?MODULE]).
|
2017-02-22 17:46:47 +01:00
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[].
|
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
c2s_stream_started(#{lserver := LServer} = State, _StreamStart) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State1 = maps:remove(mgmt_options, State),
|
2018-01-23 08:54:52 +01:00
|
|
|
ResumeTimeout = get_configured_resume_timeout(LServer),
|
|
|
|
MaxResumeTimeout = get_max_resume_timeout(LServer, ResumeTimeout),
|
2016-12-28 07:47:11 +01:00
|
|
|
State1#{mgmt_state => inactive,
|
2018-01-23 08:54:52 +01:00
|
|
|
mgmt_queue_type => get_queue_type(LServer),
|
|
|
|
mgmt_max_queue => get_max_ack_queue(LServer),
|
2016-12-28 07:47:11 +01:00
|
|
|
mgmt_timeout => ResumeTimeout,
|
|
|
|
mgmt_max_timeout => MaxResumeTimeout,
|
2018-01-23 08:54:52 +01:00
|
|
|
mgmt_ack_timeout => get_ack_timeout(LServer),
|
|
|
|
mgmt_resend => get_resend_on_timeout(LServer),
|
2016-12-29 22:00:36 +01:00
|
|
|
mgmt_stanzas_in => 0,
|
|
|
|
mgmt_stanzas_out => 0,
|
|
|
|
mgmt_stanzas_req => 0};
|
2016-12-28 07:47:11 +01:00
|
|
|
c2s_stream_started(State, _StreamStart) ->
|
|
|
|
State.
|
|
|
|
|
|
|
|
c2s_stream_features(Acc, Host) ->
|
|
|
|
case gen_mod:is_loaded(Host, ?MODULE) of
|
|
|
|
true ->
|
|
|
|
[#feature_sm{xmlns = ?NS_STREAM_MGMT_2},
|
|
|
|
#feature_sm{xmlns = ?NS_STREAM_MGMT_3}|Acc];
|
|
|
|
false ->
|
|
|
|
Acc
|
|
|
|
end.
|
|
|
|
|
2018-06-25 08:56:44 +02:00
|
|
|
c2s_unauthenticated_packet(#{lang := Lang} = State, Pkt) when ?is_sm_packet(Pkt) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
%% XEP-0198 says: "For client-to-server connections, the client MUST NOT
|
|
|
|
%% attempt to enable stream management until after it has completed Resource
|
|
|
|
%% Binding unless it is resuming a previous session". However, it also
|
|
|
|
%% says: "Stream management errors SHOULD be considered recoverable", so we
|
|
|
|
%% won't bail out.
|
2018-06-25 08:56:44 +02:00
|
|
|
Err = #sm_failed{reason = 'not-authorized',
|
2019-06-22 16:08:45 +02:00
|
|
|
text = xmpp:mk_text(?T("Unauthorized"), Lang),
|
2018-06-25 08:56:44 +02:00
|
|
|
xmlns = ?NS_STREAM_MGMT_3},
|
2016-12-28 07:47:11 +01:00
|
|
|
{stop, send(State, Err)};
|
|
|
|
c2s_unauthenticated_packet(State, _Pkt) ->
|
|
|
|
State.
|
|
|
|
|
|
|
|
c2s_unbinded_packet(State, #sm_resume{} = Pkt) ->
|
|
|
|
case handle_resume(State, Pkt) of
|
|
|
|
{ok, ResumedState} ->
|
|
|
|
{stop, ResumedState};
|
2016-12-29 22:00:36 +01:00
|
|
|
{error, State1} ->
|
|
|
|
{stop, State1}
|
2016-12-28 07:47:11 +01:00
|
|
|
end;
|
|
|
|
c2s_unbinded_packet(State, Pkt) when ?is_sm_packet(Pkt) ->
|
|
|
|
c2s_unauthenticated_packet(State, Pkt);
|
|
|
|
c2s_unbinded_packet(State, _Pkt) ->
|
|
|
|
State.
|
|
|
|
|
|
|
|
c2s_authenticated_packet(#{mgmt_state := MgmtState} = State, Pkt)
|
|
|
|
when ?is_sm_packet(Pkt) ->
|
|
|
|
if MgmtState == pending; MgmtState == active ->
|
|
|
|
{stop, perform_stream_mgmt(Pkt, State)};
|
|
|
|
true ->
|
|
|
|
{stop, negotiate_stream_mgmt(Pkt, State)}
|
|
|
|
end;
|
|
|
|
c2s_authenticated_packet(State, Pkt) ->
|
|
|
|
update_num_stanzas_in(State, Pkt).
|
|
|
|
|
2018-02-15 13:42:55 +01:00
|
|
|
c2s_handle_recv(#{mgmt_state := MgmtState,
|
|
|
|
lang := Lang} = State, El, {error, Why}) ->
|
2016-12-29 22:00:36 +01:00
|
|
|
Xmlns = xmpp:get_ns(El),
|
2018-02-15 08:18:06 +01:00
|
|
|
IsStanza = xmpp:is_stanza(El),
|
2016-12-29 22:00:36 +01:00
|
|
|
if Xmlns == ?NS_STREAM_MGMT_2; Xmlns == ?NS_STREAM_MGMT_3 ->
|
|
|
|
Txt = xmpp:io_format_error(Why),
|
|
|
|
Err = #sm_failed{reason = 'bad-request',
|
|
|
|
text = xmpp:mk_text(Txt, Lang),
|
|
|
|
xmlns = Xmlns},
|
|
|
|
send(State, Err);
|
2018-02-15 13:42:55 +01:00
|
|
|
IsStanza andalso (MgmtState == pending orelse MgmtState == active) ->
|
|
|
|
State1 = update_num_stanzas_in(State, El),
|
2018-02-15 08:18:06 +01:00
|
|
|
case xmpp:get_type(El) of
|
2018-02-15 13:42:55 +01:00
|
|
|
<<"result">> -> State1;
|
|
|
|
<<"error">> -> State1;
|
2018-02-15 08:18:06 +01:00
|
|
|
_ ->
|
2018-02-15 13:50:20 +01:00
|
|
|
State1#{mgmt_force_enqueue => true}
|
2018-02-15 08:18:06 +01:00
|
|
|
end;
|
2016-12-29 22:00:36 +01:00
|
|
|
true ->
|
|
|
|
State
|
|
|
|
end;
|
|
|
|
c2s_handle_recv(State, _, _) ->
|
|
|
|
State.
|
|
|
|
|
2018-02-15 08:48:59 +01:00
|
|
|
c2s_handle_send(#{mgmt_state := MgmtState, mod := Mod,
|
|
|
|
lang := Lang} = State, Pkt, SendResult)
|
2020-04-07 14:51:49 +02:00
|
|
|
when MgmtState == pending; MgmtState == active; MgmtState == resumed ->
|
2018-02-15 08:48:59 +01:00
|
|
|
IsStanza = xmpp:is_stanza(Pkt),
|
2017-02-21 10:38:03 +01:00
|
|
|
case Pkt of
|
2018-02-15 08:48:59 +01:00
|
|
|
_ when IsStanza ->
|
2018-02-15 13:50:20 +01:00
|
|
|
case need_to_enqueue(State, Pkt) of
|
2018-02-15 08:48:59 +01:00
|
|
|
{true, State1} ->
|
|
|
|
case mgmt_queue_add(State1, Pkt) of
|
|
|
|
#{mgmt_max_queue := exceeded} = State2 ->
|
|
|
|
State3 = State2#{mgmt_resend => false},
|
|
|
|
Err = xmpp:serr_policy_violation(
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Too many unacked stanzas"), Lang),
|
2018-02-15 08:48:59 +01:00
|
|
|
send(State3, Err);
|
|
|
|
State2 when SendResult == ok ->
|
|
|
|
send_rack(State2);
|
|
|
|
State2 ->
|
|
|
|
State2
|
2017-01-09 15:02:17 +01:00
|
|
|
end;
|
2018-02-15 08:48:59 +01:00
|
|
|
{false, State1} ->
|
|
|
|
State1
|
2017-01-09 15:02:17 +01:00
|
|
|
end;
|
2017-02-21 10:38:03 +01:00
|
|
|
#stream_error{} ->
|
|
|
|
case MgmtState of
|
2020-04-07 14:51:49 +02:00
|
|
|
resumed ->
|
|
|
|
State;
|
2017-02-21 10:38:03 +01:00
|
|
|
active ->
|
|
|
|
State;
|
|
|
|
pending ->
|
2020-04-01 14:35:49 +02:00
|
|
|
Mod:stop_async(self()),
|
|
|
|
{stop, State#{stop_reason => {stream, {out, Pkt}}}}
|
2017-02-21 10:38:03 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2017-01-09 15:02:17 +01:00
|
|
|
State
|
2016-12-28 07:47:11 +01:00
|
|
|
end;
|
|
|
|
c2s_handle_send(State, _Pkt, _Result) ->
|
|
|
|
State.
|
|
|
|
|
2020-06-01 21:33:55 +02:00
|
|
|
c2s_handle_call(#{mgmt_id := MgmtID, mgmt_queue := Queue, mod := Mod} = State,
|
|
|
|
{resume_session, MgmtID}, From) ->
|
2017-03-10 13:12:43 +01:00
|
|
|
State1 = State#{mgmt_queue => p1_queue:file_to_ram(Queue)},
|
|
|
|
Mod:reply(From, {resume, State1}),
|
2020-04-07 14:51:49 +02:00
|
|
|
{stop, State#{mgmt_state => resumed, mgmt_queue => p1_queue:clear(Queue)}};
|
2017-01-09 20:03:42 +01:00
|
|
|
c2s_handle_call(#{mod := Mod} = State, {resume_session, _}, From) ->
|
2019-06-25 19:42:54 +02:00
|
|
|
Mod:reply(From, {error, session_not_found}),
|
2016-12-29 22:00:36 +01:00
|
|
|
{stop, State};
|
|
|
|
c2s_handle_call(State, _Call, _From) ->
|
|
|
|
State.
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2017-01-09 20:03:42 +01:00
|
|
|
c2s_handle_info(#{mgmt_ack_timer := TRef, jid := JID, mod := Mod} = State,
|
2016-12-29 22:00:36 +01:00
|
|
|
{timeout, TRef, ack_timeout}) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Timed out waiting for stream management acknowledgement of ~ts",
|
2017-02-26 08:07:12 +01:00
|
|
|
[jid:encode(JID)]),
|
2019-08-08 10:21:28 +02:00
|
|
|
State1 = Mod:close(State),
|
|
|
|
State2 = State1#{stop_reason => {socket, ack_timeout}},
|
|
|
|
{stop, transition_to_pending(State2, ack_timeout)};
|
2018-02-19 19:47:20 +01:00
|
|
|
c2s_handle_info(#{mgmt_state := pending, lang := Lang,
|
2017-07-21 01:07:36 +02:00
|
|
|
mgmt_pending_timer := TRef, jid := JID, mod := Mod} = State,
|
|
|
|
{timeout, TRef, pending_timeout}) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Timed out waiting for resumption of stream for ~ts",
|
2017-02-26 08:07:12 +01:00
|
|
|
[jid:encode(JID)]),
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Timed out waiting for stream resumption"),
|
2018-02-19 19:47:20 +01:00
|
|
|
Err = xmpp:serr_connection_timeout(Txt, Lang),
|
2020-04-01 14:35:49 +02:00
|
|
|
Mod:stop_async(self()),
|
|
|
|
{stop, State#{mgmt_state => timeout,
|
|
|
|
stop_reason => {stream, {out, Err}}}};
|
2019-07-30 19:57:32 +02:00
|
|
|
c2s_handle_info(State, {_Ref, {resume, #{jid := JID} = OldState}}) ->
|
2017-01-09 15:02:17 +01:00
|
|
|
%% This happens if the resume_session/1 request timed out; the new session
|
|
|
|
%% now receives the late response.
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Received old session state for ~ts after failed resumption",
|
2017-02-26 08:07:12 +01:00
|
|
|
[jid:encode(JID)]),
|
2017-01-09 15:02:17 +01:00
|
|
|
route_unacked_stanzas(OldState#{mgmt_resend => false}),
|
2019-06-25 13:36:17 +02:00
|
|
|
{stop, State};
|
2019-07-08 18:32:37 +02:00
|
|
|
c2s_handle_info(State, {timeout, _, Timeout}) when Timeout == ack_timeout;
|
|
|
|
Timeout == pending_timeout ->
|
|
|
|
%% Late arrival of an already cancelled timer: we just ignore it.
|
|
|
|
%% This might happen because misc:cancel_timer/1 doesn't guarantee
|
|
|
|
%% timer cancelation in the case when p1_server is used.
|
|
|
|
{stop, State};
|
2016-12-28 07:47:11 +01:00
|
|
|
c2s_handle_info(State, _) ->
|
|
|
|
State.
|
|
|
|
|
2016-12-29 22:00:36 +01:00
|
|
|
c2s_closed(State, {stream, _}) ->
|
|
|
|
State;
|
2019-08-06 15:18:04 +02:00
|
|
|
c2s_closed(#{mgmt_state := active} = State, Reason) ->
|
|
|
|
{stop, transition_to_pending(State, Reason)};
|
2016-12-29 22:00:36 +01:00
|
|
|
c2s_closed(State, _Reason) ->
|
|
|
|
State.
|
|
|
|
|
2019-06-26 10:56:25 +02:00
|
|
|
c2s_terminated(#{mgmt_state := resumed, sid := SID, jid := JID} = State, _Reason) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Closing former stream of resumed session for ~ts",
|
2018-02-21 15:12:50 +01:00
|
|
|
[jid:encode(JID)]),
|
2019-07-30 14:21:58 +02:00
|
|
|
{U, S, R} = jid:tolower(JID),
|
|
|
|
ejabberd_sm:close_session(SID, U, S, R),
|
2020-04-07 14:51:49 +02:00
|
|
|
route_late_queue_after_resume(State),
|
2019-06-26 10:56:25 +02:00
|
|
|
ejabberd_c2s:bounce_message_queue(SID, JID),
|
2016-12-29 22:00:36 +01:00
|
|
|
{stop, State};
|
2018-11-30 14:18:49 +01:00
|
|
|
c2s_terminated(#{mgmt_state := MgmtState, mgmt_stanzas_in := In,
|
2020-06-01 21:33:55 +02:00
|
|
|
mgmt_id := MgmtID, jid := JID} = State, _Reason) ->
|
2018-11-30 14:18:49 +01:00
|
|
|
case MgmtState of
|
|
|
|
timeout ->
|
2020-06-01 21:33:55 +02:00
|
|
|
store_stanzas_in(jid:tolower(JID), MgmtID, In);
|
2018-11-30 14:18:49 +01:00
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
2016-12-29 22:00:36 +01:00
|
|
|
route_unacked_stanzas(State),
|
2018-11-30 14:18:49 +01:00
|
|
|
State;
|
2016-12-29 22:00:36 +01:00
|
|
|
c2s_terminated(State, _Reason) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State.
|
|
|
|
|
2017-07-21 01:07:36 +02:00
|
|
|
%%%===================================================================
|
2018-04-17 00:27:07 +02:00
|
|
|
%%% Adjust pending session timeout / access queue
|
2017-07-21 01:07:36 +02:00
|
|
|
%%%===================================================================
|
|
|
|
-spec get_resume_timeout(state()) -> non_neg_integer().
|
|
|
|
get_resume_timeout(#{mgmt_timeout := Timeout}) ->
|
|
|
|
Timeout.
|
|
|
|
|
|
|
|
-spec set_resume_timeout(state(), non_neg_integer()) -> state().
|
|
|
|
set_resume_timeout(#{mgmt_timeout := Timeout} = State, Timeout) ->
|
|
|
|
State;
|
|
|
|
set_resume_timeout(State, Timeout) ->
|
|
|
|
State1 = restart_pending_timer(State, Timeout),
|
|
|
|
State1#{mgmt_timeout => Timeout}.
|
|
|
|
|
2019-06-28 21:16:29 +02:00
|
|
|
-spec queue_find(fun((stanza()) -> boolean()), queue())
|
2018-04-17 00:27:07 +02:00
|
|
|
-> stanza() | none.
|
|
|
|
queue_find(Pred, Queue) ->
|
|
|
|
case p1_queue:out(Queue) of
|
|
|
|
{{value, {_, _, Pkt}}, Queue1} ->
|
|
|
|
case Pred(Pkt) of
|
|
|
|
true ->
|
|
|
|
Pkt;
|
|
|
|
false ->
|
|
|
|
queue_find(Pred, Queue1)
|
|
|
|
end;
|
|
|
|
{empty, _Queue1} ->
|
|
|
|
none
|
|
|
|
end.
|
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
%%%===================================================================
|
|
|
|
%%% Internal functions
|
|
|
|
%%%===================================================================
|
|
|
|
-spec negotiate_stream_mgmt(xmpp_element(), state()) -> state().
|
2018-07-10 00:46:48 +02:00
|
|
|
negotiate_stream_mgmt(Pkt, #{lang := Lang} = State) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
Xmlns = xmpp:get_ns(Pkt),
|
|
|
|
case Pkt of
|
|
|
|
#sm_enable{} ->
|
|
|
|
handle_enable(State#{mgmt_xmlns => Xmlns}, Pkt);
|
2016-12-29 22:00:36 +01:00
|
|
|
_ when is_record(Pkt, sm_a);
|
|
|
|
is_record(Pkt, sm_r);
|
|
|
|
is_record(Pkt, sm_resume) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Stream management is not enabled"),
|
2018-07-10 00:46:48 +02:00
|
|
|
Err = #sm_failed{reason = 'unexpected-request',
|
|
|
|
text = xmpp:mk_text(Txt, Lang),
|
|
|
|
xmlns = Xmlns},
|
2016-12-29 22:00:36 +01:00
|
|
|
send(State, Err)
|
2016-12-28 07:47:11 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
-spec perform_stream_mgmt(xmpp_element(), state()) -> state().
|
2018-06-25 08:56:44 +02:00
|
|
|
perform_stream_mgmt(Pkt, #{mgmt_xmlns := Xmlns, lang := Lang} = State) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
case xmpp:get_ns(Pkt) of
|
|
|
|
Xmlns ->
|
|
|
|
case Pkt of
|
|
|
|
#sm_r{} ->
|
|
|
|
handle_r(State);
|
|
|
|
#sm_a{} ->
|
|
|
|
handle_a(State, Pkt);
|
2016-12-29 22:00:36 +01:00
|
|
|
_ when is_record(Pkt, sm_enable);
|
|
|
|
is_record(Pkt, sm_resume) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Stream management is already enabled"),
|
2016-12-29 22:00:36 +01:00
|
|
|
send(State, #sm_failed{reason = 'unexpected-request',
|
2018-07-10 00:46:48 +02:00
|
|
|
text = xmpp:mk_text(Txt, Lang),
|
2016-12-29 22:00:36 +01:00
|
|
|
xmlns = Xmlns})
|
2016-12-28 07:47:11 +01:00
|
|
|
end;
|
|
|
|
_ ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Unsupported version"),
|
2018-06-25 08:56:44 +02:00
|
|
|
send(State, #sm_failed{reason = 'unexpected-request',
|
|
|
|
text = xmpp:mk_text(Txt, Lang),
|
|
|
|
xmlns = Xmlns})
|
2016-12-28 07:47:11 +01:00
|
|
|
end.
|
|
|
|
|
|
|
|
-spec handle_enable(state(), sm_enable()) -> state().
|
|
|
|
handle_enable(#{mgmt_timeout := DefaultTimeout,
|
2017-03-10 13:12:43 +01:00
|
|
|
mgmt_queue_type := QueueType,
|
2016-12-28 07:47:11 +01:00
|
|
|
mgmt_max_timeout := MaxTimeout,
|
2016-12-29 22:00:36 +01:00
|
|
|
mgmt_xmlns := Xmlns, jid := JID} = State,
|
2016-12-28 07:47:11 +01:00
|
|
|
#sm_enable{resume = Resume, max = Max}) ->
|
2020-06-01 21:33:55 +02:00
|
|
|
State1 = State#{mgmt_id => make_id()},
|
2016-12-28 07:47:11 +01:00
|
|
|
Timeout = if Resume == false ->
|
|
|
|
0;
|
2019-07-30 12:40:40 +02:00
|
|
|
Max /= undefined, Max > 0, Max*1000 =< MaxTimeout ->
|
|
|
|
Max*1000;
|
2016-12-28 07:47:11 +01:00
|
|
|
true ->
|
|
|
|
DefaultTimeout
|
|
|
|
end,
|
|
|
|
Res = if Timeout > 0 ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Stream management with resumption enabled for ~ts",
|
2018-02-21 15:12:50 +01:00
|
|
|
[jid:encode(JID)]),
|
2016-12-28 07:47:11 +01:00
|
|
|
#sm_enabled{xmlns = Xmlns,
|
2020-06-01 21:33:55 +02:00
|
|
|
id = encode_id(State1),
|
2016-12-28 07:47:11 +01:00
|
|
|
resume = true,
|
2019-07-30 11:50:31 +02:00
|
|
|
max = Timeout div 1000};
|
2016-12-28 07:47:11 +01:00
|
|
|
true ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Stream management without resumption enabled for ~ts",
|
2018-02-21 15:12:50 +01:00
|
|
|
[jid:encode(JID)]),
|
2016-12-28 07:47:11 +01:00
|
|
|
#sm_enabled{xmlns = Xmlns}
|
|
|
|
end,
|
2020-06-01 21:33:55 +02:00
|
|
|
State2 = State1#{mgmt_state => active,
|
|
|
|
mgmt_queue => p1_queue:new(QueueType),
|
|
|
|
mgmt_timeout => Timeout},
|
|
|
|
send(State2, Res).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
-spec handle_r(state()) -> state().
|
|
|
|
handle_r(#{mgmt_xmlns := Xmlns, mgmt_stanzas_in := H} = State) ->
|
|
|
|
Res = #sm_a{xmlns = Xmlns, h = H},
|
|
|
|
send(State, Res).
|
|
|
|
|
|
|
|
-spec handle_a(state(), sm_a()) -> state().
|
|
|
|
handle_a(State, #sm_a{h = H}) ->
|
|
|
|
State1 = check_h_attribute(State, H),
|
2016-12-29 22:00:36 +01:00
|
|
|
resend_rack(State1).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
-spec handle_resume(state(), sm_resume()) -> {ok, state()} | {error, state()}.
|
2017-12-26 16:55:57 +01:00
|
|
|
handle_resume(#{user := User, lserver := LServer,
|
2016-12-29 22:00:36 +01:00
|
|
|
lang := Lang, socket := Socket} = State,
|
2016-12-28 07:47:11 +01:00
|
|
|
#sm_resume{h = H, previd = PrevID, xmlns = Xmlns}) ->
|
|
|
|
R = case inherit_session_state(State, PrevID) of
|
|
|
|
{ok, InheritedState} ->
|
|
|
|
{ok, InheritedState, H};
|
|
|
|
{error, Err, InH} ->
|
|
|
|
{error, #sm_failed{reason = 'item-not-found',
|
2019-06-25 19:42:54 +02:00
|
|
|
text = xmpp:mk_text(format_error(Err), Lang),
|
2016-12-28 07:47:11 +01:00
|
|
|
h = InH, xmlns = Xmlns}, Err};
|
|
|
|
{error, Err} ->
|
|
|
|
{error, #sm_failed{reason = 'item-not-found',
|
2019-06-25 19:42:54 +02:00
|
|
|
text = xmpp:mk_text(format_error(Err), Lang),
|
2016-12-28 07:47:11 +01:00
|
|
|
xmlns = Xmlns}, Err}
|
|
|
|
end,
|
|
|
|
case R of
|
2016-12-29 22:00:36 +01:00
|
|
|
{ok, #{jid := JID} = ResumedState, NumHandled} ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State1 = check_h_attribute(ResumedState, NumHandled),
|
|
|
|
#{mgmt_xmlns := AttrXmlns, mgmt_stanzas_in := AttrH} = State1,
|
|
|
|
State2 = send(State1, #sm_resumed{xmlns = AttrXmlns,
|
|
|
|
h = AttrH,
|
2020-06-01 21:33:55 +02:00
|
|
|
previd = PrevID}),
|
2016-12-28 07:47:11 +01:00
|
|
|
State3 = resend_unacked_stanzas(State2),
|
|
|
|
State4 = send(State3, #sm_r{xmlns = AttrXmlns}),
|
|
|
|
State5 = ejabberd_hooks:run_fold(c2s_session_resumed, LServer, State4, []),
|
2019-09-23 14:17:20 +02:00
|
|
|
?INFO_MSG("(~ts) Resumed session for ~ts",
|
2017-12-26 16:55:57 +01:00
|
|
|
[xmpp_socket:pp(Socket), jid:encode(JID)]),
|
2016-12-28 07:47:11 +01:00
|
|
|
{ok, State5};
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, El, Reason} ->
|
|
|
|
log_resumption_error(User, LServer, Reason),
|
2016-12-28 07:47:11 +01:00
|
|
|
{error, send(State, El)}
|
|
|
|
end.
|
|
|
|
|
2019-08-06 15:18:04 +02:00
|
|
|
-spec transition_to_pending(state(), _) -> state().
|
2017-01-09 20:03:42 +01:00
|
|
|
transition_to_pending(#{mgmt_state := active, mod := Mod,
|
2019-08-06 15:18:04 +02:00
|
|
|
mgmt_timeout := 0} = State, _Reason) ->
|
2020-04-01 14:35:49 +02:00
|
|
|
Mod:stop_async(self()),
|
|
|
|
State;
|
2019-08-06 15:18:04 +02:00
|
|
|
transition_to_pending(#{mgmt_state := active, jid := JID, socket := Socket,
|
|
|
|
lserver := LServer, mgmt_timeout := Timeout} = State,
|
|
|
|
Reason) ->
|
2016-12-29 22:00:36 +01:00
|
|
|
State1 = cancel_ack_timer(State),
|
2019-09-23 14:17:20 +02:00
|
|
|
?INFO_MSG("(~ts) Closing c2s connection for ~ts: ~ts; "
|
2019-08-06 15:18:04 +02:00
|
|
|
"waiting ~B seconds for stream resumption",
|
|
|
|
[xmpp_socket:pp(Socket), jid:encode(JID),
|
|
|
|
format_reason(State, Reason), Timeout div 1000]),
|
2019-07-23 00:15:40 +02:00
|
|
|
TRef = erlang:start_timer(Timeout, self(), pending_timeout),
|
2017-07-21 01:07:36 +02:00
|
|
|
State2 = State1#{mgmt_state => pending, mgmt_pending_timer => TRef},
|
2016-12-31 11:48:55 +01:00
|
|
|
ejabberd_hooks:run_fold(c2s_session_pending, LServer, State2, []);
|
2019-08-06 15:18:04 +02:00
|
|
|
transition_to_pending(State, _Reason) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State.
|
|
|
|
|
|
|
|
-spec check_h_attribute(state(), non_neg_integer()) -> state().
|
2018-02-10 00:06:19 +01:00
|
|
|
check_h_attribute(#{mgmt_stanzas_out := NumStanzasOut, jid := JID,
|
|
|
|
lang := Lang} = State, H)
|
2016-12-28 07:47:11 +01:00
|
|
|
when H > NumStanzasOut ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?WARNING_MSG("~ts acknowledged ~B stanzas, but only ~B were sent",
|
2018-02-10 00:06:19 +01:00
|
|
|
[jid:encode(JID), H, NumStanzasOut]),
|
|
|
|
State1 = State#{mgmt_resend => false},
|
|
|
|
Err = xmpp:serr_undefined_condition(
|
2019-06-22 16:08:45 +02:00
|
|
|
?T("Client acknowledged more stanzas than sent by server"), Lang),
|
2018-02-10 00:06:19 +01:00
|
|
|
send(State1, Err);
|
2016-12-28 07:47:11 +01:00
|
|
|
check_h_attribute(#{mgmt_stanzas_out := NumStanzasOut, jid := JID} = State, H) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("~ts acknowledged ~B of ~B stanzas",
|
2017-02-26 08:07:12 +01:00
|
|
|
[jid:encode(JID), H, NumStanzasOut]),
|
2016-12-28 07:47:11 +01:00
|
|
|
mgmt_queue_drop(State, H).
|
|
|
|
|
2019-06-27 10:32:54 +02:00
|
|
|
-spec update_num_stanzas_in(state(), xmpp_element() | xmlel()) -> state().
|
2016-12-28 07:47:11 +01:00
|
|
|
update_num_stanzas_in(#{mgmt_state := MgmtState,
|
|
|
|
mgmt_stanzas_in := NumStanzasIn} = State, El)
|
|
|
|
when MgmtState == active; MgmtState == pending ->
|
|
|
|
NewNum = case {xmpp:is_stanza(El), NumStanzasIn} of
|
|
|
|
{true, 4294967295} ->
|
|
|
|
0;
|
|
|
|
{true, Num} ->
|
|
|
|
Num + 1;
|
|
|
|
{false, Num} ->
|
|
|
|
Num
|
|
|
|
end,
|
|
|
|
State#{mgmt_stanzas_in => NewNum};
|
|
|
|
update_num_stanzas_in(State, _El) ->
|
|
|
|
State.
|
|
|
|
|
2017-06-21 01:00:29 +02:00
|
|
|
-spec send_rack(state()) -> state().
|
2016-12-29 22:00:36 +01:00
|
|
|
send_rack(#{mgmt_ack_timer := _} = State) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State;
|
2016-12-29 22:00:36 +01:00
|
|
|
send_rack(#{mgmt_xmlns := Xmlns,
|
2020-01-14 01:17:01 +01:00
|
|
|
mgmt_stanzas_out := NumStanzasOut} = State) ->
|
|
|
|
State1 = State#{mgmt_stanzas_req => NumStanzasOut},
|
|
|
|
State2 = start_ack_timer(State1),
|
|
|
|
send(State2, #sm_r{xmlns = Xmlns}).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2017-06-21 01:00:29 +02:00
|
|
|
-spec resend_rack(state()) -> state().
|
2016-12-29 22:00:36 +01:00
|
|
|
resend_rack(#{mgmt_ack_timer := _,
|
|
|
|
mgmt_queue := Queue,
|
|
|
|
mgmt_stanzas_out := NumStanzasOut,
|
|
|
|
mgmt_stanzas_req := NumStanzasReq} = State) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State1 = cancel_ack_timer(State),
|
2017-03-10 13:12:43 +01:00
|
|
|
case NumStanzasReq < NumStanzasOut andalso not p1_queue:is_empty(Queue) of
|
2016-12-29 22:00:36 +01:00
|
|
|
true -> send_rack(State1);
|
2016-12-28 07:47:11 +01:00
|
|
|
false -> State1
|
|
|
|
end;
|
2016-12-29 22:00:36 +01:00
|
|
|
resend_rack(State) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State.
|
|
|
|
|
2018-02-15 08:18:06 +01:00
|
|
|
-spec mgmt_queue_add(state(), xmlel() | xmpp_element()) -> state().
|
2016-12-28 07:47:11 +01:00
|
|
|
mgmt_queue_add(#{mgmt_stanzas_out := NumStanzasOut,
|
2016-12-31 11:48:55 +01:00
|
|
|
mgmt_queue := Queue} = State, Pkt) ->
|
2017-01-09 15:02:17 +01:00
|
|
|
NewNum = case NumStanzasOut of
|
|
|
|
4294967295 -> 0;
|
|
|
|
Num -> Num + 1
|
|
|
|
end,
|
2019-02-27 09:56:20 +01:00
|
|
|
Queue1 = p1_queue:in({NewNum, erlang:timestamp(), Pkt}, Queue),
|
2017-01-09 15:02:17 +01:00
|
|
|
State1 = State#{mgmt_queue => Queue1, mgmt_stanzas_out => NewNum},
|
|
|
|
check_queue_length(State1).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
-spec mgmt_queue_drop(state(), non_neg_integer()) -> state().
|
|
|
|
mgmt_queue_drop(#{mgmt_queue := Queue} = State, NumHandled) ->
|
2017-03-10 13:12:43 +01:00
|
|
|
NewQueue = p1_queue:dropwhile(
|
2016-12-28 07:47:11 +01:00
|
|
|
fun({N, _T, _E}) -> N =< NumHandled end, Queue),
|
|
|
|
State#{mgmt_queue => NewQueue}.
|
|
|
|
|
|
|
|
-spec check_queue_length(state()) -> state().
|
|
|
|
check_queue_length(#{mgmt_max_queue := Limit} = State)
|
|
|
|
when Limit == infinity; Limit == exceeded ->
|
|
|
|
State;
|
|
|
|
check_queue_length(#{mgmt_queue := Queue, mgmt_max_queue := Limit} = State) ->
|
2017-03-10 13:12:43 +01:00
|
|
|
case p1_queue:len(Queue) > Limit of
|
2016-12-28 07:47:11 +01:00
|
|
|
true ->
|
|
|
|
State#{mgmt_max_queue => exceeded};
|
|
|
|
false ->
|
|
|
|
State
|
|
|
|
end.
|
|
|
|
|
2020-04-07 14:51:49 +02:00
|
|
|
-spec route_late_queue_after_resume(state()) -> ok.
|
|
|
|
route_late_queue_after_resume(#{mgmt_queue := Queue, jid := JID})
|
|
|
|
when ?qlen(Queue) > 0 ->
|
|
|
|
?DEBUG("Re-routing ~B late queued packets to ~ts",
|
|
|
|
[p1_queue:len(Queue), jid:encode(JID)]),
|
|
|
|
p1_queue:foreach(
|
|
|
|
fun({_, _Time, Pkt}) ->
|
|
|
|
ejabberd_router:route(Pkt)
|
|
|
|
end, Queue);
|
|
|
|
route_late_queue_after_resume(_State) ->
|
|
|
|
ok.
|
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
-spec resend_unacked_stanzas(state()) -> state().
|
|
|
|
resend_unacked_stanzas(#{mgmt_state := MgmtState,
|
2017-03-10 13:12:43 +01:00
|
|
|
mgmt_queue := Queue,
|
2016-12-28 07:47:11 +01:00
|
|
|
jid := JID} = State)
|
|
|
|
when (MgmtState == active orelse
|
|
|
|
MgmtState == pending orelse
|
2017-03-10 13:12:43 +01:00
|
|
|
MgmtState == timeout) andalso ?qlen(Queue) > 0 ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Resending ~B unacknowledged stanza(s) to ~ts",
|
2017-03-10 13:12:43 +01:00
|
|
|
[p1_queue:len(Queue), jid:encode(JID)]),
|
|
|
|
p1_queue:foldl(
|
2016-12-28 07:47:11 +01:00
|
|
|
fun({_, Time, Pkt}, AccState) ->
|
2018-02-15 08:18:06 +01:00
|
|
|
Pkt1 = add_resent_delay_info(AccState, Pkt, Time),
|
|
|
|
Pkt2 = if ?is_stanza(Pkt1) ->
|
|
|
|
xmpp:put_meta(Pkt1, mgmt_is_resent, true);
|
|
|
|
true ->
|
|
|
|
Pkt1
|
|
|
|
end,
|
|
|
|
send(AccState, Pkt2)
|
2016-12-28 07:47:11 +01:00
|
|
|
end, State, Queue);
|
|
|
|
resend_unacked_stanzas(State) ->
|
|
|
|
State.
|
|
|
|
|
|
|
|
-spec route_unacked_stanzas(state()) -> ok.
|
|
|
|
route_unacked_stanzas(#{mgmt_state := MgmtState,
|
|
|
|
mgmt_resend := MgmtResend,
|
|
|
|
lang := Lang, user := User,
|
|
|
|
jid := JID, lserver := LServer,
|
2017-03-10 13:12:43 +01:00
|
|
|
mgmt_queue := Queue,
|
2016-12-28 07:47:11 +01:00
|
|
|
resource := Resource} = State)
|
|
|
|
when (MgmtState == active orelse
|
|
|
|
MgmtState == pending orelse
|
2017-03-10 13:12:43 +01:00
|
|
|
MgmtState == timeout) andalso ?qlen(Queue) > 0 ->
|
2016-12-28 07:47:11 +01:00
|
|
|
ResendOnTimeout = case MgmtResend of
|
|
|
|
Resend when is_boolean(Resend) ->
|
|
|
|
Resend;
|
|
|
|
if_offline ->
|
2017-04-25 22:37:27 +02:00
|
|
|
case ejabberd_sm:get_user_resources(User, LServer) of
|
2016-12-28 07:47:11 +01:00
|
|
|
[Resource] ->
|
|
|
|
%% Same resource opened new session
|
|
|
|
true;
|
|
|
|
[] -> true;
|
|
|
|
_ -> false
|
|
|
|
end
|
|
|
|
end,
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Re-routing ~B unacknowledged stanza(s) to ~ts",
|
2017-03-10 13:12:43 +01:00
|
|
|
[p1_queue:len(Queue), jid:encode(JID)]),
|
2020-04-16 13:04:12 +02:00
|
|
|
ModOfflineEnabled = gen_mod:is_loaded(LServer, mod_offline),
|
2019-05-29 00:30:59 +02:00
|
|
|
p1_queue:foreach(
|
|
|
|
fun({_, _Time, #presence{from = From}}) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Dropping presence stanza from ~ts", [jid:encode(From)]);
|
2019-05-29 00:30:59 +02:00
|
|
|
({_, _Time, #iq{} = El}) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("User session terminated"),
|
2017-02-16 09:00:26 +01:00
|
|
|
ejabberd_router:route_error(
|
2019-05-29 00:30:59 +02:00
|
|
|
El, xmpp:err_service_unavailable(Txt, Lang));
|
|
|
|
({_, _Time, #message{from = From, meta = #{carbon_copy := true}}}) ->
|
2016-12-28 07:47:11 +01:00
|
|
|
%% XEP-0280 says: "When a receiving server attempts to deliver a
|
|
|
|
%% forked message, and that message bounces with an error for
|
|
|
|
%% any reason, the receiving server MUST NOT forward that error
|
|
|
|
%% back to the original sender." Resending such a stanza could
|
|
|
|
%% easily lead to unexpected results as well.
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Dropping forwarded message stanza from ~ts",
|
2019-05-29 00:30:59 +02:00
|
|
|
[jid:encode(From)]);
|
|
|
|
({_, Time, #message{} = Msg}) ->
|
2020-04-16 13:04:12 +02:00
|
|
|
case {ModOfflineEnabled, ResendOnTimeout,
|
|
|
|
xmpp:get_meta(Msg, mam_archived, false)} of
|
|
|
|
Val when Val == {true, true, false};
|
|
|
|
Val == {true, true, true};
|
|
|
|
Val == {false, true, false} ->
|
|
|
|
NewEl = add_resent_delay_info(State, Msg, Time),
|
|
|
|
ejabberd_router:route(NewEl);
|
|
|
|
{_, _, true} ->
|
|
|
|
?DEBUG("Dropping archived message stanza from ~s",
|
|
|
|
[jid:encode(xmpp:get_from(Msg))]);
|
|
|
|
_ ->
|
|
|
|
Txt = ?T("User session terminated"),
|
|
|
|
ejabberd_router:route_error(
|
|
|
|
Msg, xmpp:err_service_unavailable(Txt, Lang))
|
|
|
|
end;
|
2019-05-29 00:30:59 +02:00
|
|
|
({_, _Time, El}) ->
|
2017-01-09 15:02:17 +01:00
|
|
|
%% Raw element of type 'error' resulting from a validation error
|
|
|
|
%% We cannot pass it to the router, it will generate an error
|
2019-05-29 00:30:59 +02:00
|
|
|
?DEBUG("Do not route raw element from ack queue: ~p", [El])
|
|
|
|
end, Queue);
|
2016-12-28 07:47:11 +01:00
|
|
|
route_unacked_stanzas(_State) ->
|
|
|
|
ok.
|
|
|
|
|
|
|
|
-spec inherit_session_state(state(), binary()) -> {ok, state()} |
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, error_reason()} |
|
|
|
|
{error, error_reason(), non_neg_integer()}.
|
2017-03-10 13:12:43 +01:00
|
|
|
inherit_session_state(#{user := U, server := S,
|
2020-06-01 21:33:55 +02:00
|
|
|
mgmt_queue_type := QueueType} = State, PrevID) ->
|
|
|
|
case decode_id(PrevID) of
|
|
|
|
{ok, {R, MgmtID}} ->
|
|
|
|
case ejabberd_sm:get_session_sid(U, S, R) of
|
2016-12-28 07:47:11 +01:00
|
|
|
none ->
|
2020-06-01 21:33:55 +02:00
|
|
|
case pop_stanzas_in({U, S, R}, MgmtID) of
|
2018-11-30 14:18:49 +01:00
|
|
|
error ->
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, session_not_found};
|
2018-11-30 14:18:49 +01:00
|
|
|
{ok, H} ->
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, session_timed_out, H}
|
2016-12-28 07:47:11 +01:00
|
|
|
end;
|
2020-06-01 21:33:55 +02:00
|
|
|
{_, OldPID} = OldSID ->
|
|
|
|
try resume_session(OldPID, MgmtID, State) of
|
2016-12-29 22:00:36 +01:00
|
|
|
{resume, #{mgmt_xmlns := Xmlns,
|
|
|
|
mgmt_queue := Queue,
|
|
|
|
mgmt_timeout := Timeout,
|
|
|
|
mgmt_stanzas_in := NumStanzasIn,
|
|
|
|
mgmt_stanzas_out := NumStanzasOut} = OldState} ->
|
2016-12-28 07:47:11 +01:00
|
|
|
State1 = ejabberd_c2s:copy_state(State, OldState),
|
2017-03-10 13:12:43 +01:00
|
|
|
Queue1 = case QueueType of
|
|
|
|
ram -> Queue;
|
|
|
|
_ -> p1_queue:ram_to_file(Queue)
|
|
|
|
end,
|
2020-06-01 21:33:55 +02:00
|
|
|
State2 = State1#{sid => ejabberd_sm:make_sid(),
|
|
|
|
mgmt_id => MgmtID,
|
|
|
|
mgmt_xmlns => Xmlns,
|
2017-03-10 13:12:43 +01:00
|
|
|
mgmt_queue => Queue1,
|
2016-12-29 22:00:36 +01:00
|
|
|
mgmt_timeout => Timeout,
|
|
|
|
mgmt_stanzas_in => NumStanzasIn,
|
|
|
|
mgmt_stanzas_out => NumStanzasOut,
|
|
|
|
mgmt_state => active},
|
|
|
|
State3 = ejabberd_c2s:open_session(State2),
|
2020-04-01 14:35:49 +02:00
|
|
|
ejabberd_c2s:stop_async(OldPID),
|
2016-12-29 22:00:36 +01:00
|
|
|
{ok, State3};
|
2016-12-28 07:47:11 +01:00
|
|
|
{error, Msg} ->
|
|
|
|
{error, Msg}
|
|
|
|
catch exit:{noproc, _} ->
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, session_is_dead};
|
2018-02-24 21:50:54 +01:00
|
|
|
exit:{normal, _} ->
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, session_has_exited};
|
2019-07-30 22:17:10 +02:00
|
|
|
exit:{shutdown, _} ->
|
|
|
|
{error, session_has_exited};
|
2018-07-01 13:26:49 +02:00
|
|
|
exit:{killed, _} ->
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, session_was_killed};
|
2016-12-28 07:47:11 +01:00
|
|
|
exit:{timeout, _} ->
|
2018-03-06 21:03:31 +01:00
|
|
|
ejabberd_sm:close_session(OldSID, U, S, R),
|
2020-04-01 14:35:49 +02:00
|
|
|
ejabberd_c2s:stop_async(OldPID),
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, session_copy_timed_out}
|
2016-12-28 07:47:11 +01:00
|
|
|
end
|
|
|
|
end;
|
2020-06-01 21:33:55 +02:00
|
|
|
error ->
|
2019-06-25 19:42:54 +02:00
|
|
|
{error, invalid_previd}
|
2016-12-28 07:47:11 +01:00
|
|
|
end.
|
|
|
|
|
2020-06-01 21:33:55 +02:00
|
|
|
-spec resume_session(pid(), id(), state()) -> {resume, state()} |
|
|
|
|
{error, error_reason()}.
|
|
|
|
resume_session(PID, MgmtID, _State) ->
|
|
|
|
ejabberd_c2s:call(PID, {resume_session, MgmtID}, timer:seconds(15)).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2017-01-09 15:02:17 +01:00
|
|
|
-spec add_resent_delay_info(state(), stanza(), erlang:timestamp()) -> stanza();
|
|
|
|
(state(), xmlel(), erlang:timestamp()) -> xmlel().
|
|
|
|
add_resent_delay_info(#{lserver := LServer}, El, Time)
|
|
|
|
when is_record(El, message); is_record(El, presence) ->
|
2018-10-25 01:05:45 +02:00
|
|
|
misc:add_delay_info(El, jid:make(LServer), Time, <<"Resent">>);
|
2017-01-09 15:02:17 +01:00
|
|
|
add_resent_delay_info(_State, El, _Time) ->
|
2018-02-15 08:18:06 +01:00
|
|
|
%% TODO
|
2017-01-09 15:02:17 +01:00
|
|
|
El.
|
2016-12-28 07:47:11 +01:00
|
|
|
|
|
|
|
-spec send(state(), xmpp_element()) -> state().
|
|
|
|
send(#{mod := Mod} = State, Pkt) ->
|
|
|
|
Mod:send(State, Pkt).
|
|
|
|
|
2017-07-21 01:07:36 +02:00
|
|
|
-spec restart_pending_timer(state(), non_neg_integer()) -> state().
|
|
|
|
restart_pending_timer(#{mgmt_pending_timer := TRef} = State, NewTimeout) ->
|
2018-07-17 20:50:58 +02:00
|
|
|
misc:cancel_timer(TRef),
|
2019-07-23 00:15:40 +02:00
|
|
|
NewTRef = erlang:start_timer(NewTimeout, self(), pending_timeout),
|
2017-07-21 01:07:36 +02:00
|
|
|
State#{mgmt_pending_timer => NewTRef};
|
|
|
|
restart_pending_timer(State, _NewTimeout) ->
|
|
|
|
State.
|
|
|
|
|
2020-01-14 01:17:01 +01:00
|
|
|
-spec start_ack_timer(state()) -> state().
|
|
|
|
start_ack_timer(#{mgmt_ack_timeout := infinity} = State) ->
|
|
|
|
State;
|
|
|
|
start_ack_timer(#{mgmt_ack_timeout := AckTimeout} = State) ->
|
|
|
|
TRef = erlang:start_timer(AckTimeout, self(), ack_timeout),
|
|
|
|
State#{mgmt_ack_timer => TRef}.
|
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
-spec cancel_ack_timer(state()) -> state().
|
|
|
|
cancel_ack_timer(#{mgmt_ack_timer := TRef} = State) ->
|
2018-07-17 20:50:58 +02:00
|
|
|
misc:cancel_timer(TRef),
|
2016-12-28 07:47:11 +01:00
|
|
|
maps:remove(mgmt_ack_timer, State);
|
|
|
|
cancel_ack_timer(State) ->
|
|
|
|
State.
|
|
|
|
|
2018-02-15 13:50:20 +01:00
|
|
|
-spec need_to_enqueue(state(), xmlel() | stanza()) -> {boolean(), state()}.
|
|
|
|
need_to_enqueue(State, Pkt) when ?is_stanza(Pkt) ->
|
2018-02-15 08:48:59 +01:00
|
|
|
{not xmpp:get_meta(Pkt, mgmt_is_resent, false), State};
|
2018-02-15 13:50:20 +01:00
|
|
|
need_to_enqueue(#{mgmt_force_enqueue := true} = State, #xmlel{}) ->
|
2018-03-06 14:18:03 +01:00
|
|
|
State1 = maps:remove(mgmt_force_enqueue, State),
|
|
|
|
State2 = maps:remove(mgmt_is_resent, State1),
|
|
|
|
{true, State2};
|
2018-02-15 13:50:20 +01:00
|
|
|
need_to_enqueue(State, _) ->
|
2018-02-15 08:48:59 +01:00
|
|
|
{false, State}.
|
2018-02-15 08:18:06 +01:00
|
|
|
|
2020-06-01 21:33:55 +02:00
|
|
|
-spec make_id() -> id().
|
|
|
|
make_id() ->
|
|
|
|
p1_rand:bytes(8).
|
|
|
|
|
|
|
|
-spec encode_id(state()) -> binary().
|
|
|
|
encode_id(#{mgmt_id := MgmtID, resource := Resource}) ->
|
|
|
|
misc:term_to_base64({Resource, MgmtID}).
|
|
|
|
|
|
|
|
-spec decode_id(binary()) -> {ok, {binary(), id()}} | error.
|
|
|
|
decode_id(Encoded) ->
|
|
|
|
case misc:base64_to_term(Encoded) of
|
|
|
|
{term, {Resource, MgmtID}} when is_binary(Resource),
|
|
|
|
is_binary(MgmtID) ->
|
|
|
|
{ok, {Resource, MgmtID}};
|
|
|
|
_ ->
|
|
|
|
error
|
|
|
|
end.
|
|
|
|
|
2019-06-25 19:42:54 +02:00
|
|
|
%%%===================================================================
|
|
|
|
%%% Formatters and Logging
|
|
|
|
%%%===================================================================
|
|
|
|
-spec format_error(error_reason()) -> binary().
|
|
|
|
format_error(session_not_found) ->
|
|
|
|
?T("Previous session not found");
|
|
|
|
format_error(session_timed_out) ->
|
|
|
|
?T("Previous session timed out");
|
|
|
|
format_error(session_is_dead) ->
|
|
|
|
?T("Previous session PID is dead");
|
|
|
|
format_error(session_has_exited) ->
|
|
|
|
?T("Previous session PID has exited");
|
|
|
|
format_error(session_was_killed) ->
|
|
|
|
?T("Previous session PID has been killed");
|
|
|
|
format_error(session_copy_timed_out) ->
|
|
|
|
?T("Session state copying timed out");
|
|
|
|
format_error(invalid_previd) ->
|
|
|
|
?T("Invalid 'previd' value").
|
|
|
|
|
2019-08-06 15:18:04 +02:00
|
|
|
-spec format_reason(state(), term()) -> binary().
|
|
|
|
format_reason(_, ack_timeout) ->
|
|
|
|
<<"Timed out waiting for stream acknowledgement">>;
|
|
|
|
format_reason(#{stop_reason := {socket, ack_timeout}} = State, _) ->
|
|
|
|
format_reason(State, ack_timeout);
|
|
|
|
format_reason(State, Reason) ->
|
|
|
|
ejabberd_c2s:format_reason(State, Reason).
|
|
|
|
|
2019-06-25 19:42:54 +02:00
|
|
|
-spec log_resumption_error(binary(), binary(), error_reason()) -> ok.
|
|
|
|
log_resumption_error(User, Server, Reason)
|
|
|
|
when Reason == invalid_previd ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?WARNING_MSG("Cannot resume session for ~ts@~ts: ~ts",
|
2019-06-25 19:42:54 +02:00
|
|
|
[User, Server, format_error(Reason)]);
|
|
|
|
log_resumption_error(User, Server, Reason) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?INFO_MSG("Cannot resume session for ~ts@~ts: ~ts",
|
2019-06-25 19:42:54 +02:00
|
|
|
[User, Server, format_error(Reason)]).
|
|
|
|
|
2018-11-30 14:18:49 +01:00
|
|
|
%%%===================================================================
|
|
|
|
%%% Cache-like storage for last handled stanzas
|
|
|
|
%%%===================================================================
|
|
|
|
init_cache(Opts) ->
|
|
|
|
ets_cache:new(?STREAM_MGMT_CACHE, cache_opts(Opts)).
|
|
|
|
|
|
|
|
cache_opts(Opts) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
[{max_size, mod_stream_mgmt_opt:cache_size(Opts)},
|
2019-07-01 19:43:57 +02:00
|
|
|
{life_time, mod_stream_mgmt_opt:cache_life_time(Opts)},
|
|
|
|
{type, ordered_set}].
|
2018-11-30 14:18:49 +01:00
|
|
|
|
2020-06-01 21:33:55 +02:00
|
|
|
-spec store_stanzas_in(ljid(), id(), non_neg_integer()) -> boolean().
|
|
|
|
store_stanzas_in(LJID, MgmtID, Num) ->
|
|
|
|
ets_cache:insert(?STREAM_MGMT_CACHE, {LJID, MgmtID}, Num,
|
2018-11-30 14:18:49 +01:00
|
|
|
ejabberd_cluster:get_nodes()).
|
|
|
|
|
2020-06-01 21:33:55 +02:00
|
|
|
-spec pop_stanzas_in(ljid(), id()) -> {ok, non_neg_integer()} | error.
|
|
|
|
pop_stanzas_in(LJID, MgmtID) ->
|
|
|
|
case ets_cache:lookup(?STREAM_MGMT_CACHE, {LJID, MgmtID}) of
|
2018-11-30 14:18:49 +01:00
|
|
|
{ok, Val} ->
|
2019-07-01 19:43:57 +02:00
|
|
|
ets_cache:match_delete(?STREAM_MGMT_CACHE, {LJID, '_'},
|
|
|
|
ejabberd_cluster:get_nodes()),
|
2018-11-30 14:18:49 +01:00
|
|
|
{ok, Val};
|
|
|
|
error ->
|
|
|
|
error
|
|
|
|
end.
|
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
%%%===================================================================
|
|
|
|
%%% Configuration processing
|
|
|
|
%%%===================================================================
|
2018-01-23 08:54:52 +01:00
|
|
|
get_max_ack_queue(Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_stream_mgmt_opt:max_ack_queue(Host).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
get_configured_resume_timeout(Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_stream_mgmt_opt:resume_timeout(Host).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
get_max_resume_timeout(Host, ResumeTimeout) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
case mod_stream_mgmt_opt:max_resume_timeout(Host) of
|
2017-04-30 18:01:47 +02:00
|
|
|
undefined -> ResumeTimeout;
|
2016-12-28 07:47:11 +01:00
|
|
|
Max when Max >= ResumeTimeout -> Max;
|
|
|
|
_ -> ResumeTimeout
|
|
|
|
end.
|
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
get_ack_timeout(Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_stream_mgmt_opt:ack_timeout(Host).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
get_resend_on_timeout(Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_stream_mgmt_opt:resend_on_timeout(Host).
|
2016-12-28 07:47:11 +01:00
|
|
|
|
2018-01-23 08:54:52 +01:00
|
|
|
get_queue_type(Host) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_stream_mgmt_opt:queue_type(Host).
|
2017-03-10 13:12:43 +01:00
|
|
|
|
2016-12-28 07:47:11 +01:00
|
|
|
mod_opt_type(max_ack_queue) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:pos_int(infinity);
|
2016-12-28 07:47:11 +01:00
|
|
|
mod_opt_type(resume_timeout) ->
|
2019-07-23 00:15:40 +02:00
|
|
|
econf:either(
|
|
|
|
econf:int(0, 0),
|
|
|
|
econf:timeout(second));
|
2016-12-28 07:47:11 +01:00
|
|
|
mod_opt_type(max_resume_timeout) ->
|
2019-07-23 00:15:40 +02:00
|
|
|
econf:either(
|
|
|
|
econf:int(0, 0),
|
|
|
|
econf:timeout(second));
|
2016-12-28 07:47:11 +01:00
|
|
|
mod_opt_type(ack_timeout) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:timeout(second, infinity);
|
2016-12-28 07:47:11 +01:00
|
|
|
mod_opt_type(resend_on_timeout) ->
|
2019-06-14 11:33:26 +02:00
|
|
|
econf:either(
|
|
|
|
if_offline,
|
|
|
|
econf:bool());
|
2018-11-30 14:18:49 +01:00
|
|
|
mod_opt_type(cache_size) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:pos_int(infinity);
|
2019-07-01 19:43:57 +02:00
|
|
|
mod_opt_type(cache_life_time) ->
|
|
|
|
econf:timeout(second, infinity);
|
2017-03-10 13:12:43 +01:00
|
|
|
mod_opt_type(queue_type) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:queue_type().
|
2018-01-23 08:54:52 +01:00
|
|
|
|
|
|
|
mod_options(Host) ->
|
|
|
|
[{max_ack_queue, 5000},
|
2019-07-25 12:57:43 +02:00
|
|
|
{resume_timeout, timer:seconds(300)},
|
2018-01-23 08:54:52 +01:00
|
|
|
{max_resume_timeout, undefined},
|
2019-06-14 11:33:26 +02:00
|
|
|
{ack_timeout, timer:seconds(60)},
|
|
|
|
{cache_size, ejabberd_option:cache_size(Host)},
|
2019-07-01 19:43:57 +02:00
|
|
|
{cache_life_time, timer:hours(48)},
|
2018-01-23 08:54:52 +01:00
|
|
|
{resend_on_timeout, false},
|
2019-06-14 11:33:26 +02:00
|
|
|
{queue_type, ejabberd_option:queue_type(Host)}].
|
2020-01-08 10:24:51 +01:00
|
|
|
|
|
|
|
mod_doc() ->
|
|
|
|
#{desc =>
|
|
|
|
?T("This module adds support for "
|
|
|
|
"https://xmpp.org/extensions/xep-0198.html"
|
|
|
|
"[XEP-0198: Stream Management]. This protocol allows "
|
|
|
|
"active management of an XML stream between two XMPP "
|
|
|
|
"entities, including features for stanza acknowledgements "
|
|
|
|
"and stream resumption."),
|
|
|
|
opts =>
|
|
|
|
[{max_ack_queue,
|
|
|
|
#{value => ?T("Size"),
|
|
|
|
desc =>
|
|
|
|
?T("This option specifies the maximum number of "
|
|
|
|
"unacknowledged stanzas queued for possible "
|
|
|
|
"retransmission. When the limit is exceeded, "
|
|
|
|
"the client session is terminated. The allowed "
|
|
|
|
"values are positive integers and 'infinity'. "
|
|
|
|
"You should be careful when setting this value "
|
|
|
|
"as it should not be set too low, otherwise, "
|
|
|
|
"you could kill sessions in a loop, before they "
|
|
|
|
"get the chance to finish proper session initiation. "
|
|
|
|
"It should definitely be set higher that the size "
|
|
|
|
"of the offline queue (for example at least 3 times "
|
|
|
|
"the value of the max offline queue and never lower "
|
|
|
|
"than '1000'). The default value is '5000'.")}},
|
|
|
|
{resume_timeout,
|
|
|
|
#{value => "timeout()",
|
|
|
|
desc =>
|
|
|
|
?T("This option configures the (default) period of time "
|
|
|
|
"until a session times out if the connection is lost. "
|
|
|
|
"During this period of time, a client may resume its "
|
|
|
|
"session. Note that the client may request a different "
|
|
|
|
"timeout value, see the 'max_resume_timeout' option. "
|
|
|
|
"Setting it to '0' effectively disables session resumption. "
|
|
|
|
"The default value is '5' minutes.")}},
|
|
|
|
{max_resume_timeout,
|
|
|
|
#{value => "timeout()",
|
|
|
|
desc =>
|
|
|
|
?T("A client may specify the period of time until a session "
|
|
|
|
"times out if the connection is lost. During this period "
|
|
|
|
"of time, the client may resume its session. This option "
|
|
|
|
"limits the period of time a client is permitted to request. "
|
|
|
|
"It must be set to a timeout equal to or larger than the "
|
|
|
|
"default 'resume_timeout'. By default, it is set to the "
|
|
|
|
"same value as the 'resume_timeout' option.")}},
|
|
|
|
{ack_timeout,
|
|
|
|
#{value => "timeout()",
|
|
|
|
desc =>
|
|
|
|
?T("A time to wait for stanza acknowledgements. "
|
|
|
|
"Setting it to 'infinity' effectively disables the timeout. "
|
|
|
|
"The default value is '1' minute.")}},
|
|
|
|
{resend_on_timeout,
|
|
|
|
#{value => "true | false | if_offline",
|
|
|
|
desc =>
|
|
|
|
?T("If this option is set to 'true', any message stanzas "
|
|
|
|
"that weren't acknowledged by the client will be resent "
|
|
|
|
"on session timeout. This behavior might often be desired, "
|
|
|
|
"but could have unexpected results under certain circumstances. "
|
|
|
|
"For example, a message that was sent to two resources might "
|
|
|
|
"get resent to one of them if the other one timed out. "
|
|
|
|
"Therefore, the default value for this option is 'false', "
|
|
|
|
"which tells ejabberd to generate an error message instead. "
|
|
|
|
"As an alternative, the option may be set to 'if_offline'. "
|
|
|
|
"In this case, unacknowledged messages are resent only if "
|
|
|
|
"no other resource is online when the session times out. "
|
|
|
|
"Otherwise, error messages are generated.")}},
|
|
|
|
{queue_type,
|
|
|
|
#{value => "ram | file",
|
|
|
|
desc =>
|
|
|
|
?T("Same as top-level 'queue_type' option, but applied to this module only.")}},
|
|
|
|
{cache_size,
|
|
|
|
#{value => "pos_integer() | infinity",
|
|
|
|
desc =>
|
|
|
|
?T("Same as top-level 'cache_size' option, but applied to this module only.")}},
|
|
|
|
{cache_life_time,
|
|
|
|
#{value => "timeout()",
|
|
|
|
desc =>
|
|
|
|
?T("Same as top-level 'cache_life_time' option, but applied to this module only.")}}]}.
|