Skip to content

Commit

Permalink
Merge pull request #783 from redboltz/fix_topic_alias
Browse files Browse the repository at this point in the history
Fixed TopicAlias functionality.
  • Loading branch information
redboltz authored Jan 20, 2021
2 parents 3cc8622 + cc8927a commit be8bf34
Show file tree
Hide file tree
Showing 16 changed files with 846 additions and 183 deletions.
23 changes: 16 additions & 7 deletions include/mqtt/broker/broker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,22 @@ class broker_t {
);
break;
case protocol_version::v5:
ep.connack(
session_present,
v5::connect_reason_code::success,
connack_props_
);
if (connack_props_.empty()) {
ep.connack(
session_present,
v5::connect_reason_code::success,
v5::properties{
v5::property::topic_alias_maximum{topic_alias_max}
}
);
}
else {
ep.connack(
session_present,
v5::connect_reason_code::success,
connack_props_
);
}
break;
default:
BOOST_ASSERT(false);
Expand Down Expand Up @@ -930,7 +941,6 @@ class broker_t {
it,
[&](auto& e) {
e.reset_con(spep);
e.restore_topic_alias_recv();
e.update_will(ioc_, force_move(will), will_expiry_interval);
// TODO: e.will_delay = force_move(will_delay);
e.renew_session_expiry(force_move(session_expiry_interval));
Expand Down Expand Up @@ -995,7 +1005,6 @@ class broker_t {
it,
[&](auto& e) {
e.reset_con(spep);
e.restore_topic_alias_recv();
e.update_will(ioc_, force_move(will), will_expiry_interval);
// TODO: e.will_delay = force_move(will_delay);
e.renew_session_expiry(force_move(session_expiry_interval));
Expand Down
5 changes: 1 addition & 4 deletions include/mqtt/broker/inflight_message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,12 @@ class inflight_message {
make_lambda_visitor(
[&](v5::basic_publish_message<sizeof(packet_id_t)> const& m) {
auto updated_msg = m;
auto& props = updated_msg.props();

auto d =
std::chrono::duration_cast<std::chrono::seconds>(
tim_message_expiry_->expiry() - std::chrono::steady_clock::now()
).count();
if (d < 0) d = 0;
set_property<v5::property::message_expiry_interval>(
props,
updated_msg.update_prop(
v5::property::message_expiry_interval(
static_cast<uint32_t>(d)
)
Expand Down
15 changes: 0 additions & 15 deletions include/mqtt/broker/session_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ struct session_state {
}
);

// TopicAlias lifetime is the same as Session lifetime
// It is different from MQTT v5 spec but practical choice.
// See
// https://lists.oasis-open.org/archives/mqtt-comment/202009/msg00000.html
topic_alias_recv_ = con_->get_topic_alias_recv_container();
reset_con();

if (session_expiry_interval_ &&
Expand Down Expand Up @@ -237,7 +232,6 @@ struct session_state {
}

void clean() {
topic_alias_recv_ = nullopt;
inflight_messages_.clear();
offline_messages_.clear();
qos2_publish_processed_.clear();
Expand Down Expand Up @@ -412,14 +406,6 @@ struct session_state {

std::shared_ptr<as::steady_timer>& get_tim_will_expiry() { return tim_will_expiry_; }

void restore_topic_alias_recv() {
BOOST_ASSERT(con_);
if (topic_alias_recv_) {
con_->restore_topic_alias_recv_container(force_move(topic_alias_recv_.value()));
topic_alias_recv_ = nullopt;
}
}

private:
friend class session_states;

Expand All @@ -435,7 +421,6 @@ struct session_state {
optional<std::chrono::steady_clock::duration> will_delay_;
optional<std::chrono::steady_clock::duration> session_expiry_interval_;
std::shared_ptr<as::steady_timer> tim_session_expiry_;
optional<topic_alias_recv_map_t> topic_alias_recv_;

inflight_messages inflight_messages_;
std::set<packet_id_t> qos2_publish_processed_;
Expand Down
2 changes: 1 addition & 1 deletion include/mqtt/broker/shared_target.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

#include <mqtt/buffer.hpp>
#include <mqtt/optional.hpp>
#include <mqtt/time_point_t.hpp>

#include <mqtt/broker/broker_namespace.hpp>
#include <mqtt/broker/session_state_fwd.hpp>
#include <mqtt/broker/time_point_t.hpp>
#include <mqtt/broker/tags.hpp>

MQTT_BROKER_NS_BEGIN
Expand Down
Loading

0 comments on commit be8bf34

Please sign in to comment.