mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-20 17:27:00 +01:00
EJAB-994: Implements DNS timeouts and retries.
SVN Revision: 2404
This commit is contained in:
parent
ea96fe3fd1
commit
f4330e9ed3
@ -343,6 +343,8 @@ process_term(Term, State) ->
|
|||||||
add_option(outgoing_s2s_port, Port, State);
|
add_option(outgoing_s2s_port, Port, State);
|
||||||
{outgoing_s2s_options, Methods, Timeout} ->
|
{outgoing_s2s_options, Methods, Timeout} ->
|
||||||
add_option(outgoing_s2s_options, {Methods, Timeout}, State);
|
add_option(outgoing_s2s_options, {Methods, Timeout}, State);
|
||||||
|
{s2s_dns_options, PropList} ->
|
||||||
|
add_option(s2s_dns_options, PropList, State);
|
||||||
{s2s_use_starttls, Port} ->
|
{s2s_use_starttls, Port} ->
|
||||||
add_option(s2s_use_starttls, Port, State);
|
add_option(s2s_use_starttls, Port, State);
|
||||||
{s2s_certfile, CertFile} ->
|
{s2s_certfile, CertFile} ->
|
||||||
|
@ -995,11 +995,7 @@ is_verify_res(_) ->
|
|||||||
-include_lib("kernel/include/inet.hrl").
|
-include_lib("kernel/include/inet.hrl").
|
||||||
|
|
||||||
get_addr_port(Server) ->
|
get_addr_port(Server) ->
|
||||||
Res = case inet_res:getbyname("_xmpp-server._tcp." ++ Server, srv) of
|
Res = srv_lookup(Server),
|
||||||
{error, _Reason1} ->
|
|
||||||
inet_res:getbyname("_jabber._tcp." ++ Server, srv);
|
|
||||||
{ok, _HEnt} = R -> R
|
|
||||||
end,
|
|
||||||
case Res of
|
case Res of
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?DEBUG("srv lookup of '~s' failed: ~p~n", [Server, Reason]),
|
?DEBUG("srv lookup of '~s' failed: ~p~n", [Server, Reason]),
|
||||||
@ -1036,6 +1032,34 @@ get_addr_port(Server) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
srv_lookup(Server) ->
|
||||||
|
Options = case ejabberd_config:get_local_option(s2s_dns_options) of
|
||||||
|
L when is_list(L) -> L;
|
||||||
|
_ -> []
|
||||||
|
end,
|
||||||
|
Timeout = proplists:get_value(timeout, Options, timer:seconds(10)),
|
||||||
|
Retries = proplists:get_value(retries, Options, 2),
|
||||||
|
srv_lookup(Server, Timeout, Retries).
|
||||||
|
|
||||||
|
%% XXX - this behaviour is suboptimal in the case that the domain
|
||||||
|
%% has a "_xmpp-server._tcp." but not a "_jabber._tcp." record and
|
||||||
|
%% we don't get a DNS reply for the "_xmpp-server._tcp." lookup. In this
|
||||||
|
%% case we'll give up when we get the "_jabber._tcp." nxdomain reply.
|
||||||
|
srv_lookup(_Server, _Timeout, Retries) when Retries < 1 ->
|
||||||
|
{error, timeout};
|
||||||
|
srv_lookup(Server, Timeout, Retries) ->
|
||||||
|
case inet_res:getbyname("_xmpp-server._tcp." ++ Server, srv, Timeout) of
|
||||||
|
{error, _Reason} ->
|
||||||
|
case inet_res:getbyname("_jabber._tcp." ++ Server, srv, Timeout) of
|
||||||
|
{error, timeout} ->
|
||||||
|
?ERROR_MSG("Couldn't resolve SRV records for ~p via nameservers ~p.",
|
||||||
|
[Server, inet_db:res_option(nameserver)]),
|
||||||
|
srv_lookup(Server, Timeout, Retries - 1);
|
||||||
|
R -> R
|
||||||
|
end;
|
||||||
|
{ok, _HEnt} = R -> R
|
||||||
|
end.
|
||||||
|
|
||||||
test_get_addr_port(Server) ->
|
test_get_addr_port(Server) ->
|
||||||
lists:foldl(
|
lists:foldl(
|
||||||
fun(_, Acc) ->
|
fun(_, Acc) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user