增加协议版本,新版本添加对gzip的支持
This commit is contained in:
@@ -23,6 +23,7 @@ import io.moquette.spi.ClientSession;
|
||||
import io.moquette.spi.IMessagesStore.StoredMessage;
|
||||
import io.moquette.spi.ISessionsStore;
|
||||
|
||||
import io.netty.handler.codec.mqtt.MqttVersion;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
@@ -49,6 +50,8 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
|
||||
private volatile int unReceivedMsgs;
|
||||
|
||||
private MqttVersion mqttVersion = MqttVersion.MQTT_3_1_1;
|
||||
|
||||
public long getLastActiveTime() {
|
||||
return lastActiveTime;
|
||||
}
|
||||
@@ -230,7 +233,13 @@ public class MemorySessionStore implements ISessionsStore {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public MqttVersion getMqttVersion() {
|
||||
return mqttVersion;
|
||||
}
|
||||
|
||||
public void setMqttVersion(MqttVersion mqttVersion) {
|
||||
this.mqttVersion = mqttVersion;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<String, Session> sessions = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user