From 9d5223dd1ace63ea2b07dfddc7db7d99a5e846d5 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 8 Jun 2015 23:31:20 +0800 Subject: [PATCH 1/8] contributors --- README.md | 12 +++++------ apps/emqttd/src/emqttd_session.erl | 32 +++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index edfba9761..6ab9acaba 100644 --- a/README.md +++ b/README.md @@ -102,12 +102,12 @@ The MIT License (MIT) ## Contributors -[@hejin1026](https://github.com/hejin1026) -[@desoulter](https://github.com/desoulter) -[@turtleDeng](https://github.com/turtleDeng) -[@Hades32](https://github.com/Hades32) -[@huangdan](https://github.com/huangdan) -[@callbay](https://github.com/callbay) +* [@hejin1026](https://github.com/hejin1026) +* [@desoulter](https://github.com/desoulter) +* [@turtleDeng](https://github.com/turtleDeng) +* [@Hades32](https://github.com/Hades32) +* [@huangdan](https://github.com/huangdan) +* [@callbay](https://github.com/callbay) ## Author diff --git a/apps/emqttd/src/emqttd_session.erl b/apps/emqttd/src/emqttd_session.erl index 15a465d4d..a629e3b08 100644 --- a/apps/emqttd/src/emqttd_session.erl +++ b/apps/emqttd/src/emqttd_session.erl @@ -173,17 +173,31 @@ puback(SessPid, {?PUBCOMP, PacketId}) when is_pid(SessPid) -> %%------------------------------------------------------------------------------ -spec subscribe(session(), [{binary(), mqtt_qos()}]) -> {ok, session(), [mqtt_qos()]}. subscribe(SessState = #session_state{clientid = ClientId, submap = SubMap}, Topics) -> - Resubs = [Topic || {Name, _Qos} = Topic <- Topics, maps:is_key(Name, SubMap)], - case Resubs of - [] -> ok; - _ -> lager:warning("~s resubscribe ~p", [ClientId, Resubs]) - end, - SubMap1 = lists:foldl(fun({Name, Qos}, Acc) -> maps:put(Name, Qos, Acc) end, SubMap, Topics), + + %% subscribe first and don't care if the subscriptions have been existed {ok, GrantedQos} = emqttd_pubsub:subscribe(Topics), + lager:info([{client, ClientId}], "Client ~s subscribe ~p. Granted QoS: ~p", - [ClientId, Topics, GrantedQos]), - %%TODO: should be gen_event and notification... - [emqttd_msg_store:redeliver(Name, self()) || {Name, _} <- Topics], + [ClientId, Topics, GrantedQos]), + + + %% : 3.8.4 + %% Where the Topic Filter is not identical to any existing Subscription’s filter, + %% a new Subscription is created and all matching retained messages are sent. + lists:foreach(fun({Name, _Qos}) -> + case maps:is_key(Name, SubMap) of + true -> + lager:warning("~s resubscribe ~p", [ClientId, Name]); + false -> + %%TODO: this is not right, rewrite later... + emqttd_msg_store:redeliver(Name, self()) + end + end, Topics), + + SubMap1 = lists:foldl(fun({Name, Qos}, Acc) -> + maps:put(Name, Qos, Acc) + end, SubMap, Topics), + {ok, SessState#session_state{submap = SubMap1}, GrantedQos}; subscribe(SessPid, Topics) when is_pid(SessPid) -> From bfc83b8c4554c7d71ab62cd9d13e2236f697b091 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 8 Jun 2015 23:31:33 +0800 Subject: [PATCH 2/8] 0.8.4 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be3055b2d..cb598e803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ emqttd ChangeLog ================== +0.8.4-beta (2015-06-08) +------------------------- + +Bugfix: issue #165 - duplicated message when publish 'retained' message to persistent client + + 0.8.3-beta (2015-06-05) ------------------------- From f0583a1c29a91edf949dc75c58b46263d9b23079 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Mon, 8 Jun 2015 23:34:09 +0800 Subject: [PATCH 3/8] 0.8.4 --- CONTRIBUTORS | 10 ++++++++++ apps/emqtt/src/emqtt.app.src | 2 +- apps/emqttd/src/emqttd.app.src | 2 +- rel/reltool.config | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 CONTRIBUTORS diff --git a/CONTRIBUTORS b/CONTRIBUTORS new file mode 100644 index 000000000..8f1f4c344 --- /dev/null +++ b/CONTRIBUTORS @@ -0,0 +1,10 @@ + +# CONTRIBUTORS + +* [@callbay](https://github.com/callbay) +* [@hejin1026](https://github.com/hejin1026) +* [@desoulter](https://github.com/desoulter) +* [@turtleDeng](https://github.com/turtleDeng) +* [@Hades32](https://github.com/Hades32) +* [@huangdan](https://github.com/huangdan) + diff --git a/apps/emqtt/src/emqtt.app.src b/apps/emqtt/src/emqtt.app.src index c444276fa..06751dfac 100644 --- a/apps/emqtt/src/emqtt.app.src +++ b/apps/emqtt/src/emqtt.app.src @@ -1,7 +1,7 @@ {application, emqtt, [ {description, "Erlang MQTT Common Library"}, - {vsn, "0.8.3"}, + {vsn, "0.8.4"}, {modules, []}, {registered, []}, {applications, [ diff --git a/apps/emqttd/src/emqttd.app.src b/apps/emqttd/src/emqttd.app.src index 5c3347f27..a4e0d72e7 100644 --- a/apps/emqttd/src/emqttd.app.src +++ b/apps/emqttd/src/emqttd.app.src @@ -1,7 +1,7 @@ {application, emqttd, [ {description, "Erlang MQTT Broker"}, - {vsn, "0.8.3"}, + {vsn, "0.8.4"}, {modules, []}, {registered, []}, {applications, [kernel, diff --git a/rel/reltool.config b/rel/reltool.config index f26654f74..6e5d1dde7 100644 --- a/rel/reltool.config +++ b/rel/reltool.config @@ -4,7 +4,7 @@ {lib_dirs, ["../apps", "../deps", "../plugins"]}, {erts, [{mod_cond, derived}, {app_file, strip}]}, {app_file, strip}, - {rel, "emqttd", "0.8.3", + {rel, "emqttd", "0.8.4", [ kernel, stdlib, From 29540946194fe7bf32edf74b82a656ddac1e5d45 Mon Sep 17 00:00:00 2001 From: Feng Date: Tue, 9 Jun 2015 11:50:53 +0800 Subject: [PATCH 4/8] fix issue #53 - client will receive duplicate messages when overlapping subscription --- apps/emqttd/src/emqttd_pubsub.erl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/apps/emqttd/src/emqttd_pubsub.erl b/apps/emqttd/src/emqttd_pubsub.erl index b52037d29..b89355c76 100644 --- a/apps/emqttd/src/emqttd_pubsub.erl +++ b/apps/emqttd/src/emqttd_pubsub.erl @@ -24,6 +24,7 @@ %%% %%% @end %%%----------------------------------------------------------------------------- + -module(emqttd_pubsub). -author("Feng Lee "). @@ -217,6 +218,7 @@ match(Topic) when is_binary(Topic) -> init([Id, _Opts]) -> process_flag(min_heap_size, 1024*1024), gproc_pool:connect_worker(pubsub, {?MODULE, Id}), + %%TODO: gb_trees to replace maps? {ok, #state{id = Id, submap = maps:new()}}. handle_call({subscribe, SubPid, Topics}, _From, State) -> @@ -384,9 +386,24 @@ add_topic(TopicR = #mqtt_topic{topic = Topic}) -> end end. -add_subscriber({TopicR, Subscriber}) when is_record(TopicR, mqtt_topic) -> +%% Fix issue #53 - Remove Overlapping Subscriptions +add_subscriber({TopicR, Subscriber = #mqtt_subscriber{topic = Topic, qos = Qos, pid = SubPid}}) + when is_record(TopicR, mqtt_topic) -> case add_topic(TopicR) of ok -> + OverlapSubs = [Sub || Sub = #mqtt_subscriber{topic = SubTopic, qos = SubQos} + <- mnesia:index_read(subscriber, SubPid, #mqtt_subscriber.pid), + SubTopic =:= Topic, SubQos =/= Qos], + + %% remove overlapping subscribers + if + length(OverlapSubs) =:= 0 -> ok; + true -> + lager:warning("Remove overlapping subscribers: ~p", [OverlapSubs]), + [mnesia:delete_object(subscriber, OverlapSub, write) || OverlapSub <- OverlapSubs] + end, + + %% insert subscriber mnesia:write(subscriber, Subscriber, write); Error -> Error From 553fb394f37ce68437a2d8c977bdff73c30659f4 Mon Sep 17 00:00:00 2001 From: Feng Date: Tue, 9 Jun 2015 11:57:44 +0800 Subject: [PATCH 5/8] vsn 'git' --- apps/emqtt/src/emqtt.app.src | 2 +- apps/emqttd/src/emqttd.app.src | 2 +- rel/reltool.config | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/emqtt/src/emqtt.app.src b/apps/emqtt/src/emqtt.app.src index 06751dfac..c84d855f6 100644 --- a/apps/emqtt/src/emqtt.app.src +++ b/apps/emqtt/src/emqtt.app.src @@ -1,7 +1,7 @@ {application, emqtt, [ {description, "Erlang MQTT Common Library"}, - {vsn, "0.8.4"}, + {vsn, git}, {modules, []}, {registered, []}, {applications, [ diff --git a/apps/emqttd/src/emqttd.app.src b/apps/emqttd/src/emqttd.app.src index a4e0d72e7..024fcdac9 100644 --- a/apps/emqttd/src/emqttd.app.src +++ b/apps/emqttd/src/emqttd.app.src @@ -1,7 +1,7 @@ {application, emqttd, [ {description, "Erlang MQTT Broker"}, - {vsn, "0.8.4"}, + {vsn, git}, {modules, []}, {registered, []}, {applications, [kernel, diff --git a/rel/reltool.config b/rel/reltool.config index 6e5d1dde7..2dbb76ea5 100644 --- a/rel/reltool.config +++ b/rel/reltool.config @@ -4,7 +4,7 @@ {lib_dirs, ["../apps", "../deps", "../plugins"]}, {erts, [{mod_cond, derived}, {app_file, strip}]}, {app_file, strip}, - {rel, "emqttd", "0.8.4", + {rel, "emqttd", git, [ kernel, stdlib, From d5e35b2423bd0d60f9de3141b93bbd05379a9376 Mon Sep 17 00:00:00 2001 From: Feng Date: Tue, 9 Jun 2015 11:58:37 +0800 Subject: [PATCH 6/8] 0.8.5 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb598e803..6943606bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ emqttd ChangeLog ================== +0.8.5-beta (2015-06-12) +------------------------- + +Bugfix: issue #53 - client will receive duplicate messages when overlapping subscription + + 0.8.4-beta (2015-06-08) ------------------------- From 9bc84d2b53f3b2267fd80ff520f2e6a723506fdb Mon Sep 17 00:00:00 2001 From: Feng Date: Tue, 9 Jun 2015 12:01:14 +0800 Subject: [PATCH 7/8] rm .swp --- doc/.retain.md.swp | Bin 12288 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 doc/.retain.md.swp diff --git a/doc/.retain.md.swp b/doc/.retain.md.swp deleted file mode 100644 index 648c9731dc496c528162ce136a590152afb2b1ac..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&KQ9D97{~EB5|M}y-oU!8?H*UqDzCWYB6s?+``~2HGCK+ll{cYLD|KE8Dis~? z!Lw&IiY=~N`A+i7lga$a?5Eqz9Ci+R{a`2R8f~k_oZLPQ7w#YDAC`;}ca@2h1NF_0 zoz9E0Jh55b%G Date: Wed, 10 Jun 2015 16:24:31 +0800 Subject: [PATCH 8/8] 0.8.5 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6943606bf..a8b61e4a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ emqttd ChangeLog ================== -0.8.5-beta (2015-06-12) +0.8.5-beta (2015-06-10) ------------------------- Bugfix: issue #53 - client will receive duplicate messages when overlapping subscription