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,
[{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,

View File

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

View File

@ -1,12 +1,11 @@
%% -*-: erlang -*-
{VSN,
[
{"4.3.1", [
{load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []},
{load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []},
{"4.3.2", [
{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_gcli, brutal_purge, soft_purge, []},
{load_module, emqx_exproto_conn, brutal_purge, soft_purge, []},
@ -15,12 +14,11 @@
{<<".*">>, []}
],
[
{"4.3.1", [
{load_module, emqx_exproto_gsvr, brutal_purge, soft_purge, []},
{load_module, emqx_exproto_gcli, brutal_purge, soft_purge, []},
{"4.3.2", [
{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_gcli, brutal_purge, soft_purge, []},
{load_module, emqx_exproto_conn, brutal_purge, soft_purge, []},

View File

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

View File

@ -233,7 +233,11 @@ init(Parent, WrappedSock, Peername0, Options) ->
case esockd_wait(WrappedSock) of
{ok, NWrappedSock} ->
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} ->
ok = esockd_close(WrappedSock),
exit_on_sock_error(Reason)

View File

@ -91,6 +91,8 @@
-define(ENABLED(X), (X =/= undefined)).
-elvis([{elvis_style, invalid_dynamic_call, #{ignore => [emqx_stomp_connection]}}]).
-dialyzer({nowarn_function, [ ensure_stats_timer/2
]}).