Update multicast code to binarization and ejabberd 14.07
This commit is contained in:
parent
2589d6ec6f
commit
4f3a724927
|
@ -3,7 +3,6 @@
|
||||||
%%% Author : Badlop <badlop@ono.com>
|
%%% Author : Badlop <badlop@ono.com>
|
||||||
%%% Purpose : Multicast router
|
%%% Purpose : Multicast router
|
||||||
%%% Created : 11 Aug 2007 by Badlop <badlop@ono.com>
|
%%% Created : 11 Aug 2007 by Badlop <badlop@ono.com>
|
||||||
%%% Id : $Id: ejabberd_router_multicast.erl 440 2007-12-06 22:36:21Z badlop $
|
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ejabberd_router_multicast).
|
-module(ejabberd_router_multicast).
|
||||||
|
@ -25,8 +24,8 @@
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
-include("jlib.hrl").
|
||||||
|
|
||||||
-record(route_multicast, {domain, pid}).
|
-record(route_multicast, {domain, pid}).
|
||||||
-record(state, {}).
|
-record(state, {}).
|
||||||
|
@ -71,11 +70,13 @@ unregister_route(Domain) ->
|
||||||
LDomain ->
|
LDomain ->
|
||||||
Pid = self(),
|
Pid = self(),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
case mnesia:match(#route_multicast{domain = LDomain,
|
case mnesia:select(route_multicast,
|
||||||
pid = Pid}) of
|
[{#route_multicast{pid = Pid, domain = LDomain, _ = '_'},
|
||||||
|
[],
|
||||||
|
['$_']}]) of
|
||||||
[R] -> mnesia:delete_object(R);
|
[R] -> mnesia:delete_object(R);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
mnesia:transaction(F)
|
mnesia:transaction(F)
|
||||||
end.
|
end.
|
||||||
|
@ -189,21 +190,48 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
%% Destinations = [#jid]
|
%% Destinations = [#jid]
|
||||||
do_route(From, Domain, Destinations, Packet) ->
|
do_route(From, Domain, Destinations, Packet) ->
|
||||||
|
|
||||||
?DEBUG("route_multicast~n\tfrom ~p~n\tdomain ~p~n\tdestinations ~p~n\tpacket ~p~n",
|
?DEBUG("route_multicast~n\tfrom ~s~n\tdomain ~s~n\tdestinations ~p~n\tpacket ~p~n",
|
||||||
[From, Domain, Destinations, Packet]),
|
[jlib:jid_to_string(From),
|
||||||
|
Domain,
|
||||||
|
[jlib:jid_to_string(To) || To <- Destinations],
|
||||||
|
Packet]),
|
||||||
|
|
||||||
|
{Groups, Rest} = lists:foldr(
|
||||||
|
fun(Dest, {Groups1, Rest1}) ->
|
||||||
|
case ejabberd_sm:get_session_pid(Dest#jid.luser, Dest#jid.lserver, Dest#jid.lresource) of
|
||||||
|
none ->
|
||||||
|
{Groups1, [Dest|Rest1]};
|
||||||
|
Pid ->
|
||||||
|
Node = node(Pid),
|
||||||
|
if Node /= node() ->
|
||||||
|
{dict:append(Node, Dest, Groups1), Rest1};
|
||||||
|
true ->
|
||||||
|
{Groups1, [Dest|Rest1]}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end, {dict:new(), []}, Destinations),
|
||||||
|
|
||||||
|
dict:map(
|
||||||
|
fun(Node, [Single]) ->
|
||||||
|
ejabberd_cluster:send({ejabberd_sm, Node},
|
||||||
|
{route, From, Single, Packet});
|
||||||
|
(Node, Dests) ->
|
||||||
|
ejabberd_cluster:send({ejabberd_sm, Node},
|
||||||
|
{route_multiple, From, Dests, Packet})
|
||||||
|
end, Groups),
|
||||||
|
|
||||||
%% Try to find an appropriate multicast service
|
%% Try to find an appropriate multicast service
|
||||||
case mnesia:dirty_read(route_multicast, Domain) of
|
case mnesia:dirty_read(route_multicast, Domain) of
|
||||||
|
|
||||||
%% If no multicast service is available in this server, send manually
|
%% If no multicast service is available in this server, send manually
|
||||||
[] -> do_route_normal(From, Destinations, Packet);
|
[] -> do_route_normal(From, Rest, Packet);
|
||||||
|
|
||||||
%% If available, send the packet using multicast service
|
%% If available, send the packet using multicast service
|
||||||
[R] ->
|
[R] ->
|
||||||
case R#route_multicast.pid of
|
case R#route_multicast.pid of
|
||||||
Pid when is_pid(Pid) ->
|
Pid when is_pid(Pid) ->
|
||||||
Pid ! {route_trusted, From, Destinations, Packet};
|
Pid ! {route_trusted, From, Rest, Packet};
|
||||||
_ -> do_route_normal(From, Destinations, Packet)
|
_ -> do_route_normal(From, Rest, Packet)
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue