From 49070c77c129b14246c321df7d8d49f10af0c928 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Tue, 24 May 2011 19:40:57 +0000 Subject: [PATCH] replaced normal ping messages with connection less ping message to avoid all the acknowledge messages --- src/channel.cpp | 4 ---- src/channel.h | 2 -- src/client.cpp | 22 ++++++++++++++-------- src/client.h | 12 ++++-------- src/llconclientdlg.cpp | 4 ++-- src/protocol.cpp | 40 ---------------------------------------- src/protocol.h | 5 +---- src/server.cpp | 18 ++++-------------- src/server.h | 16 +++------------- src/testbench.h | 32 ++++++++++++++------------------ 10 files changed, 42 insertions(+), 113 deletions(-) diff --git a/src/channel.cpp b/src/channel.cpp index b361ff6d..efb33b72 100755 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -89,10 +89,6 @@ CChannel::CChannel ( const bool bNIsServer ) : SIGNAL ( ChatTextReceived ( QString ) ), SIGNAL ( ChatTextReceived ( QString ) ) ); - QObject::connect( &Protocol, - SIGNAL ( PingReceived ( int ) ), - SIGNAL ( PingReceived ( int ) ) ); - QObject::connect ( &Protocol, SIGNAL ( DetectedCLMessage ( CVector, int ) ), SIGNAL ( DetectedCLMessage ( CVector, int ) ) ); diff --git a/src/channel.h b/src/channel.h index 54b22e6f..8b14e8e1 100755 --- a/src/channel.h +++ b/src/channel.h @@ -130,7 +130,6 @@ void UpdateSocketBufferSize ( const double dAudioBufferDurationMs, void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); } void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); } void CreateChatTextMes ( const QString& strChatText ) { Protocol.CreateChatTextMes ( strChatText ); } - void CreatePingMes ( const int iMs ) { Protocol.CreatePingMes ( iMs ); } void CreateConClientListMes ( const CVector& vecChanInfo ) { @@ -194,7 +193,6 @@ signals: void NameHasChanged(); void ReqChanName(); void ChatTextReceived ( QString strChatText ); - void PingReceived ( int iMs ); void ReqNetTranspProps(); void Disconnected(); void DetectedCLMessage ( CVector vecbyData, diff --git a/src/client.cpp b/src/client.cpp index 87377b18..0e6eaabe 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -108,9 +108,6 @@ CClient::CClient ( const quint16 iPortNumber ) : SIGNAL ( ChatTextReceived ( QString ) ), SIGNAL ( ChatTextReceived ( QString ) ) ); - QObject::connect ( &Channel, SIGNAL ( PingReceived ( int ) ), - this, SLOT ( OnReceivePingMessage ( int ) ) ); - QObject::connect ( &ConnLessProtocol, SIGNAL ( CLMessReadyForSending ( CHostAddress, CVector ) ), this, SLOT ( OnSendCLProtMessage ( CHostAddress, CVector ) ) ); @@ -119,6 +116,10 @@ CClient::CClient ( const quint16 iPortNumber ) : SIGNAL ( CLServerListReceived ( CHostAddress, CVector ) ), SIGNAL ( CLServerListReceived ( CHostAddress, CVector ) ) ); + QObject::connect ( &ConnLessProtocol, + SIGNAL ( CLPingReceived ( CHostAddress, int ) ), + this, SLOT ( OnCLPingReceived ( CHostAddress, int ) ) ); + QObject::connect ( &ConnLessProtocol, SIGNAL ( CLPingWithNumClientsReceived ( CHostAddress, int, int ) ), this, SLOT ( OnCLPingWithNumClientsReceived ( CHostAddress, int, int ) ) ); @@ -168,13 +169,18 @@ void CClient::OnNewConnection() Channel.CreateJitBufMes ( Channel.GetSockBufNumFrames() ); } -void CClient::OnReceivePingMessage ( int iMs ) +void CClient::OnCLPingReceived ( CHostAddress InetAddr, + int iMs ) { - // take care of wrap arounds (if wrapping, do not use result) - const int iCurDiff = EvaluatePingMessage ( iMs ); - if ( iCurDiff >= 0 ) + // make sure we are running and the server address is correct + if ( IsRunning() && ( InetAddr == Channel.GetAddress() ) ) { - emit PingTimeReceived ( iCurDiff ); + // take care of wrap arounds (if wrapping, do not use result) + const int iCurDiff = EvaluatePingMessage ( iMs ); + if ( iCurDiff >= 0 ) + { + emit PingTimeReceived ( iCurDiff ); + } } } diff --git a/src/client.h b/src/client.h index 1d073b27..1a79096c 100755 --- a/src/client.h +++ b/src/client.h @@ -224,13 +224,8 @@ public: void CreateChatTextMes ( const QString& strChatText ) { Channel.CreateChatTextMes ( strChatText ); } - void CreatePingMes() - { Channel.CreatePingMes ( PreparePingMessage() ); } - -// TODO -//void CreateCLPingMes ( const CHostAddress& InetAddr ) -// { ConnLessProtocol.CreateCLPingMes ( InetAddr, PreparePingMessage() ); } - + void CreateCLPingMes() + { ConnLessProtocol.CreateCLPingMes ( Channel.GetAddress(), PreparePingMessage() ); } void CreateCLServerListPingMes ( const CHostAddress& InetAddr ) { @@ -331,7 +326,8 @@ public slots: void OnReqJittBufSize() { Channel.CreateJitBufMes ( Channel.GetSockBufNumFrames() ); } void OnReqChanName() { Channel.SetRemoteName ( strName ); } void OnNewConnection(); - void OnReceivePingMessage ( int iMs ); + void OnCLPingReceived ( CHostAddress InetAddr, + int iMs ); void OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage ); void OnCLPingWithNumClientsReceived ( CHostAddress InetAddr, diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 1fe61efb..62c8508c 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -641,8 +641,8 @@ void CLlconClientDlg::OnTimerSigMet() void CLlconClientDlg::OnTimerPing() { - // send ping message to server - pClient->CreatePingMes(); + // send ping message to the server + pClient->CreateCLPingMes(); } void CLlconClientDlg::OnPingTimeResult ( int iPingTime ) diff --git a/src/protocol.cpp b/src/protocol.cpp index 74085784..0442a42e 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -102,13 +102,6 @@ MESSAGES (with connection) +------------------+----------------------+ -- PROTMESSID_PING_MS: Ping message (for measuring the ping time) - - +-----------------------------+ - | 4 bytes transmit time in ms | - +-----------------------------+ - - - PROTMESSID_NETW_TRANSPORT_PROPS: Properties for network transport +------------------------+-------------------------+-----------------+ ... @@ -525,10 +518,6 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; bRet = EvaluateChatTextMes ( vecData ); break; - case PROTMESSID_PING_MS: - bRet = EvaluatePingMes ( vecData ); - break; - case PROTMESSID_NETW_TRANSPORT_PROPS: bRet = EvaluateNetwTranspPropsMes ( vecData ); break; @@ -924,35 +913,6 @@ bool CProtocol::EvaluateChatTextMes ( const CVector& vecData ) return false; // no error } -void CProtocol::CreatePingMes ( const int iMs ) -{ - int iPos = 0; // init position pointer - - // build data vector (4 bytes long) - CVector vecData ( 4 ); - - // transmit time (4 bytes) - PutValOnStream ( vecData, iPos, static_cast ( iMs ), 4 ); - - CreateAndSendMessage ( PROTMESSID_PING_MS, vecData ); -} - -bool CProtocol::EvaluatePingMes ( const CVector& vecData ) -{ - int iPos = 0; // init position pointer - - // check size - if ( vecData.Size() != 4 ) - { - return true; // return error code - } - - // invoke message action - emit PingReceived ( static_cast ( GetValFromStream ( vecData, iPos, 4 ) ) ); - - return false; // no error -} - void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps ) { int iPos = 0; // init position pointer diff --git a/src/protocol.h b/src/protocol.h index 0572eb0f..6854e727 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -47,7 +47,7 @@ #define PROTMESSID_REQ_CONN_CLIENTS_LIST 16 // request connected client list #define PROTMESSID_CHANNEL_NAME 17 // set channel name for fader tag #define PROTMESSID_CHAT_TEXT 18 // contains a chat text -#define PROTMESSID_PING_MS 19 // for measuring ping time +#define PROTMESSID_PING_MS 19 // OLD (not used anymore) #define PROTMESSID_NETW_TRANSPORT_PROPS 20 // properties for network transport #define PROTMESSID_REQ_NETW_TRANSPORT_PROPS 21 // request properties for network transport #define PROTMESSID_DISCONNECTION 22 // OLD (not used anymore) @@ -93,7 +93,6 @@ public: void CreateChanNameMes ( const QString strName ); void CreateReqChanNameMes(); void CreateChatTextMes ( const QString strChatText ); - void CreatePingMes ( const int iMs ); void CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps ); void CreateReqNetwTranspPropsMes(); @@ -204,7 +203,6 @@ protected: bool EvaluateChanNameMes ( const CVector& vecData ); bool EvaluateReqChanNameMes(); bool EvaluateChatTextMes ( const CVector& vecData ); - bool EvaluatePingMes ( const CVector& vecData ); bool EvaluateNetwTranspPropsMes ( const CVector& vecData ); bool EvaluateReqNetwTranspPropsMes(); @@ -252,7 +250,6 @@ signals: void ChangeChanName ( QString strName ); void ReqChanName(); void ChatTextReceived ( QString strChatText ); - void PingReceived ( int iMs ); void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps ); void ReqNetTranspProps(); diff --git a/src/server.cpp b/src/server.cpp index a35a1b61..fa2996eb 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -284,6 +284,10 @@ CServer::CServer ( const int iNewNumChan, SIGNAL ( CLMessReadyForSending ( CHostAddress, CVector ) ), this, SLOT ( OnSendCLProtMessage ( CHostAddress, CVector ) ) ); + QObject::connect ( &ConnLessProtocol, + SIGNAL ( CLPingReceived ( CHostAddress, int ) ), + this, SLOT ( OnCLPingReceived ( CHostAddress, int ) ) ); + QObject::connect ( &ConnLessProtocol, SIGNAL ( CLPingWithNumClientsReceived ( CHostAddress, int, int ) ), this, SLOT ( OnCLPingWithNumClientsReceived ( CHostAddress, int, int ) ) ); @@ -394,20 +398,6 @@ CServer::CServer ( const int iNewNumChan, QObject::connect ( &vecChannels[9], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh9 ( QString ) ) ); QObject::connect ( &vecChannels[10], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh10 ( QString ) ) ); QObject::connect ( &vecChannels[11], SIGNAL ( ChatTextReceived ( QString ) ), this, SLOT ( OnChatTextReceivedCh11 ( QString ) ) ); - - // ping message received - QObject::connect ( &vecChannels[0], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh0 ( int ) ) ); - QObject::connect ( &vecChannels[1], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh1 ( int ) ) ); - QObject::connect ( &vecChannels[2], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh2 ( int ) ) ); - QObject::connect ( &vecChannels[3], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh3 ( int ) ) ); - QObject::connect ( &vecChannels[4], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh4 ( int ) ) ); - QObject::connect ( &vecChannels[5], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh5 ( int ) ) ); - QObject::connect ( &vecChannels[6], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh6 ( int ) ) ); - QObject::connect ( &vecChannels[7], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh7 ( int ) ) ); - QObject::connect ( &vecChannels[8], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh8 ( int ) ) ); - QObject::connect ( &vecChannels[9], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh9 ( int ) ) ); - QObject::connect ( &vecChannels[10], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh10 ( int ) ) ); - QObject::connect ( &vecChannels[11], SIGNAL ( PingReceived ( int ) ), this, SLOT ( OnPingReceivedCh11 ( int ) ) ); } void CServer::OnSendProtMessage ( int iChID, CVector vecMessage ) diff --git a/src/server.h b/src/server.h index 500b9578..55a06607 100755 --- a/src/server.h +++ b/src/server.h @@ -249,6 +249,9 @@ public slots: const int iNumBytes, const CHostAddress& InetAddr ); + void OnCLPingReceived ( CHostAddress InetAddr, int iMs ) + { ConnLessProtocol.CreateCLPingMes ( InetAddr, iMs ); } + void OnCLPingWithNumClientsReceived ( CHostAddress InetAddr, int iMs, int ) @@ -366,19 +369,6 @@ public slots: void OnChatTextReceivedCh9 ( QString strChatText ) { CreateAndSendChatTextForAllConChannels ( 9, strChatText ); } void OnChatTextReceivedCh10 ( QString strChatText ) { CreateAndSendChatTextForAllConChannels ( 10, strChatText ); } void OnChatTextReceivedCh11 ( QString strChatText ) { CreateAndSendChatTextForAllConChannels ( 11, strChatText ); } - - void OnPingReceivedCh0 ( int iMs ) { vecChannels[0].CreatePingMes ( iMs ); } - void OnPingReceivedCh1 ( int iMs ) { vecChannels[1].CreatePingMes ( iMs ); } - void OnPingReceivedCh2 ( int iMs ) { vecChannels[2].CreatePingMes ( iMs ); } - void OnPingReceivedCh3 ( int iMs ) { vecChannels[3].CreatePingMes ( iMs ); } - void OnPingReceivedCh4 ( int iMs ) { vecChannels[4].CreatePingMes ( iMs ); } - void OnPingReceivedCh5 ( int iMs ) { vecChannels[5].CreatePingMes ( iMs ); } - void OnPingReceivedCh6 ( int iMs ) { vecChannels[6].CreatePingMes ( iMs ); } - void OnPingReceivedCh7 ( int iMs ) { vecChannels[7].CreatePingMes ( iMs ); } - void OnPingReceivedCh8 ( int iMs ) { vecChannels[8].CreatePingMes ( iMs ); } - void OnPingReceivedCh9 ( int iMs ) { vecChannels[9].CreatePingMes ( iMs ); } - void OnPingReceivedCh10 ( int iMs ) { vecChannels[10].CreatePingMes ( iMs ); } - void OnPingReceivedCh11 ( int iMs ) { vecChannels[11].CreatePingMes ( iMs ); } }; #endif /* !defined ( SERVER_HOIHGE7LOKIH83JH8_3_43445KJIUHF1912__INCLUDED_ ) */ diff --git a/src/testbench.h b/src/testbench.h index 9e612dc4..276c2576 100755 --- a/src/testbench.h +++ b/src/testbench.h @@ -101,7 +101,7 @@ public slots: CHostAddress CurHostAddress ( QHostAddress ( sAddress ), iPort ); // generate random protocol message - switch ( GenRandomIntInRange ( 0, 22 ) ) + switch ( GenRandomIntInRange ( 0, 21 ) ) { case 0: Protocol.CreateJitBufMes ( GenRandomIntInRange ( 0, 10 ) ); @@ -141,10 +141,6 @@ public slots: break; case 8: - Protocol.CreatePingMes ( GenRandomIntInRange ( 0, 100000 ) ); - break; - - case 9: NetTrProps.eAudioCodingType = static_cast ( GenRandomIntInRange ( 0, 2 ) ); @@ -158,26 +154,26 @@ public slots: Protocol.CreateNetwTranspPropsMes ( NetTrProps ); break; - case 10: + case 9: Protocol.CreateReqNetwTranspPropsMes(); break; - case 11: + case 10: Protocol.CreateCLPingMes ( CurHostAddress, GenRandomIntInRange ( -2, 1000 ) ); break; - case 12: + case 11: Protocol.CreateCLPingWithNumClientsMes ( CurHostAddress, GenRandomIntInRange ( -2, 1000 ), GenRandomIntInRange ( -2, 1000 ) ); break; - case 13: + case 12: Protocol.CreateCLServerFullMes ( CurHostAddress ); break; - case 14: + case 13: ServerInfo.bPermanentOnline = static_cast ( GenRandomIntInRange ( 0, 1 ) ); @@ -194,11 +190,11 @@ public slots: ServerInfo ); break; - case 15: + case 14: Protocol.CreateCLUnregisterServerMes ( CurHostAddress ); break; - case 16: + case 15: vecServerInfo[0].bPermanentOnline = static_cast ( GenRandomIntInRange ( 0, 1 ) ); @@ -216,29 +212,29 @@ public slots: vecServerInfo ); break; - case 17: + case 16: Protocol.CreateCLReqServerListMes ( CurHostAddress ); break; - case 18: + case 17: Protocol.CreateCLSendEmptyMesMes ( CurHostAddress, CurHostAddress ); break; - case 19: + case 18: Protocol.CreateCLEmptyMes ( CurHostAddress ); break; - case 20: + case 19: Protocol.CreateCLDisconnection ( CurHostAddress ); break; - case 21: + case 20: Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ), GenRandomIntInRange ( -100, 100 ) ); break; - case 22: + case 21: // arbitrary "audio" packet (with random sizes) CVector vecMessage ( GenRandomIntInRange ( 1, 1000 ) ); OnSendProtMessage ( vecMessage );