Merge remote-tracking branch 'origin/develop'
This commit is contained in:
commit
f3bcec7e31
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{deps,
|
{deps,
|
||||||
[{gproc, "0.8.0"},
|
[{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"}}},
|
{cowboy, {git, "https://github.com/emqx/cowboy", {tag, "2.7.1"}}},
|
||||||
{esockd, {git, "https://github.com/emqx/esockd", {tag, "5.6.1"}}},
|
{esockd, {git, "https://github.com/emqx/esockd", {tag, "5.6.1"}}},
|
||||||
{ekka, {git, "https://github.com/emqx/ekka", {tag, "0.7.2"}}},
|
{ekka, {git, "https://github.com/emqx/ekka", {tag, "0.7.2"}}},
|
||||||
|
|
|
@ -105,7 +105,7 @@ init(_) ->
|
||||||
{ok, []}.
|
{ok, []}.
|
||||||
|
|
||||||
handle_event({set_alarm, {AlarmId, AlarmDesc = #alarm{timestamp = undefined}}}, State) ->
|
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) ->
|
handle_event({set_alarm, Alarm = {AlarmId, AlarmDesc}}, State) ->
|
||||||
?LOG(warning, "New Alarm: ~p, Alarm Info: ~p", [AlarmId, AlarmDesc]),
|
?LOG(warning, "New Alarm: ~p, Alarm Info: ~p", [AlarmId, AlarmDesc]),
|
||||||
case encode_alarm(Alarm) of
|
case encode_alarm(Alarm) of
|
||||||
|
@ -199,5 +199,5 @@ clear_alarm_(Id) ->
|
||||||
set_alarm_history(Id, Desc) ->
|
set_alarm_history(Id, Desc) ->
|
||||||
His = #alarm_history{id = Id,
|
His = #alarm_history{id = Id,
|
||||||
desc = Desc,
|
desc = Desc,
|
||||||
clear_at = erlang:system_time(second)},
|
clear_at = erlang:system_time(millisecond)},
|
||||||
mnesia:dirty_write(?ALARM_HISTORY_TAB, His).
|
mnesia:dirty_write(?ALARM_HISTORY_TAB, His).
|
||||||
|
|
|
@ -1138,21 +1138,18 @@ do_enhanced_auth(undefined, _AuthData, Channel) ->
|
||||||
do_enhanced_auth(_AuthMethod, undefined, Channel) ->
|
do_enhanced_auth(_AuthMethod, undefined, Channel) ->
|
||||||
{error, emqx_reason_codes:connack_error(not_authorized), Channel};
|
{error, emqx_reason_codes:connack_error(not_authorized), Channel};
|
||||||
do_enhanced_auth(AuthMethod, AuthData, Channel = #channel{auth_cache = Cache}) ->
|
do_enhanced_auth(AuthMethod, AuthData, Channel = #channel{auth_cache = Cache}) ->
|
||||||
case do_auth_check(AuthMethod, AuthData, Cache) of
|
case run_hooks('client.enhanced_authenticate',[AuthMethod, AuthData, Cache]) of
|
||||||
ok -> {ok, #{}, Channel#channel{auth_cache = #{}}};
|
{ok, <<>>} -> {ok, #{}, Channel#channel{auth_cache = #{}}};
|
||||||
{ok, NAuthData} ->
|
{ok, NAuthData} ->
|
||||||
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
|
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
|
||||||
{ok, NProperties, Channel#channel{auth_cache = #{}}};
|
{ok, NProperties, Channel#channel{auth_cache = #{}}};
|
||||||
{continue, NAuthData, NCache} ->
|
{continue, NAuthData, NCache} ->
|
||||||
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
|
NProperties = #{'Authentication-Method' => AuthMethod, 'Authentication-Data' => NAuthData},
|
||||||
{continue, NProperties, Channel#channel{auth_cache = NCache}};
|
{continue, NProperties, Channel#channel{auth_cache = NCache}};
|
||||||
{error, _Reason} ->
|
_ ->
|
||||||
{error, emqx_reason_codes:connack_error(not_authorized), Channel}
|
{error, emqx_reason_codes:connack_error(not_authorized), Channel}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_auth_check(_AuthMethod, _AuthData, _AuthDataCache) ->
|
|
||||||
{error, not_authorized}.
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Process Topic Alias
|
%% Process Topic Alias
|
||||||
|
|
||||||
|
@ -1345,7 +1342,7 @@ enrich_assigned_clientid(AckProps, #channel{conninfo = ConnInfo,
|
||||||
|
|
||||||
ensure_connected(Channel = #channel{conninfo = ConnInfo,
|
ensure_connected(Channel = #channel{conninfo = ConnInfo,
|
||||||
clientinfo = ClientInfo}) ->
|
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]),
|
ok = run_hooks('client.connected', [ClientInfo, NConnInfo]),
|
||||||
Channel#channel{conninfo = NConnInfo,
|
Channel#channel{conninfo = NConnInfo,
|
||||||
conn_state = connected
|
conn_state = connected
|
||||||
|
@ -1422,7 +1419,7 @@ parse_topic_filters(TopicFilters) ->
|
||||||
|
|
||||||
ensure_disconnected(Reason, Channel = #channel{conninfo = ConnInfo,
|
ensure_disconnected(Reason, Channel = #channel{conninfo = ConnInfo,
|
||||||
clientinfo = ClientInfo}) ->
|
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]),
|
ok = run_hooks('client.disconnected', [ClientInfo, Reason, NConnInfo]),
|
||||||
Channel#channel{conninfo = NConnInfo, conn_state = disconnected}.
|
Channel#channel{conninfo = NConnInfo, conn_state = disconnected}.
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ get_commands() ->
|
||||||
|
|
||||||
help() ->
|
help() ->
|
||||||
print("Usage: ~s~n", [?MODULE]),
|
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)].
|
|| {_, {Mod, Cmd}, _} <- ets:tab2list(?CMD_TAB)].
|
||||||
|
|
||||||
-spec(print(io:format()) -> ok).
|
-spec(print(io:format()) -> ok).
|
||||||
|
@ -165,7 +165,7 @@ format_usage(CmdParams, Desc) ->
|
||||||
CmdLines = split_cmd(CmdParams),
|
CmdLines = split_cmd(CmdParams),
|
||||||
DescLines = split_cmd(Desc),
|
DescLines = split_cmd(Desc),
|
||||||
lists:foldl(fun({CmdStr, DescStr}, Usage) ->
|
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)).
|
end, "", zip_cmd(CmdLines, DescLines)).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -520,11 +520,12 @@ reserved_idx('client.connect') -> 200;
|
||||||
reserved_idx('client.connack') -> 201;
|
reserved_idx('client.connack') -> 201;
|
||||||
reserved_idx('client.connected') -> 202;
|
reserved_idx('client.connected') -> 202;
|
||||||
reserved_idx('client.authenticate') -> 203;
|
reserved_idx('client.authenticate') -> 203;
|
||||||
reserved_idx('client.auth.anonymous') -> 204;
|
reserved_idx('client.enhanced_authenticate') -> 204;
|
||||||
reserved_idx('client.check_acl') -> 205;
|
reserved_idx('client.auth.anonymous') -> 205;
|
||||||
reserved_idx('client.subscribe') -> 206;
|
reserved_idx('client.check_acl') -> 206;
|
||||||
reserved_idx('client.unsubscribe') -> 207;
|
reserved_idx('client.subscribe') -> 207;
|
||||||
reserved_idx('client.disconnected') -> 208;
|
reserved_idx('client.unsubscribe') -> 208;
|
||||||
|
reserved_idx('client.disconnected') -> 209;
|
||||||
|
|
||||||
reserved_idx('session.created') -> 220;
|
reserved_idx('session.created') -> 220;
|
||||||
reserved_idx('session.resumed') -> 221;
|
reserved_idx('session.resumed') -> 221;
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
, unregister/1
|
, unregister/1
|
||||||
, unregister_all/0
|
, unregister_all/0
|
||||||
, is_registered/1
|
, is_registered/1
|
||||||
|
, all_registered_topics/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
|
@ -194,6 +195,9 @@ unregister_all() ->
|
||||||
is_registered(Topic) ->
|
is_registered(Topic) ->
|
||||||
ets:member(?TAB, Topic).
|
ets:member(?TAB, Topic).
|
||||||
|
|
||||||
|
all_registered_topics() ->
|
||||||
|
[Topic || {Topic, _CRef} <- ets:tab2list(?TAB)].
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
, unload/0
|
, unload/0
|
||||||
, unload/1
|
, unload/1
|
||||||
, reload/1
|
, reload/1
|
||||||
|
, find_module/1
|
||||||
, load_module/2
|
, load_module/2
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ init(#{zone := Zone}, #{receive_maximum := MaxInflight}) ->
|
||||||
awaiting_rel = #{},
|
awaiting_rel = #{},
|
||||||
max_awaiting_rel = get_env(Zone, max_awaiting_rel, 100),
|
max_awaiting_rel = get_env(Zone, max_awaiting_rel, 100),
|
||||||
await_rel_timeout = timer:seconds(get_env(Zone, await_rel_timeout, 300)),
|
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
|
%% @private init mq
|
||||||
|
|
|
@ -120,7 +120,7 @@ t_handle_in_connect_auth_failed(_) ->
|
||||||
clean_start = true,
|
clean_start = true,
|
||||||
keepalive = 30,
|
keepalive = 30,
|
||||||
properties = #{
|
properties = #{
|
||||||
'Authentication-Method' => "failed_auth_method",
|
'Authentication-Method' => <<"failed_auth_method">>,
|
||||||
'Authentication-Data' => <<"failed_auth_data">>
|
'Authentication-Data' => <<"failed_auth_data">>
|
||||||
},
|
},
|
||||||
clientid = <<"clientid">>,
|
clientid = <<"clientid">>,
|
||||||
|
@ -131,7 +131,7 @@ t_handle_in_connect_auth_failed(_) ->
|
||||||
|
|
||||||
t_handle_in_continue_auth(_) ->
|
t_handle_in_continue_auth(_) ->
|
||||||
Properties = #{
|
Properties = #{
|
||||||
'Authentication-Method' => "failed_auth_method",
|
'Authentication-Method' => <<"failed_auth_method">>,
|
||||||
'Authentication-Data' => <<"failed_auth_data">>
|
'Authentication-Data' => <<"failed_auth_data">>
|
||||||
},
|
},
|
||||||
{shutdown, bad_authentication_method, ?CONNACK_PACKET(?RC_BAD_AUTHENTICATION_METHOD), _} =
|
{shutdown, bad_authentication_method, ?CONNACK_PACKET(?RC_BAD_AUTHENTICATION_METHOD), _} =
|
||||||
|
@ -141,7 +141,7 @@ t_handle_in_continue_auth(_) ->
|
||||||
|
|
||||||
t_handle_in_re_auth(_) ->
|
t_handle_in_re_auth(_) ->
|
||||||
Properties = #{
|
Properties = #{
|
||||||
'Authentication-Method' => "failed_auth_method",
|
'Authentication-Method' => <<"failed_auth_method">>,
|
||||||
'Authentication-Data' => <<"failed_auth_data">>
|
'Authentication-Data' => <<"failed_auth_data">>
|
||||||
},
|
},
|
||||||
{ok, [{outgoing, ?DISCONNECT_PACKET(?RC_BAD_AUTHENTICATION_METHOD)}, {close, bad_authentication_method}], _} =
|
{ok, [{outgoing, ?DISCONNECT_PACKET(?RC_BAD_AUTHENTICATION_METHOD)}, {close, bad_authentication_method}], _} =
|
||||||
|
|
|
@ -76,24 +76,9 @@ t_print(_) ->
|
||||||
t_usage(_) ->
|
t_usage(_) ->
|
||||||
CmdParams1 = "emqx_cmd_1 param1 param2",
|
CmdParams1 = "emqx_cmd_1 param1 param2",
|
||||||
CmdDescr1 = "emqx_cmd_1 is a test command means nothing",
|
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
|
% - usage/1,2 should return ok
|
||||||
ok = emqx_ctl:usage([{CmdParams1, CmdDescr1}, {CmdParams1, CmdDescr1}]),
|
ok = emqx_ctl:usage([{CmdParams1, CmdDescr1}, {CmdParams1, CmdDescr1}]),
|
||||||
ok = emqx_ctl:usage(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().
|
|
||||||
|
|
||||||
t_unexpected(_) ->
|
t_unexpected(_) ->
|
||||||
with_ctl_server(
|
with_ctl_server(
|
||||||
|
|
Loading…
Reference in New Issue