feat(channel): add peerport field in ClientInfo

This commit is contained in:
JimMoen 2023-12-06 15:28:28 +08:00
parent b34e66bdf7
commit 68da627b4d
No known key found for this signature in database
GPG Key ID: 87A520B4F76BA86D
3 changed files with 21 additions and 2 deletions

View File

@ -213,7 +213,7 @@ caps(#channel{clientinfo = #{zone := Zone}}) ->
-spec init(emqx_types:conninfo(), opts()) -> channel().
init(
ConnInfo = #{
peername := {PeerHost, _Port},
peername := {PeerHost, PeerPort},
sockname := {_Host, SockPort}
},
#{
@ -237,6 +237,7 @@ init(
listener => ListenerId,
protocol => Protocol,
peerhost => PeerHost,
peerport => PeerPort,
sockport => SockPort,
clientid => undefined,
username => undefined,

View File

@ -72,6 +72,22 @@ t_chan_info(_) ->
conn_state := connected,
clientinfo := ClientInfo
} = emqx_channel:info(channel()),
?assertMatch(
#{
zone := default,
listener := {tcp, default},
protocol := mqtt,
peerhost := {127, 0, 0, 1},
peerport := 3456,
sockport := 1883,
clientid := <<"clientid">>,
username := <<"username">>,
is_superuser := false,
is_bridge := false,
mountpoint := undefined
},
ClientInfo
),
?assertEqual(clientinfo(), ClientInfo).
t_chan_caps(_) ->
@ -1063,7 +1079,8 @@ clientinfo(InitProps) ->
listener => {tcp, default},
protocol => mqtt,
peerhost => {127, 0, 0, 1},
sockport => 3456,
peerport => 3456,
sockport => 1883,
clientid => <<"clientid">>,
username => <<"username">>,
is_superuser => false,

View File

@ -108,6 +108,7 @@ clientinfo() ->
{zone, zone()},
{protocol, protocol()},
{peerhost, ip()},
{peerport, port()},
{sockport, port()},
{clientid, clientid()},
{username, username()},