* src/ejabberd_s2s.erl: don't use the resource of the sender to choose

a s2s connection to ensure that a muc room always uses the same
connection

Merge branch 'ejabberd_s2s'

Conflicts:

.gitignore
src/configure
src/ejabberd_c2s.erl
src/ejabberd_s2s.erl

SVN Revision: 963
This commit is contained in:
Jérôme Sautret 2007-10-30 17:38:40 +00:00
parent 990514eef9
commit 96ded4535d
4 changed files with 66 additions and 60 deletions

6
.gitignore vendored
View File

@ -1,6 +1,12 @@
*.beam *.beam
*~ *~
*.so *.so
*.flc
*.log
erl_crash.dump
ejabberd.cfg
ejabberd.sh
Mnesia.*
Makefile Makefile
XmppAddr.asn1db XmppAddr.asn1db
XmppAddr.erl XmppAddr.erl

1
src/configure vendored
View File

@ -6871,4 +6871,3 @@ if test "$no_create" != yes; then
# would make configure fail if this is the last instruction. # would make configure fail if this is the last instruction.
$ac_cs_success || { (exit 1); exit 1; } $ac_cs_success || { (exit 1); exit 1; }
fi fi

View File

@ -132,7 +132,7 @@ get_presence(FsmRef) ->
%% Returns: {ok, StateName, StateData} | %% Returns: {ok, StateName, StateData} |
%% {ok, StateName, StateData, Timeout} | %% {ok, StateName, StateData, Timeout} |
%% ignore | %% ignore |
%% {stop, StopReason} %% {stop, StopReason}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
init([{SockMod, Socket}, Opts]) -> init([{SockMod, Socket}, Opts]) ->
Access = case lists:keysearch(access, 1, Opts) of Access = case lists:keysearch(access, 1, Opts) of
@ -178,7 +178,7 @@ init([{SockMod, Socket}, Opts]) ->
%% Func: StateName/2 %% Func: StateName/2
%% Returns: {next_state, NextStateName, NextStateData} | %% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} | %% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) -> wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
@ -313,7 +313,7 @@ wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
{stop, normal, StateData}; {stop, normal, StateData};
true -> true ->
send_text(StateData, Header), send_text(StateData, Header),
fsm_next_state(wait_for_auth, fsm_next_state(wait_for_auth,
StateData#state{ StateData#state{
server = Server, server = Server,
lang = Lang}) lang = Lang})
@ -929,7 +929,7 @@ session_established(closed, StateData) ->
%% {reply, Reply, NextStateName, NextStateData} | %% {reply, Reply, NextStateName, NextStateData} |
%% {reply, Reply, NextStateName, NextStateData, Timeout} | %% {reply, Reply, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} | %% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData} %% {stop, Reason, Reply, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
%state_name(Event, From, StateData) -> %state_name(Event, From, StateData) ->
% Reply = ok, % Reply = ok,
@ -939,7 +939,7 @@ session_established(closed, StateData) ->
%% Func: handle_event/3 %% Func: handle_event/3
%% Returns: {next_state, NextStateName, NextStateData} | %% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} | %% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_event(_Event, StateName, StateData) -> handle_event(_Event, StateName, StateData) ->
fsm_next_state(StateName, StateData). fsm_next_state(StateName, StateData).
@ -951,7 +951,7 @@ handle_event(_Event, StateName, StateData) ->
%% {reply, Reply, NextStateName, NextStateData} | %% {reply, Reply, NextStateName, NextStateData} |
%% {reply, Reply, NextStateName, NextStateData, Timeout} | %% {reply, Reply, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} | %% {stop, Reason, NewStateData} |
%% {stop, Reason, Reply, NewStateData} %% {stop, Reason, Reply, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_sync_event({get_presence}, _From, StateName, StateData) -> handle_sync_event({get_presence}, _From, StateName, StateData) ->
User = StateData#state.user, User = StateData#state.user,
@ -975,12 +975,11 @@ code_change(_OldVsn, StateName, StateData, _Extra) ->
%% Func: handle_info/3 %% Func: handle_info/3
%% Returns: {next_state, NextStateName, NextStateData} | %% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} | %% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
handle_info({send_text, Text}, StateName, StateData) -> handle_info({send_text, Text}, StateName, StateData) ->
send_text(StateData, Text), send_text(StateData, Text),
ejabberd_hooks:run(c2s_loop_debug, [Text]), ejabberd_hooks:run(c2s_loop_debug, [Text]),
fsm_next_state(StateName, StateData); fsm_next_state(StateName, StateData);
handle_info(replaced, _StateName, StateData) -> handle_info(replaced, _StateName, StateData) ->
Lang = StateData#state.lang, Lang = StateData#state.lang,
@ -1848,7 +1847,7 @@ process_unauthenticated_stanza(StateData, El) ->
jlib:make_jid("", "", ""), jlib:make_jid("", "", ""),
jlib:iq_to_xml(ResIQ)), jlib:iq_to_xml(ResIQ)),
send_element(StateData, jlib:remove_attr("to", Res1)); send_element(StateData, jlib:remove_attr("to", Res1));
_ -> _ ->
send_element(StateData, Res) send_element(StateData, Res)
end; end;
_ -> _ ->

