26
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

XEP-0198: Add timestamp to resent stanzas

When an unacknowledged stanza is resent from the Stream Management
queue, add a timestamp so that the receiving client can display the time
at which the stanza was originally sent.
This commit is contained in:
Holger Weiss 2014-12-07 16:12:06 +01:00
parent 9899935e42
commit ba8f38e2eb

View File

@ -2800,7 +2800,10 @@ handle_resume(StateData, Attrs) ->
{<<"h">>, AttrH}, {<<"h">>, AttrH},
{<<"previd">>, AttrId}], {<<"previd">>, AttrId}],
children = []}), children = []}),
SendFun = fun(_F, _T, El) -> send_element(NewState, El) end, SendFun = fun(_F, _T, El, Time) ->
NewEl = add_resent_delay_info(NewState, El, Time),
send_element(NewState, NewEl)
end,
handle_unacked_stanzas(NewState, SendFun), handle_unacked_stanzas(NewState, SendFun),
send_element(NewState, send_element(NewState,
#xmlel{name = <<"r">>, #xmlel{name = <<"r">>,
@ -2856,13 +2859,13 @@ mgmt_queue_add(StateData, El) ->
Num -> Num ->
Num + 1 Num + 1
end, end,
NewQueue = queue:in({NewNum, El}, StateData#state.mgmt_queue), NewQueue = queue:in({NewNum, now(), El}, StateData#state.mgmt_queue),
NewState = StateData#state{mgmt_queue = NewQueue, NewState = StateData#state{mgmt_queue = NewQueue,
mgmt_stanzas_out = NewNum}, mgmt_stanzas_out = NewNum},
check_queue_length(NewState). check_queue_length(NewState).
mgmt_queue_drop(StateData, NumHandled) -> mgmt_queue_drop(StateData, NumHandled) ->
NewQueue = jlib:queue_drop_while(fun({N, _Stanza}) -> N =< NumHandled end, NewQueue = jlib:queue_drop_while(fun({N, _T, _E}) -> N =< NumHandled end,
StateData#state.mgmt_queue), StateData#state.mgmt_queue),
StateData#state{mgmt_queue = NewQueue}. StateData#state{mgmt_queue = NewQueue}.
@ -2890,12 +2893,12 @@ handle_unacked_stanzas(StateData, F)
?INFO_MSG("~B stanzas were not acknowledged by ~s", ?INFO_MSG("~B stanzas were not acknowledged by ~s",
[N, jlib:jid_to_string(StateData#state.jid)]), [N, jlib:jid_to_string(StateData#state.jid)]),
lists:foreach( lists:foreach(
fun({_, #xmlel{attrs = Attrs} = El}) -> fun({_, Time, #xmlel{attrs = Attrs} = El}) ->
From_s = xml:get_attr_s(<<"from">>, Attrs), From_s = xml:get_attr_s(<<"from">>, Attrs),
From = jlib:string_to_jid(From_s), From = jlib:string_to_jid(From_s),
To_s = xml:get_attr_s(<<"to">>, Attrs), To_s = xml:get_attr_s(<<"to">>, Attrs),
To = jlib:string_to_jid(To_s), To = jlib:string_to_jid(To_s),
F(From, To, El) F(From, To, El, Time)
end, queue:to_list(Queue)) end, queue:to_list(Queue))
end; end;
handle_unacked_stanzas(_StateData, _F) -> handle_unacked_stanzas(_StateData, _F) ->
@ -2914,16 +2917,19 @@ handle_unacked_stanzas(StateData)
end, end,
ReRoute = case ResendOnTimeout of ReRoute = case ResendOnTimeout of
true -> true ->
fun ejabberd_router:route/3; fun(From, To, El, Time) ->
NewEl = add_resent_delay_info(StateData, El, Time),
ejabberd_router:route(From, To, NewEl)
end;
false -> false ->
fun(From, To, El) -> fun(From, To, El, _Time) ->
Err = Err =
jlib:make_error_reply(El, jlib:make_error_reply(El,
?ERR_SERVICE_UNAVAILABLE), ?ERR_SERVICE_UNAVAILABLE),
ejabberd_router:route(To, From, Err) ejabberd_router:route(To, From, Err)
end end
end, end,
F = fun(From, To, El) -> F = fun(From, To, El, Time) ->
%% We'll drop the stanza if it was <forwarded/> by some %% We'll drop the stanza if it was <forwarded/> by some
%% encapsulating protocol as per XEP-0297. One such protocol is %% encapsulating protocol as per XEP-0297. One such protocol is
%% XEP-0280, which says: "When a receiving server attempts to %% XEP-0280, which says: "When a receiving server attempts to
@ -2936,7 +2942,7 @@ handle_unacked_stanzas(StateData)
?DEBUG("Dropping forwarded stanza from ~s", ?DEBUG("Dropping forwarded stanza from ~s",
[xml:get_attr_s(<<"from">>, El#xmlel.attrs)]); [xml:get_attr_s(<<"from">>, El#xmlel.attrs)]);
false -> false ->
ReRoute(From, To, El) ReRoute(From, To, El, Time)
end end
end, end,
handle_unacked_stanzas(StateData, F); handle_unacked_stanzas(StateData, F);
@ -3027,6 +3033,9 @@ make_resume_id(StateData) ->
{Time, _} = StateData#state.sid, {Time, _} = StateData#state.sid,
jlib:term_to_base64({StateData#state.resource, Time}). jlib:term_to_base64({StateData#state.resource, Time}).
add_resent_delay_info(#state{server = From}, El, Time) ->
jlib:add_delay_info(El, From, Time, <<"Resent">>).
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% XEP-0352 %%% XEP-0352
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------