Skip to content

Commit

Permalink
DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
RoadRunnr committed May 13, 2024
1 parent 6812ab5 commit fc4b045
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/ergw_aaa_diameter_srv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ code_change(_OldVsn, State, _Extra) ->

%% https://medium.com/smyte/rate-limiter-df3408325846
update_bucket(#peer{last_ts = undefined, rate = Rate} = Peer) ->
ct:pal("PEER Init~n"),
Peer#peer{
last_ts = erlang:monotonic_time(microsecond),
interval = floor(1_000_000 / Rate),
Expand All @@ -299,20 +298,20 @@ update_bucket(#peer{last_ts = Last, interval = Interval,
rate = Rate, tokens = Tokens} = Peer) ->
Now = erlang:monotonic_time(microsecond),
Refill = floor((Now - Last) / Interval),
if Refill /= 0 ->
ct:pal("Now: ~s, Last: ~s, Refill: ~p, NewTS : ~s",
[
calendar:system_time_to_rfc3339(
Now + erlang:time_offset(microsecond), [{unit, microsecond}]),
calendar:system_time_to_rfc3339(
Last + erlang:time_offset(microsecond), [{unit, microsecond}]),
Refill,
calendar:system_time_to_rfc3339(
min(Now, Last + Refill * Interval) + erlang:time_offset(microsecond), [{unit, microsecond}])
]);
true ->
ok
end,
%% if Refill /= 0 ->
%% ct:pal("Now: ~s, Last: ~s, Refill: ~p, NewTS : ~s",
%% [
%% calendar:system_time_to_rfc3339(
%% Now + erlang:time_offset(microsecond), [{unit, microsecond}]),
%% calendar:system_time_to_rfc3339(
%% Last + erlang:time_offset(microsecond), [{unit, microsecond}]),
%% Refill,
%% calendar:system_time_to_rfc3339(
%% min(Now, Last + Refill * Interval) + erlang:time_offset(microsecond), [{unit, microsecond}])
%% ]);
%% true ->
%% ok
%% end,

Peer#peer{
last_ts = min(Now, Last + Refill * Interval),
Expand Down

0 comments on commit fc4b045

Please sign in to comment.