...
 
Commits (6)
# Version 1.0.13
* Add p1\_rand and shaper module
# Version 1.0.12
* Don't fetch generic\_debug option from init
......
erlang-p1-utils (1.0.12-1~bpo9+1) stretch-backports; urgency=medium
erlang-p1-utils (1.0.13-1~bpo9+1) stretch-backports; urgency=medium
* Rebuild for stretch-backports.
-- Philipp Huebner <debalance@debian.org> Fri, 20 Jul 2018 11:01:21 +0200
-- Philipp Huebner <debalance@debian.org> Sat, 17 Nov 2018 22:21:46 +0100
erlang-p1-utils (1.0.13-1) unstable; urgency=medium
* New upstream version 1.0.13
* Enabled DH_VERBOSE in debian/rules
* Updated Standards-Version: 4.2.1 (no changes needed)
-- Philipp Huebner <debalance@debian.org> Sun, 07 Oct 2018 14:58:00 +0200
erlang-p1-utils (1.0.12-1) unstable; urgency=medium
......
......@@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 11~),
erlang-crypto,
erlang-eunit,
erlang-syntax-tools
Standards-Version: 4.1.4
Standards-Version: 4.2.1
Vcs-Browser: https://salsa.debian.org/ejabberd-packaging-team/erlang-p1-utils
Vcs-Git: https://salsa.debian.org/ejabberd-packaging-team/erlang-p1-utils.git
Homepage: https://github.com/processone/p1_utils
......
#!/usr/bin/make -f
#export DH_VERBOSE = 1
export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
include /usr/share/dpkg/default.mk
......
{erl_opts, [
debug_info,
{src_dirs, ["src"]},
{platform_define, "^(15|16|17)", 'NEED_TIME_FALLBACKS'}
{platform_define, "^(15|16|17)", 'NEED_TIME_FALLBACKS'},
{platform_define, "^(18|19|([2-9][0-9]))", 'HAVE_RAND'}
]}.
{cover_enabled, true}.
......
%%%----------------------------------------------------------------------
%%% File : p1_rand.erl
%%% Author : Alexey Shchepin <alexey@process-one.net>
%%% Purpose : Random generation number wrapper
%%% Created : 13 Dec 2002 by Alexey Shchepin <alexey@process-one.net>
%%%
%%%
%%% ejabberd, Copyright (C) 2002-2018 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License along
%%% with this program; if not, write to the Free Software Foundation, Inc.,
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
%%%
%%%----------------------------------------------------------------------
-module(p1_rand).
-author('alexey@process-one.net').
-export([get_string/0, uniform/0, uniform/1, uniform/2, bytes/1,
round_robin/1, get_alphanum_string/1]).
-define(THRESHOLD, 16#10000000000000000).
-ifdef(HAVE_RAND).
get_string() ->
R = rand:uniform(?THRESHOLD),
integer_to_binary(R).
uniform() ->
rand:uniform().
uniform(N) ->
rand:uniform(N).
uniform(N, M) ->
rand:uniform(M-N+1) + N-1.
-else.
get_string() ->
R = crypto:rand_uniform(0, ?THRESHOLD),
integer_to_binary(R).
uniform() ->
crypto:rand_uniform(0, ?THRESHOLD)/?THRESHOLD.
uniform(N) ->
crypto:rand_uniform(1, N+1).
uniform(N, M) ->
crypto:rand_uniform(N, M+1).
-endif.
-spec bytes(non_neg_integer()) -> binary().
bytes(N) ->
crypto:strong_rand_bytes(N).
-spec round_robin(pos_integer()) -> non_neg_integer().
round_robin(N) ->
p1_time_compat:unique_integer([monotonic, positive]) rem N.
-spec get_alphanum_string(non_neg_integer()) -> binary().
get_alphanum_string(Length) ->
list_to_binary(get_alphanum_string([], Length)).
-spec get_alphanum_string(string(), non_neg_integer()) -> string().
get_alphanum_string(S, 0) -> S;
get_alphanum_string(S, N) ->
get_alphanum_string([make_rand_char() | S], N - 1).
-spec make_rand_char() -> char().
make_rand_char() ->
map_int_to_char(uniform(0, 61)).
-spec map_int_to_char(0..61) -> char().
map_int_to_char(N) when N =< 9 -> N + 48; % Digit.
map_int_to_char(N) when N =< 35 -> N + 55; % Upper-case character.
map_int_to_char(N) when N =< 61 -> N + 61. % Lower-case character.
%%%-------------------------------------------------------------------
%%% @author Evgeny Khramtsov <ekhramtsov@process-one.net>
%%%
%%%
%%% Copyright (C) 2002-2018 ProcessOne, SARL. All Rights Reserved.
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%% http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%%
%%%-------------------------------------------------------------------
-module(p1_shaper).
%% API
-export([new/1, new/2, update/2, pp/1]).
-record(state, {maxrate = 0 :: integer(),
burst_size = 0 :: integer(),
acquired_credit = 0 :: integer(),
lasttime = 0 :: integer()}).
-opaque state() :: #state{}.
-export_type([state/0]).
%%%===================================================================
%%% API
%%%===================================================================
-spec new(integer()) -> state().
new(MaxRate) ->
new(MaxRate, MaxRate).
-spec new(integer(), integer()) -> state().
new(MaxRate, BurstSize) ->
#state{maxrate = MaxRate,
burst_size = BurstSize,
acquired_credit = BurstSize,
lasttime = p1_time_compat:system_time(micro_seconds)}.
-spec update(state(), non_neg_integer()) -> {state(), non_neg_integer()}.
update(#state{maxrate = MR, burst_size = BS,
acquired_credit = AC, lasttime = L} = State, Size) ->
Now = p1_time_compat:system_time(micro_seconds),
AC2 = min(BS, AC + (MR*(Now - L) div 1000000) - Size),
Pause = if AC2 >= 0 -> 0;
true -> -1000*AC2 div MR
end,
{State#state{acquired_credit = AC2, lasttime = Now}, Pause}.
-spec pp(any()) -> iolist().
pp(Term) ->
io_lib_pretty:print(Term, fun pp/2).
%%%===================================================================
%%% Internal functions
%%%===================================================================
-spec pp(atom(), non_neg_integer()) -> [atom()] | no.
pp(state, 4) -> record_info(fields, state);
pp(_, _) -> no.
{application, p1_utils,
[
{description, "Erlang utility modules from ProcessOne"},
{vsn, "1.0.12"},
{vsn, "1.0.13"},
{modules, []},
{registered, []},
{applications, [
kernel,
stdlib
stdlib,
crypto
]},
{env, []},
{mod, {p1_utils, []}},
......
......@@ -32,7 +32,10 @@ stop(_State) ->
%%% API
%%%===================================================================
start() ->
application:start(p1_utils).
case application:ensure_all_started(p1_utils) of
{ok, _} -> ok;
Err -> Err
end.
stop() ->
application:stop(p1_utils).