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

mod_stream_mgmt: Allow flexible timeout format

Adjust mod_stream_mgmt and the related code in mod_push_keepalive to
support the flexible timeout format.
This commit is contained in:
Holger Weiss 2019-07-23 00:15:40 +02:00
parent c0dc95d529
commit 8ac4a5f792
2 changed files with 16 additions and 11 deletions

View File

@ -38,7 +38,7 @@
-include("logger.hrl").
-include("xmpp.hrl").
-define(PUSH_BEFORE_TIMEOUT_SECS, 120).
-define(PUSH_BEFORE_TIMEOUT_PERIOD, 120000). % 2 minutes.
-type c2s_state() :: ejabberd_c2s:state().
@ -77,14 +77,16 @@ depends(_Host, _Opts) ->
-spec mod_opt_type(atom()) -> econf:validator().
mod_opt_type(resume_timeout) ->
econf:non_neg_int();
econf:either(
econf:int(0, 0),
econf:timeout(second));
mod_opt_type(wake_on_start) ->
econf:bool();
mod_opt_type(wake_on_timeout) ->
econf:bool().
mod_options(_Host) ->
[{resume_timeout, 259200},
[{resume_timeout, timer:seconds(259200)},
{wake_on_start, false},
{wake_on_timeout, true}].
@ -216,10 +218,10 @@ maybe_restore_resume_timeout(State) ->
-spec maybe_start_wakeup_timer(c2s_state()) -> c2s_state().
maybe_start_wakeup_timer(#{push_wake_on_timeout := true,
push_resume_timeout := ResumeTimeout} = State)
when is_integer(ResumeTimeout), ResumeTimeout > ?PUSH_BEFORE_TIMEOUT_SECS ->
WakeTimeout = ResumeTimeout - ?PUSH_BEFORE_TIMEOUT_SECS,
when is_integer(ResumeTimeout), ResumeTimeout > ?PUSH_BEFORE_TIMEOUT_PERIOD ->
WakeTimeout = ResumeTimeout - ?PUSH_BEFORE_TIMEOUT_PERIOD,
?DEBUG("Scheduling wake-up timer to fire in ~B seconds", [WakeTimeout]),
erlang:start_timer(timer:seconds(WakeTimeout), self(), push_keepalive),
erlang:start_timer(WakeTimeout, self(), push_keepalive),
State;
maybe_start_wakeup_timer(State) ->
State.

View File

@ -445,7 +445,7 @@ transition_to_pending(#{mgmt_state := active, jid := JID,
lserver := LServer, mgmt_timeout := Timeout} = State) ->
State1 = cancel_ack_timer(State),
?INFO_MSG("Waiting for resumption of stream for ~s", [jid:encode(JID)]),
TRef = erlang:start_timer(timer:seconds(Timeout), self(), pending_timeout),
TRef = erlang:start_timer(Timeout, self(), pending_timeout),
State2 = State1#{mgmt_state => pending, mgmt_pending_timer => TRef},
ejabberd_hooks:run_fold(c2s_session_pending, LServer, State2, []);
transition_to_pending(State) ->
@ -699,8 +699,7 @@ send(#{mod := Mod} = State, Pkt) ->
-spec restart_pending_timer(state(), non_neg_integer()) -> state().
restart_pending_timer(#{mgmt_pending_timer := TRef} = State, NewTimeout) ->
misc:cancel_timer(TRef),
NewTRef = erlang:start_timer(timer:seconds(NewTimeout), self(),
pending_timeout),
NewTRef = erlang:start_timer(NewTimeout, self(), pending_timeout),
State#{mgmt_pending_timer => NewTRef};
restart_pending_timer(State, _NewTimeout) ->
State.
@ -805,9 +804,13 @@ get_queue_type(Host) ->
mod_opt_type(max_ack_queue) ->
econf:pos_int(infinity);
mod_opt_type(resume_timeout) ->
econf:non_neg_int();
econf:either(
econf:int(0, 0),
econf:timeout(second));
mod_opt_type(max_resume_timeout) ->
econf:non_neg_int();
econf:either(
econf:int(0, 0),
econf:timeout(second));
mod_opt_type(ack_timeout) ->
econf:timeout(second, infinity);
mod_opt_type(resend_on_timeout) ->