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

Cleaned feature negotiation code up

parent 771ce12a
No related branches found
No related tags found
No related merge requests found
...@@ -109,7 +109,7 @@ class QuasselService : LifecycleService() { ...@@ -109,7 +109,7 @@ class QuasselService : LifecycleService() {
clientData = ClientData( clientData = ClientData(
identifier = "${resources.getString(R.string.app_name)} ${BuildConfig.VERSION_NAME}", identifier = "${resources.getString(R.string.app_name)} ${BuildConfig.VERSION_NAME}",
buildDate = Instant.ofEpochSecond(BuildConfig.GIT_COMMIT_DATE), buildDate = Instant.ofEpochSecond(BuildConfig.GIT_COMMIT_DATE),
clientFeatures = Quassel_Features.of(*Quassel_Feature.values()), clientFeatures = Quassel_Features.of(*Quassel_Feature.validValues),
protocolFeatures = Protocol_Features.of( protocolFeatures = Protocol_Features.of(
Protocol_Feature.Compression, Protocol_Feature.Compression,
Protocol_Feature.TLS Protocol_Feature.TLS
......
package de.kuschku.libquassel.session package de.kuschku.libquassel.session
import de.kuschku.libquassel.protocol.Quassel_Feature
import de.kuschku.libquassel.protocol.Quassel_Features
import de.kuschku.libquassel.protocol.message.HandshakeMessage import de.kuschku.libquassel.protocol.message.HandshakeMessage
import de.kuschku.libquassel.protocol.message.SignalProxyMessage import de.kuschku.libquassel.protocol.message.SignalProxyMessage
import de.kuschku.libquassel.protocol.primitive.serializer.HandshakeVariantMapSerializer import de.kuschku.libquassel.protocol.primitive.serializer.HandshakeVariantMapSerializer
...@@ -70,12 +68,12 @@ class CoreConnection( ...@@ -70,12 +68,12 @@ class CoreConnection(
IntSerializer.serialize( IntSerializer.serialize(
chainedBuffer, chainedBuffer,
0x42b33f00 or session.clientData.protocolFeatures.toInt(), 0x42b33f00 or session.clientData.protocolFeatures.toInt(),
session.coreFeatures session.negotiatedFeatures
) )
for (supportedProtocol in session.clientData.supportedProtocols) { for (supportedProtocol in session.clientData.supportedProtocols) {
IntSerializer.serialize(chainedBuffer, supportedProtocol.toInt(), session.coreFeatures) IntSerializer.serialize(chainedBuffer, supportedProtocol.toInt(), session.negotiatedFeatures)
} }
IntSerializer.serialize(chainedBuffer, 1 shl 31, session.coreFeatures) IntSerializer.serialize(chainedBuffer, 1 shl 31, session.negotiatedFeatures)
channel?.write(chainedBuffer) channel?.write(chainedBuffer)
channel?.flush() channel?.flush()
} }
...@@ -84,7 +82,7 @@ class CoreConnection( ...@@ -84,7 +82,7 @@ class CoreConnection(
sizeBuffer.clear() sizeBuffer.clear()
channel?.read(sizeBuffer) channel?.read(sizeBuffer)
sizeBuffer.flip() sizeBuffer.flip()
val protocol = ProtocolInfoSerializer.deserialize(sizeBuffer, session.coreFeatures) val protocol = ProtocolInfoSerializer.deserialize(sizeBuffer, session.negotiatedFeatures)
log(DEBUG, TAG, "Protocol negotiated $protocol") log(DEBUG, TAG, "Protocol negotiated $protocol")
...@@ -107,7 +105,7 @@ class CoreConnection( ...@@ -107,7 +105,7 @@ class CoreConnection(
clientVersion = session.clientData.identifier, clientVersion = session.clientData.identifier,
buildDate = DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm:ss") buildDate = DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm:ss")
.format(session.clientData.buildDate.atOffset(ZoneOffset.UTC)), .format(session.clientData.buildDate.atOffset(ZoneOffset.UTC)),
clientFeatures = Quassel_Features.of(*Quassel_Feature.values()) clientFeatures = session.clientData.clientFeatures
) )
) )
} }
...@@ -134,7 +132,7 @@ class CoreConnection( ...@@ -134,7 +132,7 @@ class CoreConnection(
handlerService.write( handlerService.write(
MessageRunnable( MessageRunnable(
data, HandshakeVariantMapSerializer, chainedBuffer, channel, data, HandshakeVariantMapSerializer, chainedBuffer, channel,
session.coreFeatures session.negotiatedFeatures
) )
) )
} catch (e: Throwable) { } catch (e: Throwable) {
...@@ -148,7 +146,10 @@ class CoreConnection( ...@@ -148,7 +146,10 @@ class CoreConnection(
try { try {
val data = SignalProxyMessage.serialize(message) val data = SignalProxyMessage.serialize(message)
handlerService.write( handlerService.write(
MessageRunnable(data, VariantListSerializer, chainedBuffer, channel, session.coreFeatures) MessageRunnable(
data, VariantListSerializer, chainedBuffer, channel,
session.negotiatedFeatures
)
) )
} catch (e: Throwable) { } catch (e: Throwable) {
log(WARN, TAG, "Error encountered while serializing sigproxy message", e) log(WARN, TAG, "Error encountered while serializing sigproxy message", e)
...@@ -167,7 +168,7 @@ class CoreConnection( ...@@ -167,7 +168,7 @@ class CoreConnection(
break break
sizeBuffer.flip() sizeBuffer.flip()
val size = IntSerializer.deserialize(sizeBuffer, session.coreFeatures) val size = IntSerializer.deserialize(sizeBuffer, session.negotiatedFeatures)
if (size > 64 * 1024 * 1024) if (size > 64 * 1024 * 1024)
throw SocketException("Too large frame received: $size") throw SocketException("Too large frame received: $size")
val dataBuffer = ByteBuffer.allocateDirect(size) val dataBuffer = ByteBuffer.allocateDirect(size)
...@@ -190,7 +191,7 @@ class CoreConnection( ...@@ -190,7 +191,7 @@ class CoreConnection(
private fun processSigProxy(dataBuffer: ByteBuffer) { private fun processSigProxy(dataBuffer: ByteBuffer) {
try { try {
val msg = SignalProxyMessage.deserialize( val msg = SignalProxyMessage.deserialize(
VariantListSerializer.deserialize(dataBuffer, session.coreFeatures) VariantListSerializer.deserialize(dataBuffer, session.negotiatedFeatures)
) )
handlerService.handle { handlerService.handle {
try { try {
...@@ -209,7 +210,7 @@ class CoreConnection( ...@@ -209,7 +210,7 @@ class CoreConnection(
private fun processHandshake(dataBuffer: ByteBuffer) { private fun processHandshake(dataBuffer: ByteBuffer) {
try { try {
val msg = HandshakeMessage.deserialize( val msg = HandshakeMessage.deserialize(
HandshakeVariantMapSerializer.deserialize(dataBuffer, session.coreFeatures) HandshakeVariantMapSerializer.deserialize(dataBuffer, session.negotiatedFeatures)
) )
try { try {
session.handle(msg) session.handle(msg)
......
...@@ -86,11 +86,12 @@ abstract class ProtocolHandler : SignalProxy, AuthHandler, Closeable { ...@@ -86,11 +86,12 @@ abstract class ProtocolHandler : SignalProxy, AuthHandler, Closeable {
open fun onInitStatusChanged(progress: Int, total: Int) {} open fun onInitStatusChanged(progress: Int, total: Int) {}
override fun handle(f: SignalProxyMessage.SyncMessage): Boolean { override fun handle(f: SignalProxyMessage.SyncMessage): Boolean {
log(DEBUG, "ProtocolHandler", "< $f")
val obj = objectStorage.get(f.className, f.objectName) ?: if (isInitializing) { val obj = objectStorage.get(f.className, f.objectName) ?: if (isInitializing) {
syncQueue.add(f) syncQueue.add(f)
return true return true
} else { } else {
log(DEBUG, "ProtocolHandler", "< $f")
throw ObjectNotFoundException(f.className, f.objectName) throw ObjectNotFoundException(f.className, f.objectName)
} }
...@@ -100,8 +101,6 @@ abstract class ProtocolHandler : SignalProxy, AuthHandler, Closeable { ...@@ -100,8 +101,6 @@ abstract class ProtocolHandler : SignalProxy, AuthHandler, Closeable {
return true return true
} }
log(DEBUG, "ProtocolHandler", f.toString())
val invoker = Invokers.get(f.className) val invoker = Invokers.get(f.className)
?: throw IllegalArgumentException("Invalid classname: ${f.className}") ?: throw IllegalArgumentException("Invalid classname: ${f.className}")
currentCallClass = f.className currentCallClass = f.className
......
...@@ -5,6 +5,7 @@ import de.kuschku.libquassel.protocol.message.HandshakeMessage ...@@ -5,6 +5,7 @@ import de.kuschku.libquassel.protocol.message.HandshakeMessage
import de.kuschku.libquassel.protocol.message.SignalProxyMessage import de.kuschku.libquassel.protocol.message.SignalProxyMessage
import de.kuschku.libquassel.quassel.QuasselFeature import de.kuschku.libquassel.quassel.QuasselFeature
import de.kuschku.libquassel.quassel.syncables.* import de.kuschku.libquassel.quassel.syncables.*
import de.kuschku.libquassel.util.and
import de.kuschku.libquassel.util.compatibility.HandlerService import de.kuschku.libquassel.util.compatibility.HandlerService
import de.kuschku.libquassel.util.compatibility.LoggingHandler.LogLevel.DEBUG import de.kuschku.libquassel.util.compatibility.LoggingHandler.LogLevel.DEBUG
import de.kuschku.libquassel.util.compatibility.LoggingHandler.LogLevel.INFO import de.kuschku.libquassel.util.compatibility.LoggingHandler.LogLevel.INFO
...@@ -23,6 +24,8 @@ class Session( ...@@ -23,6 +24,8 @@ class Session(
private val userData: Pair<String, String> private val userData: Pair<String, String>
) : ProtocolHandler(), ISession { ) : ProtocolHandler(), ISession {
var coreFeatures: Quassel_Features = Quassel_Feature.NONE var coreFeatures: Quassel_Features = Quassel_Feature.NONE
val negotiatedFeatures
get() = coreFeatures and clientData.clientFeatures
private val coreConnection = CoreConnection(this, address, handlerService) private val coreConnection = CoreConnection(this, address, handlerService)
override val state = coreConnection.state override val state = coreConnection.state
...@@ -87,7 +90,7 @@ class Session( ...@@ -87,7 +90,7 @@ class Session(
synchronize(bufferSyncer, true) synchronize(bufferSyncer, true)
synchronize(bufferViewManager, true) synchronize(bufferViewManager, true)
synchronize(coreInfo, true) synchronize(coreInfo, true)
if (coreFeatures.hasFlag(QuasselFeature.DccFileTransfer)) if (negotiatedFeatures.hasFlag(QuasselFeature.DccFileTransfer))
synchronize(dccConfig, true) synchronize(dccConfig, true)
synchronize(ignoreListManager, true) synchronize(ignoreListManager, true)
synchronize(ircListHelper, true) synchronize(ircListHelper, true)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment