Просмотр исходного кода

Merge pull request #12525 from zmstone/0216-docs-add-ref-to-bridge_mode

docs: add a reference to the origin of is_bridge and bridge_mode
Zaiming (Stone) Shi 2 лет назад
Родитель
Сommit
9ffda0187f

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

@@ -1551,6 +1551,8 @@ set_username(
 set_username(_ConnPkt, ClientInfo) ->
     {ok, ClientInfo}.
 
+%% The `is_bridge` bit flag in CONNECT packet (parsed as `bridge_mode`)
+%% is invented by mosquitto, named 'try_private': https://mosquitto.org/man/mosquitto-conf-5.html
 set_bridge_mode(#mqtt_packet_connect{is_bridge = true}, ClientInfo) ->
     {ok, ClientInfo#{is_bridge => true}};
 set_bridge_mode(_ConnPkt, _ClientInfo) ->

+ 12 - 2
apps/emqx/src/emqx_config_handler.erl

@@ -675,9 +675,19 @@ merge_to_override_config(RawConf, Opts) ->
     maps:merge(UpgradedOldConf, RawConf).
 
 upgrade_conf(Conf) ->
+    ConfigLoader = emqx_app:get_config_loader(),
+    %% ensure module loaded
+    _ = ConfigLoader:module_info(),
+    case erlang:function_exported(ConfigLoader, schema_module, 0) of
+        true ->
+            try_upgrade_conf(apply(ConfigLoader, schema_module, []), Conf);
+        false ->
+            %% this happens during emqx app standalone test
+            Conf
+    end.
+
+try_upgrade_conf(SchemaModule, Conf) ->
     try
-        ConfLoader = emqx_app:get_config_loader(),
-        SchemaModule = apply(ConfLoader, schema_module, []),
         apply(SchemaModule, upgrade_raw_conf, [Conf])
     catch
         ErrorType:Reason:Stack ->

+ 2 - 0
apps/emqx/src/emqx_frame.erl

@@ -301,6 +301,7 @@ parse_connect2(
         proto_name = ProtoName,
         proto_ver = ProtoVer,
         %% For bridge mode, non-standard implementation
+        %% Invented by mosquitto, named 'try_private': https://mosquitto.org/man/mosquitto-conf-5.html
         is_bridge = (BridgeTag =:= 8),
         clean_start = bool(CleanStart),
         will_flag = bool(WillFlag),
@@ -772,6 +773,7 @@ serialize_variable(
         proto_name = ProtoName,
         proto_ver = ProtoVer,
         %% For bridge mode, non-standard implementation
+        %% Invented by mosquitto, named 'try_private': https://mosquitto.org/man/mosquitto-conf-5.html
         is_bridge = IsBridge,
         clean_start = CleanStart,
         will_flag = WillFlag,