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

Merge pull request #166 from weiss/xep-0198

Add support for XEP-0198: Stream Management
This commit is contained in:
Evgeny Khramtsov 2014-05-06 23:50:49 +04:00
commit 47f627e605
5 changed files with 789 additions and 134 deletions

View File

@ -873,9 +873,11 @@ The available modules, their purpose and the options allowed by each one are:
\titem{\texttt{ejabberd\_c2s}} \titem{\texttt{ejabberd\_c2s}}
Handles c2s connections.\\ Handles c2s connections.\\
Options: \texttt{access}, \texttt{certfile}, \texttt{ciphers}, \texttt{protocol\_options} Options: \texttt{access}, \texttt{certfile}, \texttt{ciphers}, \texttt{protocol\_options}
\texttt{max\_fsm\_queue}, \texttt{max\_ack\_queue}, \texttt{max\_fsm\_queue},
\texttt{max\_stanza\_size}, \texttt{shaper}, \texttt{max\_stanza\_size}, \texttt{resend\_on\_timeout},
\texttt{starttls}, \texttt{starttls\_required}, \texttt{tls}, \texttt{resume\_timeout}, \texttt{shaper},
\texttt{starttls}, \texttt{starttls\_required},
\texttt{stream\_management}, \texttt{tls},
\texttt{zlib}, \texttt{tls\_compression} \texttt{zlib}, \texttt{tls\_compression}
\titem{\texttt{ejabberd\_s2s\_in}} \titem{\texttt{ejabberd\_s2s\_in}}
Handles incoming s2s connections.\\ Handles incoming s2s connections.\\
@ -973,6 +975,13 @@ This is a detailed description of each option allowed by the listening modules:
\term{http\_poll\_timeout}. The default value is five minutes. \term{http\_poll\_timeout}. The default value is five minutes.
The option can be defined in \term{ejabberd.yml}, expressing the time The option can be defined in \term{ejabberd.yml}, expressing the time
in seconds: \verb|{http_poll_timeout, 300}.| in seconds: \verb|{http_poll_timeout, 300}.|
\titem{max\_ack\_queue: Size}
This option specifies the maximum number of unacknowledged stanzas
queued for possible retransmission if \term{stream\_management} is
enabled. When the limit is reached, the first stanza is dropped from
the queue before adding the next one. This option can be specified
for \term{ejabberd\_c2s} listeners. The allowed values are positive
integers and \term{infinity}. Default value: \term{500}.
\titem{max\_fsm\_queue: Size} \titem{max\_fsm\_queue: Size}
This option specifies the maximum number of elements in the queue of the FSM This option specifies the maximum number of elements in the queue of the FSM
(Finite State Machine). (Finite State Machine).
@ -1010,6 +1019,23 @@ request_handlers:
/"a"/"b": mod_foo /"a"/"b": mod_foo
/"http-bind": mod_http_bind /"http-bind": mod_http_bind
\end{verbatim} \end{verbatim}
\titem{resend\_on\_timeout: true|false}
If \term{stream\_management} is enabled and this option is set to
\term{true}, any 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 \term{false}, which
tells ejabberd to generate an error message instead. The option can
be specified for \term{ejabberd\_c2s} listeners.
\titem{resume\_timeout: Seconds}
This option configures the number of seconds until a session times
out if the connection is lost. During this period of time, a client
may resume the session if \term{stream\_management} is enabled. This
option can be specified for \term{ejabberd\_c2s} listeners. Setting
it to \term{0} effectively disables session resumption. The default
value is \term{300}.
\titem{service\_check\_from: true|false} \titem{service\_check\_from: true|false}
\ind{options!service\_check\_from} \ind{options!service\_check\_from}
This option can be used with \term{ejabberd\_service} only. This option can be used with \term{ejabberd\_service} only.
@ -1033,6 +1059,10 @@ request_handlers:
No unencrypted connections will be allowed. No unencrypted connections will be allowed.
You should also set the \option{certfile} option. You should also set the \option{certfile} option.
You can define a certificate file for a specific domain using the global option \option{domain\_certfile}. You can define a certificate file for a specific domain using the global option \option{domain\_certfile}.
\titem{stream\_management: true|false}
Setting this option to \term{false} disables ejabberd's support for
\ind{protocols!XEP-0198: Stream Management}. It can be specified for
\term{ejabberd\_c2s} listeners. The default value is \term{true}.
\titem{timeout: Integer} \ind{options!timeout} \titem{timeout: Integer} \ind{options!timeout}
Timeout of the connections, expressed in milliseconds. Timeout of the connections, expressed in milliseconds.
Default: 5000 Default: 5000

View File

