Merge remote-tracking branch 'origin/develop'

This commit is contained in:
zhanghongtong 2019-06-02 04:06:51 +08:00
commit f0a434739d
4 changed files with 20 additions and 22 deletions

View File

@ -5,7 +5,7 @@
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.3.1"}}} , {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.3.1"}}}
, {ekka, {git, "https://github.com/emqx/ekka", {tag, "v0.5.5"}}} , {ekka, {git, "https://github.com/emqx/ekka", {tag, "v0.5.5"}}}
, {replayq, {git, "https://github.com/emqx/replayq", {tag, "v0.1.1"}}} , {replayq, {git, "https://github.com/emqx/replayq", {tag, "v0.1.1"}}}
, {esockd, {git, "https://github.com/emqx/esockd", {tag, "v5.4.4"}}} , {esockd, "5.5.0"}
, {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.0.0"}}} , {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.0.0"}}}
]}. ]}.

View File

@ -89,16 +89,18 @@ ranch_opts(Options) ->
NumAcceptors = proplists:get_value(acceptors, Options, 4), NumAcceptors = proplists:get_value(acceptors, Options, 4),
MaxConnections = proplists:get_value(max_connections, Options, 1024), MaxConnections = proplists:get_value(max_connections, Options, 1024),
TcpOptions = proplists:get_value(tcp_options, Options, []), TcpOptions = proplists:get_value(tcp_options, Options, []),
RanchOpts = [{num_acceptors, NumAcceptors}, {max_connections, MaxConnections} | TcpOptions], RanchOpts = #{num_acceptors => NumAcceptors,
max_connections => MaxConnections,
socket_opts => TcpOptions},
case proplists:get_value(ssl_options, Options) of case proplists:get_value(ssl_options, Options) of
undefined -> RanchOpts; undefined -> RanchOpts;
SslOptions -> RanchOpts ++ SslOptions SslOptions -> RanchOpts#{socket_opts => TcpOptions ++ SslOptions}
end. end.
with_port(Port, Opts) when is_integer(Port) -> with_port(Port, Opts = #{socket_opts := SocketOption}) when is_integer(Port) ->
[{port, Port}|Opts]; Opts#{socket_opts => [{port, Port}| SocketOption]};
with_port({Addr, Port}, Opts) -> with_port({Addr, Port}, Opts = #{socket_opts := SocketOption}) ->
[{ip, Addr}, {port, Port}|Opts]. Opts#{socket_opts => [{ip, Addr}, {port, Port}| SocketOption]}.
%% @doc Restart all listeners %% @doc Restart all listeners
-spec(restart() -> ok). -spec(restart() -> ok).

View File

@ -1016,7 +1016,7 @@ do_check_banned(_EnableBan = true, Credentials) ->
true -> {error, ?RC_BANNED}; true -> {error, ?RC_BANNED};
false -> ok false -> ok
end; end;
do_check_banned(_EnableBan, Credentials) -> ok. do_check_banned(_EnableBan, _Credentials) -> ok.
do_acl_check(_EnableAcl = true, Action, Credentials, Topic) -> do_acl_check(_EnableAcl = true, Action, Credentials, Topic) ->
AllowTerm = ok, AllowTerm = ok,

View File

@ -41,8 +41,12 @@
, code_change/3 , code_change/3
]). ]).
%% dummy state
-record(state, {}).
-define(TAB, ?MODULE). -define(TAB, ?MODULE).
-define(SERVER, ?MODULE). -define(SERVER, ?MODULE).
-define(KEY(Zone, Key), {?MODULE, Zone, Key}).
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
%% APIs %% APIs
@ -62,7 +66,7 @@ get_env(Zone, Key) ->
get_env(undefined, Key, Def) -> get_env(undefined, Key, Def) ->
emqx_config:get_env(Key, Def); emqx_config:get_env(Key, Def);
get_env(Zone, Key, Def) -> get_env(Zone, Key, Def) ->
try persistent_term:get({Zone, Key}) try persistent_term:get(?KEY(Zone, Key))
catch error:badarg -> catch error:badarg ->
emqx_config:get_env(Key, Def) emqx_config:get_env(Key, Def)
end. end.
@ -84,7 +88,8 @@ stop() ->
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
init([]) -> init([]) ->
{ok, element(2, handle_info(reload, #{timer => undefined}))}. _ = do_reload(),
{ok, #state{}}.
handle_call(force_reload, _From, State) -> handle_call(force_reload, _From, State) ->
_ = do_reload(), _ = do_reload(),
@ -95,17 +100,13 @@ handle_call(Req, _From, State) ->
{reply, ignored, State}. {reply, ignored, State}.
handle_cast({set_env, Zone, Key, Val}, State) -> handle_cast({set_env, Zone, Key, Val}, State) ->
persistent_term:put({Zone, Key}, Val), ok = persistent_term:put(?KEY(Zone, Key), Val),
{noreply, State}; {noreply, State};
handle_cast(Msg, State) -> handle_cast(Msg, State) ->
?LOG(error, "[Zone] Unexpected cast: ~p", [Msg]), ?LOG(error, "[Zone] Unexpected cast: ~p", [Msg]),
{noreply, State}. {noreply, State}.
handle_info(reload, State) ->
_ = do_reload(),
{noreply, ensure_reload_timer(State#{timer := undefined}), hibernate};
handle_info(Info, State) -> handle_info(Info, State) ->
?LOG(error, "[Zone] Unexpected info: ~p", [Info]), ?LOG(error, "[Zone] Unexpected info: ~p", [Info]),
{noreply, State}. {noreply, State}.
@ -121,11 +122,6 @@ code_change(_OldVsn, State, _Extra) ->
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
do_reload() -> do_reload() ->
[[persistent_term:put({Zone, Key}, Val) [ persistent_term:put(?KEY(Zone, Key), Val)
|| {Key, Val} <- Opts] || {Zone, Opts} <- emqx_config:get_env(zones, []), {Key, Val} <- Opts ].
|| {Zone, Opts} <- emqx_config:get_env(zones, [])].
ensure_reload_timer(State = #{timer := undefined}) ->
State#{timer := erlang:send_after(timer:minutes(5), self(), reload)};
ensure_reload_timer(State) ->
State.