mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 03:24:33 +08:00
Add support for MQTT 3.1.1 Bridge flag.
This commit is contained in:
@@ -33,7 +33,8 @@ namespace MQTTnet.Formatter
|
||||
RequestResponseInformation = clientOptions.RequestResponseInformation,
|
||||
SessionExpiryInterval = clientOptions.SessionExpiryInterval,
|
||||
TopicAliasMaximum = clientOptions.TopicAliasMaximum,
|
||||
UserProperties = clientOptions.UserProperties
|
||||
UserProperties = clientOptions.UserProperties,
|
||||
TryPrivate = clientOptions.TryPrivate
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(clientOptions.WillTopic))
|
||||
|
||||
@@ -95,6 +95,10 @@ namespace MQTTnet.Formatter
|
||||
var protocolName = _bufferReader.ReadString();
|
||||
var protocolLevel = _bufferReader.ReadByte();
|
||||
|
||||
// Remove the mosquitto try_private flag (MQTT 3.1.1 Bridge).
|
||||
// This flag is accepted but not yet used.
|
||||
protocolLevel &= 0x7F;
|
||||
|
||||
if (protocolName == "MQTT")
|
||||
{
|
||||
if (protocolLevel == 5)
|
||||
|
||||
@@ -175,12 +175,18 @@ namespace MQTTnet.Formatter.V3
|
||||
throw new MqttProtocolViolationException("MQTT protocol name do not match MQTT v3.");
|
||||
}
|
||||
|
||||
var tryPrivate = (protocolVersion & 0x80) > 0;
|
||||
protocolVersion &= 0x7F;
|
||||
|
||||
if (protocolVersion != 3 && protocolVersion != 4)
|
||||
{
|
||||
throw new MqttProtocolViolationException("MQTT protocol version do not match MQTT v3.");
|
||||
}
|
||||
|
||||
var packet = new MqttConnectPacket();
|
||||
var packet = new MqttConnectPacket
|
||||
{
|
||||
TryPrivate = tryPrivate
|
||||
};
|
||||
|
||||
var connectFlags = _bufferReader.ReadByte();
|
||||
if ((connectFlags & 0x1) > 0)
|
||||
@@ -409,7 +415,14 @@ namespace MQTTnet.Formatter.V3
|
||||
ValidateConnectPacket(packet);
|
||||
|
||||
bufferWriter.WriteString("MQIsdp");
|
||||
bufferWriter.WriteByte(3); // Protocol Level 3
|
||||
|
||||
var protocolVersion = 3;
|
||||
if (packet.TryPrivate)
|
||||
{
|
||||
protocolVersion |= 0x80;
|
||||
}
|
||||
|
||||
bufferWriter.WriteByte((byte)protocolVersion);
|
||||
|
||||
byte connectFlags = 0x0;
|
||||
if (packet.CleanSession)
|
||||
|
||||
Reference in New Issue
Block a user