chore(gw): pass listener id into listener params
This commit is contained in:
parent
3e033b419c
commit
d8176f4378
|
@ -103,9 +103,15 @@ init(ConnInfo = #{peername := {PeerHost, _},
|
||||||
#{ctx := Ctx} = Config) ->
|
#{ctx := Ctx} = Config) ->
|
||||||
Peercert = maps:get(peercert, ConnInfo, undefined),
|
Peercert = maps:get(peercert, ConnInfo, undefined),
|
||||||
Mountpoint = maps:get(mountpoint, Config, <<>>),
|
Mountpoint = maps:get(mountpoint, Config, <<>>),
|
||||||
|
ListenerId = case maps:get(listener, Config, undefined) of
|
||||||
|
undefined -> undefined;
|
||||||
|
{GwName, Type, LisName} ->
|
||||||
|
emqx_gateway_utils:listener_id(GwName, Type, LisName)
|
||||||
|
end,
|
||||||
ClientInfo = set_peercert_infos(
|
ClientInfo = set_peercert_infos(
|
||||||
Peercert,
|
Peercert,
|
||||||
#{ zone => default
|
#{ zone => default
|
||||||
|
, listener => ListenerId
|
||||||
, protocol => 'coap'
|
, protocol => 'coap'
|
||||||
, peerhost => PeerHost
|
, peerhost => PeerHost
|
||||||
, sockport => SockPort
|
, sockport => SockPort
|
||||||
|
|
|
@ -100,8 +100,8 @@ start_listener(GwName, Ctx, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
|
|
||||||
start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) ->
|
start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) ->
|
||||||
Name = emqx_gateway_utils:listener_id(GwName, Type, LisName),
|
Name = emqx_gateway_utils:listener_id(GwName, Type, LisName),
|
||||||
NCfg = Cfg#{
|
NCfg = Cfg#{ctx => Ctx,
|
||||||
ctx => Ctx,
|
listener => {GwName, Type, LisName},
|
||||||
frame_mod => emqx_coap_frame,
|
frame_mod => emqx_coap_frame,
|
||||||
chann_mod => emqx_coap_channel
|
chann_mod => emqx_coap_channel
|
||||||
},
|
},
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
-type context() ::
|
-type context() ::
|
||||||
#{ %% Gateway Name
|
#{ %% Gateway Name
|
||||||
gwname := gateway_name()
|
gwname := gateway_name()
|
||||||
%% Autenticator
|
%% Authentication chains
|
||||||
, auth := emqx_authentication:chain_name() | undefined
|
, auth := [emqx_authentication:chain_name()] | undefined
|
||||||
%% The ConnectionManager PID
|
%% The ConnectionManager PID
|
||||||
, cm := pid()
|
, cm := pid()
|
||||||
}.
|
}.
|
||||||
|
|
|
@ -226,11 +226,7 @@ sock_opts(Name, Opts) ->
|
||||||
%% Envs
|
%% Envs
|
||||||
|
|
||||||
active_n(Options) ->
|
active_n(Options) ->
|
||||||
maps:get(
|
maps:get(active_n, Options, ?ACTIVE_N).
|
||||||
active_n,
|
|
||||||
maps:get(listener, Options, #{active_n => ?ACTIVE_N}),
|
|
||||||
?ACTIVE_N
|
|
||||||
).
|
|
||||||
|
|
||||||
-spec idle_timeout(map()) -> pos_integer().
|
-spec idle_timeout(map()) -> pos_integer().
|
||||||
idle_timeout(Options) ->
|
idle_timeout(Options) ->
|
||||||
|
|
|
@ -139,7 +139,12 @@ init(ConnInfo = #{socktype := Socktype,
|
||||||
GRpcChann = maps:get(handler, Options),
|
GRpcChann = maps:get(handler, Options),
|
||||||
PoolName = maps:get(pool_name, Options),
|
PoolName = maps:get(pool_name, Options),
|
||||||
NConnInfo = default_conninfo(ConnInfo),
|
NConnInfo = default_conninfo(ConnInfo),
|
||||||
ClientInfo = default_clientinfo(ConnInfo),
|
ListenerId = case maps:get(listener, Options, undefined) of
|
||||||
|
undefined -> undefined;
|
||||||
|
{GwName, Type, LisName} ->
|
||||||
|
emqx_gateway_utils:listener_id(GwName, Type, LisName)
|
||||||
|
end,
|
||||||
|
ClientInfo = maps:put(listener, ListenerId, default_clientinfo(ConnInfo)),
|
||||||
Channel = #channel{
|
Channel = #channel{
|
||||||
ctx = Ctx,
|
ctx = Ctx,
|
||||||
gcli = #{channel => GRpcChann, pool_name => PoolName},
|
gcli = #{channel => GRpcChann, pool_name => PoolName},
|
||||||
|
|
|
@ -156,6 +156,7 @@ start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) ->
|
||||||
Name = emqx_gateway_utils:listener_id(GwName, Type, LisName),
|
Name = emqx_gateway_utils:listener_id(GwName, Type, LisName),
|
||||||
NCfg = Cfg#{
|
NCfg = Cfg#{
|
||||||
ctx => Ctx,
|
ctx => Ctx,
|
||||||
|
listener => {GwName, Type, LisName},
|
||||||
frame_mod => emqx_exproto_frame,
|
frame_mod => emqx_exproto_frame,
|
||||||
chann_mod => emqx_exproto_channel
|
chann_mod => emqx_exproto_channel
|
||||||
},
|
},
|
||||||
|
|
|
@ -89,9 +89,15 @@ init(ConnInfo = #{peername := {PeerHost, _},
|
||||||
#{ctx := Ctx} = Config) ->
|
#{ctx := Ctx} = Config) ->
|
||||||
Peercert = maps:get(peercert, ConnInfo, undefined),
|
Peercert = maps:get(peercert, ConnInfo, undefined),
|
||||||
Mountpoint = maps:get(mountpoint, Config, undefined),
|
Mountpoint = maps:get(mountpoint, Config, undefined),
|
||||||
|
ListenerId = case maps:get(listener, Config, undefined) of
|
||||||
|
undefined -> undefined;
|
||||||
|
{GwName, Type, LisName} ->
|
||||||
|
emqx_gateway_utils:listener_id(GwName, Type, LisName)
|
||||||
|
end,
|
||||||
ClientInfo = set_peercert_infos(
|
ClientInfo = set_peercert_infos(
|
||||||
Peercert,
|
Peercert,
|
||||||
#{ zone => default
|
#{ zone => default
|
||||||
|
, listener => ListenerId
|
||||||
, protocol => lwm2m
|
, protocol => lwm2m
|
||||||
, peerhost => PeerHost
|
, peerhost => PeerHost
|
||||||
, sockport => SockPort
|
, sockport => SockPort
|
||||||
|
|
|
@ -102,6 +102,7 @@ start_listener(GwName, Ctx, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) ->
|
start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) ->
|
||||||
Name = emqx_gateway_utils:listener_id(GwName, Type, LisName),
|
Name = emqx_gateway_utils:listener_id(GwName, Type, LisName),
|
||||||
NCfg = Cfg#{ ctx => Ctx
|
NCfg = Cfg#{ ctx => Ctx
|
||||||
|
, listener => {GwName, Type, LisName}
|
||||||
, frame_mod => emqx_coap_frame
|
, frame_mod => emqx_coap_frame
|
||||||
, chann_mod => emqx_lwm2m_channel
|
, chann_mod => emqx_lwm2m_channel
|
||||||
},
|
},
|
||||||
|
|
|
@ -116,9 +116,15 @@ init(ConnInfo = #{peername := {PeerHost, _},
|
||||||
Registry = maps:get(registry, Option),
|
Registry = maps:get(registry, Option),
|
||||||
GwId = maps:get(gateway_id, Option),
|
GwId = maps:get(gateway_id, Option),
|
||||||
EnableQoS3 = maps:get(enable_qos3, Option, true),
|
EnableQoS3 = maps:get(enable_qos3, Option, true),
|
||||||
|
ListenerId = case maps:get(listener, Option, undefined) of
|
||||||
|
undefined -> undefined;
|
||||||
|
{GwName, Type, LisName} ->
|
||||||
|
emqx_gateway_utils:listener_id(GwName, Type, LisName)
|
||||||
|
end,
|
||||||
ClientInfo = set_peercert_infos(
|
ClientInfo = set_peercert_infos(
|
||||||
Peercert,
|
Peercert,
|
||||||
#{ zone => default
|
#{ zone => default
|
||||||
|
, listener => ListenerId
|
||||||
, protocol => 'mqtt-sn'
|
, protocol => 'mqtt-sn'
|
||||||
, peerhost => PeerHost
|
, peerhost => PeerHost
|
||||||
, sockport => SockPort
|
, sockport => SockPort
|
||||||
|
|
|
@ -121,6 +121,7 @@ start_listener(GwName, Ctx, Type, LisName, ListenOn, SocketOpts, Cfg) ->
|
||||||
Name = emqx_gateway_utils:listener_id(GwName, Type, LisName),
|
Name = emqx_gateway_utils:listener_id(GwName, Type, LisName),
|
||||||
NCfg = Cfg#{
|
NCfg = Cfg#{
|
||||||
ctx => Ctx,
|
ctx => Ctx,
|
||||||
|
listene => {GwName, Type, LisName},
|
||||||
frame_mod => emqx_sn_frame,
|
frame_mod => emqx_sn_frame,
|
||||||
chann_mod => emqx_sn_channel
|
chann_mod => emqx_sn_channel
|
||||||
},
|
},
|
||||||
|
@ -138,13 +139,13 @@ merge_default(Options) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
stop_listener(GwName, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
stop_listener(GwName, {Type, LisName, ListenOn, SocketOpts, Cfg}) ->
|
||||||
StopRet = stop_listener(GwName, LisName, Type, ListenOn, SocketOpts, Cfg),
|
StopRet = stop_listener(GwName, Type, LisName, ListenOn, SocketOpts, Cfg),
|
||||||
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
ListenOnStr = emqx_gateway_utils:format_listenon(ListenOn),
|
||||||
case StopRet of
|
case StopRet of
|
||||||
ok -> ?ULOG("Gateway ~s:~s:~s on ~s stopped.~n",
|
ok -> ?ULOG("Gateway ~s:~s:~s on ~s stopped.~n",
|
||||||
[GwName, Type, LisName, ListenOnStr]);
|
[GwName, Type, LisName, ListenOnStr]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?ELOG("Failed to stop gatewat ~s:~s:~s on ~s: ~0p~n",
|
?ELOG("Failed to stop gateway ~s:~s:~s on ~s: ~0p~n",
|
||||||
[GwName, Type, LisName, ListenOnStr, Reason])
|
[GwName, Type, LisName, ListenOnStr, Reason])
|
||||||
end,
|
end,
|
||||||
StopRet.
|
StopRet.
|
||||||
|
|
|
@ -33,7 +33,7 @@ gateway.lwm2m {
|
||||||
xml_dir = \"../../lib/emqx_gateway/src/lwm2m/lwm2m_xml\"
|
xml_dir = \"../../lib/emqx_gateway/src/lwm2m/lwm2m_xml\"
|
||||||
lifetime_min = 1s
|
lifetime_min = 1s
|
||||||
lifetime_max = 86400s
|
lifetime_max = 86400s
|
||||||
qmode_time_windonw = 22
|
qmode_time_window = 22
|
||||||
auto_observe = false
|
auto_observe = false
|
||||||
mountpoint = \"lwm2m/%u\"
|
mountpoint = \"lwm2m/%u\"
|
||||||
update_msg_publish_condition = contains_object_list
|
update_msg_publish_condition = contains_object_list
|
||||||
|
|
Loading…
Reference in New Issue