Skip to content

Commit

Permalink
Implement max_topic_levels configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rmqtt committed Aug 25, 2023
1 parent 15a9496 commit 69ac9a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rmqtt/src/broker/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub enum MqttError {
Utf8Error(#[from] Utf8Error),
#[error("too many subscriptions")]
TooManySubscriptions,
#[error("too many topic levels")]
TooManyTopicLevels,
#[error("{0}")]
ConfigError(#[from] ConfigError),
#[error("{0}")]
Expand Down
7 changes: 7 additions & 0 deletions rmqtt/src/broker/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::fmt;
use std::num::NonZeroU16;
use std::ops::Deref;
use std::rc::Rc;
use std::str::FromStr;
use std::sync::atomic::{AtomicBool, AtomicI64, Ordering};
use std::sync::Arc;

Expand Down Expand Up @@ -637,6 +638,12 @@ impl SessionState {
return Err(MqttError::TooManySubscriptions);
}

if self.listen_cfg.max_topic_levels > 0
&& Topic::from_str(&sub.topic_filter)?.len() > self.listen_cfg.max_topic_levels
{
return Err(MqttError::TooManyTopicLevels);
}

sub.opts.set_qos(sub.opts.qos().less_value(self.listen_cfg.max_qos_allowed));

//hook, client_subscribe
Expand Down

0 comments on commit 69ac9a9

Please sign in to comment.