From c9d3e2d29170a8f4579b56891623249f50f5cc79 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Thu, 8 Jan 2015 14:25:38 +0800 Subject: [PATCH] mqtt 3.1.1 protocol --- CHANGELOG.md | 5 ++ apps/emqtt/include/emqtt.hrl | 4 +- apps/emqtt/include/emqtt_topic.hrl | 2 +- apps/emqtt/src/emqtt.erl | 2 +- apps/emqtt/src/emqtt_app.erl | 4 +- apps/emqtt/src/emqtt_auth.erl | 4 +- apps/emqtt/src/emqtt_auth_anonymous.erl | 4 +- apps/emqtt/src/emqtt_auth_internal.erl | 4 +- apps/emqtt/src/emqtt_client.erl | 4 +- apps/emqtt/src/emqtt_cm.erl | 4 +- apps/emqtt/src/emqtt_ctl.erl | 4 +- apps/emqtt/src/emqtt_db.erl | 4 +- apps/emqtt/src/emqtt_frame.erl | 2 +- apps/emqtt/src/emqtt_http.erl | 4 +- apps/emqtt/src/emqtt_keep_alive.erl | 4 +- apps/emqtt/src/emqtt_monitor.erl | 4 +- apps/emqtt/src/emqtt_net.erl | 4 +- apps/emqtt/src/emqtt_protocol.erl | 40 +++++++---- apps/emqtt/src/emqtt_pubsub.erl | 4 +- apps/emqtt/src/emqtt_queue.erl | 2 +- apps/emqtt/src/emqtt_queue_sup.erl | 4 +- apps/emqtt/src/emqtt_retained.erl | 4 +- apps/emqtt/src/emqtt_router.erl | 3 +- apps/emqtt/src/emqtt_session.erl | 24 +++++++ apps/emqtt/src/emqtt_sm.erl | 94 +++++++++++++++++++++++++ apps/emqtt/src/emqtt_sup.erl | 4 +- apps/emqtt/src/emqtt_topic.erl | 4 +- data/.placeholder | 1 + doc/protocol.md | 4 ++ 29 files changed, 198 insertions(+), 53 deletions(-) create mode 100644 apps/emqtt/src/emqtt_session.erl create mode 100644 data/.placeholder diff --git a/CHANGELOG.md b/CHANGELOG.md index d2607c88e..dccdaa143 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ eMQTT ChangeLog ================== +TODO: 0.2.1 (2014-12-31) +------------------- + +Pass MQTT 3.1.1 Tests + 0.2.0 (2014-12-07) ------------------- diff --git a/apps/emqtt/include/emqtt.hrl b/apps/emqtt/include/emqtt.hrl index 375705483..6dbe2b20e 100644 --- a/apps/emqtt/include/emqtt.hrl +++ b/apps/emqtt/include/emqtt.hrl @@ -1,5 +1,5 @@ %%------------------------------------------------------------------------------ -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,7 @@ %% --------------------------------- %% banner %% --------------------------------- --define(COPYRIGHT, "Copyright (C) 2014, Feng Lee"). +-define(COPYRIGHT, "Copyright (C) 2014, Feng Lee"). -define(LICENSE_MESSAGE, "Licensed under MIT"). diff --git a/apps/emqtt/include/emqtt_topic.hrl b/apps/emqtt/include/emqtt_topic.hrl index c31ea8556..8ac0663e9 100644 --- a/apps/emqtt/include/emqtt_topic.hrl +++ b/apps/emqtt/include/emqtt_topic.hrl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/apps/emqtt/src/emqtt.erl b/apps/emqtt/src/emqtt.erl index 0b57307e0..651f5cad0 100644 --- a/apps/emqtt/src/emqtt.erl +++ b/apps/emqtt/src/emqtt.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/apps/emqtt/src/emqtt_app.erl b/apps/emqtt/src/emqtt_app.erl index 14c3bf29e..e0cb71f80 100644 --- a/apps/emqtt/src/emqtt_app.erl +++ b/apps/emqtt/src/emqtt_app.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_app). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -behaviour(application). diff --git a/apps/emqtt/src/emqtt_auth.erl b/apps/emqtt/src/emqtt_auth.erl index ba3202e0a..10d4513d1 100644 --- a/apps/emqtt/src/emqtt_auth.erl +++ b/apps/emqtt/src/emqtt_auth.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_auth). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -include("emqtt.hrl"). diff --git a/apps/emqtt/src/emqtt_auth_anonymous.erl b/apps/emqtt/src/emqtt_auth_anonymous.erl index a823eeef3..243cb85d8 100644 --- a/apps/emqtt/src/emqtt_auth_anonymous.erl +++ b/apps/emqtt/src/emqtt_auth_anonymous.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_auth_anonymous). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -export([init/1, add/2, diff --git a/apps/emqtt/src/emqtt_auth_internal.erl b/apps/emqtt/src/emqtt_auth_internal.erl index f2dcef1dd..be51159b2 100644 --- a/apps/emqtt/src/emqtt_auth_internal.erl +++ b/apps/emqtt/src/emqtt_auth_internal.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_auth_internal). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -include("emqtt.hrl"). diff --git a/apps/emqtt/src/emqtt_client.erl b/apps/emqtt/src/emqtt_client.erl index e3e18d1b6..13f91b8ee 100644 --- a/apps/emqtt/src/emqtt_client.erl +++ b/apps/emqtt/src/emqtt_client.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_client). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -behaviour(gen_server). diff --git a/apps/emqtt/src/emqtt_cm.erl b/apps/emqtt/src/emqtt_cm.erl index 0182f71e7..afbc180c6 100644 --- a/apps/emqtt/src/emqtt_cm.erl +++ b/apps/emqtt/src/emqtt_cm.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -23,7 +23,7 @@ %client manager -module(emqtt_cm). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -behaviour(gen_server). diff --git a/apps/emqtt/src/emqtt_ctl.erl b/apps/emqtt/src/emqtt_ctl.erl index e5f747552..116456923 100644 --- a/apps/emqtt/src/emqtt_ctl.erl +++ b/apps/emqtt/src/emqtt_ctl.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_ctl). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -include("emqtt.hrl"). diff --git a/apps/emqtt/src/emqtt_db.erl b/apps/emqtt/src/emqtt_db.erl index 0b5f508ad..f2316630a 100644 --- a/apps/emqtt/src/emqtt_db.erl +++ b/apps/emqtt/src/emqtt_db.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_db). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -export([init/0, stop/0]). diff --git a/apps/emqtt/src/emqtt_frame.erl b/apps/emqtt/src/emqtt_frame.erl index 660e2c6f8..bd31065db 100644 --- a/apps/emqtt/src/emqtt_frame.erl +++ b/apps/emqtt/src/emqtt_frame.erl @@ -1,5 +1,5 @@ %%------------------------------------------------------------------------------ -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/apps/emqtt/src/emqtt_http.erl b/apps/emqtt/src/emqtt_http.erl index e3bdc4f90..0d2a37b92 100644 --- a/apps/emqtt/src/emqtt_http.erl +++ b/apps/emqtt/src/emqtt_http.erl @@ -1,5 +1,5 @@ %%------------------------------------------------------------------------------ -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_http). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -include("emqtt.hrl"). diff --git a/apps/emqtt/src/emqtt_keep_alive.erl b/apps/emqtt/src/emqtt_keep_alive.erl index 873608fb9..5c360d3c9 100644 --- a/apps/emqtt/src/emqtt_keep_alive.erl +++ b/apps/emqtt/src/emqtt_keep_alive.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_keep_alive). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -export([new/2, state/1, diff --git a/apps/emqtt/src/emqtt_monitor.erl b/apps/emqtt/src/emqtt_monitor.erl index 996600707..d1b18e040 100644 --- a/apps/emqtt/src/emqtt_monitor.erl +++ b/apps/emqtt/src/emqtt_monitor.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_monitor). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -behavior(gen_server). diff --git a/apps/emqtt/src/emqtt_net.erl b/apps/emqtt/src/emqtt_net.erl index e6620c3b7..061956cf6 100644 --- a/apps/emqtt/src/emqtt_net.erl +++ b/apps/emqtt/src/emqtt_net.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_net). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -export([tcp_name/3, tcp_host/1, getopts/2, setopts/2, getaddr/2, port_to_listeners/1]). diff --git a/apps/emqtt/src/emqtt_protocol.erl b/apps/emqtt/src/emqtt_protocol.erl index f2504ace5..d26cf2eac 100644 --- a/apps/emqtt/src/emqtt_protocol.erl +++ b/apps/emqtt/src/emqtt_protocol.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -28,6 +28,7 @@ -record(proto_state, { socket, + connected = false, %received CONNECT action? message_id, client_id, clean_sess, @@ -43,8 +44,7 @@ -export([info/1]). --define(FRAME_TYPE(Frame, Type), - Frame = #mqtt_frame{ fixed = #mqtt_frame_fixed{ type = Type }}). +-define(FRAME_TYPE(Type), #mqtt_frame{ fixed = #mqtt_frame_fixed{ type = Type }}). initial_state(Socket) -> #proto_state{ @@ -71,6 +71,23 @@ info(#proto_state{ message_id = MsgId, State :: proto_state(), NewState :: proto_state(). + +%%CONNECT – Client requests a connection to a Server + +%%A Client can only send the CONNECT Packet once over a Network Connection. 369 + +%%First CONNECT +handle_frame(Frame = ?FRAME_TYPE(?CONNECT), State = #proto_state{connected = false}) -> + handle_connect(Frame, State#proto_state{connected = true}); + +%%Sencond CONNECT +handle_frame(?FRAME_TYPE(?CONNECT), State = #proto_state{connected = true}) -> + {error, bad_connect, State}; + +%%Received other packets when CONNECT not arrived. +handle_frame(_Frame, State = #proto_state{connected = false}) -> + {error, no_connected, State}; + handle_frame(Frame = #mqtt_frame{ fixed = #mqtt_frame_fixed{ type = Type }}, State = #proto_state{client_id = ClientId}) -> lager:info("frame from ~s: ~p", [ClientId, Frame]), @@ -81,14 +98,13 @@ handle_frame(Frame = #mqtt_frame{ fixed = #mqtt_frame_fixed{ type = Type }}, {error, Reason, State} end. -handle_request(?CONNECT, - #mqtt_frame{ variable = #mqtt_frame_connect{ - username = Username, - password = Password, - proto_ver = ProtoVersion, - clean_sess = CleanSess, - keep_alive = AlivePeriod, - client_id = ClientId } = Var}, State0 = #proto_state{socket = Sock}) -> +handle_connect(#mqtt_frame{ variable = #mqtt_frame_connect{ + username = Username, + password = Password, + proto_ver = ProtoVersion, + clean_sess = CleanSess, + keep_alive = AlivePeriod, + client_id = ClientId } = Var}, State0 = #proto_state{socket = Sock}) -> State = State0#proto_state{client_id = ClientId}, {ReturnCode, State1} = case {lists:member(ProtoVersion, proplists:get_keys(?PROTOCOL_NAMES)), @@ -117,7 +133,7 @@ handle_request(?CONNECT, fixed = #mqtt_frame_fixed{ type = ?CONNACK }, variable = #mqtt_frame_connack{ return_code = ReturnCode }}), - {ok, State1}; + {ok, State1}. handle_request(?PUBLISH, Frame=#mqtt_frame{ fixed = #mqtt_frame_fixed{qos = ?QOS_0}}, State) -> diff --git a/apps/emqtt/src/emqtt_pubsub.erl b/apps/emqtt/src/emqtt_pubsub.erl index a9785deee..0b8c5f372 100644 --- a/apps/emqtt/src/emqtt_pubsub.erl +++ b/apps/emqtt/src/emqtt_pubsub.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_pubsub). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -include("emqtt.hrl"). diff --git a/apps/emqtt/src/emqtt_queue.erl b/apps/emqtt/src/emqtt_queue.erl index da715a542..9f960618d 100644 --- a/apps/emqtt/src/emqtt_queue.erl +++ b/apps/emqtt/src/emqtt_queue.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal diff --git a/apps/emqtt/src/emqtt_queue_sup.erl b/apps/emqtt/src/emqtt_queue_sup.erl index 3cfa25383..9b7b79e10 100644 --- a/apps/emqtt/src/emqtt_queue_sup.erl +++ b/apps/emqtt/src/emqtt_queue_sup.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -21,7 +21,7 @@ %%------------------------------------------------------------------------------ -module(emqtt_queue_sup). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -behavior(supervisor). diff --git a/apps/emqtt/src/emqtt_retained.erl b/apps/emqtt/src/emqtt_retained.erl index 69d643761..fa0d9b7d2 100644 --- a/apps/emqtt/src/emqtt_retained.erl +++ b/apps/emqtt/src/emqtt_retained.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_retained). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). %%TODO: FIXME Later... diff --git a/apps/emqtt/src/emqtt_router.erl b/apps/emqtt/src/emqtt_router.erl index 43cc16268..636837370 100644 --- a/apps/emqtt/src/emqtt_router.erl +++ b/apps/emqtt/src/emqtt_router.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -89,3 +89,4 @@ retained(Msg = #mqtt_msg{retain = true, topic = Topic}) -> emqtt_retained:insert(Topic, Msg), Msg; retained(Msg) -> Msg. + diff --git a/apps/emqtt/src/emqtt_session.erl b/apps/emqtt/src/emqtt_session.erl new file mode 100644 index 000000000..35ade693e --- /dev/null +++ b/apps/emqtt/src/emqtt_session.erl @@ -0,0 +1,24 @@ +%%----------------------------------------------------------------------------- +%% Copyright (c) 2015, Feng Lee +%% +%% Permission is hereby granted, free of charge, to any person obtaining a copy +%% of this software and associated documentation files (the "Software"), to deal +%% in the Software without restriction, including without limitation the rights +%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +%% copies of the Software, and to permit persons to whom the Software is +%% furnished to do so, subject to the following conditions: +%% +%% The above copyright notice and this permission notice shall be included in all +%% copies or substantial portions of the Software. +%% +%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%% SOFTWARE. +%%------------------------------------------------------------------------------ + +-module(emqtt_session). + diff --git a/apps/emqtt/src/emqtt_sm.erl b/apps/emqtt/src/emqtt_sm.erl index cbcb477d9..92fa1c9d3 100644 --- a/apps/emqtt/src/emqtt_sm.erl +++ b/apps/emqtt/src/emqtt_sm.erl @@ -1,5 +1,99 @@ +%%----------------------------------------------------------------------------- +%% Copyright (c) 2014, Feng Lee +%% +%% Permission is hereby granted, free of charge, to any person obtaining a copy +%% of this software and associated documentation files (the "Software"), to deal +%% in the Software without restriction, including without limitation the rights +%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +%% copies of the Software, and to permit persons to whom the Software is +%% furnished to do so, subject to the following conditions: +%% +%% The above copyright notice and this permission notice shall be included in all +%% copies or substantial portions of the Software. +%% +%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +%% SOFTWARE. +%%------------------------------------------------------------------------------ + + +%%------------------------------------------------------------------------------ +%% +%% The Session state in the Server consists of: +%% The existence of a Session, even if the rest of the Session state is empty. +%% The Client’s subscriptions. +%% QoS 1 and QoS 2 messages which have been sent to the Client, but have not been completely +%% acknowledged. +%% QoS 1 and QoS 2 messages pending transmission to the Client. +%% QoS 2 messages which have been received from the Client, but have not been completely +%% acknowledged. +%% Optionally, QoS 0 messages pending transmission to the Client. +%% +%%------------------------------------------------------------------------------ + -module(emqtt_sm). %%emqtt session manager... %%cleanSess: true | false + +-include("emqtt.hrl"). + +-behaviour(gen_server). + +-define(SERVER, ?MODULE). + +%% ------------------------------------------------------------------ +%% API Function Exports +%% ------------------------------------------------------------------ + +-export([start_link/0]). + +-export([create/2, resume/2, destroy/1]). + +%% ------------------------------------------------------------------ +%% gen_server Function Exports +%% ------------------------------------------------------------------ + +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, + terminate/2, code_change/3]). + +%% ------------------------------------------------------------------ +%% API Function Definitions +%% ------------------------------------------------------------------ + +start_link() -> + gen_server:start_link({local, ?SERVER}, ?MODULE, [], []). + +create(ClientId, Pid) -> ok. + +resume(ClientId, Pid) -> ok. + +destroy(ClientId) -> ok. + +%% ------------------------------------------------------------------ +%% gen_server Function Definitions +%% ------------------------------------------------------------------ + +init(Args) -> + {ok, Args}. + +handle_call(_Request, _From, State) -> + {reply, ok, State}. + +handle_cast(_Msg, State) -> + {noreply, State}. + +handle_info(_Info, State) -> + {noreply, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + diff --git a/apps/emqtt/src/emqtt_sup.erl b/apps/emqtt/src/emqtt_sup.erl index de3d053b3..fa3785b52 100644 --- a/apps/emqtt/src/emqtt_sup.erl +++ b/apps/emqtt/src/emqtt_sup.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_sup). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -include("emqtt.hrl"). diff --git a/apps/emqtt/src/emqtt_topic.erl b/apps/emqtt/src/emqtt_topic.erl index 29d9d865d..794a1f8c1 100644 --- a/apps/emqtt/src/emqtt_topic.erl +++ b/apps/emqtt/src/emqtt_topic.erl @@ -1,5 +1,5 @@ %%----------------------------------------------------------------------------- -%% Copyright (c) 2014, Feng Lee +%% Copyright (c) 2014, Feng Lee %% %% Permission is hereby granted, free of charge, to any person obtaining a copy %% of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ -module(emqtt_topic). --author('feng@slimchat.io'). +-author('feng@emqtt.io'). -import(lists, [reverse/1]). diff --git a/data/.placeholder b/data/.placeholder new file mode 100644 index 000000000..0fec8a3ed --- /dev/null +++ b/data/.placeholder @@ -0,0 +1 @@ +durable queue data... diff --git a/doc/protocol.md b/doc/protocol.md index 2043706b9..77ba565b3 100644 --- a/doc/protocol.md +++ b/doc/protocol.md @@ -30,3 +30,7 @@ Connection, others can span multiple consecutive Network Connections between a C An expression contained in a Subscription, to indicate an interest in one or more topics. A Topic Filter can include wildcard characters. + +## Packet Identifier + +