chore(psk): improve logs for psk
This commit is contained in:
parent
84bb486c62
commit
f9aa345787
|
@ -26,13 +26,23 @@
|
||||||
|
|
||||||
-spec lookup(psk, psk_identity(), psk_user_state()) -> {ok, SharedSecret :: binary()} | error.
|
-spec lookup(psk, psk_identity(), psk_user_state()) -> {ok, SharedSecret :: binary()} | error.
|
||||||
lookup(psk, PSKIdentity, UserState) ->
|
lookup(psk, PSKIdentity, UserState) ->
|
||||||
try emqx_hooks:run_fold('tls_handshake.psk_lookup', [PSKIdentity], UserState) of
|
try emqx_hooks:run_fold('tls_handshake.psk_lookup', [PSKIdentity, UserState], normal) of
|
||||||
SharedSecret when is_binary(SharedSecret) -> {ok, SharedSecret};
|
{ok, SharedSecret} when is_binary(SharedSecret) ->
|
||||||
Error ->
|
{ok, SharedSecret};
|
||||||
?LOG(error, "Look PSK for PSKID ~p error: ~p", [PSKIdentity, Error]),
|
normal ->
|
||||||
|
?SLOG(info, #{msg => "psk_identity_not_found",
|
||||||
|
psk_identity => PSKIdentity}),
|
||||||
|
error;
|
||||||
|
{error, Reason} ->
|
||||||
|
?SLOG(warning, #{msg => "psk_identity_not_found",
|
||||||
|
psk_identity => PSKIdentity,
|
||||||
|
reason => Reason}),
|
||||||
error
|
error
|
||||||
catch
|
catch
|
||||||
Except:Error:Stacktrace ->
|
Class:Reason:Stacktrace ->
|
||||||
?LOG(error, "Lookup PSK failed, ~0p: ~0p", [{Except,Error}, Stacktrace]),
|
?SLOG(error, #{msg => "lookup_psk_failed",
|
||||||
|
class => Class,
|
||||||
|
reason => Reason,
|
||||||
|
stacktrace => Stacktrace}),
|
||||||
error
|
error
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -88,7 +88,7 @@ unload() ->
|
||||||
on_psk_lookup(PSKIdentity, _UserState) ->
|
on_psk_lookup(PSKIdentity, _UserState) ->
|
||||||
case mnesia:dirty_read(?TAB, PSKIdentity) of
|
case mnesia:dirty_read(?TAB, PSKIdentity) of
|
||||||
[#psk_entry{shared_secret = SharedSecret}] ->
|
[#psk_entry{shared_secret = SharedSecret}] ->
|
||||||
{stop, SharedSecret};
|
{stop, {ok, SharedSecret}};
|
||||||
_ ->
|
_ ->
|
||||||
ignore
|
ignore
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in New Issue