add timeout for client's authentification

This commit is contained in:
Vadim Brilyantov
2018-03-20 13:30:33 +03:00
parent f273deb18c
commit b69b386157
3 changed files with 15 additions and 4 deletions

View File

@@ -5,6 +5,8 @@
package org.jetbrains.kotlin.daemon.common.experimental
import java.util.concurrent.TimeUnit
val RMI_WRAPPER_PORTS_RANGE_START: Int = 13001
val RMI_WRAPPER_PORTS_RANGE_END: Int = 14000
@@ -18,4 +20,7 @@ val CALLBACK_SERVER_PORTS_RANGE_END: Int = 16000
val RESULTS_SERVER_PORTS_RANGE_START: Int = 16001
val RESULTS_SERVER_PORTS_RANGE_END: Int = 17000
val COMPILER_DAEMON_CLASS_FQN_EXPERIMENTAL: String = "org.jetbrains.kotlin.daemon.experimental.KotlinCompileDaemon"
val COMPILER_DAEMON_CLASS_FQN_EXPERIMENTAL: String = "org.jetbrains.kotlin.daemon.experimental.KotlinCompileDaemon"
val BYTES_TOKEN = byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8)
val AUTH_TIMEOUT_IN_MILLISECONDS = 1000L

View File

@@ -3,6 +3,7 @@ package org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure
import io.ktor.network.sockets.Socket
import io.ktor.network.sockets.aSocket
import kotlinx.coroutines.experimental.*
import org.jetbrains.kotlin.daemon.common.experimental.BYTES_TOKEN
import org.jetbrains.kotlin.daemon.common.experimental.LoopbackNetworkInterface
import java.beans.Transient
import java.io.Serializable
@@ -11,8 +12,6 @@ import java.util.ArrayList
import java.util.function.Function
import java.util.logging.Logger
val BYTES_TOKEN = byteArrayOf(1, 2, 3, 4)
interface Client : Serializable, AutoCloseable {
@Throws(Exception::class)
fun connectToServer()

View File

@@ -5,8 +5,13 @@ import io.ktor.network.sockets.aSocket
import kotlinx.coroutines.experimental.Deferred
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.channels.actor
import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.time.delay
import org.jetbrains.kotlin.daemon.common.experimental.AUTH_TIMEOUT_IN_MILLISECONDS
import org.jetbrains.kotlin.daemon.common.experimental.BYTES_TOKEN
import java.io.Serializable
import java.net.InetSocketAddress
import java.util.concurrent.TimeUnit
import java.util.logging.Logger
/*
@@ -40,7 +45,9 @@ interface Server<out T : ServerBase> : ServerBase {
suspend fun attachClient(client: Socket): Deferred<State> = async {
val (input, output) = client.openIO(log)
try {
val bytes = input.readBytes(BYTES_TOKEN.size)
val bytesAsync = async { input.readBytes(BYTES_TOKEN.size) }
delay(AUTH_TIMEOUT_IN_MILLISECONDS, TimeUnit.MILLISECONDS)
val bytes = bytesAsync.getCompleted()
log.info("bytes : ${bytes.toList()}")
if (bytes.zip(BYTES_TOKEN).any { it.first != it.second }) {
log.info("BAD TOKEN")