Commit 89361aef authored by Philipp Huebner's avatar Philipp Huebner

New upstream version 1.0.21

parent 0d4113cc
# Version 1.0.21
* Updating fast_tls to version 1.0.21.
* Updating p1_utils to version 1.0.11.
* Fix compilation with rebar3
* Fix warning about deprecated random
* Fix typo in README
# Version 1.0.20
* Updating fast_tls to version 1.0.20.
......
......@@ -20,7 +20,7 @@ They are part of a more general negotiation technique know as
To summarize:
* A STUN server is used to get an external network address. It does
not serve as a relay for the mediat raffic.
not serve as a relay for the media traffic.
* TURN servers are used to relay traffic if direct (peer to peer)
connection fails.
......
......@@ -22,8 +22,8 @@
{erl_opts, [debug_info, {i, "include"}]}.
{deps, [{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.20"}}},
{p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.10"}}}]}.
{deps, [{fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.21"}}},
{p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.11"}}}]}.
{cover_enabled, true}.
{cover_export_enabled, true}.
......
......@@ -23,7 +23,7 @@
IsRebar3 = case application:get_key(rebar, vsn) of
{ok, VSN} ->
[VSN1 | _] = string:tokens(VSN, "-"),
[Maj, Min, Patch] = string:tokens(VSN1, "."),
[Maj|_] = string:tokens(VSN1, "."),
(list_to_integer(Maj) >= 3);
undefined ->
lists:keymember(mix, 1, application:loaded_applications())
......@@ -93,11 +93,16 @@ GlobalDepsFilter = fun(Deps) ->
end, DepNames)
end,
code:ensure_loaded(rand),
RandUniform = erlang:function_exported(rand, uniform, 1),
Rules = [
{[deps], IsRebar3,
Rebar3DepsFilter, []},
{[plugins], IsRebar3,
AppendList([rebar3_hex, pc]), []},
{[erl_opts], RandUniform,
AppendList([{d, 'RAND_UNIFORM'}]), []},
{[provider_hooks], IsRebar3,
AppendList([{pre, [
{compile, {pc, compile}},
......
......@@ -23,7 +23,7 @@
{application, stun,
[{description, "STUN and TURN library for Erlang / Elixir"},
{vsn, "1.0.20"},
{vsn, "1.0.21"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib, p1_utils]},
......
......@@ -46,6 +46,9 @@
%% gen_fsm states
-export([session_established/2]).
%% helper functions
-export([rand_uniform/0, rand_uniform/1, rand_uniform/2]).
-include("stun.hrl").
-define(MAX_BUF_SIZE, 64*1024). %% 64kb
......@@ -101,7 +104,6 @@ tcp_init(_Sock, Opts) ->
Opts.
udp_init(Sock, Opts) ->
seed(),
prepare_state(Opts, Sock, {{0,0,0,0}, 0}, gen_udp).
udp_recv(Sock, Addr, Port, Data, State) ->
......@@ -120,7 +122,6 @@ udp_recv(Sock, Addr, Port, Data, State) ->
init([Sock, Opts]) ->
case inet:peername(Sock) of
{ok, Addr} ->
seed(),
TRef = erlang:start_timer(?TIMEOUT, self(), stop),
SockMod = get_sockmod(Opts),
State = prepare_state(Opts, Sock, Addr, SockMod),
......@@ -597,7 +598,7 @@ clean_treap(Treap, CleanPriority) ->
make_nonce(Addr, Nonces) ->
Priority = now_priority(),
{TS, _} = Priority,
Nonce = list_to_binary(integer_to_list(random:uniform(1 bsl 32))),
Nonce = list_to_binary(integer_to_list(rand_uniform(1 bsl 32))),
NewNonces = clean_treap(Nonces, TS + ?NONCE_LIFETIME),
{Nonce, treap:insert(Nonce, Priority, Addr, NewNonces)}.
......@@ -642,12 +643,31 @@ maybe_starttls(Sock, fast_tls, CertFile, _PeerAddr) ->
maybe_starttls(Sock, gen_tcp, _CertFile, _PeerAddr) ->
{ok, Sock}.
seed() ->
{A, B, C} = p1_time_compat:timestamp(),
random:seed(A, B, C).
prepare_response(State, Msg) ->
#stun{method = Msg#stun.method,
magic = Msg#stun.magic,
trid = Msg#stun.trid,
'SOFTWARE' = State#state.server_name}.
-define(THRESHOLD, 16#10000000000000000).
-ifdef(RAND_UNIFORM).
rand_uniform() ->
rand:uniform().
rand_uniform(N) ->
rand:uniform(N).
rand_uniform(N, M) ->
rand:uniform(M-N+1) + N-1.
-else.
rand_uniform() ->
crypto:rand_uniform(0, ?THRESHOLD)/?THRESHOLD.
rand_uniform(N) ->
crypto:rand_uniform(1, N+1).
rand_uniform(N, M) ->
crypto:rand_uniform(N, M+1).
-endif.
......@@ -355,9 +355,7 @@ recv(TLSSocket, Buf, true) ->
end.
mk_trid() ->
{A, B, C} = p1_time_compat:timestamp(),
random:seed(A, B, C),
random:uniform(1 bsl 96).
stun:rand_uniform(1 bsl 96).
get_cert() ->
<<"-----BEGIN CERTIFICATE-----
......
......@@ -115,8 +115,6 @@ init([Opts]) ->
ok
end,
TRef = erlang:start_timer(?DEFAULT_LIFETIME, self(), stop),
{A1, A2, A3} = p1_time_compat:timestamp(),
random:seed(A1, A2, A3),
case turn_sm:add_allocation(AddrPort, Username, Realm, MaxAllocs, self()) of
ok ->
{ok, wait_for_allocate, State#state{life_timer = TRef}};
......@@ -436,7 +434,7 @@ time_left(TRef) ->
%% draft-ietf-tsvwg-port-randomization-04
allocate_addr({Min, Max}) ->
Count = Max - Min + 1,
Next = Min + random:uniform(Count) - 1,
Next = Min + stun:rand_uniform(Count) - 1,
allocate_addr(Min, Max, Next, Count).
allocate_addr(_Min, _Max, _Next, 0) ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment