feat(exhook): provide the `peerport` field

- both in `ConnInfo` and `ClientInfo`
This commit is contained in:
JimMoen 2023-12-06 10:54:55 +08:00
parent 68da627b4d
commit 46201a8796
No known key found for this signature in database
GPG Key ID: 87A520B4F76BA86D
4 changed files with 15 additions and 1 deletions

View File

@ -368,6 +368,8 @@ message ConnInfo {
string proto_ver = 7;
uint32 keepalive = 8;
uint32 peerport = 9;
}
message ClientInfo {
@ -397,6 +399,8 @@ message ClientInfo {
// subject of client TLS cert
string dn = 12;
uint32 peerport = 13;
}
message Message {

View File

@ -294,7 +294,7 @@ conninfo(
ConnInfo =
#{
clientid := ClientId,
peername := {Peerhost, _},
peername := {Peerhost, PeerPort},
sockname := {_, SockPort}
}
) ->
@ -307,6 +307,7 @@ conninfo(
clientid => ClientId,
username => maybe(Username),
peerhost => ntoa(Peerhost),
peerport => PeerPort,
sockport => SockPort,
proto_name => ProtoName,
proto_ver => stringfy(ProtoVer),
@ -319,6 +320,7 @@ clientinfo(
clientid := ClientId,
username := Username,
peerhost := PeerHost,
peerport := PeerPort,
sockport := SockPort,
protocol := Protocol,
mountpoint := Mountpoiont
@ -330,6 +332,7 @@ clientinfo(
username => maybe(Username),
password => maybe(maps:get(password, ClientInfo, undefined)),
peerhost => ntoa(PeerHost),
peerport => PeerPort,
sockport => SockPort,
protocol => stringfy(Protocol),
mountpoint => maybe(Mountpoiont),

View File

@ -118,6 +118,7 @@ t_access_failed_if_no_server_running(Config) ->
clientid => <<"user-id-1">>,
username => <<"usera">>,
peerhost => {127, 0, 0, 1},
peerport => 3456,
sockport => 1883,
protocol => mqtt,
mountpoint => undefined
@ -301,6 +302,7 @@ t_simulated_handler(_) ->
clientid => <<"user-id-1">>,
username => <<"usera">>,
peerhost => {127, 0, 0, 1},
peerport => 3456,
sockport => 1883,
protocol => mqtt,
mountpoint => undefined

View File

@ -496,6 +496,9 @@ nodestr() ->
peerhost(#{peername := {Host, _}}) ->
ntoa(Host).
peerport(#{peername := {_, Port}}) ->
Port.
sockport(#{sockname := {_, Port}}) ->
Port.
@ -564,6 +567,7 @@ from_conninfo(ConnInfo) ->
clientid => maps:get(clientid, ConnInfo),
username => maybe(maps:get(username, ConnInfo, <<>>)),
peerhost => peerhost(ConnInfo),
peerport => peerport(ConnInfo),
sockport => sockport(ConnInfo),
proto_name => maps:get(proto_name, ConnInfo),
proto_ver => stringfy(maps:get(proto_ver, ConnInfo)),
@ -577,6 +581,7 @@ from_clientinfo(ClientInfo) ->
username => maybe(maps:get(username, ClientInfo, <<>>)),
password => maybe(maps:get(password, ClientInfo, <<>>)),
peerhost => ntoa(maps:get(peerhost, ClientInfo)),
peerport => maps:get(peerport, ClientInfo),
sockport => maps:get(sockport, ClientInfo),
protocol => stringfy(maps:get(protocol, ClientInfo)),
mountpoint => maybe(maps:get(mountpoint, ClientInfo, <<>>)),