-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add maximum-qos support to broker and client.
This comes in the form of: * Per listener maximum_qos option, which can be in the range 0-2. * Changes to mosquitto_publish*() to return MOSQ_ERR_QOS_NOT_SUPPORTED if attempting to publish with a higher QoS than supported. * Bridges will downgrade messages to match the maximum QoS. More tests on the broker side (specifically bridges) are required. This needs bridge support for MQTT 5 first.
- Loading branch information
Showing
20 changed files
with
323 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python | ||
|
||
# Test whether a client correctly handles sending a message with QoS > maximum QoS. | ||
|
||
from mosq_test_helper import * | ||
|
||
port = mosq_test.get_lib_port() | ||
|
||
rc = 1 | ||
keepalive = 60 | ||
connect_packet = mosq_test.gen_connect("publish-qos2-test", keepalive=keepalive, proto_ver=5) | ||
|
||
props = mqtt5_props.gen_byte_prop(mqtt5_props.PROP_MAXIMUM_QOS, 0) | ||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props) | ||
|
||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5) | ||
|
||
publish_1_packet = mosq_test.gen_publish("maximum/qos/qos0", qos=0, payload="message", proto_ver=5) | ||
|
||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5) | ||
|
||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
sock.settimeout(10) | ||
sock.bind(('', port)) | ||
sock.listen(5) | ||
|
||
|
||
client_args = sys.argv[1:] | ||
env = dict(os.environ) | ||
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp' | ||
try: | ||
pp = env['PYTHONPATH'] | ||
except KeyError: | ||
pp = '' | ||
env['PYTHONPATH'] = '../../lib/python:'+pp | ||
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port) | ||
|
||
|
||
try: | ||
(conn, address) = sock.accept() | ||
conn.settimeout(10) | ||
|
||
if mosq_test.expect_packet(conn, "connect", connect_packet): | ||
conn.send(connack_packet) | ||
|
||
if mosq_test.expect_packet(conn, "publish 1", publish_1_packet): | ||
if mosq_test.expect_packet(conn, "disconnect", disconnect_packet): | ||
rc = 0 | ||
|
||
conn.close() | ||
finally: | ||
for i in range(0, 5): | ||
if client.returncode != None: | ||
break | ||
time.sleep(0.1) | ||
|
||
try: | ||
client.terminate() | ||
except OSError: | ||
pass | ||
|
||
client.wait() | ||
sock.close() | ||
if client.returncode != 0: | ||
exit(1) | ||
|
||
exit(rc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env python | ||
|
||
# Test whether a client correctly handles sending a message with QoS > maximum QoS. | ||
|
||
from mosq_test_helper import * | ||
|
||
port = mosq_test.get_lib_port() | ||
|
||
rc = 1 | ||
keepalive = 60 | ||
connect_packet = mosq_test.gen_connect("publish-qos2-test", keepalive=keepalive, proto_ver=5) | ||
|
||
props = mqtt5_props.gen_byte_prop(mqtt5_props.PROP_MAXIMUM_QOS, 1) | ||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props) | ||
|
||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5) | ||
|
||
mid = 1 | ||
publish_1_packet = mosq_test.gen_publish("maximum/qos/qos1", qos=1, mid=mid, payload="message", proto_ver=5) | ||
puback_1_packet = mosq_test.gen_puback(mid, proto_ver=5) | ||
|
||
publish_2_packet = mosq_test.gen_publish("maximum/qos/qos0", qos=0, payload="message", proto_ver=5) | ||
|
||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5) | ||
|
||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | ||
sock.settimeout(10) | ||
sock.bind(('', port)) | ||
sock.listen(5) | ||
|
||
|
||
client_args = sys.argv[1:] | ||
env = dict(os.environ) | ||
env['LD_LIBRARY_PATH'] = '../../lib:../../lib/cpp' | ||
try: | ||
pp = env['PYTHONPATH'] | ||
except KeyError: | ||
pp = '' | ||
env['PYTHONPATH'] = '../../lib/python:'+pp | ||
client = mosq_test.start_client(filename=sys.argv[1].replace('/', '-'), cmd=client_args, env=env, port=port) | ||
|
||
|
||
try: | ||
(conn, address) = sock.accept() | ||
conn.settimeout(10) | ||
|
||
if mosq_test.expect_packet(conn, "connect", connect_packet): | ||
conn.send(connack_packet) | ||
|
||
if mosq_test.expect_packet(conn, "publish 1", publish_1_packet): | ||
conn.send(puback_1_packet) | ||
if mosq_test.expect_packet(conn, "publish 2", publish_2_packet): | ||
if mosq_test.expect_packet(conn, "disconnect", disconnect_packet): | ||
rc = 0 | ||
|
||
conn.close() | ||
finally: | ||
for i in range(0, 5): | ||
if client.returncode != None: | ||
break | ||
time.sleep(0.1) | ||
|
||
try: | ||
client.terminate() | ||
except OSError: | ||
pass | ||
|
||
client.wait() | ||
sock.close() | ||
if client.returncode != 0: | ||
exit(1) | ||
|
||
exit(rc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <mosquitto.h> | ||
|
||
static int run = -1; | ||
|
||
void on_connect(struct mosquitto *mosq, void *obj, int rc) | ||
{ | ||
if(rc){ | ||
exit(1); | ||
}else{ | ||
rc = mosquitto_publish(mosq, NULL, "maximum/qos/qos2", strlen("message"), "message", 2, false); | ||
if(rc != MOSQ_ERR_QOS_NOT_SUPPORTED) run = 1; | ||
rc = mosquitto_publish(mosq, NULL, "maximum/qos/qos1", strlen("message"), "message", 1, false); | ||
if(rc != MOSQ_ERR_QOS_NOT_SUPPORTED) run = 1; | ||
rc = mosquitto_publish(mosq, NULL, "maximum/qos/qos0", strlen("message"), "message", 0, false); | ||
if(rc != MOSQ_ERR_SUCCESS) run = 1; | ||
} | ||
} | ||
|
||
void on_publish(struct mosquitto *mosq, void *obj, int mid) | ||
{ | ||
if(mid == 1){ | ||
mosquitto_disconnect(mosq); | ||
} | ||
} | ||
|
||
void on_disconnect(struct mosquitto *mosq, void *obj, int rc) | ||
{ | ||
run = 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int rc; | ||
struct mosquitto *mosq; | ||
|
||
int port = atoi(argv[1]); | ||
|
||
mosquitto_lib_init(); | ||
|
||
mosq = mosquitto_new("publish-qos2-test", true, NULL); | ||
mosquitto_int_option(mosq, MOSQ_OPT_PROTOCOL_VERSION, MQTT_PROTOCOL_V5); | ||
mosquitto_connect_callback_set(mosq, on_connect); | ||
mosquitto_disconnect_callback_set(mosq, on_disconnect); | ||
mosquitto_publish_callback_set(mosq, on_publish); | ||
|
||
rc = mosquitto_connect(mosq, "localhost", port, 60); | ||
|
||
while(run == -1){ | ||
mosquitto_loop(mosq, 50, 1); | ||
} | ||
|
||
mosquitto_lib_cleanup(); | ||
return run; | ||
} |
Oops, something went wrong.