mirror of
https://github.com/processone/ejabberd.git
synced 2024-09-27 14:30:55 +02:00
ejabberd_stun: Set a default 'turn_ip'
Try to resolve the local hostname, use the result as the default 'turn_ip', and only log a warning if that fails. Using the local hostname's address by default is analogous to mod_proxy65's behavior.
This commit is contained in:
parent
b0f95975c2
commit
c836dc66a8
@ -85,11 +85,13 @@ prepare_turn_opts(Opts, _UseTurn = false) ->
|
|||||||
set_certfile(Opts);
|
set_certfile(Opts);
|
||||||
prepare_turn_opts(Opts, _UseTurn = true) ->
|
prepare_turn_opts(Opts, _UseTurn = true) ->
|
||||||
NumberOfMyHosts = length(ejabberd_option:hosts()),
|
NumberOfMyHosts = length(ejabberd_option:hosts()),
|
||||||
case proplists:get_value(turn_ip, Opts) of
|
case {proplists:get_value(turn_ip, Opts),
|
||||||
undefined ->
|
proplists:get_value(turn_ip, listen_options())} of
|
||||||
?WARNING_MSG("Option 'turn_ip' is undefined, "
|
{undefined, {127, _, _, _}} ->
|
||||||
"most likely the TURN relay won't be working "
|
?WARNING_MSG("Option 'turn_ip' is undefined and the server's "
|
||||||
"properly", []);
|
"hostname doesn't resolve to a public IPv4 address, "
|
||||||
|
"most likely the TURN relay won't be working properly",
|
||||||
|
[]);
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
@ -158,7 +160,7 @@ listen_opt_type(certfile) ->
|
|||||||
listen_options() ->
|
listen_options() ->
|
||||||
[{shaper, none},
|
[{shaper, none},
|
||||||
{use_turn, false},
|
{use_turn, false},
|
||||||
{turn_ip, undefined},
|
{turn_ip, misc:get_my_ip()},
|
||||||
{auth_type, user},
|
{auth_type, user},
|
||||||
{auth_realm, undefined},
|
{auth_realm, undefined},
|
||||||
{tls, false},
|
{tls, false},
|
||||||
|
12
src/misc.erl
12
src/misc.erl
@ -40,8 +40,8 @@
|
|||||||
read_css/1, read_img/1, read_js/1, read_lua/1, try_url/1,
|
read_css/1, read_img/1, read_js/1, read_lua/1, try_url/1,
|
||||||
intersection/2, format_val/1, cancel_timer/1, unique_timestamp/0,
|
intersection/2, format_val/1, cancel_timer/1, unique_timestamp/0,
|
||||||
is_mucsub_message/1, best_match/2, pmap/2, peach/2, format_exception/4,
|
is_mucsub_message/1, best_match/2, pmap/2, peach/2, format_exception/4,
|
||||||
parse_ip_mask/1, match_ip_mask/3, format_hosts_list/1, format_cycle/1,
|
get_my_ip/0, parse_ip_mask/1, match_ip_mask/3, format_hosts_list/1,
|
||||||
delete_dir/1]).
|
format_cycle/1, delete_dir/1]).
|
||||||
|
|
||||||
%% Deprecated functions
|
%% Deprecated functions
|
||||||
-export([decode_base64/1, encode_base64/1]).
|
-export([decode_base64/1, encode_base64/1]).
|
||||||
@ -509,6 +509,14 @@ format_exception(Level, Class, Reason, Stacktrace) ->
|
|||||||
end).
|
end).
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
-spec get_my_ip() -> inet:ip_address().
|
||||||
|
get_my_ip() ->
|
||||||
|
{ok, MyHostName} = inet:gethostname(),
|
||||||
|
case inet:getaddr(MyHostName, inet) of
|
||||||
|
{ok, Addr} -> Addr;
|
||||||
|
{error, _} -> {127, 0, 0, 1}
|
||||||
|
end.
|
||||||
|
|
||||||
-spec parse_ip_mask(binary()) -> {ok, {inet:ip4_address(), 0..32}} |
|
-spec parse_ip_mask(binary()) -> {ok, {inet:ip4_address(), 0..32}} |
|
||||||
{ok, {inet:ip6_address(), 0..128}} |
|
{ok, {inet:ip6_address(), 0..128}} |
|
||||||
error.
|
error.
|
||||||
|
@ -266,19 +266,11 @@ get_streamhost(Host, ServerHost) ->
|
|||||||
get_endpoint(Host) ->
|
get_endpoint(Host) ->
|
||||||
Port = mod_proxy65_opt:port(Host),
|
Port = mod_proxy65_opt:port(Host),
|
||||||
IP = case mod_proxy65_opt:ip(Host) of
|
IP = case mod_proxy65_opt:ip(Host) of
|
||||||
undefined -> get_my_ip();
|
undefined -> misc:get_my_ip();
|
||||||
Addr -> Addr
|
Addr -> Addr
|
||||||
end,
|
end,
|
||||||
{Port, IP, tcp}.
|
{Port, IP, tcp}.
|
||||||
|
|
||||||
-spec get_my_ip() -> inet:ip_address().
|
|
||||||
get_my_ip() ->
|
|
||||||
{ok, MyHostName} = inet:gethostname(),
|
|
||||||
case inet:getaddr(MyHostName, inet) of
|
|
||||||
{ok, Addr} -> Addr;
|
|
||||||
{error, _} -> {127, 0, 0, 1}
|
|
||||||
end.
|
|
||||||
|
|
||||||
max_connections(ServerHost) ->
|
max_connections(ServerHost) ->
|
||||||
mod_proxy65_opt:max_connections(ServerHost).
|
mod_proxy65_opt:max_connections(ServerHost).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user