Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supported request_response_information and response_topic. #892

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions include/mqtt/broker/broker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,11 +1014,22 @@ class broker_t {

optional<std::chrono::steady_clock::duration> session_expiry_interval;
optional<std::chrono::steady_clock::duration> will_expiry_interval;
v5::properties connack_props;

if (ep.get_protocol_version() == protocol_version::v5) {
auto v = get_property<v5::property::session_expiry_interval>(props);
if (v && v.value().val() != 0) {
session_expiry_interval.emplace(std::chrono::seconds(v.value().val()));
{
auto v = get_property<v5::property::session_expiry_interval>(props);
if (v && v.value().val() != 0) {
session_expiry_interval.emplace(std::chrono::seconds(v.value().val()));
}
}
{
auto v = get_property<v5::property::request_response_information>(props);
if (v && v.value().val() == 1) {
connack_props.emplace_back(
v5::property::response_topic(allocate_buffer(create_uuid_string()))
);
}
}

if (will) {
Expand All @@ -1033,8 +1044,6 @@ class broker_t {
}
}

v5::properties connack_props;

switch (ep.get_protocol_version()) {
case protocol_version::v3_1_1:
if (client_id.empty()) {
Expand Down
64 changes: 64 additions & 0 deletions test/system/st_connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,70 @@ BOOST_AUTO_TEST_CASE( connack_prop ) {
do_combi_test_sync(test);
}

BOOST_AUTO_TEST_CASE( request_response ) {
auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) {
auto& c = cs[0];
clear_ordered();
if (c->get_protocol_version() != MQTT_NS::protocol_version::v5) {
finish();
return;
}

c->set_client_id("cid1");
c->set_clean_session(true);
BOOST_TEST(c->connected() == false);

checker chk = {
// connect
cont("h_connack"),
// disconnect
cont("h_close"),
};

c->set_v5_connack_handler(
[&chk, &c]
(bool sp, MQTT_NS::v5::connect_reason_code connect_reason_code, MQTT_NS::v5::properties props) {
MQTT_CHK("h_connack");
BOOST_TEST(c->connected() == true);
BOOST_TEST(sp == false);
BOOST_TEST(connect_reason_code == MQTT_NS::v5::connect_reason_code::success);

std::size_t times = 0;
MQTT_NS::v5::visit_props(
props,
[&](MQTT_NS::v5::property::response_topic const&) {
++times;
},
[](auto){}
);
BOOST_TEST(times == 1);

c->disconnect();
BOOST_TEST(c->connected() == true);
return true;
});
c->set_close_handler(
[&chk, &finish]
() {
MQTT_CHK("h_close");
finish();
});
c->set_error_handler(
[]
(MQTT_NS::error_code) {
BOOST_CHECK(false);
});
c->connect(
MQTT_NS::v5::properties{
MQTT_NS::v5::property::request_response_information(true)
}
);
ioc.run();
BOOST_TEST(chk.all());
};
do_combi_test_sync(test);
}

BOOST_AUTO_TEST_CASE( session_taken_over ) {
auto test = [](boost::asio::io_context& ioc, auto& cs, auto finish, auto& /*b*/) {
auto& c1 = cs[0];
Expand Down