From 9181c273ed5c7df2c6e43aba275da0e92ac8d16c Mon Sep 17 00:00:00 2001 From: J Phani Mahesh Date: Tue, 21 Jun 2016 00:35:45 +0530 Subject: [PATCH 1/2] enhance emqttd_client ratelimit handling This allows rate limits on a client to be queried and changed dynamically (possibly by plugins), by exposing additional apis. `set_rate_limit/2` expects a Ratelimit tuple module of the form `{module, record}` where module implements `check(NumBytes, RlTuple) -> {TimeToPause, NewRlTuple}` It is recommended that the rate limit module also implement `new` to allow creating new RateLimit records. See `esockd_ratelimit` for a reference implementation. --- src/emqttd_client.erl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/emqttd_client.erl b/src/emqttd_client.erl index f3169339a..9d29f4c68 100644 --- a/src/emqttd_client.erl +++ b/src/emqttd_client.erl @@ -26,7 +26,8 @@ -include("emqttd_internal.hrl"). %% 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. -export([subscribe/2, unsubscribe/2]). @@ -59,6 +60,12 @@ info(CPid) -> kick(CPid) -> 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) -> gen_server:cast(CPid, {subscribe, TopicTable}). @@ -120,6 +127,12 @@ handle_call(info, _From, State = #client_state{connection = Connection, handle_call(kick, _From, 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) -> ?UNEXPECTED_REQ(Req, State). From f273a8635e20e42f9fcd3fa6422d8ec78f46969a Mon Sep 17 00:00:00 2001 From: Lars-Magnus Skog Date: Sat, 25 Jun 2016 20:46:42 +0200 Subject: [PATCH 2/2] typos --- docs/source/config.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/config.rst b/docs/source/config.rst index bc5fdf71e..7ddab18d9 100644 --- a/docs/source/config.rst +++ b/docs/source/config.rst @@ -111,7 +111,7 @@ This is the main emqttd broker configuration file. File Syntax ----------- -The file users the standard Erlang config syntax, consists of a list of erlang applications and their environments. +The file use the standard Erlang config syntax and consists of a list of erlang applications and their environments. .. code-block:: erlang @@ -541,7 +541,7 @@ Plugins Folder TCP Listeners ------------- -Congfigure the TCP listeners for MQTT, MQTT(SSL) and HTTP Protocols. +Configure the TCP listeners for MQTT, MQTT(SSL) and HTTP Protocols. The most important parameter is 'max_clients' - max concurrent clients allowed.