Skip to content

Commit

Permalink
Add the bridge_max_packet_size option.
Browse files Browse the repository at this point in the history
Closes #265.
  • Loading branch information
ralight committed Oct 27, 2020
1 parent 916c374 commit d8f5aac
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Broker:
- The broker now sends the receive-maximum property for MQTT v5 CONNACKs.
- mosquitto_password now forbids the : character. Closes #1833.
- Fix `log_timestamp_format` not applying to `log_dest topic`. Closes #1862.
- Add the `bridge_max_packet_size` option. Closes #265.

Client library:
- Client no longer generates random client ids for v3.1.1 clients, these are
Expand Down
14 changes: 14 additions & 0 deletions man/mosquitto.conf.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,20 @@ openssl dhparam -out dhparam.pem 2048</programlisting>
<replaceable>true</replaceable>.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>bridge_max_packet_size</option> <replaceable>value</replaceable></term>
<listitem>
<para>
If you wish to restrict the size of messages sent to a
remote bridge, use this option. This sets the maximum
number of bytes for the total message, including headers
and payload. Note that MQTT v5 brokers may provide their
own maximum-packet-size property. In this case, the
smaller of the two limits will be used. Set to 0 for
"unlimited".
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>bridge_outgoing_retain</option> [ true | false ]</term>
<listitem>
Expand Down
8 changes: 8 additions & 0 deletions mosquitto.conf
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,14 @@
# all outgoing messages to that bridge, regardless of any other setting.
#bridge_outgoing_retain true

# If you wish to restrict the size of messages sent to a remote bridge, use the
# bridge_max_packet_size option. This sets the maximum number of bytes for
# the total message, including headers and payload.
# Note that MQTT v5 brokers may provide their own maximum-packet-size property.
# In this case, the smaller of the two limits will be used.
# Set to 0 for "unlimited".
#bridge_max_packet_size 0


# -----------------------------------------------------------------
# Certificate based SSL/TLS support
Expand Down
2 changes: 2 additions & 0 deletions src/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ int bridge__connect_step1(struct mosquitto_db *db, struct mosquitto *context)
context->in_packet.payload = NULL;
context->ping_t = 0;
context->bridge->lazy_reconnect = false;
context->maximum_packet_size = context->bridge->maximum_packet_size;
bridge__packet_cleanup(context);
db__message_reconnect_reset(db, context);

Expand Down Expand Up @@ -339,6 +340,7 @@ int bridge__connect(struct mosquitto_db *db, struct mosquitto *context)
context->in_packet.payload = NULL;
context->ping_t = 0;
context->bridge->lazy_reconnect = false;
context->maximum_packet_size = context->bridge->maximum_packet_size;
bridge__packet_cleanup(context);
db__message_reconnect_reset(db, context);

Expand Down
13 changes: 13 additions & 0 deletions src/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,19 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, struct
if(conf__parse_bool(&token, "bridge_require_ocsp", &cur_bridge->tls_ocsp_required, saveptr)) return MOSQ_ERR_INVAL;
#else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: TLS support not available.");
#endif
}else if(!strcmp(token, "bridge_max_packet_size")){
#if defined(WITH_BRIDGE)
if(reload) continue; // Bridges not valid for reloading.
if(!cur_bridge){
log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid bridge configuration.");
return MOSQ_ERR_INVAL;
}
if(conf__parse_int(&token, "bridge_max_packet_size", &tmp_int, saveptr)) return MOSQ_ERR_INVAL;
if(tmp_int < 0) tmp_int = 0;
cur_bridge->maximum_packet_size = (uint32_t)tmp_int;
#else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Bridge support not available.");
#endif
}else if(!strcmp(token, "bridge_outgoing_retain")){
#if defined(WITH_BRIDGE)
Expand Down
10 changes: 10 additions & 0 deletions src/handle_connack.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context)
uint8_t connect_acknowledge;
uint8_t reason_code;
mosquitto_property *properties = NULL;
uint32_t maximum_packet_size;

if(!context){
return MOSQ_ERR_INVAL;
Expand All @@ -55,6 +56,15 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context)
}
rc = property__read_all(CMD_CONNACK, &context->in_packet, &properties);
if(rc) return rc;

if(mosquitto_property_read_int32(properties, MQTT_PROP_MAXIMUM_PACKET_SIZE,
&maximum_packet_size, false)){

if(context->maximum_packet_size == 0 || context->maximum_packet_size > maximum_packet_size){
context->maximum_packet_size = maximum_packet_size;
}
}

mosquitto_property_free_all(&properties);
}
mosquitto_property_free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
Expand Down
1 change: 1 addition & 0 deletions src/mosquitto_broker_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ struct mosquitto__bridge{
int backoff_base;
int backoff_cap;
int threshold;
uint32_t maximum_packet_size;
bool lazy_reconnect;
bool attempt_unsubscribe;
bool initial_notification_done;
Expand Down

0 comments on commit d8f5aac

Please sign in to comment.