emqx_types.erl 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_types).
  17. -include("emqx.hrl").
  18. -include("emqx_mqtt.hrl").
  19. -include("types.hrl").
  20. -export_type([ ver/0
  21. , qos/0
  22. , qos_name/0
  23. ]).
  24. -export_type([ zone/0
  25. , pubsub/0
  26. , topic/0
  27. , subid/0
  28. ]).
  29. -export_type([ socktype/0
  30. , sockstate/0
  31. , conninfo/0
  32. , clientinfo/0
  33. , clientid/0
  34. , username/0
  35. , password/0
  36. , peerhost/0
  37. , peername/0
  38. , protocol/0
  39. ]).
  40. -export_type([ connack/0
  41. , subopts/0
  42. , reason_code/0
  43. , alias_id/0
  44. , topic_aliases/0
  45. , properties/0
  46. ]).
  47. -export_type([ packet_id/0
  48. , packet_type/0
  49. , packet/0
  50. ]).
  51. -export_type([ subscription/0
  52. , subscriber/0
  53. , topic_filters/0
  54. ]).
  55. -export_type([ payload/0
  56. , message/0
  57. ]).
  58. -export_type([ deliver/0
  59. , delivery/0
  60. , publish_result/0
  61. , deliver_result/0
  62. ]).
  63. -export_type([ route/0
  64. , route_entry/0
  65. ]).
  66. -export_type([ alarm/0
  67. , plugin/0
  68. , banned/0
  69. , command/0
  70. ]).
  71. -export_type([ caps/0
  72. , attrs/0
  73. , infos/0
  74. , stats/0
  75. ]).
  76. -export_type([oom_policy/0]).
  77. -type(ver() :: ?MQTT_PROTO_V3
  78. | ?MQTT_PROTO_V4
  79. | ?MQTT_PROTO_V5).
  80. -type(qos() :: ?QOS_0 | ?QOS_1 | ?QOS_2).
  81. -type(qos_name() :: qos0 | at_most_once |
  82. qos1 | at_least_once |
  83. qos2 | exactly_once).
  84. -type(zone() :: emqx_zone:zone()).
  85. -type(pubsub() :: publish | subscribe).
  86. -type(topic() :: emqx_topic:topic()).
  87. -type(subid() :: binary() | atom()).
  88. -type(socktype() :: tcp | udp | ssl | proxy | atom()).
  89. -type(sockstate() :: idle | running | blocked | closed).
  90. -type(conninfo() :: #{socktype := socktype(),
  91. sockname := peername(),
  92. peername := peername(),
  93. peercert := esockd_peercert:peercert(),
  94. conn_mod := module(),
  95. proto_name := binary(),
  96. proto_ver := ver(),
  97. clean_start := boolean(),
  98. clientid := clientid(),
  99. username := username(),
  100. conn_props := properties(),
  101. connected := boolean(),
  102. connected_at := erlang:timestamp(),
  103. keepalive := 0..16#FFFF,
  104. receive_maximum := non_neg_integer(),
  105. expiry_interval := non_neg_integer(),
  106. atom() => term()
  107. }).
  108. -type(clientinfo() :: #{zone := zone(),
  109. protocol := protocol(),
  110. peerhost := peerhost(),
  111. sockport := non_neg_integer(),
  112. clientid := clientid(),
  113. username := username(),
  114. peercert := esockd_peercert:peercert(),
  115. is_bridge := boolean(),
  116. is_superuser := boolean(),
  117. mountpoint := maybe(binary()),
  118. ws_cookie := maybe(list()),
  119. password => maybe(binary()),
  120. auth_result => auth_result(),
  121. anonymous => boolean(),
  122. atom() => term()
  123. }).
  124. -type(clientid() :: binary()|atom()).
  125. -type(username() :: maybe(binary())).
  126. -type(password() :: maybe(binary())).
  127. -type(peerhost() :: inet:ip_address()).
  128. -type(peername() :: {inet:ip_address(), inet:port_number()}).
  129. -type(protocol() :: mqtt | 'mqtt-sn' | coap | lwm2m | stomp | none | atom()).
  130. -type(auth_result() :: success
  131. | client_identifier_not_valid
  132. | bad_username_or_password
  133. | bad_clientid_or_password
  134. | not_authorized
  135. | server_unavailable
  136. | server_busy
  137. | banned
  138. | bad_authentication_method).
  139. -type(packet_type() :: ?RESERVED..?AUTH).
  140. -type(connack() :: ?CONNACK_ACCEPT..?CONNACK_AUTH).
  141. -type(subopts() :: #{rh := 0 | 1 | 2,
  142. rap := 0 | 1,
  143. nl := 0 | 1,
  144. qos := qos(),
  145. share => binary(),
  146. atom() => term()
  147. }).
  148. -type(reason_code() :: 0..16#FF).
  149. -type(packet_id() :: 1..16#FFFF).
  150. -type(alias_id() :: 0..16#FFFF).
  151. -type(topic_aliases() :: #{inbound => maybe(map()),
  152. outbound => maybe(map())}).
  153. -type(properties() :: #{atom() => term()}).
  154. -type(topic_filters() :: list({topic(), subopts()})).
  155. -type(packet() :: #mqtt_packet{}).
  156. -type(subscription() :: #subscription{}).
  157. -type(subscriber() :: {pid(), subid()}).
  158. -type(payload() :: binary() | iodata()).
  159. -type(message() :: #message{}).
  160. -type(banned() :: #banned{}).
  161. -type(deliver() :: {deliver, topic(), message()}).
  162. -type(delivery() :: #delivery{}).
  163. -type(deliver_result() :: ok | {error, term()}).
  164. -type(publish_result() :: [{node(), topic(), deliver_result()} |
  165. {share, topic(), deliver_result()}]).
  166. -type(route() :: #route{}).
  167. -type(sub_group() :: tuple() | binary()).
  168. -type(route_entry() :: {topic(), node()} | {topic, sub_group()}).
  169. -type(alarm() :: #alarm{}).
  170. -type(plugin() :: #plugin{}).
  171. -type(command() :: #command{}).
  172. -type(caps() :: emqx_mqtt_caps:caps()).
  173. -type(attrs() :: #{atom() => term()}).
  174. -type(infos() :: #{atom() => term()}).
  175. -type(stats() :: #{atom() => non_neg_integer()|stats()}).
  176. -type(oom_policy() :: #{message_queue_len => non_neg_integer(),
  177. max_heap_size => non_neg_integer()
  178. }).