Skip to content

Commit 6c4c136

Browse files
dsshfdsoulayrol
authored andcommitted
Added configuration item for handshake timeout on SSL channel (#531)
1 parent 3a61b14 commit 6c4c136

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

broker/src/main/java/io/moquette/BrokerConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public final class BrokerConstants {
7878
public static final String NETTY_TCP_NODELAY_PROPERTY_NAME = "netty.tcp_nodelay";
7979
public static final String NETTY_SO_KEEPALIVE_PROPERTY_NAME = "netty.so_keepalive";
8080
public static final String NETTY_CHANNEL_TIMEOUT_SECONDS_PROPERTY_NAME = "netty.channel_timeout.seconds";
81+
public static final String NETTY_CHANNEL_HANDSHAKE_TIMEOUT_SECONDS_PROPERTY_NAME = "netty.channel_handshake_timeout.seconds";
8182
public static final String NETTY_EPOLL_PROPERTY_NAME = "netty.epoll";
8283
public static final String NETTY_MAX_BYTES_PROPERTY_NAME = "netty.mqtt.message_size";
8384
public static final int DEFAULT_NETTY_MAX_BYTES_IN_MESSAGE = 8092;

broker/src/main/java/io/moquette/broker/NewNettyAcceptor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public void operationComplete(ChannelFuture future) throws Exception {
133133
private boolean nettyTcpNodelay;
134134
private boolean nettySoKeepalive;
135135
private int nettyChannelTimeoutSeconds;
136+
private int nettyChannelHandshakeTimeoutSeconds;
136137
private int maxBytesInMessage;
137138

138139
private Class<? extends ServerSocketChannel> channelClass;
@@ -145,6 +146,8 @@ public void initialize(NewNettyMQTTHandler mqttHandler, IConfig props, ISslConte
145146
nettyTcpNodelay = props.boolProp(BrokerConstants.NETTY_TCP_NODELAY_PROPERTY_NAME, true);
146147
nettySoKeepalive = props.boolProp(BrokerConstants.NETTY_SO_KEEPALIVE_PROPERTY_NAME, true);
147148
nettyChannelTimeoutSeconds = props.intProp(BrokerConstants.NETTY_CHANNEL_TIMEOUT_SECONDS_PROPERTY_NAME, 10);
149+
nettyChannelHandshakeTimeoutSeconds = props.intProp(
150+
BrokerConstants.NETTY_CHANNEL_HANDSHAKE_TIMEOUT_SECONDS_PROPERTY_NAME, 10);
148151
maxBytesInMessage = props.intProp(BrokerConstants.NETTY_MAX_BYTES_PROPERTY_NAME,
149152
BrokerConstants.DEFAULT_NETTY_MAX_BYTES_IN_MESSAGE);
150153

@@ -414,6 +417,7 @@ public void close() {
414417
}
415418

416419
private ChannelHandler createSslHandler(SocketChannel channel, SslContext sslContext, boolean needsClientAuth) {
420+
SslHandler handler;
417421
SSLEngine sslEngine = sslContext.newEngine(
418422
channel.alloc(),
419423
channel.remoteAddress().getHostString(),
@@ -422,6 +426,10 @@ private ChannelHandler createSslHandler(SocketChannel channel, SslContext sslCon
422426
if (needsClientAuth) {
423427
sslEngine.setNeedClientAuth(true);
424428
}
425-
return new SslHandler(sslEngine);
429+
430+
handler = new SslHandler(sslEngine);
431+
handler.setHandshakeTimeoutMillis(nettyChannelHandshakeTimeoutSeconds * 1000);
432+
433+
return handler;
426434
}
427435
}

distribution/src/main/resources/moquette.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,16 @@ password_file config/password_file.conf
141141
# netty.mqtt.message_size : by default the max size of message is set at 8092 bytes
142142
# http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180836
143143
# Fore more information about payload size specs.
144+
#
145+
# Optional
146+
# netty.channel_handshake_timeout.seconds:
147+
# The number of seconds before the SSL handshake times out. The
148+
# value is provided to Netty's SslHandler, and its current
149+
# default value is 10.
144150
#*********************************************************************
145151
# netty.epoll true
146152
# netty.mqtt.message_size 8092
153+
# netty.channel_handshake_timeout.seconds 10
147154

148155
#*********************************************************************
149156
# Command session queues

0 commit comments

Comments
 (0)