diff --git a/src/channel.h b/src/channel.h index b6982892..206646c1 100755 --- a/src/channel.h +++ b/src/channel.h @@ -202,6 +202,14 @@ public: void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; } CHostAddress GetAddress() const { return InetAddr; } + bool ParseConnectionLessMessage ( const CVector& vecbyData, + const int iNumBytes ) + { + return Protocol.ParseConnectionLessMessage ( vecbyData, iNumBytes ); + } + + void CreateAndImmSendServerFullMes() { Protocol.CreateAndImmSendServerFullMes(); } + protected: // connection parameters CHostAddress InetAddr; diff --git a/src/protocol.cpp b/src/protocol.cpp index d0a3fc5e..9677019b 100755 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -408,10 +408,6 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; bRet = EvaluateReqJitBufMes(); break; - case PROTMESSID_SERVER_FULL: - bRet = EvaluateServerFullMes(); - break; - case PROTMESSID_CHANNEL_GAIN: bRet = EvaluateChanGainMes ( vecData ); break; @@ -471,6 +467,69 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false; return bRet; } +bool CProtocol::ParseConnectionLessMessage ( const CVector& vecbyData, + const int iNumBytes ) +{ +/* + return code: false -> ok; true -> error +*/ + bool bRet = false; + int iRecCounter, iRecID; + CVector vecData; + + if ( !ParseMessageFrame ( vecbyData, iNumBytes, iRecCounter, iRecID, vecData ) ) + { + if ( IsConnectionLessMessageID ( iRecID ) ) + { + // check which type of message we received and do action + switch ( iRecID ) + { + case PROTMESSID_CLM_PING_MS: + bRet = EvaluatePingMes ( vecData ); + break; + + case PROTMESSID_CLM_SERVER_FULL: + bRet = EvaluateServerFullMes(); + break; + + case PROTMESSID_CLM_SERVER_LIST: +// TODO + break; + + case PROTMESSID_CLM_REQ_SERVER_LIST: +// TODO + break; + + case PROTMESSID_CLM_SEND_EMPTY_MESSAGE: +// TODO + break; + + case PROTMESSID_CLM_EMPTY_MESSAGE: +// TODO + break; + + case PROTMESSID_CLM_REGISTER_SERVER: +// TODO + break; + + case PROTMESSID_CLM_UNREGISTER_SERVER: +// TODO + break; + } + } + else + { + bRet = true; // return error code + } + } + else + { + bRet = true; // return error code + } + + return bRet; +} + // Access-functions for creating and parsing messages -------------------------- void CProtocol::CreateJitBufMes ( const int iJitBufSize ) @@ -512,7 +571,8 @@ bool CProtocol::EvaluateJitBufMes ( const CVector& vecData ) void CProtocol::CreateReqJitBufMes() { - CreateAndSendMessage ( PROTMESSID_REQ_JITT_BUF_SIZE, CVector ( 0 ) ); + CreateAndSendMessage ( PROTMESSID_REQ_JITT_BUF_SIZE, + CVector ( 0 ) ); } bool CProtocol::EvaluateReqJitBufMes() @@ -528,14 +588,6 @@ void CProtocol::CreateServerFullMes() CreateAndSendMessage ( PROTMESSID_SERVER_FULL, CVector ( 0 ) ); } -bool CProtocol::EvaluateServerFullMes() -{ - // invoke message action - emit ServerFull(); - - return false; // no error -} - void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) { CVector vecData ( 3 ); // 3 bytes of data @@ -1023,6 +1075,22 @@ bool CProtocol::EvaluateDisconnectionMes() } +// Connection less messages ---------------------------------------------------- +void CProtocol::CreateAndImmSendServerFullMes() +{ + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_FULL, + CVector ( 0 ) ); +} + +bool CProtocol::EvaluateServerFullMes() +{ + // invoke message action + emit ServerFull(); + + return false; // no error +} + + /******************************************************************************\ * Message generation (parsing) * \******************************************************************************/ diff --git a/src/protocol.h b/src/protocol.h index 72638333..8e39413a 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -97,11 +97,15 @@ public: void CreateReqNetwTranspPropsMes(); void CreateAndImmSendDisconnectionMes(); + void CreateAndImmSendServerFullMes(); void CreateAndImmSendAcknMess ( const int& iID, const int& iCnt ); bool ParseMessage ( const CVector& vecbyData, const int iNumBytes ); + bool ParseConnectionLessMessage ( const CVector& vecbyData, + const int iNumBytes ); + bool IsProtocolMessage ( const CVector& vecbyData, const int iNumBytes ); diff --git a/src/server.cpp b/src/server.cpp index e604ca96..8efa8a70 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -861,47 +861,49 @@ bool CServer::PutData ( const CVector& vecbyRecBuf, if ( iCurChanID == INVALID_CHANNEL_ID ) { + // this is a new client, we then first check if this is a connection + // less message before we create a new official channel (note that + // we have to set the internet address first, before we parse the + // connection less message!) + ConnLessChannel.SetAddress ( HostAdr ); - -// TODO at this point we have to check for connection less protocol messages! - - - - // a new client is calling, look for free channel - iCurChanID = GetFreeChan(); - - if ( iCurChanID != INVALID_CHANNEL_ID ) + if ( ConnLessChannel.ParseConnectionLessMessage ( vecbyRecBuf, + iNumBytesRead ) ) { - // initialize current channel by storing the calling host - // address - vecChannels[iCurChanID].SetAddress ( HostAdr ); + // a new client is calling, look for free channel + iCurChanID = GetFreeChan(); - // reset channel name - vecChannels[iCurChanID].ResetName(); - - // reset the channel gains of current channel, at the same - // time reset gains of this channel ID for all other channels - for ( int i = 0; i < USED_NUM_CHANNELS; i++ ) + if ( iCurChanID != INVALID_CHANNEL_ID ) { - vecChannels[iCurChanID].SetGain ( i, (double) 1.0 ); + // initialize current channel by storing the calling host + // address + vecChannels[iCurChanID].SetAddress ( HostAdr ); - // other channels (we do not distinguish the case if - // i == iCurChanID for simplicity) - vecChannels[i].SetGain ( iCurChanID, (double) 1.0 ); + // reset channel name + vecChannels[iCurChanID].ResetName(); + + // reset the channel gains of current channel, at the same + // time reset gains of this channel ID for all other channels + for ( int i = 0; i < USED_NUM_CHANNELS; i++ ) + { + vecChannels[iCurChanID].SetGain ( i, (double) 1.0 ); + + // other channels (we do not distinguish the case if + // i == iCurChanID for simplicity) + vecChannels[i].SetGain ( iCurChanID, (double) 1.0 ); + } + + // set flag for new reserved channel + bNewChannelReserved = true; } + else + { + // no free channel available + bChanOK = false; - // set flag for new reserved channel - bNewChannelReserved = true; - } - else - { - // no free channel available - bChanOK = false; - - // create and send "server full" message - -// TODO problem: if channel is not officially connected, we cannot send messages - + // create and send "server full" message + ConnLessChannel.CreateAndImmSendServerFullMes(); + } } }