chore(gw-sn): append messge headers
This commit is contained in:
parent
d0bdf27e0c
commit
ad2dbb5a49
|
@ -39,7 +39,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(?CMD_REPLACE, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -39,7 +39,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_dashboard, emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -48,7 +48,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -36,7 +36,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -53,7 +53,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -51,7 +51,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -51,7 +51,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_resource]),
|
||||||
meck:unload(emqx_resource),
|
meck:unload(emqx_resource),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -41,7 +41,11 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx:update_config(
|
||||||
|
[authorization],
|
||||||
|
#{<<"no_match">> => <<"allow">>,
|
||||||
|
<<"cache">> => #{<<"enable">> => <<"true">>},
|
||||||
|
<<"sources">> => []}),
|
||||||
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
emqx_common_test_helpers:stop_apps([emqx_authz, emqx_conf]),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ handle_method(post, Topic, #coap_message{payload = Payload} = Msg, Ctx, CInfo) -
|
||||||
#{clientid := ClientId} = CInfo,
|
#{clientid := ClientId} = CInfo,
|
||||||
MountTopic = mount(CInfo, Topic),
|
MountTopic = mount(CInfo, Topic),
|
||||||
QOS = get_publish_qos(Msg),
|
QOS = get_publish_qos(Msg),
|
||||||
|
%% TODO: Append message metadata into headers
|
||||||
MQTTMsg = emqx_message:make(ClientId, QOS, MountTopic, Payload),
|
MQTTMsg = emqx_message:make(ClientId, QOS, MountTopic, Payload),
|
||||||
MQTTMsg2 = apply_publish_opts(Msg, MQTTMsg),
|
MQTTMsg2 = apply_publish_opts(Msg, MQTTMsg),
|
||||||
_ = emqx_broker:publish(MQTTMsg2),
|
_ = emqx_broker:publish(MQTTMsg2),
|
||||||
|
|
|
@ -603,6 +603,7 @@ send_to_mqtt(Ctx, EventType, Payload, {Topic, Qos},
|
||||||
proto_publish(Topic, Payload, Qos, Headers, WithContext,
|
proto_publish(Topic, Payload, Qos, Headers, WithContext,
|
||||||
#session{endpoint_name = Epn} = Session) ->
|
#session{endpoint_name = Epn} = Session) ->
|
||||||
MountedTopic = mount(Topic, Session),
|
MountedTopic = mount(Topic, Session),
|
||||||
|
%% TODO: Append message metadata into headers
|
||||||
Msg = emqx_message:make(Epn, Qos, MountedTopic,
|
Msg = emqx_message:make(Epn, Qos, MountedTopic,
|
||||||
emqx_json:encode(Payload), #{}, Headers),
|
emqx_json:encode(Payload), #{}, Headers),
|
||||||
WithContext(publish, [MountedTopic, Msg]),
|
WithContext(publish, [MountedTopic, Msg]),
|
||||||
|
|
|
@ -790,16 +790,26 @@ check_pub_authz({TopicName, _Flags, _Data},
|
||||||
end.
|
end.
|
||||||
|
|
||||||
convert_pub_to_msg({TopicName, Flags, Data},
|
convert_pub_to_msg({TopicName, Flags, Data},
|
||||||
Channel = #channel{
|
Channel = #channel{clientinfo = #{clientid := ClientId}}) ->
|
||||||
clientinfo = #{clientid := ClientId}}) ->
|
|
||||||
#mqtt_sn_flags{qos = QoS, dup = Dup, retain = Retain} = Flags,
|
#mqtt_sn_flags{qos = QoS, dup = Dup, retain = Retain} = Flags,
|
||||||
NewQoS = get_corrected_qos(QoS),
|
NewQoS = get_corrected_qos(QoS),
|
||||||
Message = emqx_message:make(ClientId, NewQoS, TopicName, Data),
|
Message = put_message_headers(
|
||||||
NMessage = emqx_message:set_flags(
|
emqx_message:make(
|
||||||
#{dup => Dup, retain => Retain},
|
ClientId, NewQoS, TopicName, Data,
|
||||||
Message
|
#{dup => Dup, retain => Retain}, #{}), Channel),
|
||||||
),
|
{ok, Message, Channel}.
|
||||||
{ok, NMessage, Channel}.
|
|
||||||
|
put_message_headers(Msg, #channel{
|
||||||
|
conninfo = #{proto_ver := ProtoVer},
|
||||||
|
clientinfo = #{
|
||||||
|
protocol := Protocol,
|
||||||
|
username := Username,
|
||||||
|
peerhost := PeerHost}}) ->
|
||||||
|
emqx_message:set_headers(
|
||||||
|
#{proto_ver => ProtoVer,
|
||||||
|
protocol => Protocol,
|
||||||
|
username => Username,
|
||||||
|
peerhost => PeerHost}, Msg).
|
||||||
|
|
||||||
get_corrected_qos(?QOS_NEG1) -> ?QOS_0;
|
get_corrected_qos(?QOS_NEG1) -> ?QOS_0;
|
||||||
get_corrected_qos(QoS) -> QoS.
|
get_corrected_qos(QoS) -> QoS.
|
||||||
|
@ -1307,7 +1317,7 @@ ensure_disconnected(Reason, Channel = #channel{
|
||||||
mabye_publish_will_msg(Channel = #channel{will_msg = undefined}) ->
|
mabye_publish_will_msg(Channel = #channel{will_msg = undefined}) ->
|
||||||
Channel;
|
Channel;
|
||||||
mabye_publish_will_msg(Channel = #channel{will_msg = WillMsg}) ->
|
mabye_publish_will_msg(Channel = #channel{will_msg = WillMsg}) ->
|
||||||
ok = publish_will_msg(WillMsg),
|
ok = publish_will_msg(put_message_headers(WillMsg, Channel)),
|
||||||
Channel#channel{will_msg = undefined}.
|
Channel#channel{will_msg = undefined}.
|
||||||
|
|
||||||
publish_will_msg(Msg) ->
|
publish_will_msg(Msg) ->
|
||||||
|
|
|
@ -107,16 +107,16 @@ t_lookup_cmd_read(Config) ->
|
||||||
emqtt:subscribe(?config(emqx_c, Config), RespTopic, qos0),
|
emqtt:subscribe(?config(emqx_c, Config), RespTopic, qos0),
|
||||||
timer:sleep(200),
|
timer:sleep(200),
|
||||||
%% step 1, device register ...
|
%% step 1, device register ...
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request(
|
||||||
post,
|
UdpSock,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
post,
|
||||||
#coap_content{
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
||||||
content_format = <<"text/plain">>,
|
#coap_content{
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,"
|
content_format = <<"text/plain">>,
|
||||||
"</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,"
|
||||||
},
|
"</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
[],
|
[],
|
||||||
MsgId1),
|
MsgId1),
|
||||||
#coap_message{method = Method1} = test_recv_coap_response(UdpSock),
|
#coap_message{method = Method1} = test_recv_coap_response(UdpSock),
|
||||||
?assertEqual({ok,created}, Method1),
|
?assertEqual({ok,created}, Method1),
|
||||||
|
|
||||||
|
@ -192,7 +192,8 @@ t_lookup_cmd_discover(Config) ->
|
||||||
"127.0.0.1",
|
"127.0.0.1",
|
||||||
?PORT,
|
?PORT,
|
||||||
{ok, content},
|
{ok, content},
|
||||||
#coap_content{content_format = <<"application/link-format">>, payload = PayloadDiscover},
|
#coap_content{content_format = <<"application/link-format">>,
|
||||||
|
payload = PayloadDiscover},
|
||||||
Request2,
|
Request2,
|
||||||
true),
|
true),
|
||||||
timer:sleep(200),
|
timer:sleep(200),
|
||||||
|
@ -206,13 +207,15 @@ t_read(Config) ->
|
||||||
emqtt:subscribe(?config(emqx_c, Config), RespTopic, qos0),
|
emqtt:subscribe(?config(emqx_c, Config), RespTopic, qos0),
|
||||||
timer:sleep(200),
|
timer:sleep(200),
|
||||||
%% step 1, device register ...
|
%% step 1, device register ...
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request(
|
||||||
post,
|
UdpSock,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
post,
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
[],
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,"
|
||||||
MsgId1),
|
"</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
|
[],
|
||||||
|
MsgId1),
|
||||||
#coap_message{method = Method1} = test_recv_coap_response(UdpSock),
|
#coap_message{method = Method1} = test_recv_coap_response(UdpSock),
|
||||||
?assertEqual({ok,created}, Method1),
|
?assertEqual({ok,created}, Method1),
|
||||||
|
|
||||||
|
@ -236,13 +239,15 @@ t_write(Config) ->
|
||||||
emqtt:subscribe(?config(emqx_c, Config), RespTopic, qos0),
|
emqtt:subscribe(?config(emqx_c, Config), RespTopic, qos0),
|
||||||
timer:sleep(200),
|
timer:sleep(200),
|
||||||
%% step 1, device register ...
|
%% step 1, device register ...
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request(
|
||||||
post,
|
UdpSock,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
post,
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
[],
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,"
|
||||||
MsgId1),
|
"</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
|
[],
|
||||||
|
MsgId1),
|
||||||
#coap_message{method = Method1} = test_recv_coap_response(UdpSock),
|
#coap_message{method = Method1} = test_recv_coap_response(UdpSock),
|
||||||
?assertEqual({ok,created}, Method1),
|
?assertEqual({ok,created}, Method1),
|
||||||
|
|
||||||
|
@ -268,13 +273,15 @@ t_observe(Config) ->
|
||||||
emqtt:subscribe(?config(emqx_c, Config), RespTopic, qos0),
|
emqtt:subscribe(?config(emqx_c, Config), RespTopic, qos0),
|
||||||
timer:sleep(200),
|
timer:sleep(200),
|
||||||
%% step 1, device register ...
|
%% step 1, device register ...
|
||||||
test_send_coap_request( UdpSock,
|
test_send_coap_request(
|
||||||
post,
|
UdpSock,
|
||||||
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
post,
|
||||||
#coap_content{content_format = <<"text/plain">>,
|
sprintf("coap://127.0.0.1:~b/rd?ep=~ts<=600&lwm2m=1", [?PORT, Epn]),
|
||||||
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
#coap_content{content_format = <<"text/plain">>,
|
||||||
[],
|
payload = <<"</lwm2m>;rt=\"oma.lwm2m\";ct=11543,"
|
||||||
MsgId1),
|
"</lwm2m/1/0>,</lwm2m/2/0>,</lwm2m/3/0>">>},
|
||||||
|
[],
|
||||||
|
MsgId1),
|
||||||
#coap_message{method = Method1} = test_recv_coap_response(UdpSock),
|
#coap_message{method = Method1} = test_recv_coap_response(UdpSock),
|
||||||
?assertEqual({ok,created}, Method1),
|
?assertEqual({ok,created}, Method1),
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue