aboutsummaryrefslogtreecommitdiff
path: root/src/ejabberd_stun.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ejabberd_stun.erl')
-rw-r--r--src/ejabberd_stun.erl74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/ejabberd_stun.erl b/src/ejabberd_stun.erl
index 53ecd5cc1..1e00c85f5 100644
--- a/src/ejabberd_stun.erl
+++ b/src/ejabberd_stun.erl
@@ -24,27 +24,29 @@
%%%-------------------------------------------------------------------
-module(ejabberd_stun).
-
+-behaviour(ejabberd_listener).
-protocol({rfc, 5766}).
-protocol({xep, 176, '1.0'}).
-ifndef(STUN).
-include("logger.hrl").
--export([socket_type/0, start/2, listen_opt_type/1]).
-log_error() ->
- ?CRITICAL_MSG("ejabberd is not compiled with STUN/TURN support", []).
-socket_type() ->
- log_error(),
- raw.
-listen_opt_type(_) ->
- log_error(),
- [].
+-export([accept/1, start/2, start_link/2, listen_options/0]).
+fail() ->
+ ?CRITICAL_MSG("Listening module ~s is not available: "
+ "ejabberd is not compiled with STUN/TURN support",
+ [?MODULE]),
+ erlang:error(stun_not_compiled).
+accept(_) ->
+ fail().
+listen_options() ->
+ fail().
start(_, _) ->
- log_error(),
- {error, sip_not_compiled}.
+ fail().
+start_link(_, _) ->
+ fail().
-else.
-export([tcp_init/2, udp_init/2, udp_recv/5, start/2,
- socket_type/0, listen_opt_type/1]).
+ start_link/2, accept/1, listen_opt_type/1, listen_options/0]).
-include("logger.hrl").
@@ -65,8 +67,11 @@ udp_recv(Socket, Addr, Port, Packet, Opts) ->
start(Opaque, Opts) ->
stun:start(Opaque, Opts).
-socket_type() ->
- raw.
+start_link({gen_tcp, Sock}, Opts) ->
+ stun:start_link(Sock, Opts).
+
+accept(_Pid) ->
+ ok.
%%%===================================================================
%%% Internal functions
@@ -138,27 +143,16 @@ listen_opt_type(turn_ip) ->
{ok, Addr} = inet_parse:ipv4_address(binary_to_list(S)),
Addr
end;
-listen_opt_type(shaper) ->
- fun acl:shaper_rules_validator/1;
listen_opt_type(auth_type) ->
fun(anonymous) -> anonymous;
(user) -> user
end;
listen_opt_type(auth_realm) ->
fun iolist_to_binary/1;
-listen_opt_type(tls) ->
- fun(B) when is_boolean(B) -> B end;
-listen_opt_type(certfile) ->
- fun(S) ->
- %% We cannot deprecate the option for now:
- %% I think STUN/TURN clients are too stupid to set SNI
- ejabberd_pkix:add_certfile(S),
- iolist_to_binary(S)
- end;
listen_opt_type(turn_min_port) ->
- fun(P) when is_integer(P), P > 0, P =< 65535 -> P end;
+ fun(P) when is_integer(P), P > 1024, P < 65536 -> P end;
listen_opt_type(turn_max_port) ->
- fun(P) when is_integer(P), P > 0, P =< 65535 -> P end;
+ fun(P) when is_integer(P), P > 1024, P < 65536 -> P end;
listen_opt_type(turn_max_allocations) ->
fun(I) when is_integer(I), I>0 -> I;
(unlimited) -> infinity;
@@ -170,13 +164,19 @@ listen_opt_type(turn_max_permissions) ->
(infinity) -> infinity
end;
listen_opt_type(server_name) ->
- fun iolist_to_binary/1;
-listen_opt_type(backlog) ->
- fun(I) when is_integer(I), I>0 -> I end;
-listen_opt_type(accept_interval) ->
- fun(I) when is_integer(I), I>=0 -> I end;
-listen_opt_type(_) ->
- [shaper, auth_type, auth_realm, tls, certfile, turn_min_port,
- turn_max_port, turn_max_allocations, turn_max_permissions,
- server_name, backlog, accept_interval].
+ fun iolist_to_binary/1.
+
+listen_options() ->
+ [{shaper, none},
+ {use_turn, false},
+ {turn_ip, undefined},
+ {auth_type, user},
+ {auth_realm, undefined},
+ {tls, false},
+ {certfile, undefined},
+ {turn_min_port, 49152},
+ {turn_max_port, 65535},
+ {turn_max_allocations, 10},
+ {turn_max_permissions, 10},
+ {server_name, <<"ejabberd">>}].
-endif.