Improve protocol version detection.

This commit is contained in:
Christian Kratky
2019-04-11 20:13:30 +02:00
parent 631f660d5c
commit 65896269da
4 changed files with 29 additions and 24 deletions
@@ -8,7 +8,7 @@ namespace MQTTnet.Client.Options
public int? Port { get; set; }
public int BufferSize { get; set; } = 1024;
public int BufferSize { get; set; } = 65536;
public bool DualMode { get; set; } = true;
@@ -227,11 +227,20 @@ namespace MQTTnet.Formatter.V3
{
ThrowIfBodyIsEmpty(body);
var packet = new MqttConnectPacket
var protocolName = body.ReadStringWithLengthPrefix();
var protocolVersion = body.ReadByte();
if (protocolName != "MQTT" && protocolName != "MQIsdp")
{
ProtocolName = body.ReadStringWithLengthPrefix(),
ProtocolLevel = body.ReadByte()
};
throw new MqttProtocolViolationException("MQTT protocol name do not match MQTT v3.");
}
if (protocolVersion != 3 && protocolVersion != 4)
{
throw new MqttProtocolViolationException("MQTT protocol version do not match MQTT v3.");
}
var packet = new MqttConnectPacket();
var connectFlags = body.ReadByte();
if ((connectFlags & 0x1) > 0)
+1 -5
View File
@@ -2,10 +2,6 @@
{
public class MqttConnectPacket : MqttBasePacket
{
public string ProtocolName { get; set; }
public byte? ProtocolLevel { get; set; }
public string ClientId { get; set; }
public string Username { get; set; }
@@ -33,7 +29,7 @@
password = "****";
}
return string.Concat("Connect: [ProtocolLevel=", ProtocolLevel, "] [ClientId=", ClientId, "] [Username=", Username, "] [Password=", password, "] [KeepAlivePeriod=", KeepAlivePeriod, "] [CleanSession=", CleanSession, "]");
return string.Concat("Connect: [ClientId=", ClientId, "] [Username=", Username, "] [Password=", password, "] [KeepAlivePeriod=", KeepAlivePeriod, "] [CleanSession=", CleanSession, "]");
}
}
}