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

View File

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

View File

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