Skip to content

Commit 2496e2e

Browse files
committed
Added configuration item for handshake timeout on SSL channel (#531)
1 parent 1d38a1b commit 2496e2e

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
@@ -68,6 +68,7 @@ public final class BrokerConstants {
6868
public static final String NETTY_TCP_NODELAY_PROPERTY_NAME = "netty.tcp_nodelay";
6969
public static final String NETTY_SO_KEEPALIVE_PROPERTY_NAME = "netty.so_keepalive";
7070
public static final String NETTY_CHANNEL_TIMEOUT_SECONDS_PROPERTY_NAME = "netty.channel_timeout.seconds";
71+
public static final String NETTY_CHANNEL_HANDSHAKE_TIMEOUT_SECONDS_PROPERTY_NAME = "netty.channel_handshake_timeout.seconds";
7172
public static final String NETTY_EPOLL_PROPERTY_NAME = "netty.epoll";
7273
public static final String NETTY_MAX_BYTES_PROPERTY_NAME = "netty.mqtt.message_size";
7374
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
@@ -127,9 +127,16 @@ password_file config/password_file.conf
127127
# netty.mqtt.message_size : by default the max size of message is set at 8092 bytes
128128
# http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html#_Toc442180836
129129
# Fore more information about payload size specs.
130+
#
131+
# Optional
132+
# netty.channel_handshake_timeout.seconds:
133+
# The number of seconds before the SSL handshake times out. The
134+
# value is provided to Netty's SslHandler, and its current
135+
# default value is 10.
130136
#*********************************************************************
131137
# netty.epoll true
132138
# netty.mqtt.message_size 8092
139+
# netty.channel_handshake_timeout.seconds 10
133140

134141
#*********************************************************************
135142
# Metrics Configuration

0 commit comments

Comments
 (0)