*/
package org.onap.dcae.collectors.veshv.impl.socket
+import arrow.core.Option
import arrow.core.getOrElse
import arrow.effects.IO
+import io.netty.handler.ssl.SslContext
import org.onap.dcae.collectors.veshv.boundary.Collector
import org.onap.dcae.collectors.veshv.boundary.CollectorProvider
import org.onap.dcae.collectors.veshv.boundary.Metrics
import org.onap.dcae.collectors.veshv.impl.adapters.ClientContextLogging.info
import org.onap.dcae.collectors.veshv.model.ClientContext
import org.onap.dcae.collectors.veshv.model.ServiceContext
-import org.onap.dcae.collectors.veshv.ssl.boundary.SslContextFactory
import org.onap.dcae.collectors.veshv.utils.NettyServerHandle
import org.onap.dcae.collectors.veshv.utils.ServerHandle
import org.onap.dcae.collectors.veshv.utils.logging.Logger
import reactor.netty.NettyOutbound
import reactor.netty.tcp.TcpServer
import java.net.InetAddress
+import java.net.InetSocketAddress
import java.time.Duration
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
* @since May 2018
*/
-internal class NettyTcpServer(private val serverConfig: ServerConfiguration,
- private val sslContextFactory: SslContextFactory,
+internal class NettyTcpServer(private val serverConfiguration: ServerConfiguration,
+ private val sslContext: Option<SslContext>,
private val collectorProvider: CollectorProvider,
private val metrics: Metrics) : Server {
override fun start(): IO<ServerHandle> = IO {
TcpServer.create()
- .addressSupplier { serverConfig.serverListenAddress }
+ .addressSupplier { InetSocketAddress(serverConfiguration.listenPort) }
.configureSsl()
.handle(this::handleConnection)
.doOnUnbound {
}
private fun TcpServer.configureSsl() =
- sslContextFactory
- .createServerContext(serverConfig.securityConfiguration)
- .map { sslContext ->
+ sslContext
+ .map { serverContext ->
logger.info { "Collector configured with SSL enabled" }
- this.secure { b -> b.sslContext(sslContext) }
+ this.secure { it.sslContext(serverContext) }
}.getOrElse {
logger.info { "Collector configured with SSL disabled" }
this
nettyInbound: NettyInbound): (Collector) -> Mono<Void> = { collector ->
withConnectionFrom(nettyInbound) { connection ->
connection
- .configureIdleTimeout(clientContext, serverConfig.idleTimeout)
+ .configureIdleTimeout(clientContext, serverConfiguration.idleTimeout)
.logConnectionClosed(clientContext)
}.run {
collector.handleConnection(nettyInbound.createDataStream())