+ connect(socket, &QIODevice::readyRead, this, &CoreAuthHandler::onReadyRead);
+
+ // TODO: Timeout for the handshake phase
+}
+
+void CoreAuthHandler::onReadyRead()
+{
+ if (socket()->bytesAvailable() < 4)
+ return;
+
+ // once we have selected a peer, we certainly don't want to read more data!
+ if (_peer)
+ return;
+
+ if (!_magicReceived) {
+ quint32 magic;
+ socket()->peek((char*)&magic, 4);
+ magic = qFromBigEndian<quint32>(magic);
+
+ if ((magic & 0xffffff00) != Protocol::magic) {
+ // no magic, assume legacy protocol
+ qDebug() << "Legacy client detected, switching to compatibility mode";
+ _legacy = true;
+ RemotePeer* peer = PeerFactory::createPeer(PeerFactory::ProtoDescriptor(Protocol::LegacyProtocol, 0),
+ this,
+ socket(),
+ Compressor::NoCompression,
+ this);
+ connect(peer, &RemotePeer::protocolVersionMismatch, this, &CoreAuthHandler::onProtocolVersionMismatch);
+ setPeer(peer);
+ return;
+ }
+
+ _magicReceived = true;
+ quint8 features = magic & 0xff;
+ // figure out which connection features we'll use based on the client's support
+ if (Core::sslSupported() && (features & Protocol::Encryption))
+ _connectionFeatures |= Protocol::Encryption;
+ if (features & Protocol::Compression)
+ _connectionFeatures |= Protocol::Compression;