chore: sync ce code added only to ee back to ce

This commit is contained in:
Zaiming Shi 2021-11-05 13:05:34 +01:00
parent 1e47dbf14b
commit 325c5e5a97
6 changed files with 39 additions and 21 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.3"}, %% strict semver
{modules, []}, {modules, []},
{registered, []}, {registered, []},
{mod, {emqx_exproto_app, []}}, {mod, {emqx_exproto_app, []}},

View File

@ -1,12 +1,11 @@
%% -*-: erlang -*- %% -*-: erlang -*-
{VSN, {VSN,
[ [
{"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", [ {<<"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, []},
@ -15,12 +14,11 @@
{<<".*">>, []} {<<".*">>, []}
], ],
[ [
{"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", [ {<<"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, []},

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
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -155,13 +158,20 @@ init(ConnInfo = #{socktype := Socktype,
conn_state = connecting, conn_state = connecting,
timers = #{} timers = #{}
}, },
%% Check license limitation
Req = #{conninfo => case emqx_hooks:run_fold('client.connect', [NConnInfo], #{}) of
peercert(Peercert, {error, _Reason} ->
#{socktype => socktype(Socktype), throw(nopermission);
peername => address(Peername), _ ->
sockname => address(Sockname)})}, ConnMod = maps:get(conn_mod, NConnInfo),
try_dispatch(on_socket_created, wrap(Req), Channel). true = ets:insert(?CHAN_CONN_TAB, {?CHANMOCK(self()), ConnMod}),
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 +293,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 +410,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 +592,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

@ -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)

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,