mirror of
https://github.com/eclipse/mosquitto.git
synced 2025-05-09 01:01:11 +08:00
The broker now sends the receive-maximum property for MQTT v5 CONNACKs.
This commit is contained in:
parent
57ef576867
commit
4ae8971ce1
@ -55,6 +55,7 @@ Broker:
|
|||||||
- Document that X509_free() must be called after using
|
- Document that X509_free() must be called after using
|
||||||
mosquitto_client_certificate(). Closes #1842.
|
mosquitto_client_certificate(). Closes #1842.
|
||||||
- Add "deny" acl type. Closes #1611.
|
- Add "deny" acl type. Closes #1611.
|
||||||
|
- The broker now sends the receive-maximum property for MQTT v5 CONNACKs.
|
||||||
|
|
||||||
Client library:
|
Client library:
|
||||||
- Client no longer generates random client ids for v3.1.1 clients, these are
|
- Client no longer generates random client ids for v3.1.1 clients, these are
|
||||||
|
@ -51,13 +51,20 @@ int send__connack(struct mosquitto_db *db, struct mosquitto *context, uint8_t ac
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(db->config->max_packet_size > 0){
|
if(reason_code < 128 && db->config->max_packet_size > 0){
|
||||||
rc = mosquitto_property_add_int32(&connack_props, MQTT_PROP_MAXIMUM_PACKET_SIZE, db->config->max_packet_size);
|
rc = mosquitto_property_add_int32(&connack_props, MQTT_PROP_MAXIMUM_PACKET_SIZE, db->config->max_packet_size);
|
||||||
if(rc){
|
if(rc){
|
||||||
mosquitto_property_free_all(&connack_props);
|
mosquitto_property_free_all(&connack_props);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(reason_code < 128 && db->config->max_inflight_messages > 0){
|
||||||
|
rc = mosquitto_property_add_int16(&connack_props, MQTT_PROP_RECEIVE_MAXIMUM, db->config->max_inflight_messages);
|
||||||
|
if(rc){
|
||||||
|
mosquitto_property_free_all(&connack_props);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
remaining_length += property__get_remaining_length(connack_props);
|
remaining_length += property__get_remaining_length(connack_props);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ def do_test(per_listener, proto_ver, clean_start, allow_zero, client_port, expec
|
|||||||
# Remove the "xxxx" part - this means the front part of the packet
|
# Remove the "xxxx" part - this means the front part of the packet
|
||||||
# is correct (so remaining length etc. is correct), but we don't
|
# is correct (so remaining length etc. is correct), but we don't
|
||||||
# need to match against the random id.
|
# need to match against the random id.
|
||||||
connack_packet = connack_packet[:-36]
|
connack_packet = connack_packet[:-39]
|
||||||
|
|
||||||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port1, use_conf=True)
|
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port1, use_conf=True)
|
||||||
|
|
||||||
|
@ -8,17 +8,20 @@ from mosq_test_helper import *
|
|||||||
def write_config(filename, port):
|
def write_config(filename, port):
|
||||||
with open(filename, 'w') as f:
|
with open(filename, 'w') as f:
|
||||||
f.write("port %d\n" % (port))
|
f.write("port %d\n" % (port))
|
||||||
|
f.write("allow_anonymous true\n")
|
||||||
f.write("max_inflight_messages 1\n")
|
f.write("max_inflight_messages 1\n")
|
||||||
|
|
||||||
def do_test(proto_ver):
|
def do_test(proto_ver):
|
||||||
rc = 1
|
rc = 1
|
||||||
keepalive = 60
|
keepalive = 60
|
||||||
connect_packet = mosq_test.gen_connect("pub-qos1-test", keepalive=keepalive, proto_ver=proto_ver)
|
connect_packet = mosq_test.gen_connect("pub-qos1-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
properties = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS_MAXIMUM, 10) \
|
||||||
|
+ mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 1)
|
||||||
|
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver, properties=properties, property_helper=False)
|
||||||
|
|
||||||
mid = 311
|
mid = 311
|
||||||
publish_packet = mosq_test.gen_publish("pub/qos1/test", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
|
publish_packet = mosq_test.gen_publish("pub/qos1/test", qos=1, mid=mid, payload="message", proto_ver=proto_ver)
|
||||||
puback_packet = mosq_test.gen_puback(mid, proto_ver=proto_ver)
|
puback_packet = mosq_test.gen_puback(mid, reason_code=mqtt5_rc.MQTT_RC_NO_MATCHING_SUBSCRIBERS, proto_ver=proto_ver)
|
||||||
|
|
||||||
port = mosq_test.get_port()
|
port = mosq_test.get_port()
|
||||||
conf_file = os.path.basename(__file__).replace('.py', '.conf')
|
conf_file = os.path.basename(__file__).replace('.py', '.conf')
|
||||||
@ -47,5 +50,5 @@ def do_test(proto_ver):
|
|||||||
|
|
||||||
do_test(proto_ver=4)
|
do_test(proto_ver=4)
|
||||||
do_test(proto_ver=5)
|
do_test(proto_ver=5)
|
||||||
exit(rc)
|
exit(0)
|
||||||
|
|
||||||
|
@ -20,7 +20,9 @@ def do_test(proto_ver):
|
|||||||
rc = 1
|
rc = 1
|
||||||
keepalive = 60
|
keepalive = 60
|
||||||
connect_packet = mosq_test.gen_connect("pub-qos2-test", keepalive=keepalive, proto_ver=proto_ver)
|
connect_packet = mosq_test.gen_connect("pub-qos2-test", keepalive=keepalive, proto_ver=proto_ver)
|
||||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
|
properties = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS_MAXIMUM, 10) \
|
||||||
|
+ mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 1)
|
||||||
|
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver, properties=properties, property_helper=False)
|
||||||
|
|
||||||
mid = 312
|
mid = 312
|
||||||
publish_packet = mosq_test.gen_publish("pub/qos2/test", qos=2, mid=mid, payload="message", proto_ver=proto_ver)
|
publish_packet = mosq_test.gen_publish("pub/qos2/test", qos=2, mid=mid, payload="message", proto_ver=proto_ver)
|
||||||
|
@ -73,6 +73,7 @@ tests = [
|
|||||||
(1, './03-publish-dollar.py'),
|
(1, './03-publish-dollar.py'),
|
||||||
(1, './03-publish-invalid-utf8.py'),
|
(1, './03-publish-invalid-utf8.py'),
|
||||||
(1, './03-publish-long-topic.py'),
|
(1, './03-publish-long-topic.py'),
|
||||||
|
(1, './03-publish-qos1-max-inflight.py'),
|
||||||
(1, './03-publish-qos1-no-subscribers-v5.py'),
|
(1, './03-publish-qos1-no-subscribers-v5.py'),
|
||||||
(1, './03-publish-qos1-retain-disabled.py'),
|
(1, './03-publish-qos1-retain-disabled.py'),
|
||||||
(1, './03-publish-qos1.py'),
|
(1, './03-publish-qos1.py'),
|
||||||
|
@ -12,7 +12,7 @@ keepalive = 60
|
|||||||
connect_packet = mosq_test.gen_connect("publish-qos1-test", keepalive=keepalive, proto_ver=5)
|
connect_packet = mosq_test.gen_connect("publish-qos1-test", keepalive=keepalive, proto_ver=5)
|
||||||
|
|
||||||
props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 3)
|
props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 3)
|
||||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props)
|
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props, property_helper=False)
|
||||||
|
|
||||||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ keepalive = 60
|
|||||||
connect_packet = mosq_test.gen_connect("publish-qos2-test", keepalive=keepalive, proto_ver=5)
|
connect_packet = mosq_test.gen_connect("publish-qos2-test", keepalive=keepalive, proto_ver=5)
|
||||||
|
|
||||||
props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 1)
|
props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 1)
|
||||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props)
|
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props, property_helper=False)
|
||||||
|
|
||||||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ keepalive = 60
|
|||||||
connect_packet = mosq_test.gen_connect("publish-qos2-test", keepalive=keepalive, proto_ver=5)
|
connect_packet = mosq_test.gen_connect("publish-qos2-test", keepalive=keepalive, proto_ver=5)
|
||||||
|
|
||||||
props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 1)
|
props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 1)
|
||||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props)
|
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props, property_helper=False)
|
||||||
|
|
||||||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ keepalive = 60
|
|||||||
connect_packet = mosq_test.gen_connect("publish-qos2-test", keepalive=keepalive, proto_ver=5)
|
connect_packet = mosq_test.gen_connect("publish-qos2-test", keepalive=keepalive, proto_ver=5)
|
||||||
|
|
||||||
props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 2)
|
props = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 2)
|
||||||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props)
|
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5, properties=props, property_helper=False)
|
||||||
|
|
||||||
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
disconnect_packet = mosq_test.gen_disconnect(proto_ver=5)
|
||||||
|
|
||||||
|
@ -444,12 +444,14 @@ def gen_connect(client_id, clean_session=True, keepalive=60, username=None, pass
|
|||||||
packet = packet + struct.pack("!H"+str(len(password))+"s", len(password), password)
|
packet = packet + struct.pack("!H"+str(len(password))+"s", len(password), password)
|
||||||
return packet
|
return packet
|
||||||
|
|
||||||
def gen_connack(flags=0, rc=0, proto_ver=4, properties=b""):
|
def gen_connack(flags=0, rc=0, proto_ver=4, properties=b"", property_helper=True):
|
||||||
if proto_ver == 5:
|
if proto_ver == 5:
|
||||||
if properties is not None:
|
if property_helper == True:
|
||||||
properties = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS_MAXIMUM, 10) + properties
|
if properties is not None:
|
||||||
else:
|
properties = mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_TOPIC_ALIAS_MAXIMUM, 10) \
|
||||||
properties = b""
|
+ properties + mqtt5_props.gen_uint16_prop(mqtt5_props.PROP_RECEIVE_MAXIMUM, 20)
|
||||||
|
else:
|
||||||
|
properties = b""
|
||||||
properties = mqtt5_props.prop_finalise(properties)
|
properties = mqtt5_props.prop_finalise(properties)
|
||||||
|
|
||||||
packet = struct.pack('!BBBB', 32, 2+len(properties), flags, rc) + properties
|
packet = struct.pack('!BBBB', 32, 2+len(properties), flags, rc) + properties
|
||||||
|
Loading…
x
Reference in New Issue
Block a user