Update copyright and change the format of -type, -callback

This commit is contained in:
Feng Lee 2017-02-16 11:07:47 +08:00
parent cae247be97
commit 9e0b2ed57b
33 changed files with 142 additions and 96 deletions

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,29 +16,25 @@
-module(emqttd_access_control). -module(emqttd_access_control).
-include("emqttd.hrl").
-behaviour(gen_server). -behaviour(gen_server).
-define(SERVER, ?MODULE). -author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl").
%% API Function Exports %% API Function Exports
-export([start_link/0, -export([start_link/0, auth/2, check_acl/3, reload_acl/0, lookup_mods/1,
auth/2, % authentication register_mod/3, register_mod/4, unregister_mod/2, stop/0]).
check_acl/3, % acl check
reload_acl/0, % reload acl
lookup_mods/1,
register_mod/3, register_mod/4,
unregister_mod/2,
stop/0]).
%% gen_server callbacks %% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]). terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
-define(ACCESS_CONTROL_TAB, mqtt_access_control). -define(ACCESS_CONTROL_TAB, mqtt_access_control).
-type password() :: undefined | binary(). -type(password() :: undefined | binary()).
-record(state, {}). -record(state, {}).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,21 +16,24 @@
-module(emqttd_access_rule). -module(emqttd_access_rule).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-type who() :: all | binary() |
-type(who() :: all | binary() |
{ipaddr, esockd_cidr:cidr_string()} | {ipaddr, esockd_cidr:cidr_string()} |
{client, binary()} | {client, binary()} |
{user, binary()}. {user, binary()}).
-type access() :: subscribe | publish | pubsub. -type(access() :: subscribe | publish | pubsub).
-type topic() :: binary(). -type(topic() :: binary()).
-type rule() :: {allow, all} | -type(rule() :: {allow, all} |
{allow, who(), access(), list(topic())} | {allow, who(), access(), list(topic())} |
{deny, all} | {deny, all} |
{deny, who(), access(), list(topic())}. {deny, who(), access(), list(topic())}).
-export_type([rule/0]). -export_type([rule/0]).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@
-behaviour(emqttd_acl_mod). -behaviour(emqttd_acl_mod).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-export([all_rules/0]). -export([all_rules/0]).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_acl_mod). -module(emqttd_acl_mod).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -26,10 +28,9 @@
-callback(init(AclOpts :: list()) -> {ok, State :: any()}). -callback(init(AclOpts :: list()) -> {ok, State :: any()}).
-callback(check_acl({Client, PubSub, Topic}, State :: any()) -> allow | deny | ignore when -callback(check_acl({Client :: mqtt_client(),
Client :: mqtt_client(), PubSub :: pubsub(),
PubSub :: pubsub(), Topic :: binary()}, State :: any()) -> allow | deny | ignore).
Topic :: binary()).
-callback(reload_acl(State :: any()) -> ok | {error, any()}). -callback(reload_acl(State :: any()) -> ok | {error, any()}).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_alarm). -module(emqttd_alarm).
-author("Feng Lee <feng@emqtt.io>").
-behaviour(gen_event). -behaviour(gen_event).
-include("emqttd.hrl"). -include("emqttd.hrl").

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_auth_mod). -module(emqttd_auth_mod).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-export([passwd_hash/2]). -export([passwd_hash/2]).
@ -30,10 +32,10 @@
-callback(init(AuthOpts :: list()) -> {ok, State :: any()}). -callback(init(AuthOpts :: list()) -> {ok, State :: any()}).
-callback(check(Client, Password, State) -> ok | | {ok, boolean()} | ignore | {error, string()} when -callback(check(Client :: mqtt_client(),
Client :: mqtt_client(), Password :: binary(),
Password :: binary(), State :: any())
State :: any()). -> ok | | {ok, boolean()} | ignore | {error, string()}).
-callback(description() -> string()). -callback(description() -> string()).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2016-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_base62). -module(emqttd_base62).
-author("Feng Lee <feng@emqtt.io>").
-export([encode/1, decode/1]). -export([encode/1, decode/1]).
%% @doc Encode an integer to base62 string %% @doc Encode an integer to base62 string

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_boot). -module(emqttd_boot).
-author("Feng Lee <feng@emqtt.io>").
-export([apply_module_attributes/1, all_module_attributes/1]). -export([apply_module_attributes/1, all_module_attributes/1]).
%% only {F, Args}... %% only {F, Args}...

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@
-behaviour(gen_server2). -behaviour(gen_server2).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-include("emqttd_protocol.hrl"). -include("emqttd_protocol.hrl").
@ -43,11 +45,11 @@
ping_down_interval = ?PING_DOWN_INTERVAL, ping_down_interval = ?PING_DOWN_INTERVAL,
status = up}). status = up}).
-type option() :: {qos, mqtt_qos()} | -type(option() :: {qos, mqtt_qos()} |
{topic_suffix, binary()} | {topic_suffix, binary()} |
{topic_prefix, binary()} | {topic_prefix, binary()} |
{max_queue_len, pos_integer()} | {max_queue_len, pos_integer()} |
{ping_down_interval, pos_integer()}. {ping_down_interval, pos_integer()}).
-export_type([option/0]). -export_type([option/0]).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@
-behavior(supervisor). -behavior(supervisor).
-author("Feng Lee <feng@emqtt.io>").
-export([start_link/0, bridges/0, start_bridge/2, start_bridge/3, stop_bridge/2]). -export([start_link/0, bridges/0, start_bridge/2, start_bridge/3, stop_bridge/2]).
-export([init/1]). -export([init/1]).
@ -47,7 +49,7 @@ start_bridge(Node, _Topic, _Options) when Node =:= node() ->
{error, bridge_to_self}; {error, bridge_to_self};
start_bridge(Node, Topic, Options) when is_atom(Node) andalso is_binary(Topic) -> start_bridge(Node, Topic, Options) when is_atom(Node) andalso is_binary(Topic) ->
{ok, BridgeEnv} = emqttd:env(bridge), {ok, BridgeEnv} = emqttd:env(bridge),
Options1 = emqttd_opts:merge(BridgeEnv, Options), Options1 = emqttd_misc:merge_opts(BridgeEnv, Options),
supervisor:start_child(?MODULE, bridge_spec(Node, Topic, Options1)). supervisor:start_child(?MODULE, bridge_spec(Node, Topic, Options1)).
%% @doc Stop a bridge %% @doc Stop a bridge

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@
-behaviour(gen_server). -behaviour(gen_server).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-include("emqttd_internal.hrl"). -include("emqttd_internal.hrl").
@ -40,16 +42,18 @@
-record(state, {started_at, sys_interval, heartbeat, tick_tref, version, sysdescr}). -record(state, {started_at, sys_interval, heartbeat, tick_tref, version, sysdescr}).
-define(APP, emqttd).
-define(SERVER, ?MODULE). -define(SERVER, ?MODULE).
-define(BROKER_TAB, mqtt_broker). -define(BROKER_TAB, mqtt_broker).
%% $SYS Topics of Broker %% $SYS Topics of Broker
-define(SYSTOP_BROKERS, [ -define(SYSTOP_BROKERS, [
version, % Broker version version, % Broker version
uptime, % Broker uptime uptime, % Broker uptime
datetime, % Broker local datetime datetime, % Broker local datetime
sysdescr % Broker description sysdescr % Broker description
]). ]).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -74,12 +78,12 @@ notify(EventType, Event) ->
%% @doc Get broker version %% @doc Get broker version
-spec(version() -> string()). -spec(version() -> string()).
version() -> version() ->
{ok, Version} = application:get_key(emqttd, vsn), Version. {ok, Version} = application:get_key(?APP, vsn), Version.
%% @doc Get broker description %% @doc Get broker description
-spec(sysdescr() -> string()). -spec(sysdescr() -> string()).
sysdescr() -> sysdescr() ->
{ok, Descr} = application:get_key(emqttd, description), Descr. {ok, Descr} = application:get_key(?APP, description), Descr.
%% @doc Get broker uptime %% @doc Get broker uptime
-spec(uptime() -> string()). -spec(uptime() -> string()).
@ -161,13 +165,11 @@ retain(brokers) ->
Payload = list_to_binary(string:join([atom_to_list(N) || Payload = list_to_binary(string:join([atom_to_list(N) ||
N <- emqttd_mnesia:running_nodes()], ",")), N <- emqttd_mnesia:running_nodes()], ",")),
Msg = emqttd_message:make(broker, <<"$SYS/brokers">>, Payload), Msg = emqttd_message:make(broker, <<"$SYS/brokers">>, Payload),
Msg1 = emqttd_message:set_flag(sys, emqttd_message:set_flag(retain, Msg)), emqttd:publish(emqttd_message:set_flag(sys, emqttd_message:set_flag(retain, Msg))).
emqttd:publish(Msg1).
retain(Topic, Payload) when is_binary(Payload) -> retain(Topic, Payload) when is_binary(Payload) ->
Msg = emqttd_message:make(broker, emqttd_topic:systop(Topic), Payload), Msg = emqttd_message:make(broker, emqttd_topic:systop(Topic), Payload),
Msg1 = emqttd_message:set_flag(sys, emqttd_message:set_flag(retain, Msg)), emqttd:publish(emqttd_message:set_flag(sys, emqttd_message:set_flag(retain, Msg))).
emqttd:publish(Msg1).
publish(Topic, Payload) when is_binary(Payload) -> publish(Topic, Payload) when is_binary(Payload) ->
Msg = emqttd_message:make(broker, emqttd_topic:systop(Topic), Payload), Msg = emqttd_message:make(broker, emqttd_topic:systop(Topic), Payload),

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_cluster). -module(emqttd_cluster).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
%% Cluster API %% Cluster API

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -18,6 +18,8 @@
-behaviour(gen_server). -behaviour(gen_server).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-include("emqttd_cli.hrl"). -include("emqttd_cli.hrl").
@ -134,7 +136,9 @@ next_seq(State = #state{seq = Seq}) ->
State#state{seq = Seq + 1}. State#state{seq = Seq + 1}.
-ifdef(TEST). -ifdef(TEST).
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
register_cmd_test_() -> register_cmd_test_() ->
{setup, {setup,
fun() -> fun() ->
@ -149,4 +153,5 @@ register_cmd_test_() ->
[?_assertMatch([{{0,test0},{?MODULE, test0}, []}], ets:lookup(?CMD_TAB, {Seq,test0}))] [?_assertMatch([{{0,test0},{?MODULE, test0}, []}], ets:lookup(?CMD_TAB, {Seq,test0}))]
end end
}. }.
-endif. -endif.

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -15,15 +15,18 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc emqttd gen_mod behaviour %% @doc emqttd gen_mod behaviour
-module(emqttd_gen_mod). -module(emqttd_gen_mod).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-ifdef(use_specs). -ifdef(use_specs).
-callback load(Opts :: any()) -> ok | {error, any()}. -callback(load(Opts :: any()) -> ok | {error, any()}).
-callback unload(State :: any()) -> any(). -callback(unload(State :: any()) -> any()).
-else. -else.
@ -35,4 +38,3 @@ behaviour_info(_Other) ->
undefined. undefined.
-endif. -endif.

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -27,13 +27,14 @@
%% 4. Sequence: 2 bytes sequence in one process %% 4. Sequence: 2 bytes sequence in one process
%% %%
%% @end %% @end
-module(emqttd_guid). -module(emqttd_guid).
-export([gen/0, new/0, timestamp/1, to_hexstr/1, from_hexstr/1, to_base62/1, from_base62/1]). -export([gen/0, new/0, timestamp/1, to_hexstr/1, from_hexstr/1, to_base62/1, from_base62/1]).
-define(MAX_SEQ, 16#FFFF). -define(MAX_SEQ, 16#FFFF).
-type guid() :: <<_:128>>. -type(guid() :: <<_:128>>).
%% @doc Generate a global unique id. %% @doc Generate a global unique id.
-spec(gen() -> guid()). -spec(gen() -> guid()).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -14,9 +14,12 @@
%% limitations under the License. %% limitations under the License.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc emqttd http publish API and websocket client. %% @doc HTTP publish API and websocket client.
-module(emqttd_http). -module(emqttd_http).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-include("emqttd_protocol.hrl"). -include("emqttd_protocol.hrl").

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -15,15 +15,18 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Client Keepalive %% @doc Client Keepalive
-module(emqttd_keepalive). -module(emqttd_keepalive).
-author("Feng Lee <feng@emqtt.io>").
-export([start/3, check/1, cancel/1]). -export([start/3, check/1, cancel/1]).
-record(keepalive, {statfun, statval, -record(keepalive, {statfun, statval, tsec, tmsg, tref, repeat = 0}).
tsec, tmsg, tref,
repeat = 0}).
-type keepalive() :: #keepalive{}. -type(keepalive() :: #keepalive{}).
-export_type([keepalive/0]).
%% @doc Start a keepalive %% @doc Start a keepalive
-spec(start(fun(), integer(), any()) -> undefined | keepalive()). -spec(start(fun(), integer(), any()) -> undefined | keepalive()).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_mnesia). -module(emqttd_mnesia).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-include("emqttd_internal.hrl"). -include("emqttd_internal.hrl").

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -39,11 +39,7 @@ start_link() ->
start_child(ChildSpec) when is_tuple(ChildSpec) -> start_child(ChildSpec) when is_tuple(ChildSpec) ->
supervisor:start_child(?MODULE, ChildSpec). supervisor:start_child(?MODULE, ChildSpec).
%% start_child(Mod, Type) when is_atom(Mod) andalso is_atom(Type) ->
%% start_child(Mod::atom(), Type::type()) -> {ok, pid()}
%% @type type() = worker | supervisor
%%
start_child(Mod, Type) when is_atom(Mod) and is_atom(Type) ->
supervisor:start_child(?MODULE, ?CHILD(Mod, Type)). supervisor:start_child(?MODULE, ?CHILD(Mod, Type)).
-spec(stop_child(any()) -> ok | {error, any()}). -spec(stop_child(any()) -> ok | {error, any()}).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -14,7 +14,6 @@
%% limitations under the License. %% limitations under the License.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc emqttd net utilities.
-module(emqttd_net). -module(emqttd_net).
-include_lib("kernel/include/inet.hrl"). -include_lib("kernel/include/inet.hrl").

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_node). -module(emqttd_node).
-author("Feng Lee <feng@emqtt.io>").
-import(lists, [concat/1]). -import(lists, [concat/1]).
-export([is_aliving/1, parse_name/1]). -export([is_aliving/1, parse_name/1]).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
%% @doc Common Pool Supervisor %% @doc Common Pool Supervisor
-module(emqttd_pool_sup). -module(emqttd_pool_sup).
-author("Feng Lee <feng@emqtt.io>").
-behaviour(supervisor). -behaviour(supervisor).
%% API %% API

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc.
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -39,6 +39,7 @@ start_link() ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% API %% API
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec(start_link(atom(), pos_integer()) -> {ok, pid()} | ignore | {error, any()}). -spec(start_link(atom(), pos_integer()) -> {ok, pid()} | ignore | {error, any()}).
start_link(Pool, Id) -> start_link(Pool, Id) ->
gen_server:start_link({local, ?PROC_NAME(?MODULE, Id)}, ?MODULE, [Pool, Id], []). gen_server:start_link({local, ?PROC_NAME(?MODULE, Id)}, ?MODULE, [Pool, Id], []).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -18,11 +18,12 @@
-behaviour(gen_server2). -behaviour(gen_server2).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd.hrl"). -include("emqttd.hrl").
-include("emqttd_internal.hrl"). -include("emqttd_internal.hrl").
%% Start API.
-export([start_link/3]). -export([start_link/3]).
%% PubSub API. %% PubSub API.
@ -31,7 +32,7 @@
-export([dispatch/2]). -export([dispatch/2]).
%% gen_server. %% gen_server Callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, -export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]). terminate/2, code_change/3]).
@ -45,7 +46,6 @@
%% Start PubSub %% Start PubSub
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc Start one Pubsub
-spec(start_link(atom(), pos_integer(), list()) -> {ok, pid()} | ignore | {error, any()}). -spec(start_link(atom(), pos_integer(), list()) -> {ok, pid()} | ignore | {error, any()}).
start_link(Pool, Id, Env) -> start_link(Pool, Id, Env) ->
gen_server2:start_link({local, ?PROC_NAME(?MODULE, Id)}, ?MODULE, [Pool, Id, Env], []). gen_server2:start_link({local, ?PROC_NAME(?MODULE, Id)}, ?MODULE, [Pool, Id, Env], []).
@ -115,6 +115,7 @@ dispatch({_Share, [Sub]}, Topic, Msg) ->
dispatch(Sub, Topic, Msg); dispatch(Sub, Topic, Msg);
dispatch({_Share, []}, _Topic, _Msg) -> dispatch({_Share, []}, _Topic, _Msg) ->
ok; ok;
%%TODO: round-robbin
dispatch({_Share, Subs}, Topic, Msg) -> dispatch({_Share, Subs}, Topic, Msg) ->
dispatch(lists:nth(rand:uniform(length(Subs)), Subs), Topic, Msg). dispatch(lists:nth(rand:uniform(length(Subs)), Subs), Topic, Msg).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
%% @doc PubSub Supervisor. %% @doc PubSub Supervisor.
-module(emqttd_pubsub_sup). -module(emqttd_pubsub_sup).
-author("Feng Lee <feng@emqtt.io>").
-behaviour(supervisor). -behaviour(supervisor).
%% API %% API

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -17,6 +17,8 @@
%% @doc VM System Monitor %% @doc VM System Monitor
-module(emqttd_sysmon). -module(emqttd_sysmon).
-author("Feng Lee <feng@emqtt.io>").
-behavior(gen_server). -behavior(gen_server).
-include("emqttd_internal.hrl"). -include("emqttd_internal.hrl").

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -14,13 +14,13 @@
%% limitations under the License. %% limitations under the License.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @docTrace MQTT packets/messages by ClientID or Topic.
%% Trace MQTT packets/messages by ClientID or Topic.
%% @end
-module(emqttd_trace). -module(emqttd_trace).
-behaviour(gen_server). -behaviour(gen_server).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd_internal.hrl"). -include("emqttd_internal.hrl").
%% API Function Exports %% API Function Exports
@ -34,7 +34,7 @@
-record(state, {level, traces}). -record(state, {level, traces}).
-type trace_who() :: {client | topic, binary()}. -type(trace_who() :: {client | topic, binary()}).
-define(TRACE_OPTIONS, [{formatter_config, [time, " [",severity,"] ", message, "\n"]}]). -define(TRACE_OPTIONS, [{formatter_config, [time, " [",severity,"] ", message, "\n"]}]).

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(emqttd_trace_sup). -module(emqttd_trace_sup).
-author("Feng Lee <feng@emqtt.io>").
-behaviour(supervisor). -behaviour(supervisor).
%% API %% API
@ -29,6 +31,6 @@ start_link() ->
init([]) -> init([]) ->
Trace = {trace, {emqttd_trace, start_link, []}, Trace = {trace, {emqttd_trace, start_link, []},
permanent, 5000, worker, [emqttd_trace]}, permanent, 5000, worker, [emqttd_trace]},
{ok, {{one_for_one, 10, 100}, [Trace]}}. {ok, {{one_for_one, 10, 3600}, [Trace]}}.

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -17,8 +17,11 @@
%% @doc MQTT Topic Trie: %% @doc MQTT Topic Trie:
%% [Trie](http://en.wikipedia.org/wiki/Trie) %% [Trie](http://en.wikipedia.org/wiki/Trie)
%% @end %% @end
-module(emqttd_trie). -module(emqttd_trie).
-author("Feng Lee <feng@emqtt.io>").
-include("emqttd_trie.hrl"). -include("emqttd_trie.hrl").
%% Mnesia Callbacks %% Mnesia Callbacks

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.

View File

@ -1,5 +1,5 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Copyright (c) 2012-2017 Feng Lee <feng@emqtt.io>. %% Copyright (c) 2013-2017 EMQ Enterprise, Inc. (http://emqtt.io)
%% %%
%% Licensed under the Apache License, Version 2.0 (the "License"); %% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License. %% you may not use this file except in compliance with the License.
@ -16,6 +16,8 @@
-module(lager_emqtt_backend). -module(lager_emqtt_backend).
-author("Feng Lee <feng@emqtt.io>").
-behaviour(gen_event). -behaviour(gen_event).
-include_lib("lager/include/lager.hrl"). -include_lib("lager/include/lager.hrl").