Browse Source

feat(channel): add peerport field in ClientInfo

JimMoen 2 năm trước cách đây
mục cha
commit
68da627b4d

+ 2 - 1
apps/emqx/src/emqx_channel.erl

@@ -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,

+ 18 - 1
apps/emqx/test/emqx_channel_SUITE.erl

@@ -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,

+ 1 - 0
apps/emqx/test/emqx_proper_types.erl

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