diff --git a/rebar.config b/rebar.config index 8f9c63b3b..e42f1e4ea 100644 --- a/rebar.config +++ b/rebar.config @@ -2,7 +2,7 @@ {deps, [{gproc, "0.8.0"}, - {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.2"}}}, + {jiffy, {git, "https://github.com/emqx/jiffy", {tag, "1.0.4"}}}, {cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.7.1"}}}, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.6.1"}}}, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.7.2"}}}, diff --git a/src/emqx_alarm_handler.erl b/src/emqx_alarm_handler.erl index b57a04380..990f8a76e 100644 --- a/src/emqx_alarm_handler.erl +++ b/src/emqx_alarm_handler.erl @@ -105,7 +105,7 @@ init(_) -> {ok, []}. handle_event({set_alarm, {AlarmId, AlarmDesc = #alarm{timestamp = undefined}}}, State) -> - handle_event({set_alarm, {AlarmId, AlarmDesc#alarm{timestamp = erlang:system_time(second)}}}, State); + handle_event({set_alarm, {AlarmId, AlarmDesc#alarm{timestamp = erlang:system_time(millisecond)}}}, State); handle_event({set_alarm, Alarm = {AlarmId, AlarmDesc}}, State) -> ?LOG(warning, "New Alarm: ~p, Alarm Info: ~p", [AlarmId, AlarmDesc]), case encode_alarm(Alarm) of @@ -199,5 +199,5 @@ clear_alarm_(Id) -> set_alarm_history(Id, Desc) -> His = #alarm_history{id = Id, desc = Desc, - clear_at = erlang:system_time(second)}, + clear_at = erlang:system_time(millisecond)}, mnesia:dirty_write(?ALARM_HISTORY_TAB, His). diff --git a/src/emqx_channel.erl b/src/emqx_channel.erl index 4490ca40f..9a3339c65 100644 --- a/src/emqx_channel.erl +++ b/src/emqx_channel.erl @@ -1138,21 +1138,18 @@ do_enhanced_auth(undefined, _AuthData, Channel) -> do_enhanced_auth(_AuthMethod, undefined, Channel) -> {error, emqx_reason_codes:connack_error(not_authorized), Channel}; do_enhanced_auth(AuthMethod, AuthData, Channel = #channel{auth_cache = Cache}) -> - case do_auth_check(AuthMethod, AuthData, Cache) of - ok -> {ok, #{}, Channel#channel{auth_cache = #{}}}; + case run_hooks('client.enhanced_authenticate',[AuthMethod, AuthData, Cache]) of + {ok, <<>>} -> {ok, #{}, Channel#channel{auth_cache = #{}}}; {ok, NAuthData} -> NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData}, {ok, NProperties, Channel#channel{auth_cache = #{}}}; {continue, NAuthData, NCache} -> NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData}, {continue, NProperties, Channel#channel{auth_cache = NCache}}; - {error, _Reason} -> + _ -> {error, emqx_reason_codes:connack_error(not_authorized), Channel} end. -do_auth_check(_AuthMethod, _AuthData, _AuthDataCache) -> - {error, not_authorized}. - %%-------------------------------------------------------------------- %% Process Topic Alias @@ -1345,7 +1342,7 @@ enrich_assigned_clientid(AckProps, #channel{conninfo = ConnInfo, ensure_connected(Channel = #channel{conninfo = ConnInfo, clientinfo = ClientInfo}) -> - NConnInfo = ConnInfo#{connected_at => erlang:system_time(second)}, + NConnInfo = ConnInfo#{connected_at => erlang:system_time(millisecond)}, ok = run_hooks('client.connected', [ClientInfo, NConnInfo]), Channel#channel{conninfo = NConnInfo, conn_state = connected @@ -1422,7 +1419,7 @@ parse_topic_filters(TopicFilters) -> ensure_disconnected(Reason, Channel = #channel{conninfo = ConnInfo, clientinfo = ClientInfo}) -> - NConnInfo = ConnInfo#{disconnected_at => erlang:system_time(second)}, + NConnInfo = ConnInfo#{disconnected_at => erlang:system_time(millisecond)}, ok = run_hooks('client.disconnected', [ClientInfo, Reason, NConnInfo]), Channel#channel{conninfo = NConnInfo, conn_state = disconnected}. diff --git a/src/emqx_ctl.erl b/src/emqx_ctl.erl index d2cbf9b04..4b6c375d1 100644 --- a/src/emqx_ctl.erl +++ b/src/emqx_ctl.erl @@ -126,7 +126,7 @@ get_commands() -> help() -> print("Usage: ~s~n", [?MODULE]), - [begin print("~80..-s~n", [""]), Mod:Cmd(usage) end + [begin print("~110..-s~n", [""]), Mod:Cmd(usage) end || {_, {Mod, Cmd}, _} <- ets:tab2list(?CMD_TAB)]. -spec(print(io:format()) -> ok). @@ -165,7 +165,7 @@ format_usage(CmdParams, Desc) -> CmdLines = split_cmd(CmdParams), DescLines = split_cmd(Desc), lists:foldl(fun({CmdStr, DescStr}, Usage) -> - Usage ++ format("~-48s# ~s~n", [CmdStr, DescStr]) + Usage ++ format("~-70s# ~s~n", [CmdStr, DescStr]) end, "", zip_cmd(CmdLines, DescLines)). %%-------------------------------------------------------------------- diff --git a/src/emqx_metrics.erl b/src/emqx_metrics.erl index 47c2e9a6a..4009ca67c 100644 --- a/src/emqx_metrics.erl +++ b/src/emqx_metrics.erl @@ -520,11 +520,12 @@ reserved_idx('client.connect') -> 200; reserved_idx('client.connack') -> 201; reserved_idx('client.connected') -> 202; reserved_idx('client.authenticate') -> 203; -reserved_idx('client.auth.anonymous') -> 204; -reserved_idx('client.check_acl') -> 205; -reserved_idx('client.subscribe') -> 206; -reserved_idx('client.unsubscribe') -> 207; -reserved_idx('client.disconnected') -> 208; +reserved_idx('client.enhanced_authenticate') -> 204; +reserved_idx('client.auth.anonymous') -> 205; +reserved_idx('client.check_acl') -> 206; +reserved_idx('client.subscribe') -> 207; +reserved_idx('client.unsubscribe') -> 208; +reserved_idx('client.disconnected') -> 209; reserved_idx('session.created') -> 220; reserved_idx('session.resumed') -> 221; diff --git a/src/emqx_mod_topic_metrics.erl b/src/emqx_mod_topic_metrics.erl index 5deb42b92..4e9b44fa8 100644 --- a/src/emqx_mod_topic_metrics.erl +++ b/src/emqx_mod_topic_metrics.erl @@ -49,6 +49,7 @@ , unregister/1 , unregister_all/0 , is_registered/1 + , all_registered_topics/0 ]). %% gen_server callbacks @@ -194,6 +195,9 @@ unregister_all() -> is_registered(Topic) -> ets:member(?TAB, Topic). +all_registered_topics() -> + [Topic || {Topic, _CRef} <- ets:tab2list(?TAB)]. + %%-------------------------------------------------------------------- %% gen_server callbacks %%-------------------------------------------------------------------- diff --git a/src/emqx_modules.erl b/src/emqx_modules.erl index 948359aa7..75ac35ce5 100644 --- a/src/emqx_modules.erl +++ b/src/emqx_modules.erl @@ -26,6 +26,7 @@ , unload/0 , unload/1 , reload/1 + , find_module/1 , load_module/2 ]). diff --git a/src/emqx_session.erl b/src/emqx_session.erl index 2b03b7868..684589ff2 100644 --- a/src/emqx_session.erl +++ b/src/emqx_session.erl @@ -168,7 +168,7 @@ init(#{zone := Zone}, #{receive_maximum := MaxInflight}) -> awaiting_rel = #{}, max_awaiting_rel = get_env(Zone, max_awaiting_rel, 100), await_rel_timeout = timer:seconds(get_env(Zone, await_rel_timeout, 300)), - created_at = erlang:system_time(second) + created_at = erlang:system_time(millisecond) }. %% @private init mq diff --git a/test/emqx_channel_SUITE.erl b/test/emqx_channel_SUITE.erl index a94095b2b..0bddae09d 100644 --- a/test/emqx_channel_SUITE.erl +++ b/test/emqx_channel_SUITE.erl @@ -120,7 +120,7 @@ t_handle_in_connect_auth_failed(_) -> clean_start = true, keepalive = 30, properties = #{ - 'Authentication-Method' => "failed_auth_method", + 'Authentication-Method' => <<"failed_auth_method">>, 'Authentication-Data' => <<"failed_auth_data">> }, clientid = <<"clientid">>, @@ -131,7 +131,7 @@ t_handle_in_connect_auth_failed(_) -> t_handle_in_continue_auth(_) -> Properties = #{ - 'Authentication-Method' => "failed_auth_method", + 'Authentication-Method' => <<"failed_auth_method">>, 'Authentication-Data' => <<"failed_auth_data">> }, {shutdown, bad_authentication_method, ?CONNACK_PACKET(?RC_BAD_AUTHENTICATION_METHOD), _} = @@ -141,7 +141,7 @@ t_handle_in_continue_auth(_) -> t_handle_in_re_auth(_) -> Properties = #{ - 'Authentication-Method' => "failed_auth_method", + 'Authentication-Method' => <<"failed_auth_method">>, 'Authentication-Data' => <<"failed_auth_data">> }, {ok, [{outgoing, ?DISCONNECT_PACKET(?RC_BAD_AUTHENTICATION_METHOD)}, {close, bad_authentication_method}], _} = diff --git a/test/emqx_ctl_SUITE.erl b/test/emqx_ctl_SUITE.erl index 9a310de5c..a73d011bd 100644 --- a/test/emqx_ctl_SUITE.erl +++ b/test/emqx_ctl_SUITE.erl @@ -76,24 +76,9 @@ t_print(_) -> t_usage(_) -> CmdParams1 = "emqx_cmd_1 param1 param2", CmdDescr1 = "emqx_cmd_1 is a test command means nothing", - Output1 = "emqx_cmd_1 param1 param2 # emqx_cmd_1 is a test command means nothing\n", % - usage/1,2 should return ok ok = emqx_ctl:usage([{CmdParams1, CmdDescr1}, {CmdParams1, CmdDescr1}]), - ok = emqx_ctl:usage(CmdParams1, CmdDescr1), - - % - check the output of the usage - mock_print(), - ?assertEqual(Output1, emqx_ctl:usage(CmdParams1, CmdDescr1)), - ?assertEqual([Output1, Output1], emqx_ctl:usage([{CmdParams1, CmdDescr1}, {CmdParams1, CmdDescr1}])), - - % - for the commands or descriptions have multi-lines - CmdParams2 = "emqx_cmd_2 param1 param2", - CmdDescr2 = "emqx_cmd_2 is a test command\nmeans nothing", - Output2 = "emqx_cmd_2 param1 param2 # emqx_cmd_2 is a test command\n" - " ""# means nothing\n", - ?assertEqual(Output2, emqx_ctl:usage(CmdParams2, CmdDescr2)), - ?assertEqual([Output2, Output2], emqx_ctl:usage([{CmdParams2, CmdDescr2}, {CmdParams2, CmdDescr2}])), - unmock_print(). + ok = emqx_ctl:usage(CmdParams1, CmdDescr1). t_unexpected(_) -> with_ctl_server(