From 388664e48e49e972e62ed2a43a66215732c6cb22 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Fri, 21 Feb 2014 21:25:26 +0000 Subject: [PATCH] support for querying the server version and OS type for debugging purpose (not in the regular version available) --- src/client.cpp | 3 ++ src/client.h | 10 +++++ src/clientdlg.cpp | 7 ++++ src/clientdlg.h | 8 ++++ src/connectdlg.cpp | 40 ++++++++++++++++++ src/connectdlg.h | 5 +++ src/global.h | 1 + src/protocol.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++ src/protocol.h | 65 ++++++++++++++++------------- src/server.cpp | 3 ++ src/server.h | 3 ++ src/testbench.h | 18 +++++--- src/util.h | 43 +++++++++++++++++++ 13 files changed, 274 insertions(+), 34 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 6969ea3a..c4d99f08 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -199,6 +199,9 @@ QObject::connect ( &Channel, SIGNAL ( OpusSupported() ), SIGNAL ( CLPingWithNumClientsReceived ( CHostAddress, int, int ) ), this, SLOT ( OnCLPingWithNumClientsReceived ( CHostAddress, int, int ) ) ); + QObject::connect ( &ConnLessProtocol, + SIGNAL ( CLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType, QString ) ), + SIGNAL ( CLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType, QString ) ) ); // other QObject::connect ( &Sound, SIGNAL ( ReinitRequest ( int ) ), diff --git a/src/client.h b/src/client.h index f41a6077..0a9c952e 100755 --- a/src/client.h +++ b/src/client.h @@ -260,6 +260,11 @@ public: 0 /* dummy */ ); } + void CreateCLServerListReqVerAndOSMes ( const CHostAddress& InetAddr ) + { + ConnLessProtocol.CreateCLReqVersionAndOSMes ( InetAddr ); + } + void CreateCLReqServerListMes ( const CHostAddress& InetAddr ) { ConnLessProtocol.CreateCLReqServerListMes ( InetAddr ); } @@ -410,6 +415,11 @@ signals: void CLPingTimeWithNumClientsReceived ( CHostAddress InetAddr, int iPingTime, int iNumClients ); + + void CLVersionAndOSReceived ( CHostAddress InetAddr, + COSUtil::EOpSystemType eOSType, + QString strVersion ); + void Disconnected(); // #### COMPATIBILITY OLD VERSION, TO BE REMOVED #### diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index d010c9e1..b6b7beab 100755 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -495,6 +495,10 @@ CClientDlg::CClientDlg ( CClient* pNCliP, SIGNAL ( CLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ), this, SLOT ( OnCLPingTimeWithNumClientsReceived ( CHostAddress, int, int ) ) ); + QObject::connect ( pClient, + SIGNAL ( CLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType, QString ) ), + this, SLOT ( OnCLVersionAndOSReceived ( CHostAddress, COSUtil::EOpSystemType, QString ) ) ); + QObject::connect ( pClient, SIGNAL ( UpstreamRateChanged() ), this, SLOT ( OnUpstreamRateChanged() ) ); @@ -523,6 +527,9 @@ CClientDlg::CClientDlg ( CClient* pNCliP, QObject::connect ( &ConnectDlg, SIGNAL ( CreateCLServerListPingMes ( CHostAddress ) ), this, SLOT ( OnCreateCLServerListPingMes ( CHostAddress ) ) ); + QObject::connect ( &ConnectDlg, SIGNAL ( CreateCLServerListReqVerAndOSMes ( CHostAddress ) ), + this, SLOT ( OnCreateCLServerListReqVerAndOSMes ( CHostAddress ) ) ); + QObject::connect ( &ConnectDlg, SIGNAL ( accepted() ), this, SLOT ( OnConnectDlgAccepted() ) ); diff --git a/src/clientdlg.h b/src/clientdlg.h index 4042fca2..3096712f 100755 --- a/src/clientdlg.h +++ b/src/clientdlg.h @@ -129,6 +129,11 @@ public slots: int iPingTime, int iNumClients ); + void OnCLVersionAndOSReceived ( CHostAddress InetAddr, + COSUtil::EOpSystemType eOSType, + QString strVersion ) + { ConnectDlg.SetVersionAndOSType ( InetAddr, eOSType, strVersion ); } + void OnOpenConnectionSetupDialog() { ShowConnectionSetupDialog(); } void OnOpenGeneralSettings() { ShowGeneralSettings(); } void OnOpenChatDialog() { ShowChatWindow(); } @@ -166,6 +171,9 @@ public slots: void OnCreateCLServerListPingMes ( CHostAddress InetAddr ) { pClient->CreateCLServerListPingMes ( InetAddr ); } + void OnCreateCLServerListReqVerAndOSMes ( CHostAddress InetAddr ) + { pClient->CreateCLServerListReqVerAndOSMes ( InetAddr ); } + void OnCLServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ) { ConnectDlg.SetServerList ( InetAddr, vecServerInfo ); } diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index 425bef8d..56177ec5 100755 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -385,7 +385,17 @@ void CConnectDlg::OnTimerPing() CurServerAddress ) ) { // if address is valid, send ping + +// TEST send request for version and OS instead of ping message +const bool bEnableVerOSDebugging = false; // if this is set the "false", we have to regular version +if ( bEnableVerOSDebugging ) +{ + emit CreateCLServerListReqVerAndOSMes ( CurServerAddress ); +} +else +{ emit CreateCLServerListPingMes ( CurServerAddress ); +} } } } @@ -468,3 +478,33 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( CHostAddress& } } } + +void CConnectDlg::SetVersionAndOSType ( CHostAddress InetAddr, + COSUtil::EOpSystemType eOSType, + QString strVersion ) +{ + // apply the received version and OS type to the correct server list entry + const int iServerListLen = lvwServers->topLevelItemCount(); + + for ( int iIdx = 0; iIdx < iServerListLen; iIdx++ ) + { + // compare the received address with the user data string of the + // host address by a string compare + if ( !lvwServers->topLevelItem ( iIdx )-> + data ( 0, Qt::UserRole ).toString(). + compare ( InetAddr.toString() ) ) + { +// TEST since this is just a debug info, we just reuse the ping column (note +// the we have to replace the ping message emit with the version and OS request +// so that this works, see above code) +lvwServers->topLevelItem ( iIdx )-> + setText ( 1, strVersion + "/" + COSUtil::GetOperatingSystemString ( eOSType ) ); + +// a version and OS type was received, set item to visible +if ( lvwServers->topLevelItem ( iIdx )->isHidden() ) +{ + lvwServers->topLevelItem ( iIdx )->setHidden ( false ); +} + } + } +} diff --git a/src/connectdlg.h b/src/connectdlg.h index 4b59866c..e1cdca74 100755 --- a/src/connectdlg.h +++ b/src/connectdlg.h @@ -62,6 +62,10 @@ public: const CMultiColorLED::ELightColor ePingTimeLEDColor, const int iNumClients ); + void SetVersionAndOSType ( CHostAddress InetAddr, + COSUtil::EOpSystemType eOSType, + QString strVersion ); + bool GetServerListItemWasChosen() const { return bServerListItemWasChosen; } QString GetSelectedAddress() const { return strSelectedAddress; } QString GetSelectedServerName() const { return strSelectedServerName; } @@ -92,4 +96,5 @@ public slots: signals: void ReqServerListQuery ( CHostAddress InetAddr ); void CreateCLServerListPingMes ( CHostAddress InetAddr ); + void CreateCLServerListReqVerAndOSMes ( CHostAddress InetAddr ); }; diff --git a/src/global.h b/src/global.h index 656853ca..121bc152 100755 --- a/src/global.h +++ b/src/global.h @@ -213,6 +213,7 @@ LED bar: lbr #define MAX_LEN_SERVER_NAME 20 #define MAX_LEN_SERVER_TOPIC 32 #define MAX_LEN_SERVER_CITY 20 +#define MAX_LEN_VERSION_TEXT 20 // common tool tip bottom line text #define TOOLTIP_COM_END_TEXT tr ( \ diff --git a/src/protocol.cpp b/src/protocol.cpp index 204b6bf8..120c64e7 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -263,6 +263,17 @@ CONNECTION LESS MESSAGES note: does not have any data -> n = 0 +- PROTMESSID_CLM_VERSION_AND_OS: Version number and operating system + + +-------------------------+------------------+------------------------------+ + | 1 byte operating system | 2 bytes number n | n bytes UTF-8 string version | + +-------------------------+------------------+------------------------------+ + + +- PROTMESSID_CLM_REQ_VERSION_AND_OS: Request version number and operating system + + note: does not have any data -> n = 0 + ****************************************************************************** * * This program is free software; you can redistribute it and/or modify it under @@ -615,6 +626,14 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; case PROTMESSID_CLM_DISCONNECTION: bRet = EvaluateCLDisconnectionMes ( InetAddr ); break; + + case PROTMESSID_CLM_VERSION_AND_OS: + bRet = EvaluateCLVersionAndOSMes ( InetAddr, vecbyMesBodyData ); + break; + + case PROTMESSID_CLM_REQ_VERSION_AND_OS: + bRet = EvaluateCLReqVersionAndOSMes ( InetAddr ); + break; } } else @@ -1784,6 +1803,89 @@ bool CProtocol::EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr ) return false; // no error } +void CProtocol::CreateCLVersionAndOSMes ( const CHostAddress& InetAddr ) +{ + int iPos = 0; // init position pointer + + // get the version number string + const QString strVerion = VERSION; + + // convert version string to utf-8 + const QByteArray strUTF8Version = strVerion.toUtf8(); + + // size of current message body + const int iEntrLen = + 1 /* operating system */ + + 2 /* version utf-8 string size */ + strUTF8Version.size(); + + // build data vector + CVector vecData ( iEntrLen ); + + // operating system (1 byte) + PutValOnStream ( vecData, iPos, + static_cast ( COSUtil::GetOperatingSystem() ), 1 ); + + // version + PutStringUTF8OnStream ( vecData, iPos, strUTF8Version ); + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_VERSION_AND_OS, + vecData, + InetAddr ); +} + +bool CProtocol::EvaluateCLVersionAndOSMes ( const CHostAddress& InetAddr, + const CVector& vecData ) +{ + int iPos = 0; // init position pointer + const int iDataLen = vecData.Size(); + + // check size (the first 1 byte) + if ( iDataLen < 1 ) + { + return true; // return error code + } + + // operating system (1 byte) + const COSUtil::EOpSystemType eOSType = + static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + + // version text + QString strVersion; + if ( GetStringFromStream ( vecData, + iPos, + MAX_LEN_VERSION_TEXT, + strVersion ) ) + { + return true; // return error code + } + + // check size: all data is read, the position must now be at the end + if ( iPos != iDataLen ) + { + return true; // return error code + } + + // invoke message action + emit CLVersionAndOSReceived ( InetAddr, eOSType, strVersion ); + + return false; // no error +} + +void CProtocol::CreateCLReqVersionAndOSMes ( const CHostAddress& InetAddr ) +{ + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_VERSION_AND_OS, + CVector ( 0 ), + InetAddr ); +} + +bool CProtocol::EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr ) +{ + // invoke message action + emit CLReqVersionAndOS ( InetAddr ); + + return false; // no error +} + /******************************************************************************\ * Message generation and parsing * diff --git a/src/protocol.h b/src/protocol.h index 01df0173..eb973cfc 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -67,10 +67,8 @@ #define PROTMESSID_CLM_SEND_EMPTY_MESSAGE 1008 // an empty message shall be send #define PROTMESSID_CLM_EMPTY_MESSAGE 1009 // empty message #define PROTMESSID_CLM_DISCONNECTION 1010 // disconnection - - -// TODO implement message for querying the version and operating system of the server - +#define PROTMESSID_CLM_VERSION_AND_OS 1011 // version number and operating system +#define PROTMESSID_CLM_REQ_VERSION_AND_OS 1012 // request version number and operating system // lengths of message as defined in protocol.cpp file #define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2) @@ -104,21 +102,23 @@ public: void CreateReqNetwTranspPropsMes(); void CreateOpusSupportedMes(); - void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ); + void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs ); void CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, const int iMs, const int iNumClients ); - void CreateCLServerFullMes ( const CHostAddress& InetAddr ); - void CreateCLRegisterServerMes ( const CHostAddress& InetAddr, - const CServerCoreInfo& ServerInfo ); - void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr ); - void CreateCLServerListMes ( const CHostAddress& InetAddr, - const CVector vecServerInfo ); - void CreateCLReqServerListMes ( const CHostAddress& InetAddr ); - void CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr, - const CHostAddress& TargetInetAddr ); - void CreateCLEmptyMes ( const CHostAddress& InetAddr ); - void CreateCLDisconnection ( const CHostAddress& InetAddr ); + void CreateCLServerFullMes ( const CHostAddress& InetAddr ); + void CreateCLRegisterServerMes ( const CHostAddress& InetAddr, + const CServerCoreInfo& ServerInfo ); + void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr ); + void CreateCLServerListMes ( const CHostAddress& InetAddr, + const CVector vecServerInfo ); + void CreateCLReqServerListMes ( const CHostAddress& InetAddr ); + void CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr, + const CHostAddress& TargetInetAddr ); + void CreateCLEmptyMes ( const CHostAddress& InetAddr ); + void CreateCLDisconnection ( const CHostAddress& InetAddr ); + void CreateCLVersionAndOSMes ( const CHostAddress& InetAddr ); + void CreateCLReqVersionAndOSMes ( const CHostAddress& InetAddr ); static bool ParseMessageFrame ( const CVector& vecbyData, const int iNumBytesIn, @@ -228,6 +228,9 @@ protected: bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr ); bool EvaluateCLSendEmptyMesMes ( const CVector& vecData ); bool EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr ); + bool EvaluateCLVersionAndOSMes ( const CHostAddress& InetAddr, + const CVector& vecData ); + bool EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr ); int iOldRecID; int iOldRecCnt; @@ -265,19 +268,23 @@ signals: void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ); void ReqNetTranspProps(); - void CLPingReceived ( CHostAddress InetAddr, - int iMs ); - void CLPingWithNumClientsReceived ( CHostAddress InetAddr, - int iMs, - int iNumClients ); - void CLRegisterServerReceived ( CHostAddress InetAddr, - CServerCoreInfo ServerInfo ); - void CLUnregisterServerReceived ( CHostAddress InetAddr ); - void CLServerListReceived ( CHostAddress InetAddr, - CVector vecServerInfo ); - void CLReqServerList ( CHostAddress InetAddr ); - void CLSendEmptyMes ( CHostAddress TargetInetAddr ); - void CLDisconnection ( CHostAddress InetAddr ); + void CLPingReceived ( CHostAddress InetAddr, + int iMs ); + void CLPingWithNumClientsReceived ( CHostAddress InetAddr, + int iMs, + int iNumClients ); + void CLRegisterServerReceived ( CHostAddress InetAddr, + CServerCoreInfo ServerInfo ); + void CLUnregisterServerReceived ( CHostAddress InetAddr ); + void CLServerListReceived ( CHostAddress InetAddr, + CVector vecServerInfo ); + void CLReqServerList ( CHostAddress InetAddr ); + void CLSendEmptyMes ( CHostAddress TargetInetAddr ); + void CLDisconnection ( CHostAddress InetAddr ); + void CLVersionAndOSReceived ( CHostAddress InetAddr, + COSUtil::EOpSystemType eOSType, + QString strVersion ); + void CLReqVersionAndOS ( CHostAddress InetAddr ); }; #endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */ diff --git a/src/server.cpp b/src/server.cpp index 8aa91818..5e8033c7 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -422,6 +422,9 @@ CServer::CServer ( const int iNewMaxNumChan, SIGNAL ( CLDisconnection ( CHostAddress ) ), this, SLOT ( OnCLDisconnection ( CHostAddress ) ) ); + QObject::connect ( &ConnLessProtocol, + SIGNAL ( CLReqVersionAndOS ( CHostAddress ) ), + this, SLOT ( OnCLReqVersionAndOS ( CHostAddress ) ) ); // CODE TAG: MAX_NUM_CHANNELS_TAG // make sure we have MAX_NUM_CHANNELS connections!!! diff --git a/src/server.h b/src/server.h index 9b7a9192..ca62ca60 100755 --- a/src/server.h +++ b/src/server.h @@ -317,6 +317,9 @@ public slots: void OnCLReqServerList ( CHostAddress InetAddr ) { ServerListManager.CentralServerQueryServerList ( InetAddr ); } + void OnCLReqVersionAndOS ( CHostAddress InetAddr ) + { ConnLessProtocol.CreateCLVersionAndOSMes ( InetAddr ); } + void OnCLRegisterServerReceived ( CHostAddress InetAddr, CServerCoreInfo ServerInfo ) { diff --git a/src/testbench.h b/src/testbench.h index 6c5012f6..b8249781 100755 --- a/src/testbench.h +++ b/src/testbench.h @@ -106,7 +106,7 @@ public slots: CChannelCoreInfo ChannelCoreInfo; // generate random protocol message - switch ( GenRandomIntInRange ( 0, 24 ) ) + switch ( GenRandomIntInRange ( 0, 26 ) ) { case 0: // PROTMESSID_JITT_BUF_SIZE Protocol.CreateJitBufMes ( GenRandomIntInRange ( 0, 10 ) ); @@ -260,12 +260,20 @@ public slots: Protocol.CreateCLDisconnection ( CurHostAddress ); break; - case 23: // PROTMESSID_ACKN - Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ), - GenRandomIntInRange ( -100, 100 ) ); + case 23: // PROTMESSID_CLM_VERSION_AND_OS + Protocol.CreateCLVersionAndOSMes ( CurHostAddress ); break; - case 24: + case 24: // PROTMESSID_CLM_REQ_VERSION_AND_OS + Protocol.CreateCLReqVersionAndOSMes ( CurHostAddress ); + break; + + case 25: // PROTMESSID_ACKN + Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ), + GenRandomIntInRange ( -100, 100 ) ); + break; + + case 26: // arbitrary "audio" packet (with random sizes) CVector vecMessage ( GenRandomIntInRange ( 1, 1000 ) ); OnSendProtMessage ( vecMessage ); diff --git a/src/util.h b/src/util.h index b5c1fce5..2d0adad8 100755 --- a/src/util.h +++ b/src/util.h @@ -861,6 +861,49 @@ public: }; +// Operating system utility functions ------------------------------------------ +class COSUtil +{ +public: + enum EOpSystemType + { + // used for protocol -> enum values must be fixed! + OT_WINDOWS = 0, + OT_MAC_OS = 1, + OT_LINUX = 2, + OT_ANDROID = 3, + OT_I_OS = 4, + OT_UNIX = 5 + }; + + static QString GetOperatingSystemString ( const EOpSystemType eOSType ) + { + switch ( eOSType ) + { + case OT_WINDOWS: return "Windows"; break; + case OT_MAC_OS: return "MacOS"; break; + case OT_LINUX: return "Linux"; break; + case OT_ANDROID: return "Android"; break; + case OT_I_OS: return "iOS"; break; + case OT_UNIX: return "Unix"; break; + } + } + + static EOpSystemType GetOperatingSystem() + { +#ifdef _WIN32 + return OT_WINDOWS; +#elif defined ( __APPLE__ ) || defined ( __MACOSX ) + return OT_MAC_OS; +#elif definded ( ANDROID ) + return OT_ANDROID; +#else + return OT_LINUX; +#endif + } +}; + + // Audio reverbration ---------------------------------------------------------- class CAudioReverb {