Fixed bug #108, remove of clientID for a stolen session the new session get immediately removed
This commit is contained in:
@@ -31,11 +31,13 @@ public class NettyChannel implements ServerChannel {
|
||||
private ChannelHandlerContext m_channel;
|
||||
|
||||
public static final String ATTR_USERNAME = "username";
|
||||
public static final String ATTR_SESSION_STOLEN = "sessionStolen";
|
||||
|
||||
public static final AttributeKey<Object> ATTR_KEY_KEEPALIVE = AttributeKey.valueOf(Constants.KEEP_ALIVE);
|
||||
public static final AttributeKey<Object> ATTR_KEY_CLEANSESSION = AttributeKey.valueOf(Constants.CLEAN_SESSION);
|
||||
public static final AttributeKey<Object> ATTR_KEY_CLIENTID = AttributeKey.valueOf(Constants.ATTR_CLIENTID);
|
||||
public static final AttributeKey<Object> ATTR_KEY_USERNAME = AttributeKey.valueOf(ATTR_USERNAME);
|
||||
public static final AttributeKey<Object> ATTR_KEY_SESSION_STOLEN = AttributeKey.valueOf(ATTR_SESSION_STOLEN);
|
||||
|
||||
NettyChannel(ChannelHandlerContext ctx) {
|
||||
m_channel = ctx;
|
||||
|
||||
@@ -98,9 +98,14 @@ public class NettyMQTTHandler extends ChannelInboundHandlerAdapter {
|
||||
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
|
||||
String clientID = (String) NettyUtils.getAttribute(ctx, NettyChannel.ATTR_KEY_CLIENTID);
|
||||
if (clientID != null && !clientID.isEmpty()) {
|
||||
//if the channel was of a correctly connected client, inform messagin
|
||||
//else it was of a not completed CONNECT message
|
||||
m_processor.processConnectionLost(new LostConnectionEvent(clientID));
|
||||
//if the channel was of a correctly connected client, inform messaging
|
||||
//else it was of a not completed CONNECT message or sessionStolen
|
||||
boolean stolen = false;
|
||||
Boolean stolenAttr = (Boolean) NettyUtils.getAttribute(ctx, NettyChannel.ATTR_KEY_SESSION_STOLEN);
|
||||
if (stolenAttr != null && stolenAttr == Boolean.TRUE) {
|
||||
stolen = stolenAttr;
|
||||
}
|
||||
m_processor.processConnectionLost(new LostConnectionEvent(clientID, stolen));
|
||||
}
|
||||
ctx.close(/*false*/);
|
||||
}
|
||||
|
||||
@@ -181,6 +181,7 @@ public class ProtocolProcessor {
|
||||
cleanSession(msg.getClientID());
|
||||
}
|
||||
|
||||
oldSession.setAttribute(NettyChannel.ATTR_KEY_SESSION_STOLEN, true);
|
||||
oldSession.close(false);
|
||||
LOG.debug("Existing connection with same client ID <{}>, forced to close", msg.getClientID());
|
||||
}
|
||||
@@ -544,14 +545,13 @@ public class ProtocolProcessor {
|
||||
public void processConnectionLost(LostConnectionEvent evt) {
|
||||
String clientID = evt.clientID;
|
||||
//If already removed a disconnect message was already processed for this clientID
|
||||
if (m_clientIDs.remove(clientID) != null) {
|
||||
|
||||
if (evt.sessionStolen && m_clientIDs.remove(clientID) != null) {
|
||||
//de-activate the subscriptions for this ClientID
|
||||
subscriptions.deactivate(clientID);
|
||||
LOG.info("Lost connection with client <{}>", clientID);
|
||||
}
|
||||
//publish the Will message (if any) for the clientID
|
||||
if (m_willStore.containsKey(clientID)) {
|
||||
if (!evt.sessionStolen && m_willStore.containsKey(clientID)) {
|
||||
WillMessage will = m_willStore.get(clientID);
|
||||
forwardPublishWill(will, clientID);
|
||||
m_willStore.remove(clientID);
|
||||
|
||||
@@ -15,19 +15,21 @@
|
||||
*/
|
||||
package org.eclipse.moquette.spi.impl.events;
|
||||
|
||||
import org.eclipse.moquette.server.ServerChannel;
|
||||
|
||||
/**
|
||||
* Used to model the connection lost event
|
||||
*
|
||||
* @author andrea
|
||||
*/
|
||||
public class LostConnectionEvent extends MessagingEvent {
|
||||
// public final ServerChannel session;
|
||||
public final String clientID;
|
||||
public final boolean sessionStolen;
|
||||
|
||||
public LostConnectionEvent(/*ServerChannel session, */String clientID) {
|
||||
// this.session = session;
|
||||
public LostConnectionEvent(String clientID) {
|
||||
this(clientID, false);
|
||||
}
|
||||
|
||||
public LostConnectionEvent(String clientID, boolean stolen) {
|
||||
this.clientID = clientID;
|
||||
this.sessionStolen = stolen;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user