Cleaned up logging, code polish

This commit is contained in:
nathan 2020-08-27 00:46:17 +02:00
parent e7a7ec9737
commit 006e597867
3 changed files with 11 additions and 18 deletions

View File

@ -15,16 +15,10 @@
*/
package dorkbox.network.handshake
import org.slf4j.Logger
internal class ClientConnectionInfo(val subscriptionPort: Int,
val publicationPort: Int,
val sessionId: Int,
val streamId: Int,
val publicKey: ByteArray,
val kryoIdsForRmi: IntArray) {
fun log(handshakeSessionId: Int, logger: Logger) {
logger.debug("[{}] connected {}|{} (encrypted {})", handshakeSessionId, publicationPort, subscriptionPort, sessionId)
}
}

View File

@ -82,7 +82,6 @@ internal class ClientHandshake<CONNECTION: Connection>(private val logger: KLogg
// The message was intended for this client. Try to parse it as one of the available message types.
// this message is ENCRYPTED!
connectionHelloInfo = crypto.decrypt(message.registrationData, message.publicKey)
connectionHelloInfo!!.log(sessionId, logger)
}
HandshakeMessage.DONE_ACK -> {

View File

@ -79,7 +79,10 @@ internal class ServerHandshake<CONNECTION : Connection>(private val logger: KLog
pendingConnectionsLock.write {
val pendingConnection = pendingConnections.remove(sessionId)
if (pendingConnection != null) {
logger.debug("Connection from client $clientAddressString ready")
logger.trace { "Connection from client $clientAddressString done with handshake." }
// this enables the connection to start polling for messages
server.connections.add(pendingConnection)
// now tell the client we are done
server.writeHandshakeMessage(handshakePublication, HandshakeMessage.doneToClient(sessionId))
@ -88,9 +91,6 @@ internal class ServerHandshake<CONNECTION : Connection>(private val logger: KLog
listenerManager.notifyConnect(pendingConnection)
}
// this enables the connection to start polling for messages
server.connections.add(pendingConnection)
return
}
}
@ -199,11 +199,11 @@ internal class ServerHandshake<CONNECTION : Connection>(private val logger: KLog
// we have to construct how the connection will communicate!
clientConnection.buildServer(aeron)
logger.trace {
"Creating new connection $clientConnection"
logger.info {
"Creating new connection from $clientConnection"
}
val connection = server.newConnection(ConnectionParams(server, clientConnection, validateRemoteAddress)) as CONNECTION
val connection = server.newConnection(ConnectionParams(server, clientConnection, validateRemoteAddress))
// VALIDATE:: are we allowed to connect to this server (now that we have the initial server information)
@Suppress("UNCHECKED_CAST")
@ -214,8 +214,6 @@ internal class ServerHandshake<CONNECTION : Connection>(private val logger: KLog
sessionIdAllocator.free(connectionSessionId)
streamIdAllocator.free(connectionStreamId)
logger.error("Error creating new connection")
val exception = ClientRejectedException("Connection was not permitted!")
ListenerManager.cleanStackTrace(exception)
listenerManager.notifyError(connection, exception)
@ -231,8 +229,10 @@ internal class ServerHandshake<CONNECTION : Connection>(private val logger: KLog
///////////////
// if necessary (and only for RMI id's that have never been seen before) we want to re-write our kryo information
val rmiModificationIds = message.registrationRmiIdData!!
server.updateKryoIdsForRmi(connection, rmiModificationIds)
serialization.updateKryoIdsForRmi(connection, message.registrationRmiIdData!!) { errorMessage ->
listenerManager.notifyError(connection,
ClientRejectedException(errorMessage))
}