25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

XEP-0198: Improve handling of too large 'h' values

If the client says that it handled more stanzas than we sent (due to a
bug in the client's or in our code), increase our outgoing stanza count
accordingly.  There's no point in sticking to the old value even if it
was correct, as the client surely won't fix its count during the current
session.
This commit is contained in:
Holger Weiss 2014-05-09 18:28:14 +02:00
parent 15369ff9d7
commit 6d5bfcfe9b

View File

@ -2686,16 +2686,13 @@ handle_r(StateData) ->
send_element(StateData, Res), send_element(StateData, Res),
StateData. StateData.
handle_a(#state{jid = JID, mgmt_stanzas_out = NumStanzasOut} = StateData, handle_a(StateData, Attrs) ->
Attrs) ->
case catch jlib:binary_to_integer(xml:get_attr_s(<<"h">>, Attrs)) of case catch jlib:binary_to_integer(xml:get_attr_s(<<"h">>, Attrs)) of
H when is_integer(H), H >= 0 -> H when is_integer(H), H >= 0 ->
?DEBUG("~s acknowledged ~B of ~B stanzas", check_h_attribute(StateData, H);
[jlib:jid_to_string(JID), H, NumStanzasOut]),
mgmt_queue_drop(StateData, H);
_ -> _ ->
?DEBUG("Ignoring invalid ACK element from ~s", ?DEBUG("Ignoring invalid ACK element from ~s",
[jlib:jid_to_string(JID)]), [jlib:jid_to_string(StateData#state.jid)]),
StateData StateData
end. end.
@ -2728,7 +2725,7 @@ handle_resume(StateData, Attrs) ->
end, end,
case R of case R of
{ok, ResumedState, NumHandled} -> {ok, ResumedState, NumHandled} ->
NewState = mgmt_queue_drop(ResumedState, NumHandled), NewState = check_h_attribute(ResumedState, NumHandled),
AttrXmlns = NewState#state.mgmt_xmlns, AttrXmlns = NewState#state.mgmt_xmlns,
AttrId = make_resume_id(NewState), AttrId = make_resume_id(NewState),
AttrH = jlib:integer_to_binary(NewState#state.mgmt_stanzas_in), AttrH = jlib:integer_to_binary(NewState#state.mgmt_stanzas_in),
@ -2754,6 +2751,16 @@ handle_resume(StateData, Attrs) ->
error error
end. end.
check_h_attribute(#state{mgmt_stanzas_out = NumStanzasOut} = StateData, H)
when H > NumStanzasOut ->
?DEBUG("~s acknowledged ~B stanzas, but only ~B were sent",
[jlib:jid_to_string(StateData#state.jid), H, NumStanzasOut]),
mgmt_queue_drop(StateData#state{mgmt_stanzas_out = H}, NumStanzasOut);
check_h_attribute(#state{mgmt_stanzas_out = NumStanzasOut} = StateData, H) ->
?DEBUG("~s acknowledged ~B of ~B stanzas",
[jlib:jid_to_string(StateData#state.jid), H, NumStanzasOut]),
mgmt_queue_drop(StateData, H).
update_num_stanzas_in(#state{mgmt_state = active} = StateData, El) -> update_num_stanzas_in(#state{mgmt_state = active} = StateData, El) ->
NewNum = case {is_stanza(El), StateData#state.mgmt_stanzas_in} of NewNum = case {is_stanza(El), StateData#state.mgmt_stanzas_in} of
{true, 4294967295} -> {true, 4294967295} ->