From 9c0ca310ca1b6938cf100c9f7772d39ede630b31 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 23 Jan 2014 22:30:59 +0100 Subject: [PATCH] Have the PeerFactory provide the list of supported protocols ... and make use of that in ClientAuthHandler, instead of hardcoding the available protocols there. --- src/client/clientauthhandler.cpp | 9 ++++++++- src/common/peerfactory.cpp | 9 +++++++++ src/common/peerfactory.h | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/client/clientauthhandler.cpp b/src/client/clientauthhandler.cpp index 415a7ddb..74bb295b 100644 --- a/src/client/clientauthhandler.cpp +++ b/src/client/clientauthhandler.cpp @@ -180,7 +180,14 @@ void ClientAuthHandler::onSocketConnected() stream << magic; // here goes the list of protocols we support, in order of preference - stream << ((quint32)Protocol::LegacyProtocol | 0x80000000); // end list + PeerFactory::ProtoList protos = PeerFactory::supportedProtocols(); + for (int i = 0; i < protos.count(); ++i) { + quint32 reply = protos[i].first; + reply |= protos[i].second<<8; + if (i == protos.count() - 1) + reply |= 0x80000000; // end list + stream << reply; + } socket()->flush(); // make sure the probing data is sent immediately return; diff --git a/src/common/peerfactory.cpp b/src/common/peerfactory.cpp index 9d55fccd..32ea16af 100644 --- a/src/common/peerfactory.cpp +++ b/src/common/peerfactory.cpp @@ -22,6 +22,15 @@ #include "protocols/legacy/legacypeer.h" + +PeerFactory::ProtoList PeerFactory::supportedProtocols() +{ + ProtoList result; + result.append(ProtoDescriptor(Protocol::LegacyProtocol, 0)); + return result; +} + + RemotePeer *PeerFactory::createPeer(const ProtoDescriptor &protocol, AuthHandler *authHandler, QTcpSocket *socket, QObject *parent) { return createPeer(ProtoList() << protocol, authHandler, socket, parent); diff --git a/src/common/peerfactory.h b/src/common/peerfactory.h index 96737119..79a0c355 100644 --- a/src/common/peerfactory.h +++ b/src/common/peerfactory.h @@ -39,6 +39,8 @@ public: typedef QPair ProtoDescriptor; typedef QVector ProtoList; + static ProtoList supportedProtocols(); + static RemotePeer *createPeer(const ProtoDescriptor &protocol, AuthHandler *authHandler, QTcpSocket *socket, QObject *parent = 0); static RemotePeer *createPeer(const ProtoList &protocols, AuthHandler *authHandler, QTcpSocket *socket, QObject *parent = 0); -- 2.20.1