Fixing QOSType encoding and decoding of FAILURE qos (0x80). This was causing bug with decoding a SubAck with failure qos type. See Appendix B: MQTT-3.9.3-2

This commit is contained in:
Victor Kazakov
2015-09-23 16:30:40 -07:00
parent 33bc23b4e1
commit 767e2ba4b7
12 changed files with 95 additions and 23 deletions
@@ -224,7 +224,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
//Handle will flag
if (msg.isWillFlag()) {
AbstractMessage.QOSType willQos = AbstractMessage.QOSType.values()[msg.getWillQos()];
AbstractMessage.QOSType willQos = AbstractMessage.QOSType.valueOf(msg.getWillQos());
byte[] willPayload = msg.getWillMessage();
ByteBuffer bb = (ByteBuffer) ByteBuffer.allocate(willPayload.length).put(willPayload).flip();
//save the will testament in the clientID store
@@ -391,7 +391,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
}
for (final Subscription sub : subscriptions.matches(topic)) {
AbstractMessage.QOSType qos = publishingQos;
if (qos.ordinal() > sub.getRequestedQos().ordinal()) {
if (qos.byteValue() > sub.getRequestedQos().byteValue()) {
qos = sub.getRequestedQos();
}
@@ -637,7 +637,7 @@ class ProtocolProcessor implements EventHandler<ValueEvent> {
ackMessage.setMessageID(msg.getMessageID());
for (SubscribeMessage.Couple req : msg.subscriptions()) {
AbstractMessage.QOSType qos = AbstractMessage.QOSType.values()[req.getQos()];
AbstractMessage.QOSType qos = AbstractMessage.QOSType.valueOf(req.getQos());
Subscription newSubscription = new Subscription(clientID, req.getTopicFilter(), qos, cleanSession);
boolean valid = subscribeSingleTopic(newSubscription, req.getTopicFilter());
ackMessage.addType(valid ? qos : AbstractMessage.QOSType.FAILURE);
@@ -237,7 +237,7 @@ public class SubscriptionsStore {
for (Subscription sub : matchingSubs) {
Subscription existingSub = subsForClient.get(sub.getClientId());
//update the selected subscriptions if not present or if has a greater qos
if (existingSub == null || existingSub.getRequestedQos().ordinal() < sub.getRequestedQos().ordinal()) {
if (existingSub == null || existingSub.getRequestedQos().byteValue() < sub.getRequestedQos().byteValue()) {
subsForClient.put(sub.getClientId(), sub);
}
}