@ -143,3 +143,5 @@
-define(NS_MEDIA, <<"urn:xmpp:media-element">>). -define(NS_MEDIA, <<"urn:xmpp:media-element">>).
-define(NS_BOB, <<"urn:xmpp:bob">>). -define(NS_BOB, <<"urn:xmpp:bob">>).
-define(NS_PING, <<"urn:xmpp:ping">>). -define(NS_PING, <<"urn:xmpp:ping">>).
-define(NS_STREAM_MGMT_2, <<"urn:xmpp:sm:2">>).
-define(NS_STREAM_MGMT_3, <<"urn:xmpp:sm:3">>).

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,9 @@
%% API %% API
-export([start_link/0, -export([start_link/0,
route/3, route/3,
open_session/5, close_session/4, open_session/5,
open_session/6,
close_session/4,
check_in_subscription/6, check_in_subscription/6,
bounce_offline_message/3, bounce_offline_message/3,
disconnect_removed_user/2, disconnect_removed_user/2,
@ -109,10 +111,10 @@ route(From, To, Packet) ->
_ -> ok _ -> ok
end. end.
-spec open_session(sid(), binary(), binary(), binary(), info()) -> ok. -spec open_session(sid(), binary(), binary(), binary(), prio(), info()) -> ok.
open_session(SID, User, Server, Resource, Info) -> open_session(SID, User, Server, Resource, Priority, Info) ->
set_session(SID, User, Server, Resource, undefined, Info), set_session(SID, User, Server, Resource, Priority, Info),
mnesia:dirty_update_counter(session_counter, mnesia:dirty_update_counter(session_counter,
jlib:nameprep(Server), 1), jlib:nameprep(Server), 1),
check_for_sessions_to_replace(User, Server, Resource), check_for_sessions_to_replace(User, Server, Resource),
@ -120,6 +122,11 @@ open_session(SID, User, Server, Resource, Info) ->
ejabberd_hooks:run(sm_register_connection_hook, ejabberd_hooks:run(sm_register_connection_hook,
JID#jid.lserver, [SID, JID, Info]). JID#jid.lserver, [SID, JID, Info]).
-spec open_session(sid(), binary(), binary(), binary(), info()) -> ok.
open_session(SID, User, Server, Resource, Info) ->
open_session(SID, User, Server, Resource, undefined, Info).
-spec close_session(sid(), binary(), binary(), binary()) -> ok. -spec close_session(sid(), binary(), binary(), binary()) -> ok.
close_session(SID, User, Server, Resource) -> close_session(SID, User, Server, Resource) ->

View File

@ -45,12 +45,13 @@
timestamp_to_iso/2, timestamp_to_xml/4, timestamp_to_iso/2, timestamp_to_xml/4,
timestamp_to_xml/1, now_to_utc_string/1, timestamp_to_xml/1, now_to_utc_string/1,
now_to_local_string/1, datetime_string_to_timestamp/1, now_to_local_string/1, datetime_string_to_timestamp/1,
term_to_base64/1, base64_to_term/1,
decode_base64/1, encode_base64/1, ip_to_list/1, decode_base64/1, encode_base64/1, ip_to_list/1,
rsm_encode/1, rsm_encode/2, rsm_decode/1, rsm_encode/1, rsm_encode/2, rsm_decode/1,
binary_to_integer/1, binary_to_integer/2, binary_to_integer/1, binary_to_integer/2,
integer_to_binary/1, integer_to_binary/2, integer_to_binary/1, integer_to_binary/2,
atom_to_binary/1, binary_to_atom/1, tuple_to_binary/1, atom_to_binary/1, binary_to_atom/1, tuple_to_binary/1,
l2i/1, i2l/1, i2l/2]). l2i/1, i2l/1, i2l/2, queue_drop_while/2]).
%% TODO: Remove once XEP-0091 is Obsolete %% TODO: Remove once XEP-0091 is Obsolete
%% TODO: Remove once XEP-0091 is Obsolete %% TODO: Remove once XEP-0091 is Obsolete
@ -779,6 +780,21 @@ check_list(List) ->
% Base64 stuff (based on httpd_util.erl) % Base64 stuff (based on httpd_util.erl)
% %
-spec term_to_base64(term()) -> binary().
term_to_base64(Term) ->
encode_base64(term_to_binary(Term)).
-spec base64_to_term(binary()) -> {term, term()} | error.
base64_to_term(Base64) ->
case catch binary_to_term(decode_base64(Base64), [safe]) of
{'EXIT', _} ->
error;
Term ->
{term, Term}
end.
-spec decode_base64(binary()) -> binary(). -spec decode_base64(binary()) -> binary().
decode_base64(S) -> decode_base64(S) ->
@ -893,3 +909,18 @@ i2l(L, N) when is_binary(L) ->
C when C > N -> L; C when C > N -> L;
_ -> i2l(<<$0, L/binary>>, N) _ -> i2l(<<$0, L/binary>>, N)
end. end.
-spec queue_drop_while(fun((term()) -> boolean()), queue()) -> queue().
queue_drop_while(F, Q) ->
case queue:peek(Q) of
{value, Item} ->
case F(Item) of
true ->
queue_drop_while(F, queue:drop(Q));
_ ->
Q
end;
empty ->
Q
end.