增加协议版本,新版本添加对gzip的支持

This commit is contained in:
heavyrain.lee
2019-05-27 10:06:22 +08:00
parent d3aa68df05
commit b4b70ca7e5
6 changed files with 32 additions and 10 deletions
@@ -143,7 +143,8 @@ public class ProtocolProcessor {
LOG.info("Processing CONNECT message. CId={}, username={}", clientId, payload.userName());
if (msg.variableHeader().version() != MqttVersion.MQTT_3_1.protocolLevel()
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()) {
&& msg.variableHeader().version() != MqttVersion.MQTT_3_1_1.protocolLevel()
&& msg.variableHeader().version() != MqttVersion.Wildfire_1.protocolLevel()) {
MqttConnAckMessage badProto = connAck(CONNECTION_REFUSED_UNACCEPTABLE_PROTOCOL_VERSION);
LOG.error("MQTT protocol version is not valid. CId={}", clientId);
@@ -162,7 +163,8 @@ public class ProtocolProcessor {
}
if (!login(channel, msg, clientId)) {
MqttVersion mqttVersion = MqttVersion.fromProtocolLevel(msg.variableHeader().version());
if (!login(channel, msg, clientId, mqttVersion)) {
channel.close();
return;
}
@@ -238,7 +240,7 @@ public class ProtocolProcessor {
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(returnCode, sessionPresent);
return new MqttConnAckMessage(mqttFixedHeader, mqttConnAckVariableHeader, new MqttConnectAckPayload(data));
}
private boolean login(Channel channel, MqttConnectMessage msg, final String clientId) {
private boolean login(Channel channel, MqttConnectMessage msg, final String clientId, MqttVersion mqttVersion) {
// handle user authentication
if (msg.variableHeader().hasUserName()) {
int status = m_messagesStore.getUserStatus(msg.payload().userName());
@@ -269,6 +271,7 @@ public class ProtocolProcessor {
failedCredentials(channel);
return false;
}
session.setMqttVersion(mqttVersion);
} else if (!this.allowAnonymous) {
LOG.error("Client didn't supply any password and MQTT anonymous mode is disabled CId={}", clientId);
failedCredentials(channel);
@@ -41,6 +41,7 @@ import io.moquette.server.ConnectionDescriptor;
import io.moquette.server.Server;
import io.moquette.spi.ClientSession;
import io.moquette.spi.impl.security.AES;
import io.netty.handler.codec.mqtt.MqttVersion;
import io.netty.util.ReferenceCountUtil;
import io.netty.util.internal.StringUtil;
import org.slf4j.Logger;
@@ -177,7 +178,7 @@ public class Qos1PublishHandler extends QosPublishHandler {
} else {
MemorySessionStore.Session session = m_sessionStore.getSession(clientID);
if (session != null && session.getUsername().equals(fromUser)) {
if (data.length > 10*1024) {
if (data.length > 7*1024 && session.getMqttVersion() == MqttVersion.Wildfire_1) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip;
try {