View File

@ -3,12 +3,12 @@
%%% Author : Alexey Shchepin <alexey@sevcom.net> %%% Author : Alexey Shchepin <alexey@sevcom.net>
%%% Purpose : S2S connections manager %%% Purpose : S2S connections manager
%%% Created : 7 Dec 2002 by Alexey Shchepin <alexey@sevcom.net> %%% Created : 7 Dec 2002 by Alexey Shchepin <alexey@sevcom.net>
%%% Id : $Id$ %%% Id : $Id: ejabberd_s2s.erl 820 2007-07-19 21:17:13Z mremond $
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
-module(ejabberd_s2s). -module(ejabberd_s2s).
-author('alexey@sevcom.net'). -author('alexey@sevcom.net').
-vsn('$Revision$ '). -vsn('$Revision: 820 $ ').
-behaviour(gen_server). -behaviour(gen_server).
@ -26,7 +26,7 @@
%% gen_server callbacks %% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]). terminate/2, code_change/3]).
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("jlib.hrl"). -include("jlib.hrl").
@ -50,11 +50,11 @@ start_link() ->
route(From, To, Packet) -> route(From, To, Packet) ->
case catch do_route(From, To, Packet) of case catch do_route(From, To, Packet) of
{'EXIT', Reason} -> {'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p", ?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]); [Reason, {From, To, Packet}]);
_ -> _ ->
ok ok
end. end.
remove_connection(FromTo, Pid, Key) -> remove_connection(FromTo, Pid, Key) ->
@ -74,10 +74,10 @@ remove_connection(FromTo, Pid, Key) ->
have_connection(FromTo) -> have_connection(FromTo) ->
case catch mnesia:dirty_read(s2s, FromTo) of case catch mnesia:dirty_read(s2s, FromTo) of
[_] -> [_] ->
true; true;
_ -> _ ->
false false
end. end.
has_key(FromTo, Key) -> has_key(FromTo, Key) ->
@ -112,10 +112,10 @@ try_register(FromTo) ->
end end
end, end,
case mnesia:transaction(F) of case mnesia:transaction(F) of
{atomic, Res} -> {atomic, Res} ->
Res; Res;
_ -> _ ->
false false
end. end.
dirty_get_connections() -> dirty_get_connections() ->
@ -177,11 +177,11 @@ handle_info({mnesia_system_event, {mnesia_down, Node}}, State) ->
{noreply, State}; {noreply, State};
handle_info({route, From, To, Packet}, State) -> handle_info({route, From, To, Packet}, State) ->
case catch do_route(From, To, Packet) of case catch do_route(From, To, Packet) of
{'EXIT', Reason} -> {'EXIT', Reason} ->
?ERROR_MSG("~p~nwhen processing: ~p", ?ERROR_MSG("~p~nwhen processing: ~p",
[Reason, {From, To, Packet}]); [Reason, {From, To, Packet}]);
_ -> _ ->
ok ok
end, end,
{noreply, State}; {noreply, State};
handle_info(_Info, State) -> handle_info(_Info, State) ->
@ -222,7 +222,7 @@ clean_table_from_bad_node(Node) ->
do_route(From, To, Packet) -> do_route(From, To, Packet) ->
?DEBUG("s2s manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n", ?DEBUG("s2s manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
[From, To, Packet, 8]), [From, To, Packet, 8]),
case find_connection(From, To) of case find_connection(From, To) of
{atomic, Pid} when pid(Pid) -> {atomic, Pid} when pid(Pid) ->
?DEBUG("sending to process ~p~n", [Pid]), ?DEBUG("sending to process ~p~n", [Pid]),
@ -296,8 +296,11 @@ choose_pid(From, Pids) ->
[] -> Pids; [] -> Pids;
Ps -> Ps Ps -> Ps
end, end,
%% use sticky connections based on the full JID of the sender % Use sticky connections based on the JID of the sender (whithout
Pid = lists:nth(erlang:phash(From, length(Pids1)), Pids1), % the resource to ensure that a muc room always uses the same
% connection)
Pid = lists:nth(erlang:phash(jlib:jid_remove_resource(From), length(Pids1)),
Pids1),
?DEBUG("Using ejabberd_s2s_out ~p~n", [Pid]), ?DEBUG("Using ejabberd_s2s_out ~p~n", [Pid]),
Pid. Pid.
@ -373,12 +376,12 @@ needed_connections_number(Ls, MaxS2SConnectionsNumber,
is_service(From, To) -> is_service(From, To) ->
LFromDomain = From#jid.lserver, LFromDomain = From#jid.lserver,
case ejabberd_config:get_local_option({route_subdomains, LFromDomain}) of case ejabberd_config:get_local_option({route_subdomains, LFromDomain}) of
s2s -> % bypass RFC 3920 10.3 s2s -> % bypass RFC 3920 10.3
false; false;
_ -> _ ->
LDstDomain = To#jid.lserver, LDstDomain = To#jid.lserver,
P = fun(Domain) -> is_subdomain(LDstDomain, Domain) end, P = fun(Domain) -> is_subdomain(LDstDomain, Domain) end,
lists:any(P, ?MYHOSTS) lists:any(P, ?MYHOSTS)
end. end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -415,31 +418,30 @@ update_tables() ->
mnesia:delete_table(s2s) mnesia:delete_table(s2s)
end, end,
case catch mnesia:table_info(s2s, attributes) of case catch mnesia:table_info(s2s, attributes) of
[fromto, node, key] -> [fromto, node, key] ->
mnesia:transform_table(s2s, ignore, [fromto, pid, key]), mnesia:transform_table(s2s, ignore, [fromto, pid, key]),
mnesia:clear_table(s2s); mnesia:clear_table(s2s);
[fromto, pid, key] -> [fromto, pid, key] ->
ok; ok;
{'EXIT', _} -> {'EXIT', _} ->
ok ok
end, end,
case lists:member(local_s2s, mnesia:system_info(tables)) of case lists:member(local_s2s, mnesia:system_info(tables)) of
true -> true ->
mnesia:delete_table(local_s2s); mnesia:delete_table(local_s2s);
false -> false ->
ok ok
end. end.
%% Check if host is in blacklist or white list %% Check if host is in blacklist or white list
allow_host(MyServer, S2SHost) -> allow_host(MyServer, S2SHost) ->
case ejabberd_config:get_local_option({{s2s_host, S2SHost},MyServer}) of case ejabberd_config:get_local_option({{s2s_host, S2SHost},MyServer}) of
deny -> false; deny -> false;
allow -> true; allow -> true;
_ -> _ ->
case ejabberd_config:get_local_option({s2s_default_policy, MyServer}) of case ejabberd_config:get_local_option({s2s_default_policy, MyServer}) of
deny -> false; deny -> false;
allow -> true; allow -> true;
_ -> true %% The default s2s policy is allow _ -> true %% The default s2s policy is allow
end end
end. end.