mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
* src/ejabberd_s2s.erl: Partially rewrited
* src/mod_roster.erl: Removed debugging code SVN Revision: 184
This commit is contained in:
parent
91fe973361
commit
4413036585
@ -1,3 +1,9 @@
|
|||||||
|
2003-12-13 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
|
* src/ejabberd_s2s.erl: Partially rewrited
|
||||||
|
|
||||||
|
* src/mod_roster.erl: Removed debugging code
|
||||||
|
|
||||||
2003-12-12 Alexey Shchepin <alexey@sevcom.net>
|
2003-12-12 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
* src/ejabberd_s2s_out.erl: Bugfix
|
* src/ejabberd_s2s_out.erl: Bugfix
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% File : ejabberd_s2s.erl
|
%%% File : ejabberd_s2s.erl
|
||||||
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
||||||
%%% Purpose :
|
%%% 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$
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
@ -16,42 +16,30 @@
|
|||||||
try_register/1,
|
try_register/1,
|
||||||
dirty_get_connections/0]).
|
dirty_get_connections/0]).
|
||||||
|
|
||||||
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
-include("jlib.hrl").
|
||||||
|
|
||||||
-record(s2s, {fromto, node, key}).
|
-record(s2s, {fromto, pid, key}).
|
||||||
-record(local_s2s, {fromto, pid}).
|
|
||||||
|
|
||||||
|
|
||||||
start_link() ->
|
start_link() ->
|
||||||
{ok, proc_lib:spawn_link(ejabberd_s2s, init, [])}.
|
Pid = proc_lib:spawn_link(ejabberd_s2s, init, []),
|
||||||
|
register(ejabberd_s2s, Pid),
|
||||||
|
{ok, Pid}.
|
||||||
|
|
||||||
init() ->
|
init() ->
|
||||||
register(ejabberd_s2s, self()),
|
update_tables(),
|
||||||
mnesia:create_table(s2s,[{ram_copies, [node()]},
|
mnesia:create_table(s2s,[{ram_copies, [node()]},
|
||||||
{attributes, record_info(fields, s2s)}]),
|
{attributes, record_info(fields, s2s)}]),
|
||||||
mnesia:add_table_index(session, node),
|
mnesia:add_table_copy(s2s, node(), ram_copies),
|
||||||
mnesia:create_table(local_s2s,
|
|
||||||
[{ram_copies, [node()]},
|
|
||||||
{local_content, true},
|
|
||||||
{attributes, record_info(fields, local_s2s)}]),
|
|
||||||
mnesia:add_table_copy(local_s2s, node(), ram_copies),
|
|
||||||
mnesia:subscribe(system),
|
mnesia:subscribe(system),
|
||||||
loop().
|
loop().
|
||||||
|
|
||||||
loop() ->
|
loop() ->
|
||||||
receive
|
receive
|
||||||
%{open_connection, User, Resource, From} ->
|
|
||||||
% replace_and_register_my_connection(User, Resource, From),
|
|
||||||
% replace_alien_connection(User, Resource),
|
|
||||||
% loop();
|
|
||||||
{closed_conection, FromTo} ->
|
{closed_conection, FromTo} ->
|
||||||
remove_connection(FromTo),
|
remove_connection(FromTo),
|
||||||
loop();
|
loop();
|
||||||
%{replace, User, Resource} ->
|
|
||||||
% replace_my_connection(User, Resource),
|
|
||||||
% loop();
|
|
||||||
{mnesia_system_event, {mnesia_down, Node}} ->
|
{mnesia_system_event, {mnesia_down, Node}} ->
|
||||||
clean_table_from_bad_node(Node),
|
clean_table_from_bad_node(Node),
|
||||||
loop();
|
loop();
|
||||||
@ -68,16 +56,9 @@ loop() ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
%open_session(User, Resource) ->
|
|
||||||
% ejabberd_s2s ! {open_session, User, Resource, self()}.
|
|
||||||
%
|
|
||||||
%close_session(User, Resource) ->
|
|
||||||
% ejabberd_s2s ! {close_session, User, Resource}.
|
|
||||||
|
|
||||||
|
|
||||||
remove_connection(FromTo) ->
|
remove_connection(FromTo) ->
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
mnesia:delete({local_s2s, FromTo}),
|
|
||||||
mnesia:delete({s2s, FromTo})
|
mnesia:delete({s2s, FromTo})
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
@ -86,24 +67,17 @@ remove_connection(FromTo) ->
|
|||||||
|
|
||||||
clean_table_from_bad_node(Node) ->
|
clean_table_from_bad_node(Node) ->
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
Es = mnesia:index_read(s2s, Node, #s2s.node),
|
Es = mnesia:select(
|
||||||
|
s2s,
|
||||||
|
[{#s2s{pid = '$1', _ = '_'},
|
||||||
|
[{'==', {node, '$1'}, Node}],
|
||||||
|
['$_']}]),
|
||||||
lists:foreach(fun(E) ->
|
lists:foreach(fun(E) ->
|
||||||
mnesia:delete_object(s2s, E, write)
|
mnesia:delete_object(E)
|
||||||
end, Es)
|
end, Es)
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
%have_connection(FromTo) ->
|
|
||||||
% F = fun() ->
|
|
||||||
% [E] = mnesia:read({s2s, FromTo})
|
|
||||||
% end,
|
|
||||||
% case mnesia:transaction(F) of
|
|
||||||
% {atomic, _} ->
|
|
||||||
% true;
|
|
||||||
% _ ->
|
|
||||||
% false
|
|
||||||
% end.
|
|
||||||
|
|
||||||
have_connection(FromTo) ->
|
have_connection(FromTo) ->
|
||||||
case catch mnesia:dirty_read(s2s, FromTo) of
|
case catch mnesia:dirty_read(s2s, FromTo) of
|
||||||
[_] ->
|
[_] ->
|
||||||
@ -126,10 +100,8 @@ try_register(FromTo) ->
|
|||||||
case mnesia:read({s2s, FromTo}) of
|
case mnesia:read({s2s, FromTo}) of
|
||||||
[] ->
|
[] ->
|
||||||
mnesia:write(#s2s{fromto = FromTo,
|
mnesia:write(#s2s{fromto = FromTo,
|
||||||
node = node(),
|
pid = self(),
|
||||||
key = Key}),
|
key = Key}),
|
||||||
mnesia:write(#local_s2s{fromto = FromTo,
|
|
||||||
pid = self()}),
|
|
||||||
{key, Key};
|
{key, Key};
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
@ -149,12 +121,8 @@ try_register(FromTo) ->
|
|||||||
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]),
|
||||||
#jid{lserver = MyServer} = From,
|
case find_connection(From, To) of
|
||||||
#jid{lserver = Server} = To,
|
{atomic, Pid} when pid(Pid) ->
|
||||||
FromTo = {MyServer, Server},
|
|
||||||
Key = randoms:get_string(),
|
|
||||||
case find_connection(FromTo, Key) of
|
|
||||||
{atomic, {local, Pid}} ->
|
|
||||||
?DEBUG("sending to process ~p~n", [Pid]),
|
?DEBUG("sending to process ~p~n", [Pid]),
|
||||||
% TODO
|
% TODO
|
||||||
{xmlelement, Name, Attrs, Els} = Packet,
|
{xmlelement, Name, Attrs, Els} = Packet,
|
||||||
@ -163,60 +131,36 @@ do_route(From, To, Packet) ->
|
|||||||
Attrs),
|
Attrs),
|
||||||
send_element(Pid, {xmlelement, Name, NewAttrs, Els}),
|
send_element(Pid, {xmlelement, Name, NewAttrs, Els}),
|
||||||
ok;
|
ok;
|
||||||
{atomic, {remote, Node}} ->
|
|
||||||
?DEBUG("sending to node ~p~n", [Node]),
|
|
||||||
{ejabberd_s2s, Node} ! {route, From, To, Packet},
|
|
||||||
ok;
|
|
||||||
{atomic, new} ->
|
|
||||||
?DEBUG("starting new s2s connection~n", []),
|
|
||||||
{ok, Pid} = ejabberd_s2s_out:start(MyServer, Server, {new, Key}),
|
|
||||||
mnesia:transaction(fun() ->
|
|
||||||
mnesia:write(#local_s2s{fromto = FromTo,
|
|
||||||
pid = Pid})
|
|
||||||
end),
|
|
||||||
{xmlelement, Name, Attrs, Els} = Packet,
|
|
||||||
NewAttrs = jlib:replace_from_to_attrs(jlib:jid_to_string(From),
|
|
||||||
jlib:jid_to_string(To),
|
|
||||||
Attrs),
|
|
||||||
send_element(Pid, {xmlelement, Name, NewAttrs, Els}),
|
|
||||||
ok;
|
|
||||||
{atomic, not_exists} ->
|
|
||||||
?DEBUG("packet droped~n", []),
|
|
||||||
ok;
|
|
||||||
{aborted, Reason} ->
|
{aborted, Reason} ->
|
||||||
?DEBUG("delivery failed: ~p~n", [Reason]),
|
?DEBUG("delivery failed: ~p~n", [Reason]),
|
||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
find_connection(FromTo, Key) ->
|
find_connection(From, To) ->
|
||||||
F = fun() ->
|
#jid{lserver = MyServer} = From,
|
||||||
case mnesia:read({local_s2s, FromTo}) of
|
#jid{lserver = Server} = To,
|
||||||
[] ->
|
FromTo = {MyServer, Server},
|
||||||
case mnesia:read({s2s, FromTo}) of
|
case catch mnesia:dirty_read(s2s, FromTo) of
|
||||||
[Er] ->
|
|
||||||
{remote, Er#s2s.node};
|
|
||||||
[] ->
|
|
||||||
mnesia:write(#s2s{fromto = FromTo,
|
|
||||||
node = node(),
|
|
||||||
key = Key}),
|
|
||||||
new
|
|
||||||
end;
|
|
||||||
[El] ->
|
|
||||||
{local, El#local_s2s.pid}
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
case catch mnesia:dirty_read({local_s2s, FromTo}) of
|
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
{aborted, Reason};
|
{aborted, Reason};
|
||||||
[] ->
|
[] ->
|
||||||
case catch mnesia:dirty_read({s2s, FromTo}) of
|
?DEBUG("starting new s2s connection~n", []),
|
||||||
[Er] ->
|
Key = randoms:get_string(),
|
||||||
{atomic, {remote, Er#s2s.node}};
|
{ok, Pid} = ejabberd_s2s_out:start(MyServer, Server, {new, Key}),
|
||||||
[] ->
|
F = fun() ->
|
||||||
mnesia:transaction(F)
|
case mnesia:read({s2s, FromTo}) of
|
||||||
end;
|
|
||||||
[El] ->
|
[El] ->
|
||||||
{atomic, {local, El#local_s2s.pid}}
|
El#s2s.pid;
|
||||||
|
[] ->
|
||||||
|
mnesia:write(#s2s{fromto = FromTo,
|
||||||
|
pid = Pid,
|
||||||
|
key = Key}),
|
||||||
|
Pid
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
mnesia:transaction(F);
|
||||||
|
[El] ->
|
||||||
|
{atomic, El#s2s.pid}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
@ -227,3 +171,21 @@ send_element(Pid, El) ->
|
|||||||
dirty_get_connections() ->
|
dirty_get_connections() ->
|
||||||
mnesia:dirty_all_keys(s2s).
|
mnesia:dirty_all_keys(s2s).
|
||||||
|
|
||||||
|
|
||||||
|
update_tables() ->
|
||||||
|
case catch mnesia:table_info(s2s, attributes) of
|
||||||
|
[fromto, node, key] ->
|
||||||
|
mnesia:transform_table(s2s, ignore, [fromto, pid, key]),
|
||||||
|
mnesia:clear_table(s2s);
|
||||||
|
[fromto, pid, key] ->
|
||||||
|
ok;
|
||||||
|
{'EXIT', _} ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
case lists:member(local_s2s, mnesia:system_info(tables)) of
|
||||||
|
true ->
|
||||||
|
mnesia:delete_table(local_s2s);
|
||||||
|
false ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
|
@ -351,8 +351,6 @@ out_subscription(User, JID, Type) ->
|
|||||||
process_subscription(out, User, JID, Type).
|
process_subscription(out, User, JID, Type).
|
||||||
|
|
||||||
process_subscription(Direction, User, JID1, Type) ->
|
process_subscription(Direction, User, JID1, Type) ->
|
||||||
io:format("S10N: Dir=~p User=~p JID=~p Type=~p~n",
|
|
||||||
[Direction, User, JID1, Type]),
|
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LJID = jlib:jid_tolower(JID1),
|
LJID = jlib:jid_tolower(JID1),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
@ -391,7 +389,6 @@ process_subscription(Direction, User, JID1, Type) ->
|
|||||||
{atomic, ok} ->
|
{atomic, ok} ->
|
||||||
false;
|
false;
|
||||||
{atomic, {push, Item}} ->
|
{atomic, {push, Item}} ->
|
||||||
io:format("S10N: Item=~p~n", [Item]),
|
|
||||||
push_item(User, {"", ?MYNAME, ""}, Item),
|
push_item(User, {"", ?MYNAME, ""}, Item),
|
||||||
true;
|
true;
|
||||||
_ ->
|
_ ->
|
||||||
|
Loading…
Reference in New Issue
Block a user