Skip to content

Commit

Permalink
Merge pull request #27 from okumin/tls-support
Browse files Browse the repository at this point in the history
Support SSL/TLS
  • Loading branch information
okumin authored Aug 6, 2017
2 parents 8f929cf + 0100512 commit c0e2cb4
Show file tree
Hide file tree
Showing 6 changed files with 379 additions and 10 deletions.
2 changes: 1 addition & 1 deletion influent-java-sample/src/main/java/sample/TLSPrint.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void main(final String[] args) throws Exception {
final ForwardServer server =
new ForwardServer.Builder(callback)
.sslEnabled(true)
.tlsVersions(new String[]{"TLSv1.2"})
.tlsVersions("TLSv1.2")
.keystorePath("./out/influent-server.jks")
.keystorePassword("password")
.keyPassword("password")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Builder sslEnabled(final boolean value) {
* @param value the TLS versions. Available elements are "TLS", "TLSv1", "TLSv1.1" or "TLSv1.2"
* @return this builder
*/
public Builder tlsVersions(final String[] value) {
public Builder tlsVersions(final String... value) {
tlsVersions = value;
return this;
}
Expand Down Expand Up @@ -276,8 +276,8 @@ public ForwardServer build() {
receiveBufferSize,
keepAliveEnabled,
tcpNoDelayEnabled,
workerPoolSize == 0 ? DEFAULT_WORKER_POOL_SIZE : workerPoolSize
// TODO Add channelConfig here
workerPoolSize == 0 ? DEFAULT_WORKER_POOL_SIZE : workerPoolSize,
channelConfig
);
}
}
Expand Down
20 changes: 15 additions & 5 deletions influent-java/src/main/java/influent/forward/NioForwardServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.concurrent.ThreadFactory;
import java.util.function.Consumer;

import influent.internal.nio.NioChannelConfig;
import influent.internal.nio.NioEventLoop;
import influent.internal.nio.NioEventLoopPool;
import influent.internal.nio.NioTcpAcceptor;
Expand Down Expand Up @@ -57,13 +58,22 @@ final class NioForwardServer implements ForwardServer {
final int receiveBufferSize,
final boolean keepAliveEnabled,
final boolean tcpNoDelayEnabled,
final int workerPoolSize) {
final int workerPoolSize,
final NioChannelConfig channelConfig) {
bossEventLoop = NioEventLoop.open();
workerEventLoopPool = NioEventLoopPool.open(workerPoolSize);
final Consumer<SocketChannel> channelFactory = socketChannel -> new NioForwardConnection(
socketChannel, workerEventLoopPool.next(), callback, chunkSizeLimit, sendBufferSize,
keepAliveEnabled, tcpNoDelayEnabled
);
final Consumer<SocketChannel> channelFactory;
if (channelConfig.isSslEnabled()) {
channelFactory = socketChannel -> new NioSslForwardConnection(
socketChannel, workerEventLoopPool.next(), callback, channelConfig.createSSLEngine(),
chunkSizeLimit, sendBufferSize, keepAliveEnabled, tcpNoDelayEnabled
);
} else {
channelFactory = socketChannel -> new NioForwardConnection(
socketChannel, workerEventLoopPool.next(), callback,
chunkSizeLimit, sendBufferSize, keepAliveEnabled, tcpNoDelayEnabled
);
}
new NioTcpAcceptor(
localAddress, bossEventLoop, channelFactory, backlog, receiveBufferSize
);
Expand Down
Loading

0 comments on commit c0e2cb4

Please sign in to comment.