Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ejabberd_s2s.erl
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ start_connection(From, To, Opts) ->
MaxS2SConnectionsNumber,
MaxS2SConnectionsNumberPerNode, Opts);
true ->
%% We choose a connexion from the pool of opened ones.
%% We choose a connection from the pool of opened ones.
{ok, choose_connection(From, L)}
end
end.
Expand Down
22 changes: 16 additions & 6 deletions src/ejabberd_s2s_in.erl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
-export([handle_unexpected_info/2, handle_unexpected_cast/2,
reject_unauthenticated_packet/2, process_closed/2]).
%% API
-export([stop/1, close/1, close/2, send/2, update_state/2, establish/1,
-export([stop/1, close/1, close/2, send/2, call/3, reply/2, update_state/2, establish/1,
host_up/1, host_down/1]).

-include("ejabberd.hrl").
Expand Down Expand Up @@ -96,6 +96,13 @@ establish(State) ->
update_state(Ref, Callback) ->
xmpp_stream_in:cast(Ref, {update_state, Callback}).

-spec call(pid(), term(), non_neg_integer() | infinity) -> term().
call(Ref, Msg, Timeout) ->
xmpp_stream_in:call(Ref, Msg, Timeout).

reply(Ref, Reply) ->
xmpp_stream_in:reply(Ref, Reply).

-spec host_up(binary()) -> ok.
host_up(Host) ->
ejabberd_hooks:add(s2s_in_closed, Host, ?MODULE,
Expand Down Expand Up @@ -169,15 +176,17 @@ handle_stream_start(_StreamStart, #{lserver := LServer} = State) ->
send(State, xmpp:serr_host_unknown());
true ->
ServerHost = ejabberd_router:host_of_route(LServer),
State#{server_host => ServerHost}
State1 = State#{server_host => ServerHost},
ejabberd_hooks:run_fold(s2s_in_stream_started, ServerHost, State1, [])
end.

handle_stream_end(Reason, #{server_host := LServer} = State) ->
State1 = State#{stop_reason => Reason},
ejabberd_hooks:run_fold(s2s_in_closed, LServer, State1, [Reason]).

handle_stream_established(State) ->
set_idle_timeout(State#{established => true}).
UniqueId = p1_time_compat:unique_integer(), % for xep-0198 s2s
set_idle_timeout(State#{established => true, unique_id => UniqueId}).

handle_auth_success(RServer, Mech, _AuthModule,
#{sockmod := SockMod,
Expand Down Expand Up @@ -286,7 +295,7 @@ handle_info(Info, #{server_host := LServer} = State) ->
ejabberd_hooks:run_fold(s2s_in_handle_info, LServer, State, [Info]).

terminate(Reason, #{auth_domains := AuthDomains,
sockmod := SockMod, socket := Socket} = State) ->
sockmod := SockMod, socket := Socket, server_host := LServer} = State) ->
case maps:get(stop_reason, State, undefined) of
{tls, _} = Err ->
?ERROR_MSG("(~s) Failed to secure inbound s2s connection: ~s",
Expand All @@ -302,7 +311,8 @@ terminate(Reason, #{auth_domains := AuthDomains,
end, ok, AuthDomains);
_ ->
ok
end.
end,
ejabberd_hooks:run_fold(s2s_in_terminate, LServer, State, [Reason]).

code_change(_OldVsn, State, _Extra) ->
{ok, State}.
Expand Down
17 changes: 12 additions & 5 deletions src/ejabberd_s2s_out.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
handle_auth_success/2, handle_auth_failure/3, handle_packet/2,
handle_stream_end/2, handle_stream_downgraded/2,
handle_recv/3, handle_send/3, handle_cdata/2,
handle_stream_established/1, handle_timeout/1]).
handle_stream_established/1, handle_timeout/1,
handle_authenticated_features/2]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
%% Hooks
Expand Down Expand Up @@ -210,6 +211,10 @@ dns_retries(#{server := LServer}) ->
dns_timeout(#{server := LServer}) ->
ejabberd_config:get_option({s2s_dns_timeout, LServer}, timer:seconds(10)).

handle_authenticated_features(StreamFeatures, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_out_authenticated_features,
ServerHost, State, [StreamFeatures]).

handle_auth_success(Mech, #{sockmod := SockMod,
socket := Socket, ip := IP,
remote_server := RServer,
Expand Down Expand Up @@ -242,8 +247,9 @@ handle_stream_end(Reason, #{server_host := ServerHost} = State) ->
handle_stream_downgraded(StreamStart, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_out_downgraded, ServerHost, State, [StreamStart]).

handle_stream_established(State) ->
State1 = State#{on_route => send},
handle_stream_established(#{server_host := ServerHost} = State) ->
State0 = ejabberd_hooks:run_fold(s2s_out_established, ServerHost, State, []),
State1 = State0#{on_route => send},
State2 = resend_queue(State1),
set_idle_timeout(State2).

Expand Down Expand Up @@ -306,15 +312,16 @@ handle_info({route, Pkt}, #{queue := Q, on_route := Action} = State) ->
handle_info(Info, #{server_host := ServerHost} = State) ->
ejabberd_hooks:run_fold(s2s_out_handle_info, ServerHost, State, [Info]).

terminate(Reason, #{server := LServer,
terminate(Reason, #{server := LServer, server_host := ServerHost,
remote_server := RServer} = State) ->
ejabberd_s2s:remove_connection({LServer, RServer}, self()),
State1 = case Reason of
normal -> State;
_ -> State#{stop_reason => internal_failure}
end,
bounce_queue(State1),
bounce_message_queue(State1).
bounce_message_queue(State1),
ejabberd_hooks:run_fold(s2s_out_terminate, ServerHost, State1, [Reason]).

code_change(_OldVsn, State, _Extra) ->
{ok, State}.
Expand Down
3 changes: 3 additions & 0 deletions src/mod_stream_mgmt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
c2s_handle_recv/3]).
%% adjust pending session timeout
-export([get_resume_timeout/1, set_resume_timeout/2]).
%% API (used by mod_stream_mgmt_s2s)
-export ([mgmt_queue_drop/2, mgmt_queue_add/2, cancel_ack_timer/1,
update_num_stanzas_in/2]).

-include("xmpp.hrl").
-include("logger.hrl").
Expand Down
Loading