mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-24 17:29:28 +01: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);
|
||||
prepare_turn_opts(Opts, _UseTurn = true) ->
|
||||
NumberOfMyHosts = length(ejabberd_option:hosts()),
|
||||
case proplists:get_value(turn_ip, Opts) of
|
||||
undefined ->
|
||||
?WARNING_MSG("Option 'turn_ip' is undefined, "
|
||||
"most likely the TURN relay won't be working "
|
||||
"properly", []);
|
||||
case {proplists:get_value(turn_ip, Opts),
|
||||
proplists:get_value(turn_ip, listen_options())} of
|
||||
{undefined, {127, _, _, _}} ->
|
||||
?WARNING_MSG("Option 'turn_ip' is undefined and the server's "
|
||||
"hostname doesn't resolve to a public IPv4 address, "
|
||||
"most likely the TURN relay won't be working properly",
|
||||
[]);
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
@ -158,7 +160,7 @@ listen_opt_type(certfile) ->
|
||||
listen_options() ->
|
||||
[{shaper, none},
|
||||
{use_turn, false},
|
||||
{turn_ip, undefined},
|
||||
{turn_ip, misc:get_my_ip()},
|
||||
{auth_type, user},
|
||||
{auth_realm, undefined},
|
||||
{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,
|
||||
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,
|
||||
parse_ip_mask/1, match_ip_mask/3, format_hosts_list/1, format_cycle/1,
|
||||
delete_dir/1]).
|
||||
get_my_ip/0, parse_ip_mask/1, match_ip_mask/3, format_hosts_list/1,
|
||||
format_cycle/1, delete_dir/1]).
|
||||
|
||||
%% Deprecated functions
|
||||
-export([decode_base64/1, encode_base64/1]).
|
||||
@ -509,6 +509,14 @@ format_exception(Level, Class, Reason, Stacktrace) ->
|
||||
end).
|
||||
-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}} |
|
||||
{ok, {inet:ip6_address(), 0..128}} |
|
||||
error.
|
||||
|
@ -266,19 +266,11 @@ get_streamhost(Host, ServerHost) ->
|
||||
get_endpoint(Host) ->
|
||||
Port = mod_proxy65_opt:port(Host),
|
||||
IP = case mod_proxy65_opt:ip(Host) of
|
||||
undefined -> get_my_ip();
|
||||
undefined -> misc:get_my_ip();
|
||||
Addr -> Addr
|
||||
end,
|
||||
{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) ->
|
||||
mod_proxy65_opt:max_connections(ServerHost).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user