From 369c5e86c5487a87eb37a1fb69d8a894b1f2e440 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Wed, 17 Feb 2016 21:15:34 +0800 Subject: [PATCH] fix issue #438 - Bridge emqttd broker to another emqttd broker & emqttd to mosquitto bridge --- src/emqttd.app.src | 2 +- src/emqttd_parser.erl | 3 ++- test/emqttd_protocol_SUITE.erl | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/emqttd.app.src b/src/emqttd.app.src index b95538fb4..19e661993 100644 --- a/src/emqttd.app.src +++ b/src/emqttd.app.src @@ -1,7 +1,7 @@ {application, emqttd, [ {description, "Erlang MQTT Broker"}, - {vsn, "0.16.0"}, + {vsn, "0.17.0"}, {id, "emqttd"}, {modules, []}, {registered, []}, diff --git a/src/emqttd_parser.erl b/src/emqttd_parser.erl index 8423308a3..5788499b4 100644 --- a/src/emqttd_parser.erl +++ b/src/emqttd_parser.erl @@ -208,6 +208,7 @@ parse_msg(<>, _) -> bool(0) -> false; bool(1) -> true. +%% Fix mosquitto bridge: 0x83, 0x84 protocol_name_approved(Ver, Name) -> - lists:member({Ver, Name}, ?PROTOCOL_NAMES). + lists:member({Ver band 16#0F, Name}, ?PROTOCOL_NAMES). diff --git a/test/emqttd_protocol_SUITE.erl b/test/emqttd_protocol_SUITE.erl index 9b0311c2b..f5f63a185 100644 --- a/test/emqttd_protocol_SUITE.erl +++ b/test/emqttd_protocol_SUITE.erl @@ -33,6 +33,7 @@ all() -> groups() -> [{parser, [], [parse_connect, + parse_bridge, parse_publish, parse_puback, parse_subscribe, @@ -122,6 +123,27 @@ parse_connect(_) -> password = <<"public">>}}, <<>>} = Parser(ConnBinWithWill), ok. +parse_bridge(_) -> + Parser = emqttd_parser:new([]), + Data = <<16,86,0,6,77,81,73,115,100,112,131,44,0,60,0,19,67,95,48,48,58,48,67,58,50,57,58,50,66,58,55,55,58,53,50, + 0,48,36,83,89,83,47,98,114,111,107,101,114,47,99,111,110,110,101,99,116,105,111,110,47,67,95,48,48,58,48, + 67,58,50,57,58,50,66,58,55,55,58,53,50,47,115,116,97,116,101,0,1,48>>, + + %% CONNECT(Q0, R0, D0, ClientId=C_00:0C:29:2B:77:52, ProtoName=MQIsdp, ProtoVsn=131, CleanSess=false, KeepAlive=60, + %% Username=undefined, Password=undefined, Will(Q1, R1, Topic=$SYS/broker/connection/C_00:0C:29:2B:77:52/state, Msg=0)) + {ok, #mqtt_packet{variable = Variable}, <<>>} = Parser(Data), + ct:print("~p", [Variable]), + #mqtt_packet_connect{client_id = <<"C_00:0C:29:2B:77:52">>, + proto_ver = 16#83, + proto_name = <<"MQIsdp">>, + will_retain = true, + will_qos = 1, + will_flag = true, + clean_sess = false, + keep_alive = 60, + will_topic = <<"$SYS/broker/connection/C_00:0C:29:2B:77:52/state">>, + will_msg = <<"0">>} = Variable. + parse_publish(_) -> Parser = emqttd_parser:new([]), %%PUBLISH(Qos=1, Retain=false, Dup=false, TopicName=a/b/c, PacketId=1, Payload=<<"hahah">>)