Merge pull request #605 from apinf/dynamic_ratelimit
enhance emqttd_client ratelimit handling
This commit is contained in:
commit
1f40f6a629
|
@ -26,7 +26,8 @@
|
||||||
-include("emqttd_internal.hrl").
|
-include("emqttd_internal.hrl").
|
||||||
|
|
||||||
%% API Function Exports
|
%% API Function Exports
|
||||||
-export([start_link/2, session/1, info/1, kick/1]).
|
-export([start_link/2, session/1, info/1, kick/1,
|
||||||
|
set_rate_limit/2, get_rate_limit/1]).
|
||||||
|
|
||||||
%% SUB/UNSUB Asynchronously. Called by plugins.
|
%% SUB/UNSUB Asynchronously. Called by plugins.
|
||||||
-export([subscribe/2, unsubscribe/2]).
|
-export([subscribe/2, unsubscribe/2]).
|
||||||
|
@ -59,6 +60,12 @@ info(CPid) ->
|
||||||
kick(CPid) ->
|
kick(CPid) ->
|
||||||
gen_server:call(CPid, kick).
|
gen_server:call(CPid, kick).
|
||||||
|
|
||||||
|
set_rate_limit(Cpid, Rl) ->
|
||||||
|
gen_server:call(Cpid, {set_rate_limit, Rl}).
|
||||||
|
|
||||||
|
get_rate_limit(Cpid) ->
|
||||||
|
gen_server:call(Cpid, get_rate_limit).
|
||||||
|
|
||||||
subscribe(CPid, TopicTable) ->
|
subscribe(CPid, TopicTable) ->
|
||||||
gen_server:cast(CPid, {subscribe, TopicTable}).
|
gen_server:cast(CPid, {subscribe, TopicTable}).
|
||||||
|
|
||||||
|
@ -120,6 +127,12 @@ handle_call(info, _From, State = #client_state{connection = Connection,
|
||||||
handle_call(kick, _From, State) ->
|
handle_call(kick, _From, State) ->
|
||||||
{stop, {shutdown, kick}, ok, State};
|
{stop, {shutdown, kick}, ok, State};
|
||||||
|
|
||||||
|
handle_call({set_rate_limit, Rl}, _From, State) ->
|
||||||
|
{reply, ok, State#client_state{rate_limit = Rl}};
|
||||||
|
|
||||||
|
handle_call(get_rate_limit, _From, State = #client_state{rate_limit = Rl}) ->
|
||||||
|
{reply, Rl, State};
|
||||||
|
|
||||||
handle_call(Req, _From, State) ->
|
handle_call(Req, _From, State) ->
|
||||||
?UNEXPECTED_REQ(Req, State).
|
?UNEXPECTED_REQ(Req, State).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue