Skip to content

Commit

Permalink
Merge pull request #113 from quartiq/feature/subscription-codes
Browse files Browse the repository at this point in the history
Removing arbitrary limit on subscription topic count
  • Loading branch information
ryan-summers authored Sep 19, 2022
2 parents e028556 + e7e1e53 commit 65fe11b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 22 deletions.
10 changes: 2 additions & 8 deletions src/de/received_packet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
message_types::MessageType,
packets::{ConnAck, Disconnect, Pub, PubAck, PubComp, PubRec, SubAck},
reason_codes::ReasonCode,
varint::Varint,
ProtocolError, QoS, Retain,
};
Expand Down Expand Up @@ -38,12 +37,7 @@ impl<'a> ReceivedPacket<'a> {
publish.payload = remaining_payload;
}
ReceivedPacket::SubAck(suback) => {
for code in remaining_payload.iter().map(|&x| ReasonCode::from(x)) {
suback
.codes
.push(code)
.map_err(|_| ProtocolError::BufferSize)?;
}
suback.codes = remaining_payload;
}
_ => return Err(ProtocolError::MalformedPacket),
}
Expand Down Expand Up @@ -222,7 +216,7 @@ mod test {
match packet {
ReceivedPacket::SubAck(sub_ack) => {
assert_eq!(sub_ack.codes.len(), 1);
assert_eq!(sub_ack.codes[0], ReasonCode::GrantedQos2);
assert_eq!(ReasonCode::from(sub_ack.codes[0]), ReasonCode::GrantedQos2);
assert_eq!(sub_ack.packet_identifier, 5);
}
_ => panic!("Invalid message"),
Expand Down
4 changes: 0 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ pub const MQTT_INSECURE_DEFAULT_PORT: u16 = 1883;
/// See [IANA Port Numbers](https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt)
pub const MQTT_SECURE_DEFAULT_PORT: u16 = 8883;

/// The maximum number of subscriptions supported in a single request.
pub const MAX_TOPICS_PER_SUBSCRIPTION: usize = 8;

/// The quality-of-service for an MQTT message.
#[derive(Debug, Copy, Clone, PartialEq, TryFromPrimitive, PartialOrd)]
#[repr(u8)]
Expand Down Expand Up @@ -184,7 +181,6 @@ pub enum Error<E> {
Protocol(ProtocolError),
SessionReset,
Clock(embedded_time::clock::Error),
TooManyTopics,
}

impl<E> From<embedded_time::clock::Error> for Error<E> {
Expand Down
10 changes: 2 additions & 8 deletions src/mqtt_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ where
Some(index) => self.session_state.pending_subscriptions.swap_remove(index),
};

for code in subscribe_acknowledge.codes.iter() {
code.as_result()?;
for &code in subscribe_acknowledge.codes.iter() {
ReasonCode::from(code).as_result()?;
}

Ok(())
Expand Down Expand Up @@ -266,12 +266,6 @@ impl<
return Err(Error::NotReady);
}

// We can only support so many received response codes. As such, make sure that we don't
// allow too many concurrent topics.
if topics.len() > crate::MAX_TOPICS_PER_SUBSCRIPTION {
return Err(Error::TooManyTopics);
}

// We can't subscribe if there's a pending write in the network.
if self.network.has_pending_write() {
return Err(Error::NotReady);
Expand Down
3 changes: 1 addition & 2 deletions src/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{
QoS, Retain,
};
use bit_field::BitField;
use heapless::Vec;
use serde::{Deserialize, Serialize};

use serde::ser::SerializeStruct;
Expand Down Expand Up @@ -142,7 +141,7 @@ pub struct SubAck<'a> {

/// The response status code of the subscription request.
#[serde(skip)]
pub codes: Vec<ReasonCode, { crate::MAX_TOPICS_PER_SUBSCRIPTION }>,
pub codes: &'a [u8],
}

/// An MQTT PUBREC control packet
Expand Down

0 comments on commit 65fe11b

Please sign in to comment.