Merge pull request #6077 from zmstone/sync-exproto-code

Sync exproto code from ee to ce
This commit is contained in:
Zaiming (Stone) Shi 2021-11-08 16:43:01 +01:00 committed by GitHub
commit 6b06142562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 121 additions and 117 deletions

View File

@ -1,5 +1,5 @@
{deps, {deps,
[{epgsql, {git, "https://github.com/epgsql/epgsql", {tag, "4.4.0"}}} [{epgsql, {git, "https://github.com/epgsql/epgsql.git", {tag, "4.4.0"}}}
]}. ]}.
{erl_opts, [warn_unused_vars, {erl_opts, [warn_unused_vars,

View File

@ -1,6 +1,6 @@
{application, emqx_exproto, {application, emqx_exproto,
[{description, "EMQ X Extension for Protocol"}, [{description, "EMQ X Extension for Protocol"},
{vsn, "4.3.2"}, %% strict semver {vsn, "4.3.4"}, %% 4.3.3 is used by ee
{modules, []}, {modules, []},
{registered, []}, {registered, []},
{mod, {emqx_exproto_app, []}}, {mod, {emqx_exproto_app, []}},

View File

@ -1,31 +1,26 @@
%% -*-: erlang -*- %% -*- mode: erlang -*-
{VSN, {VSN,
[ [{"4.3.3",
{"4.3.1", [ [{load_module,emqx_exproto_conn,brutal_purge,soft_purge,[]},
{load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []}, {load_module,emqx_exproto_channel,brutal_purge,soft_purge,[]}]},
{load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []}, {"4.3.2",
{load_module, emqx_exproto_channel, brutal_purge, soft_purge, []} [{load_module,emqx_exproto_conn,brutal_purge,soft_purge,[]},
]}, {load_module,emqx_exproto_channel,brutal_purge,soft_purge,[]}]},
{"4.3.0", [ {<<"4.3.[0-1]">>,
{load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []}, [{load_module,emqx_exproto_gsvr,brutal_purge,soft_purge,[]},
{load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []}, {load_module,emqx_exproto_gcli,brutal_purge,soft_purge,[]},
{load_module, emqx_exproto_conn, brutal_purge, soft_purge, []}, {load_module,emqx_exproto_conn,brutal_purge,soft_purge,[]},
{load_module, emqx_exproto_channel, brutal_purge, soft_purge, []} {load_module,emqx_exproto_channel,brutal_purge,soft_purge,[]}]},
]}, {<<".*">>,[]}],
{<<".*">>, []} [{"4.3.3",
], [{load_module,emqx_exproto_conn,brutal_purge,soft_purge,[]},
[ {load_module,emqx_exproto_channel,brutal_purge,soft_purge,[]}]},
{"4.3.1", [ {"4.3.2",
{load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []}, [{load_module,emqx_exproto_conn,brutal_purge,soft_purge,[]},
{load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []}, {load_module,emqx_exproto_channel,brutal_purge,soft_purge,[]}]},
{load_module, emqx_exproto_channel, brutal_purge, soft_purge, []} {<<"4.3.[0-1]">>,
]}, [{load_module,emqx_exproto_gsvr,brutal_purge,soft_purge,[]},
{"4.3.0", [ {load_module,emqx_exproto_gcli,brutal_purge,soft_purge,[]},
{load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []}, {load_module,emqx_exproto_conn,brutal_purge,soft_purge,[]},
{load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []}, {load_module,emqx_exproto_channel,brutal_purge,soft_purge,[]}]},
{load_module, emqx_exproto_conn, brutal_purge, soft_purge, []}, {<<".*">>,[]}]}.
{load_module, emqx_exproto_channel, brutal_purge, soft_purge, []}
]},
{<<".*">>, []}
]
}.

View File

@ -94,6 +94,9 @@
awaiting_rel_max awaiting_rel_max
]). ]).
-define(CHANMOCK(P), {exproto_anonymous_client, P}).
-define(CHAN_CONN_TAB, emqx_channel_conn).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Info, Attrs and Caps %% Info, Attrs and Caps
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -103,7 +106,7 @@
info(Channel) -> info(Channel) ->
maps:from_list(info(?INFO_KEYS, Channel)). maps:from_list(info(?INFO_KEYS, Channel)).
-spec(info(list(atom())|atom(), channel()) -> term()). -spec(info(list(atom()) | atom(), channel()) -> term()).
info(Keys, Channel) when is_list(Keys) -> info(Keys, Channel) when is_list(Keys) ->
[{Key, info(Key, Channel)} || Key <- Keys]; [{Key, info(Key, Channel)} || Key <- Keys];
info(conninfo, #channel{conninfo = ConnInfo}) -> info(conninfo, #channel{conninfo = ConnInfo}) ->
@ -155,13 +158,19 @@ init(ConnInfo = #{socktype := Socktype,
conn_state = connecting, conn_state = connecting,
timers = #{} timers = #{}
}, },
case emqx_hooks:run_fold('client.connect', [NConnInfo], #{}) of
Req = #{conninfo => {error, _Reason} ->
peercert(Peercert, throw(nopermission);
#{socktype => socktype(Socktype), _ ->
peername => address(Peername), ConnMod = maps:get(conn_mod, NConnInfo),
sockname => address(Sockname)})}, true = ets:insert(?CHAN_CONN_TAB, {?CHANMOCK(self()), ConnMod}),
try_dispatch(on_socket_created, wrap(Req), Channel). Req = #{conninfo =>
peercert(Peercert,
#{socktype => socktype(Socktype),
peername => address(Peername),
sockname => address(Sockname)})},
try_dispatch(on_socket_created, wrap(Req), Channel)
end.
%% @private %% @private
peercert(NoSsl, ConnInfo) when NoSsl == nossl; peercert(NoSsl, ConnInfo) when NoSsl == nossl;
@ -283,6 +292,7 @@ handle_call({auth, ClientInfo0, Password},
emqx_metrics:inc('client.auth.anonymous'), emqx_metrics:inc('client.auth.anonymous'),
NClientInfo = maps:merge(ClientInfo1, AuthResult), NClientInfo = maps:merge(ClientInfo1, AuthResult),
NChannel = Channel1#channel{clientinfo = NClientInfo}, NChannel = Channel1#channel{clientinfo = NClientInfo},
clean_anonymous_clients(),
case emqx_cm:open_session(true, NClientInfo, NConnInfo) of case emqx_cm:open_session(true, NClientInfo, NConnInfo) of
{ok, _Session} -> {ok, _Session} ->
?LOG(debug, "Client ~s (Username: '~s') authorized successfully!", ?LOG(debug, "Client ~s (Username: '~s') authorized successfully!",
@ -399,12 +409,16 @@ handle_info(Info, Channel) ->
-spec(terminate(any(), channel()) -> channel()). -spec(terminate(any(), channel()) -> channel()).
terminate(Reason, Channel) -> terminate(Reason, Channel) ->
clean_anonymous_clients(),
Req = #{reason => stringfy(Reason)}, Req = #{reason => stringfy(Reason)},
try_dispatch(on_socket_closed, wrap(Req), Channel). try_dispatch(on_socket_closed, wrap(Req), Channel).
is_anonymous(#{anonymous := true}) -> true; is_anonymous(#{anonymous := true}) -> true;
is_anonymous(_AuthResult) -> false. is_anonymous(_AuthResult) -> false.
clean_anonymous_clients() ->
ets:delete(?CHAN_CONN_TAB, ?CHANMOCK(self())).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Sub/UnSub %% Sub/UnSub
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -577,7 +591,6 @@ default_conninfo(ConnInfo) ->
ConnInfo#{clean_start => true, ConnInfo#{clean_start => true,
clientid => undefined, clientid => undefined,
username => undefined, username => undefined,
conn_mod => undefined,
conn_props => #{}, conn_props => #{},
connected => true, connected => true,
connected_at => erlang:system_time(millisecond), connected_at => erlang:system_time(millisecond),

View File

@ -115,7 +115,7 @@ start_link(esockd_transport, Sock, Options) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Get infos of the connection/channel. %% @doc Get infos of the connection/channel.
-spec(info(pid()|state()) -> emqx_types:infos()). -spec(info(pid() | state()) -> emqx_types:infos()).
info(CPid) when is_pid(CPid) -> info(CPid) when is_pid(CPid) ->
call(CPid, info); call(CPid, info);
info(State = #state{channel = Channel}) -> info(State = #state{channel = Channel}) ->
@ -137,7 +137,7 @@ info(sockstate, #state{sockstate = SockSt}) ->
info(active_n, #state{active_n = ActiveN}) -> info(active_n, #state{active_n = ActiveN}) ->
ActiveN. ActiveN.
-spec(stats(pid()|state()) -> emqx_types:stats()). -spec(stats(pid() | state()) -> emqx_types:stats()).
stats(CPid) when is_pid(CPid) -> stats(CPid) when is_pid(CPid) ->
call(CPid, stats); call(CPid, stats);
stats(#state{socket = Socket, stats(#state{socket = Socket,
@ -233,7 +233,11 @@ init(Parent, WrappedSock, Peername0, Options) ->
case esockd_wait(WrappedSock) of case esockd_wait(WrappedSock) of
{ok, NWrappedSock} -> {ok, NWrappedSock} ->
Peername = esockd_peername(NWrappedSock, Peername0), Peername = esockd_peername(NWrappedSock, Peername0),
run_loop(Parent, init_state(NWrappedSock, Peername, Options)); try
run_loop(Parent, init_state(NWrappedSock, Peername, Options))
catch
throw : nopermission -> erlang:exit(normal)
end;
{error, Reason} -> {error, Reason} ->
ok = esockd_close(WrappedSock), ok = esockd_close(WrappedSock),
exit_on_sock_error(Reason) exit_on_sock_error(Reason)
@ -337,7 +341,7 @@ cancel_stats_timer(State) -> State.
process_msg([], Parent, State) -> recvloop(Parent, State); process_msg([], Parent, State) -> recvloop(Parent, State);
process_msg([Msg|More], Parent, State) -> process_msg([Msg | More], Parent, State) ->
case catch handle_msg(Msg, State) of case catch handle_msg(Msg, State) of
ok -> ok ->
process_msg(More, Parent, State); process_msg(More, Parent, State);
@ -413,7 +417,7 @@ handle_msg({Passive, _Sock}, State)
handle_msg(Deliver = {deliver, _Topic, _Msg}, handle_msg(Deliver = {deliver, _Topic, _Msg},
State = #state{active_n = ActiveN}) -> State = #state{active_n = ActiveN}) ->
Delivers = [Deliver|emqx_misc:drain_deliver(ActiveN)], Delivers = [Deliver | emqx_misc:drain_deliver(ActiveN)],
with_channel(handle_deliver, [Delivers], State); with_channel(handle_deliver, [Delivers], State);
%% Something sent %% Something sent
@ -601,9 +605,9 @@ handle_outgoing(IoData, State = #state{socket = Socket}) ->
handle_info(activate_socket, State = #state{sockstate = OldSst}) -> handle_info(activate_socket, State = #state{sockstate = OldSst}) ->
case activate_socket(State) of case activate_socket(State) of
{ok, NState = #state{sockstate = NewSst}} -> {ok, NState = #state{sockstate = NewSst}} ->
if OldSst =/= NewSst -> case OldSst =/= NewSst of
{ok, {event, NewSst}, NState}; true -> {ok, {event, NewSst}, NState};
true -> {ok, NState} false -> {ok, NState}
end; end;
{error, Reason} -> {error, Reason} ->
handle_info({sock_error, Reason}, State) handle_info({sock_error, Reason}, State)

View File

@ -1,6 +1,6 @@
{application, emqx_rule_engine, {application, emqx_rule_engine,
[{description, "EMQ X Rule Engine"}, [{description, "EMQ X Rule Engine"},
{vsn, "4.3.5"}, % strict semver, bump manually! {vsn, "4.3.6"}, % strict semver, bump manually!
{modules, []}, {modules, []},
{registered, [emqx_rule_engine_sup, emqx_rule_registry]}, {registered, [emqx_rule_engine_sup, emqx_rule_registry]},
{applications, [kernel,stdlib,rulesql,getopt]}, {applications, [kernel,stdlib,rulesql,getopt]},

View File

@ -1,64 +1,52 @@
%% -*-: erlang -*- %% -*- mode: erlang -*-
{"4.3.5", {VSN,
[ {"4.3.0", [{"4.3.5",[{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
[ {load_module, emqx_rule_funcs, brutal_purge, soft_purge, []}
, {load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
, {load_module, emqx_rule_registry, brutal_purge, soft_purge, []}
, {apply, {emqx_stats, cancel_update, [rule_registery_stats]}}
, {load_module, emqx_rule_actions, brutal_purge, soft_purge, []}
]},
{"4.3.1",
[ {load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
, {load_module, emqx_rule_registry, brutal_purge, soft_purge, []}
, {apply, {emqx_stats, cancel_update, [rule_registery_stats]}}
, {load_module, emqx_rule_actions, brutal_purge, soft_purge, []}
]},
{"4.3.2",
[ {load_module, emqx_rule_registry, brutal_purge, soft_purge, []}
, {apply, {emqx_stats, cancel_update, [rule_registery_stats]}}
, {load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
, {load_module, emqx_rule_actions, brutal_purge, soft_purge, []}
]},
{"4.3.3",
[ {load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
, {load_module, emqx_rule_actions, brutal_purge, soft_purge, []}
, {load_module, emqx_rule_registry, brutal_purge, soft_purge, []}
]},
{"4.3.4",
[ {load_module, emqx_rule_engine, brutal_purge, soft_purge, []}
, {load_module, emqx_rule_registry, brutal_purge, soft_purge, []}
]},
{<<".*">>, []}
],
[
{"4.3.0", {"4.3.0",
[ {load_module, emqx_rule_funcs, brutal_purge, soft_purge, []} [{load_module,emqx_rule_funcs,brutal_purge,soft_purge,[]},
, {load_module, emqx_rule_engine, brutal_purge, soft_purge, []} {load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
, {load_module, emqx_rule_registry, brutal_purge, soft_purge, []} {load_module,emqx_rule_registry,brutal_purge,soft_purge,[]},
, {apply, {emqx_stats, cancel_update, [rule_registery_stats]}} {apply,{emqx_stats,cancel_update,[rule_registery_stats]}},
, {load_module, emqx_rule_actions, brutal_purge, soft_purge, []} {load_module,emqx_rule_actions,brutal_purge,soft_purge,[]}]},
]},
{"4.3.1", {"4.3.1",
[ {load_module, emqx_rule_engine, brutal_purge, soft_purge, []} [{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
, {load_module, emqx_rule_registry, brutal_purge, soft_purge, []} {load_module,emqx_rule_registry,brutal_purge,soft_purge,[]},
, {apply, {emqx_stats, cancel_update, [rule_registery_stats]}} {apply,{emqx_stats,cancel_update,[rule_registery_stats]}},
, {load_module, emqx_rule_actions, brutal_purge, soft_purge, []} {load_module,emqx_rule_actions,brutal_purge,soft_purge,[]}]},
]},
{"4.3.2", {"4.3.2",
[ {load_module, emqx_rule_registry, brutal_purge, soft_purge, []} [{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]},
, {apply, {emqx_stats, cancel_update, [rule_registery_stats]}} {apply,{emqx_stats,cancel_update,[rule_registery_stats]}},
, {load_module, emqx_rule_engine, brutal_purge, soft_purge, []} {load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
, {load_module, emqx_rule_actions, brutal_purge, soft_purge, []} {load_module,emqx_rule_actions,brutal_purge,soft_purge,[]}]},
]},
{"4.3.3", {"4.3.3",
[ {load_module, emqx_rule_engine, brutal_purge, soft_purge, []} [{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
, {load_module, emqx_rule_actions, brutal_purge, soft_purge, []} {load_module,emqx_rule_actions,brutal_purge,soft_purge,[]},
, {load_module, emqx_rule_registry, brutal_purge, soft_purge, []} {load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
]},
{"4.3.4", {"4.3.4",
[ {load_module, emqx_rule_engine, brutal_purge, soft_purge, []} [{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
, {load_module, emqx_rule_registry, brutal_purge, soft_purge, []} {load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
]}, {<<".*">>,[]}],
{<<".*">>, []} [{"4.3.5",[{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
] {"4.3.0",
}. [{load_module,emqx_rule_funcs,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]},
{apply,{emqx_stats,cancel_update,[rule_registery_stats]}},
{load_module,emqx_rule_actions,brutal_purge,soft_purge,[]}]},
{"4.3.1",
[{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]},
{apply,{emqx_stats,cancel_update,[rule_registery_stats]}},
{load_module,emqx_rule_actions,brutal_purge,soft_purge,[]}]},
{"4.3.2",
[{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]},
{apply,{emqx_stats,cancel_update,[rule_registery_stats]}},
{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_actions,brutal_purge,soft_purge,[]}]},
{"4.3.3",
[{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_actions,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
{"4.3.4",
[{load_module,emqx_rule_engine,brutal_purge,soft_purge,[]},
{load_module,emqx_rule_registry,brutal_purge,soft_purge,[]}]},
{<<".*">>,[]}]}.

View File

@ -1,6 +1,6 @@
{application, emqx_stomp, {application, emqx_stomp,
[{description, "EMQ X Stomp Protocol Plugin"}, [{description, "EMQ X Stomp Protocol Plugin"},
{vsn, "4.3.1"}, % strict semver, bump manually! {vsn, "4.3.2"}, % strict semver, bump manually!
{modules, []}, {modules, []},
{registered, [emqx_stomp_sup]}, {registered, [emqx_stomp_sup]},
{applications, [kernel,stdlib]}, {applications, [kernel,stdlib]},

View File

@ -1,8 +1,10 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{"4.3.1", {VSN,
[{"4.3.0", [{"4.3.1",[{load_module,emqx_stomp_connection,brutal_purge,soft_purge,[]}]},
{"4.3.0",
[{restart_application,emqx_stomp}]}, [{restart_application,emqx_stomp}]},
{<<".*">>,[]}], {<<".*">>,[]}],
[{"4.3.0", [{"4.3.1",[{load_module,emqx_stomp_connection,brutal_purge,soft_purge,[]}]},
[{restart_application,emqx_stomp}]}, {"4.3.0",
[{restart_application,emqx_stomp}]},
{<<".*">>,[]}]}. {<<".*">>,[]}]}.

View File

@ -91,6 +91,8 @@
-define(ENABLED(X), (X =/= undefined)). -define(ENABLED(X), (X =/= undefined)).
-elvis([{elvis_style, invalid_dynamic_call, #{ignore => [emqx_stomp_connection]}}]).
-dialyzer({nowarn_function, [ ensure_stats_timer/2 -dialyzer({nowarn_function, [ ensure_stats_timer/2
]}). ]}).
@ -101,7 +103,7 @@
start_link(Transport, Sock, ProtoEnv) -> start_link(Transport, Sock, ProtoEnv) ->
{ok, proc_lib:spawn_link(?MODULE, init, [[Transport, Sock, ProtoEnv]])}. {ok, proc_lib:spawn_link(?MODULE, init, [[Transport, Sock, ProtoEnv]])}.
-spec info(pid()|state()) -> emqx_types:infos(). -spec info(pid() | state()) -> emqx_types:infos().
info(CPid) when is_pid(CPid) -> info(CPid) when is_pid(CPid) ->
call(CPid, info); call(CPid, info);
info(State = #state{pstate = PState}) -> info(State = #state{pstate = PState}) ->
@ -123,7 +125,7 @@ info(sockstate, #state{sockstate = SockSt}) ->
info(active_n, #state{active_n = ActiveN}) -> info(active_n, #state{active_n = ActiveN}) ->
ActiveN. ActiveN.
-spec stats(pid()|state()) -> emqx_types:stats(). -spec stats(pid() | state()) -> emqx_types:stats().
stats(CPid) when is_pid(CPid) -> stats(CPid) when is_pid(CPid) ->
call(CPid, stats); call(CPid, stats);
stats(#state{transport = Transport, stats(#state{transport = Transport,

View File

@ -1,6 +1,6 @@
{application, emqx_dashboard, {application, emqx_dashboard,
[{description, "EMQ X Web Dashboard"}, [{description, "EMQ X Web Dashboard"},
{vsn, "4.3.5"}, % strict semver, bump manually! {vsn, "4.3.6"}, % strict semver, bump manually!
{modules, []}, {modules, []},
{registered, [emqx_dashboard_sup]}, {registered, [emqx_dashboard_sup]},
{applications, [kernel,stdlib,mnesia,minirest]}, {applications, [kernel,stdlib,mnesia,minirest]},