mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +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>
|
||||
|
||||
* src/ejabberd_s2s_out.erl: Bugfix
|
||||
|
@ -1,7 +1,7 @@
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% File : ejabberd_s2s.erl
|
||||
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
||||
%%% Purpose :
|
||||
%%% Purpose : S2S connections manager
|
||||
%%% Created : 7 Dec 2002 by Alexey Shchepin <alexey@sevcom.net>
|
||||
%%% Id : $Id$
|
||||
%%%----------------------------------------------------------------------
|
||||
@ -16,42 +16,30 @@
|
||||
try_register/1,
|
||||
dirty_get_connections/0]).
|
||||
|
||||
-include_lib("mnemosyne/include/mnemosyne.hrl").
|
||||
-include("ejabberd.hrl").
|
||||
-include("jlib.hrl").
|
||||
|
||||
-record(s2s, {fromto, node, key}).
|
||||
-record(local_s2s, {fromto, pid}).
|
||||
-record(s2s, {fromto, pid, key}).
|
||||
|
||||
|
||||
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() ->
|
||||
register(ejabberd_s2s, self()),
|
||||
update_tables(),
|
||||
mnesia:create_table(s2s,[{ram_copies, [node()]},
|
||||
{attributes, record_info(fields, s2s)}]),
|
||||
mnesia:add_table_index(session, node),
|
||||
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:add_table_copy(s2s, node(), ram_copies),
|
||||
mnesia:subscribe(system),
|
||||
loop().
|
||||
|
||||
loop() ->
|
||||
receive
|
||||
%{open_connection, User, Resource, From} ->
|
||||
% replace_and_register_my_connection(User, Resource, From),
|
||||
% replace_alien_connection(User, Resource),
|
||||
% loop();
|
||||
{closed_conection, FromTo} ->
|
||||
remove_connection(FromTo),
|
||||
loop();
|
||||
%{replace, User, Resource} ->
|
||||
% replace_my_connection(User, Resource),
|
||||
% loop();
|
||||
{mnesia_system_event, {mnesia_down, Node}} ->
|
||||
clean_table_from_bad_node(Node),
|
||||
loop();
|
||||
@ -68,16 +56,9 @@ loop() ->
|
||||
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) ->
|
||||
F = fun() ->
|
||||
mnesia:delete({local_s2s, FromTo}),
|
||||
mnesia:delete({s2s, FromTo})
|
||||
end,
|
||||
mnesia:transaction(F).
|
||||
@ -86,24 +67,17 @@ remove_connection(FromTo) ->
|
||||
|
||||
clean_table_from_bad_node(Node) ->
|
||||
F = fun() ->
|
||||
Es = mnesia:index_read(s2s, Node, #s2s.node),
|
||||
Es = mnesia:select(
|
||||
s2s,
|
||||
[{#s2s{pid = '$1', _ = '_'},
|
||||
[{'==', {node, '$1'}, Node}],
|
||||
['$_']}]),
|
||||
lists:foreach(fun(E) ->
|
||||
mnesia:delete_object(s2s, E, write)
|
||||
mnesia:delete_object(E)
|
||||
end, Es)
|
||||
end,
|
||||
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) ->
|
||||
case catch mnesia:dirty_read(s2s, FromTo) of
|
||||
[_] ->
|
||||
@ -126,10 +100,8 @@ try_register(FromTo) ->
|
||||
case mnesia:read({s2s, FromTo}) of
|
||||
[] ->
|
||||
mnesia:write(#s2s{fromto = FromTo,
|
||||
node = node(),
|
||||
pid = self(),
|
||||
key = Key}),
|
||||
mnesia:write(#local_s2s{fromto = FromTo,
|
||||
pid = self()}),
|
||||
{key, Key};
|
||||
_ ->
|
||||
false
|
||||
@ -149,12 +121,8 @@ try_register(FromTo) ->
|
||||
do_route(From, To, Packet) ->
|
||||
?DEBUG("s2s manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
||||
[From, To, Packet, 8]),
|
||||
#jid{lserver = MyServer} = From,
|
||||
#jid{lserver = Server} = To,
|
||||
FromTo = {MyServer, Server},
|
||||
Key = randoms:get_string(),
|
||||
case find_connection(FromTo, Key) of
|
||||
{atomic, {local, Pid}} ->
|
||||
case find_connection(From, To) of
|
||||
{atomic, Pid} when pid(Pid) ->
|
||||
?DEBUG("sending to process ~p~n", [Pid]),
|
||||
% TODO
|
||||
{xmlelement, Name, Attrs, Els} = Packet,
|
||||
@ -163,60 +131,36 @@ do_route(From, To, Packet) ->
|
||||
Attrs),
|
||||
send_element(Pid, {xmlelement, Name, NewAttrs, Els}),
|
||||
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} ->
|
||||
?DEBUG("delivery failed: ~p~n", [Reason]),
|
||||
false
|
||||
end.
|
||||
|
||||
find_connection(FromTo, Key) ->
|
||||
F = fun() ->
|
||||
case mnesia:read({local_s2s, FromTo}) of
|
||||
[] ->
|
||||
case mnesia: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
|
||||
find_connection(From, To) ->
|
||||
#jid{lserver = MyServer} = From,
|
||||
#jid{lserver = Server} = To,
|
||||
FromTo = {MyServer, Server},
|
||||
case catch mnesia:dirty_read(s2s, FromTo) of
|
||||
{'EXIT', Reason} ->
|
||||
{aborted, Reason};
|
||||
[] ->
|
||||
case catch mnesia:dirty_read({s2s, FromTo}) of
|
||||
[Er] ->
|
||||
{atomic, {remote, Er#s2s.node}};
|
||||
[] ->
|
||||
mnesia:transaction(F)
|
||||
end;
|
||||
?DEBUG("starting new s2s connection~n", []),
|
||||
Key = randoms:get_string(),
|
||||
{ok, Pid} = ejabberd_s2s_out:start(MyServer, Server, {new, Key}),
|
||||
F = fun() ->
|
||||
case mnesia:read({s2s, FromTo}) of
|
||||
[El] ->
|
||||
El#s2s.pid;
|
||||
[] ->
|
||||
mnesia:write(#s2s{fromto = FromTo,
|
||||
pid = Pid,
|
||||
key = Key}),
|
||||
Pid
|
||||
end
|
||||
end,
|
||||
mnesia:transaction(F);
|
||||
[El] ->
|
||||
{atomic, {local, El#local_s2s.pid}}
|
||||
{atomic, El#s2s.pid}
|
||||
end.
|
||||
|
||||
|
||||
@ -227,3 +171,21 @@ send_element(Pid, El) ->
|
||||
dirty_get_connections() ->
|
||||
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(Direction, User, JID1, Type) ->
|
||||
io:format("S10N: Dir=~p User=~p JID=~p Type=~p~n",
|
||||
[Direction, User, JID1, Type]),
|
||||
LUser = jlib:nodeprep(User),
|
||||
LJID = jlib:jid_tolower(JID1),
|
||||
F = fun() ->
|
||||
@ -391,7 +389,6 @@ process_subscription(Direction, User, JID1, Type) ->
|
||||
{atomic, ok} ->
|
||||
false;
|
||||
{atomic, {push, Item}} ->
|
||||
io:format("S10N: Item=~p~n", [Item]),
|
||||
push_item(User, {"", ?MYNAME, ""}, Item),
|
||||
true;
|
||||
_ ->
|
||||
|
Loading…
Reference in New Issue
Block a user