Skip to content

Commit

Permalink
Rewrite S2S incoming connections as a gen_statem
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jan 23, 2025
1 parent ba36f3f commit 2de5b95
Show file tree
Hide file tree
Showing 10 changed files with 679 additions and 1,003 deletions.
13 changes: 8 additions & 5 deletions big_tests/tests/s2s_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ dialback_with_wrong_key(_Config) ->
{ok, _} = rpc(rpc_spec(mim), ejabberd_s2s_out, start, [FromTo, StartType]),
receive
%% Remote server (fed1) rejected out request
{'$gen_event', {validity_from_s2s_out, false, FromTo}} ->
{'$gen_cast', {validity_from_s2s_out, false, FromTo}} ->
ok
after 5000 ->
ct:fail(timeout)
after 5000 ->
ct:fail(timeout)
end.

nonascii_addr(Config) ->
Expand Down Expand Up @@ -512,6 +512,7 @@ element_count(in, false) ->
% Since S2S connections are unidirectional, mim1 acts both as initiating,
% and receiving (and authoritative) server in the dialback procedure.
% 1. Stream start response from fed1 (as initiating server)
% 1.b. Stream features after the response
% 2. Stream start from fed1 (as receiving server)
% 3. Dialback key (step 1, as receiving server)
% 4. Dialback verification request (step 2, as authoritative server)
Expand All @@ -520,13 +521,14 @@ element_count(in, false) ->
% This process sends a new stream header, as it opens a new connection to fed1,
% now acting as an authoritative server. Also see comment on L360 in ejabberd_s2s.
% 6. Stream start response from fed1
% 6.b. Stream features after the response
% 7. Dialback verification response (step 3, as receiving server)
% 8. Message from federated Alice
% The number can be seen as the sum of all arrows from the dialback diagram, since mim
% acts as all three roles in the two dialback procedures that occur:
% https://xmpp.org/extensions/xep-0220.html#intro-howitworks
% (6 arrows) + one for stream header response + one for the actual message
8;
10;
element_count(out, false) ->
% Since S2S connections are unidirectional, mim1 acts both as initiating,
% and receiving (and authoritative) server in the dialback procedure.
Expand All @@ -539,8 +541,9 @@ element_count(out, false) ->
% sent as XML elements, but straight as text, and so these three events do not appear:
% - open stream to fed1,
% - stream response for fed1->mim stream,
% -.b. Stream features after the response
% - open stream to fed1 as authoritative server.
5.
9.

group_with_tls(both_tls_optional) -> true;
group_with_tls(both_tls_required) -> true;
Expand Down
2 changes: 1 addition & 1 deletion doc/developers-guide/accumulators.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Accumulators

XMPP stanza processing starts in the `mongoose_c2s` module, which receives the stanza from a socket, or in `ejabberd_s2s_in` which receives stanzas from federated XMPP clusters.
XMPP stanza processing starts in the `mongoose_c2s` module, which receives the stanza from a socket, or in `mongoose_s2s_in` which receives stanzas from federated XMPP clusters.
The stanza is processed and eventually it and/or other messages are sent out, either to the original sender, to another c2s process within the same MongooseIM installation, or to another XMPP server.

At the beginning of the main processing chain an accumulator is created containing following set of keys:
Expand Down
2 changes: 2 additions & 0 deletions include/mongoose_ns.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
-define(MONGOOSEIM_NS_HRL, true).

-define(NS_CLIENT, <<"jabber:client">>).
-define(NS_SERVER, <<"jabber:server">>).
-define(NS_SERVER_DIALBACK, <<"jabber:server:dialback">>).
-define(NS_COMPONENT_ACCEPT, <<"jabber:component:accept">>).
-define(NS_CONFERENCE, <<"jabber:x:conference">>).
-define(NS_DISCO_ITEMS, <<"http://jabber.org/protocol/disco#items">>).
Expand Down
18 changes: 8 additions & 10 deletions src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,17 @@ xmpp_listener_common() ->
<<"proxy_protocol">> => #option{type = boolean},
<<"reuse_port">> => #option{type = boolean},
<<"shaper">> => #option{type = atom,
validate = non_empty}},
validate = non_empty},
<<"state_timeout">> => #option{type = int_or_infinity,
validate = non_negative}},
defaults = #{<<"backlog">> => 1024,
<<"max_connections">> => infinity,
<<"max_stanza_size">> => 0,
<<"num_acceptors">> => 100,
<<"proxy_protocol">> => false,
<<"reuse_port">> => false,
<<"shaper">> => none}}.
<<"shaper">> => none,
<<"state_timeout">> => 5000}}.

xmpp_listener_extra(<<"c2s">>) ->
#section{items = #{<<"access">> => #option{type = atom,
Expand All @@ -291,12 +294,10 @@ xmpp_listener_extra(<<"c2s">>) ->
validate = {module, ejabberd_auth}},
validate = unique},
<<"backwards_compatible_session">> => #option{type = boolean},
<<"state_timeout">> => #option{type = int_or_infinity,
validate = non_negative},
<<"tls">> => tls([server, xmpp])},
defaults = #{<<"access">> => all,
<<"backwards_compatible_session">> => true,
<<"state_timeout">> => 5000}};
<<"backwards_compatible_session">> => true
}};
xmpp_listener_extra(<<"component">>) ->
#section{items = #{<<"access">> => #option{type = atom,
validate = non_empty},
Expand All @@ -306,15 +307,12 @@ xmpp_listener_extra(<<"component">>) ->
<<"hidden_components">> => #option{type = boolean},
<<"password">> => #option{type = string,
validate = non_empty},
<<"state_timeout">> => #option{type = int_or_infinity,
validate = non_negative},
<<"tls">> => tls([server, xmpp_tls])},
required = [<<"password">>],
defaults = #{<<"access">> => all,
<<"check_from">> => true,
<<"conflict_behaviour">> => disconnect,
<<"hidden_components">> => false,
<<"state_timeout">> => 5000}};
<<"hidden_components">> => false}};
xmpp_listener_extra(<<"s2s">>) ->
#section{items = #{<<"tls">> => tls([server, xmpp])}}.

Expand Down
Loading

0 comments on commit 2de5b95

Please sign in to comment.