Skip to content
Snippets Groups Projects
Verified Commit 0ab64730 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Implement further tests and cleanup connection init parsing

parent 0ea27011
Branches
No related tags found
No related merge requests found
Showing
with 717 additions and 30 deletions
package de.kuschku.quasseldroid
import de.kuschku.libquassel.protocol.connection.ProtocolInfoSerializer
import de.kuschku.bitflags.of
import de.kuschku.libquassel.protocol.connection.*
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.io.contentToString
......@@ -84,9 +85,22 @@ class ExampleUnitTest {
println("Writing protocol")
write(sizePrefix = false) {
UIntSerializer.serialize(it, 0x42b3_3f00u or 0x03u, connectionFeatureSet)
IntSerializer.serialize(it, 2, connectionFeatureSet)
UIntSerializer.serialize(it, 0x8000_0000u, connectionFeatureSet)
ConnectionHeaderSerializer.serialize(
it,
ConnectionHeader(
features = ProtocolFeature.of(
ProtocolFeature.Compression,
ProtocolFeature.TLS
),
versions = listOf(
ProtocolMeta(
0x0000u,
ProtocolVersion.Datastream,
),
)
),
connectionFeatureSet
)
}
println("Reading protocol")
......
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.connection
data class ConnectionHeader(
val features: ProtocolFeatures,
val versions: List<ProtocolMeta>
)
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.connection
import de.kuschku.bitflags.of
import de.kuschku.bitflags.toBits
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.serializers.primitive.Serializer
import de.kuschku.libquassel.protocol.serializers.primitive.UByteSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.UIntSerializer
import java.nio.ByteBuffer
object ConnectionHeaderSerializer : Serializer<ConnectionHeader> {
private const val magic: UInt = 0x42b3_3f00u
private const val featureMask: UInt = 0x0000_00ffu
private const val lastMagic: UByte = 0x80u
private fun addMagic(data: UByte): UInt =
magic or data.toUInt()
private fun removeMagic(data: UInt): UByte =
(data and featureMask).toUByte()
private fun <T> writeList(
buffer: ChainedByteBuffer,
list: List<T>,
featureSet: FeatureSet,
f: (T) -> Unit
) {
for (index in list.indices) {
val isLast = index + 1 == list.size
val magic = if (isLast) lastMagic else 0x00u
UByteSerializer.serialize(buffer, magic, featureSet)
f(list[index])
}
}
private fun <T> readList(
buffer: ByteBuffer,
featureSet: FeatureSet,
f: () -> T
) : List<T> {
val list = mutableListOf<T>()
while (true) {
val isLast = UByteSerializer.deserialize(buffer, featureSet) != 0x00u.toUByte()
list.add(f())
if (isLast) {
break
}
}
return list
}
override fun serialize(buffer: ChainedByteBuffer, data: ConnectionHeader, featureSet: FeatureSet) {
UIntSerializer.serialize(buffer, addMagic(data.features.toBits()), featureSet)
writeList(buffer, data.versions, featureSet) {
ProtocolMetaSerializer.serialize(buffer, it, featureSet)
}
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet) = ConnectionHeader(
features = ProtocolFeature.of(
removeMagic(UIntSerializer.deserialize(buffer, featureSet))
),
versions = readList(buffer, featureSet) {
ProtocolMetaSerializer.deserialize(buffer, featureSet)
}
)
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.connection
import de.kuschku.bitflags.Flag
import de.kuschku.bitflags.Flags
import de.kuschku.bitflags.toEnumSet
enum class ProtocolFeature(
override val value: UByte,
) : Flag<UByte> {
None(0x00u),
TLS(0x01u),
Compression(0x02u);
companion object : Flags<UByte, ProtocolFeature> {
private val values = values().associateBy(ProtocolFeature::value)
override val all: ProtocolFeatures = values.values.toEnumSet()
}
}
typealias ProtocolFeatures = Set<ProtocolFeature>
......@@ -20,7 +20,6 @@
package de.kuschku.libquassel.protocol.connection
data class ProtocolInfo(
val flags: UByte,
val data: UShort,
val version: UByte,
val flags: ProtocolFeatures,
val meta: ProtocolMeta,
)
......@@ -19,24 +19,22 @@
package de.kuschku.libquassel.protocol.connection
import de.kuschku.bitflags.of
import de.kuschku.bitflags.toBits
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.serializers.primitive.Serializer
import de.kuschku.libquassel.protocol.serializers.primitive.UByteSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.UShortSerializer
import java.nio.ByteBuffer
object ProtocolInfoSerializer {
fun serialize(buffer: ChainedByteBuffer, data: ProtocolInfo, featureSet: FeatureSet) {
UByteSerializer.serialize(buffer, data.flags, featureSet)
UShortSerializer.serialize(buffer, data.data, featureSet)
UByteSerializer.serialize(buffer, data.version, featureSet)
object ProtocolInfoSerializer : Serializer<ProtocolInfo> {
override fun serialize(buffer: ChainedByteBuffer, data: ProtocolInfo, featureSet: FeatureSet) {
UByteSerializer.serialize(buffer, data.flags.toBits(), featureSet)
ProtocolMetaSerializer.serialize(buffer, data.meta, featureSet)
}
fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): ProtocolInfo {
return ProtocolInfo(
UByteSerializer.deserialize(buffer, featureSet),
UShortSerializer.deserialize(buffer, featureSet),
UByteSerializer.deserialize(buffer, featureSet)
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet) = ProtocolInfo(
ProtocolFeature.of(UByteSerializer.deserialize(buffer, featureSet)),
ProtocolMetaSerializer.deserialize(buffer, featureSet)
)
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.connection
data class ProtocolMeta(
val data: UShort,
val version: ProtocolVersion
)
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.connection
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.serializers.primitive.Serializer
import de.kuschku.libquassel.protocol.serializers.primitive.UByteSerializer
import de.kuschku.libquassel.protocol.serializers.primitive.UShortSerializer
import java.nio.ByteBuffer
object ProtocolMetaSerializer : Serializer<ProtocolMeta> {
override fun serialize(buffer: ChainedByteBuffer, data: ProtocolMeta, featureSet: FeatureSet) {
UShortSerializer.serialize(buffer, data.data, featureSet)
UByteSerializer.serialize(buffer, data.version.value, featureSet)
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet) = ProtocolMeta(
UShortSerializer.deserialize(buffer, featureSet),
ProtocolVersion.of(UByteSerializer.deserialize(buffer, featureSet))
)
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.connection
enum class ProtocolVersion(
val value: UByte,
) {
Legacy(0x01u),
Datastream(0x02u);
companion object {
private val values = values().associateBy(ProtocolVersion::value)
fun of(value: UByte): ProtocolVersion = values[value]
?: throw IllegalArgumentException("Protocol not supported: $value")
}
}
......@@ -31,6 +31,12 @@ sealed class NoSerializerForTypeException : Exception() {
type: QtType,
javaType: Class<*>? = null
) : this(type.id, javaType)
override fun toString(): String {
return "NoSerializerForTypeException.Qt(type=$type, javaType=$javaType)"
}
}
data class Quassel(
......@@ -48,10 +54,18 @@ sealed class NoSerializerForTypeException : Exception() {
type: QuasselType,
javaType: Class<*>? = null
) : this(type.qtType, type.typeName, javaType)
override fun toString(): String {
return "NoSerializerForTypeException.Quassel(type=$type, typename=$typename, javaType=$javaType)"
}
}
data class Handshake(
private val type: String,
private val javaType: Class<*>? = null
) : NoSerializerForTypeException()
) : NoSerializerForTypeException() {
override fun toString(): String {
return "NoSerializerForTypeException.Handshake(type='$type', javaType=$javaType)"
}
}
}
......@@ -27,8 +27,8 @@ object QuasselSerializers {
private val serializers = listOf<QuasselSerializer<*>>(
BufferIdSerializer,
BufferInfoSerializer,
//DccConfigIpDetectionModeSerializer,
//DccConfigPortSelectionModeSerializer,
DccIpDetectionModeSerializer,
DccPortSelectionModeSerializer,
//IrcUserSerializer,
//IrcChannelSerializer,
//IdentitySerializer,
......@@ -38,7 +38,7 @@ object QuasselSerializers {
NetworkIdSerializer,
//NetworkInfoSerializer,
//NetworkServerSerializer,
//QHostAddressSerializer,
QHostAddressSerializer,
PeerPtrSerializer,
).associateBy(QuasselSerializer<*>::quasselType)
......
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2020 Janne Mareike Koschinski
* Copyright (c) 2020 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.serializers.primitive
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.types.DccIpDetectionMode
import de.kuschku.libquassel.protocol.types.DccPortSelectionMode
import de.kuschku.libquassel.protocol.variant.QuasselType
import java.nio.ByteBuffer
object DccIpDetectionModeSerializer : QuasselSerializer<DccIpDetectionMode?> {
override val quasselType: QuasselType = QuasselType.DccConfigIpDetectionMode
@Suppress("UNCHECKED_CAST")
override val javaType: Class<out DccIpDetectionMode?> =
DccIpDetectionMode::class.java
override fun serialize(
buffer: ChainedByteBuffer,
data: DccIpDetectionMode?,
featureSet: FeatureSet
) {
UByteSerializer.serialize(buffer, data?.value ?: 0x00u, featureSet)
}
override fun deserialize(
buffer: ByteBuffer,
featureSet: FeatureSet
): DccIpDetectionMode? {
return DccIpDetectionMode.of(UByteSerializer.deserialize(buffer, featureSet))
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2020 Janne Mareike Koschinski
* Copyright (c) 2020 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.serializers.primitive
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.types.DccPortSelectionMode
import de.kuschku.libquassel.protocol.variant.QuasselType
import java.nio.ByteBuffer
object DccPortSelectionModeSerializer : QuasselSerializer<DccPortSelectionMode?> {
override val quasselType: QuasselType = QuasselType.DccConfigPortSelectionMode
@Suppress("UNCHECKED_CAST")
override val javaType: Class<out DccPortSelectionMode?> =
DccPortSelectionMode::class.java
override fun serialize(
buffer: ChainedByteBuffer,
data: DccPortSelectionMode?,
featureSet: FeatureSet
) {
UByteSerializer.serialize(buffer, data?.value ?: 0x00u, featureSet)
}
override fun deserialize(
buffer: ByteBuffer,
featureSet: FeatureSet
): DccPortSelectionMode? {
return DccPortSelectionMode.of(UByteSerializer.deserialize(buffer, featureSet))
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2020 Janne Mareike Koschinski
* Copyright (c) 2020 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.serializers.primitive
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.types.NetworkLayerProtocol
import de.kuschku.libquassel.protocol.variant.QuasselType
import java.net.Inet4Address
import java.net.Inet6Address
import java.net.InetAddress
import java.nio.ByteBuffer
object QHostAddressSerializer : QuasselSerializer<InetAddress> {
override val quasselType: QuasselType = QuasselType.QHostAddress
override val javaType: Class<out InetAddress> = InetAddress::class.java
override fun serialize(
buffer: ChainedByteBuffer,
data: InetAddress,
featureSet: FeatureSet
) {
when (data) {
is Inet4Address -> {
UByteSerializer.serialize(
buffer,
NetworkLayerProtocol.IPv4Protocol.value,
featureSet
)
buffer.put(data.address)
}
is Inet6Address -> {
UByteSerializer.serialize(
buffer,
NetworkLayerProtocol.IPv6Protocol.value,
featureSet
)
buffer.put(data.address)
}
else -> {
UByteSerializer.serialize(
buffer,
NetworkLayerProtocol.UnknownNetworkLayerProtocol.value,
featureSet
)
throw IllegalArgumentException("Invalid network protocol ${data.javaClass.canonicalName}")
}
}
}
override fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): InetAddress {
val type = UByteSerializer.deserialize(buffer, featureSet)
return when (NetworkLayerProtocol.of(type)) {
NetworkLayerProtocol.IPv4Protocol -> {
val buf = ByteArray(4)
buffer.get(buf)
Inet4Address.getByAddress(buf)
}
NetworkLayerProtocol.IPv6Protocol -> {
val buf = ByteArray(16)
buffer.get(buf)
Inet6Address.getByAddress(buf)
}
else -> {
throw IllegalArgumentException("Invalid network protocol $type")
}
}
}
}
......@@ -19,14 +19,9 @@
package de.kuschku.libquassel.protocol.serializers.primitive
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import de.kuschku.libquassel.protocol.variant.QtType
import java.nio.ByteBuffer
interface QtSerializer<T> {
interface QtSerializer<T> : Serializer<T> {
val qtType: QtType
val javaType: Class<out T>
fun serialize(buffer: ChainedByteBuffer, data: T, featureSet: FeatureSet)
fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): T
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.serializers.primitive
import de.kuschku.libquassel.protocol.features.FeatureSet
import de.kuschku.libquassel.protocol.io.ChainedByteBuffer
import java.nio.ByteBuffer
interface Serializer<T> {
fun serialize(buffer: ChainedByteBuffer, data: T, featureSet: FeatureSet)
fun deserialize(buffer: ByteBuffer, featureSet: FeatureSet): T
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.types
/**
* Mode for detecting the outgoing IP
*/
enum class DccIpDetectionMode(
val value: UByte,
) {
/** Automatic detection (network socket or USERHOST) */
Automatic(0x00u),
/** Manually specified IP */
Manual(0x01u);
companion object {
private val values = values().associateBy(DccIpDetectionMode::value)
fun of(value: UByte): DccIpDetectionMode? = values[value]
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.types
/**
* Mode for selecting the port range for DCC
*/
enum class DccPortSelectionMode(
val value: UByte,
) {
/** Automatic port selection */
Automatic(0x00u),
/** Manually specified port range */
Manual(0x01u);
companion object {
private val values = values().associateBy(DccPortSelectionMode::value)
fun of(value: UByte): DccPortSelectionMode? = values[value]
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2020 Janne Mareike Koschinski
* Copyright (c) 2020 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.types
enum class NetworkLayerProtocol(
val value: UByte,
) {
IPv4Protocol(0x00u),
IPv6Protocol(0x01u),
AnyIPProtocol(0x02u),
UnknownNetworkLayerProtocol(0xFFu);
companion object {
private val values = values().associateBy(NetworkLayerProtocol::value)
fun of(value: UByte): NetworkLayerProtocol? = values[value]
}
}
/*
* Quasseldroid - Quassel client for Android
*
* Copyright (c) 2021 Janne Mareike Koschinski
* Copyright (c) 2021 The Quassel Project
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.kuschku.libquassel.protocol.connection
import de.kuschku.bitflags.of
import de.kuschku.libquassel.protocol.testutil.byteBufferOf
import de.kuschku.libquassel.protocol.testutil.serializerTest
import org.junit.jupiter.api.Test
class ConnectionHeaderSerializerTest {
@Test
fun testQuasseldroid() = serializerTest(
ConnectionHeaderSerializer,
ConnectionHeader(
features = ProtocolFeature.of(
ProtocolFeature.TLS,
ProtocolFeature.Compression,
),
versions = listOf(
ProtocolMeta(
data = 0x0000u,
version = ProtocolVersion.Datastream,
)
)
),
byteBufferOf(
0x42u, 0xb3u, 0x3fu, 0x03u,
0x80u, 0x00u, 0x00u, 0x02u
)
)
@Test
fun testQuasselClient() = serializerTest(
ConnectionHeaderSerializer,
ConnectionHeader(
features = ProtocolFeature.of(
ProtocolFeature.TLS,
ProtocolFeature.Compression,
),
versions = listOf(
ProtocolMeta(
data = 0x0000u,
version = ProtocolVersion.Legacy,
),
ProtocolMeta(
data = 0x0000u,
version = ProtocolVersion.Datastream,
)
)
),
byteBufferOf(
0x42u, 0xb3u, 0x3fu, 0x03u,
0x00u, 0x00u, 0x00u, 0x01u,
0x80u, 0x00u, 0x00u, 0x02u
)
)
@Test
fun testDebugClient() = serializerTest(
ConnectionHeaderSerializer,
ConnectionHeader(
features = ProtocolFeature.of( ),
versions = listOf(
ProtocolMeta(
data = 0x0000u,
version = ProtocolVersion.Legacy,
),
ProtocolMeta(
data = 0x0000u,
version = ProtocolVersion.Datastream,
)
)
),
byteBufferOf(
0x42u, 0xb3u, 0x3fu, 0x00u,
0x00u, 0x00u, 0x00u, 0x01u,
0x80u, 0x00u, 0x00u, 0x02u
)
)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment