-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from inside shapers to opuntia
- Loading branch information
1 parent
f44b5b0
commit 60c0de8
Showing
18 changed files
with
90 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-module(mongoose_shapers). | ||
|
||
-export([child_spec/0, get_shaper_rate/1, wait/5, reset_all_shapers/1]). | ||
-ignore_xref([reset_all_shapers/1]). | ||
|
||
-spec child_spec() -> supervisor:child_spec(). | ||
child_spec() -> | ||
WPoolOpts = [{workers, 10}, {worker, {opuntia_srv, []}}], | ||
{mongoose_shapers, | ||
{wpool, start_pool, [mongoose_shapers, WPoolOpts]}, | ||
permanent, infinity, supervisor, [opuntia_srv]}. | ||
|
||
-spec get_shaper_rate(atom()) -> number(). | ||
get_shaper_rate(Name) -> | ||
case mongoose_config:lookup_opt([shaper, Name]) of | ||
{ok, #{max_rate := MaxRatePerSecond}} -> | ||
MaxRatePerSecond / 1000; | ||
{error, not_found} -> 0 | ||
end. | ||
|
||
%% @doc Shapes the caller from executing the action. | ||
-spec wait(HostType :: mongooseim:host_type(), | ||
Domain :: jid:server(), | ||
Action :: atom(), | ||
FromJID :: jid:jid() | global, | ||
Size :: integer()) -> continue | {error, max_delay_reached}. | ||
wait(HostType, Domain, Action, FromJID, Size) -> | ||
Config = get_shaper_rate(get_shaper_name(HostType, Domain, Action, FromJID)), | ||
Worker = wpool_pool:hash_worker(mongoose_shapers, FromJID), | ||
opuntia_srv:wait(Worker, FromJID, Size, Config). | ||
|
||
%% @doc Ask all shaper servers to forget current shapers and read settings again | ||
reset_all_shapers(_HostType) -> | ||
[ opuntia_srv:reset_shapers(ProcName) | ||
|| ProcName <- wpool:get_workers(mongoose_shapers)]. | ||
|
||
-spec get_shaper_name(HostType :: mongooseim:host_type(), | ||
Domain :: global | jid:server(), | ||
Action :: atom(), | ||
FromJID :: jid:jid()) -> allow | none. | ||
get_shaper_name(HostType, Domain, Action, FromJID) -> | ||
case acl:match_rule(HostType, Domain, Action, FromJID) of | ||
deny -> default_shaper(); | ||
Value -> Value | ||
end. | ||
|
||
default_shaper() -> | ||
none. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.