diff --git a/projector-client-web/src/main/kotlin/org/jetbrains/projector/client/web/state/ClientState.kt b/projector-client-web/src/main/kotlin/org/jetbrains/projector/client/web/state/ClientState.kt index 47caba7fd..945f71c57 100644 --- a/projector-client-web/src/main/kotlin/org/jetbrains/projector/client/web/state/ClientState.kt +++ b/projector-client-web/src/main/kotlin/org/jetbrains/projector/client/web/state/ClientState.kt @@ -49,10 +49,7 @@ import org.jetbrains.projector.common.protocol.MessageDecoder import org.jetbrains.projector.common.protocol.MessageEncoder import org.jetbrains.projector.common.protocol.compress.MessageCompressor import org.jetbrains.projector.common.protocol.compress.MessageDecompressor -import org.jetbrains.projector.common.protocol.handshake.COMMON_VERSION -import org.jetbrains.projector.common.protocol.handshake.ToClientHandshakeFailureEvent -import org.jetbrains.projector.common.protocol.handshake.ToClientHandshakeSuccessEvent -import org.jetbrains.projector.common.protocol.handshake.ToServerHandshakeEvent +import org.jetbrains.projector.common.protocol.handshake.* import org.jetbrains.projector.common.protocol.toClient.ServerDrawCommandsEvent import org.jetbrains.projector.common.protocol.toClient.ToClientMessageDecoder import org.jetbrains.projector.common.protocol.toServer.* @@ -133,6 +130,7 @@ sealed class ClientState { val handshakeEvent = with(SupportedTypesProvider) { ToServerHandshakeEvent( commonVersion = COMMON_VERSION, + commonVersionId = commonVersionList.indexOf(COMMON_VERSION), token = ParamsProvider.HANDSHAKE_TOKEN, initialSize = windowSizeController.currentSize, supportedToClientCompressions = supportedToClientDecompressors.map(MessageDecompressor<*>::compressionType), diff --git a/projector-common/src/commonMain/kotlin/org/jetbrains/projector/common/protocol/handshake/Constant.kt b/projector-common/src/commonMain/kotlin/org/jetbrains/projector/common/protocol/handshake/Constant.kt index 87d9d3efd..57698772a 100644 --- a/projector-common/src/commonMain/kotlin/org/jetbrains/projector/common/protocol/handshake/Constant.kt +++ b/projector-common/src/commonMain/kotlin/org/jetbrains/projector/common/protocol/handshake/Constant.kt @@ -31,3 +31,8 @@ import org.jetbrains.projector.common.protocol.toServer.ClientEvent val COMMON_VERSION = listOf(ServerEvent.serializer(), ClientEvent.serializer()) .map { it.list.descriptor.compatibilityHash } .reduce(Int::xor) + +// Don't change order here: it's used to obtain readable "human id" +val commonVersionList = listOf( + -1663032476 +) diff --git a/projector-common/src/commonMain/kotlin/org/jetbrains/projector/common/protocol/handshake/ToServerHandshakeEvent.kt b/projector-common/src/commonMain/kotlin/org/jetbrains/projector/common/protocol/handshake/ToServerHandshakeEvent.kt index 1b834765d..1244a26d0 100644 --- a/projector-common/src/commonMain/kotlin/org/jetbrains/projector/common/protocol/handshake/ToServerHandshakeEvent.kt +++ b/projector-common/src/commonMain/kotlin/org/jetbrains/projector/common/protocol/handshake/ToServerHandshakeEvent.kt @@ -29,6 +29,7 @@ import org.jetbrains.projector.common.protocol.data.CommonIntSize @Serializable data class ToServerHandshakeEvent( val commonVersion: Int, + val commonVersionId: Int, val token: String? = null, val initialSize: CommonIntSize, val supportedToClientCompressions: List, diff --git a/projector-common/src/commonTest/kotlin/org/jetbrains/projector/common/protocol/CommonVersionPresenceTest.kt b/projector-common/src/commonTest/kotlin/org/jetbrains/projector/common/protocol/CommonVersionPresenceTest.kt new file mode 100644 index 000000000..58520ad3e --- /dev/null +++ b/projector-common/src/commonTest/kotlin/org/jetbrains/projector/common/protocol/CommonVersionPresenceTest.kt @@ -0,0 +1,47 @@ +/* + * MIT License + * + * Copyright (c) 2019-2020 JetBrains s.r.o. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package org.jetbrains.projector.common.protocol + +import org.jetbrains.projector.common.protocol.handshake.COMMON_VERSION +import org.jetbrains.projector.common.protocol.handshake.commonVersionList +import kotlin.test.Test +import kotlin.test.assertTrue + +class CommonVersionPresenceTest { + + @Test + fun commonVersionListShouldContainCurrentCommonVersion() { + assertTrue( + COMMON_VERSION in commonVersionList, + """ + |Current common version of protocol should be in `commonVersionList`. + |It seems that protocol has been updated. + |Please append the current COMMON_VERSION to the commonVersionList as the last element. + |Current values: + |COMMON_VERSION = $COMMON_VERSION + |commonVersionList = $commonVersionList + """.trimMargin() + ) + } +}