diff --git a/src/emqx_connection.erl b/src/emqx_connection.erl index da75d211e..225973d52 100644 --- a/src/emqx_connection.erl +++ b/src/emqx_connection.erl @@ -62,17 +62,14 @@ start_link(Transport, Socket, Options) -> info(CPid) when is_pid(CPid) -> call(CPid, info); -info(#state{transport = Transport, - socket = Socket, - peername = Peername, +info(#state{peername = Peername, sockname = Sockname, conn_state = ConnState, active_n = ActiveN, rate_limit = RateLimit, pub_limit = PubLimit, proto_state = ProtoState}) -> - ConnInfo = [{socktype, Transport:type(Socket)}, - {peername, Peername}, + ConnInfo = [{peername, Peername}, {sockname, Sockname}, {conn_state, ConnState}, {active_n, ActiveN}, @@ -137,7 +134,8 @@ init([Transport, RawSocket, Options]) -> ProtoState = emqx_protocol:init(#{peername => Peername, sockname => Sockname, peercert => Peercert, - sendfun => SendFun}, Options), + sendfun => SendFun, + socktype => Transport:type(Socket)}, Options), ParserState = emqx_protocol:parser(ProtoState), GcPolicy = emqx_zone:get_env(Zone, force_gc_policy, false), GcState = emqx_gc:init(GcPolicy), diff --git a/src/emqx_protocol.erl b/src/emqx_protocol.erl index c6260168c..85eaabc26 100644 --- a/src/emqx_protocol.erl +++ b/src/emqx_protocol.erl @@ -65,7 +65,8 @@ connected, connected_at, ignore_loop, - topic_alias_maximum + topic_alias_maximum, + socktype }). -opaque(state() :: #pstate{}). @@ -82,7 +83,7 @@ %%------------------------------------------------------------------------------ -spec(init(map(), list()) -> state()). -init(#{peername := Peername, peercert := Peercert, sendfun := SendFun}, Options) -> +init(#{peername := Peername, peercert := Peercert, sendfun := SendFun, socktype := SockType}, Options) -> Zone = proplists:get_value(zone, Options), #pstate{zone = Zone, sendfun = SendFun, @@ -107,7 +108,8 @@ init(#{peername := Peername, peercert := Peercert, sendfun := SendFun}, Options) send_stats = #{msg => 0, pkt => 0}, connected = false, ignore_loop = emqx_config:get_env(mqtt_ignore_loop_deliver, false), - topic_alias_maximum = #{to_client => 0, from_client => 0}}. + topic_alias_maximum = #{to_client => 0, from_client => 0}, + socktype = SockType}. init_username(Peercert, Options) -> case proplists:get_value(peer_cert_as_username, Options) of @@ -149,7 +151,8 @@ attrs(#pstate{zone = Zone, mountpoint = Mountpoint, is_super = IsSuper, is_bridge = IsBridge, - connected_at = ConnectedAt}) -> + connected_at = ConnectedAt, + socktype = SockType}) -> [{zone, Zone}, {client_id, ClientId}, {username, Username}, @@ -162,7 +165,8 @@ attrs(#pstate{zone = Zone, {mountpoint, Mountpoint}, {is_super, IsSuper}, {is_bridge, IsBridge}, - {connected_at, ConnectedAt}]. + {connected_at, ConnectedAt}, + {socktype, SockType}]. attr(max_inflight, #pstate{proto_ver = ?MQTT_PROTO_V5, conn_props = ConnProps}) -> get_property('Receive-Maximum', ConnProps, 65535); diff --git a/src/emqx_ws_connection.erl b/src/emqx_ws_connection.erl index fec52995f..2b50559cc 100644 --- a/src/emqx_ws_connection.erl +++ b/src/emqx_ws_connection.erl @@ -58,11 +58,10 @@ info(#state{peername = Peername, sockname = Sockname, proto_state = ProtoState}) -> ProtoInfo = emqx_protocol:info(ProtoState), - ConnInfo = [{socktype, websocket}, - {conn_state, running}, + ConnInfo = [{conn_state, running}, {peername, Peername}, {sockname, Sockname}], - lists:append([ConnInfo, ProtoInfo]). + lists:append([ConnInfo, ProtoInfo]). %% for dashboard attrs(WSPid) when is_pid(WSPid) -> @@ -127,7 +126,8 @@ websocket_init(#state{request = Req, options = Options}) -> ProtoState = emqx_protocol:init(#{peername => Peername, sockname => Sockname, peercert => Peercert, - sendfun => send_fun(self())}, Options), + sendfun => send_fun(self()), + socktype => websocket}, Options), ParserState = emqx_protocol:parser(ProtoState), Zone = proplists:get_value(zone, Options), EnableStats = emqx_zone:get_env(Zone, enable_stats, true),