support for server full message and parsing of connection less messages at the server

This commit is contained in:
Volker Fischer 2011-03-27 16:13:44 +00:00
parent 9903fab723
commit 184b995904
4 changed files with 129 additions and 47 deletions

View file

@ -202,6 +202,14 @@ public:
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; } void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
CHostAddress GetAddress() const { return InetAddr; } CHostAddress GetAddress() const { return InetAddr; }
bool ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes )
{
return Protocol.ParseConnectionLessMessage ( vecbyData, iNumBytes );
}
void CreateAndImmSendServerFullMes() { Protocol.CreateAndImmSendServerFullMes(); }
protected: protected:
// connection parameters // connection parameters
CHostAddress InetAddr; CHostAddress InetAddr;

View file

@ -408,10 +408,6 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
bRet = EvaluateReqJitBufMes(); bRet = EvaluateReqJitBufMes();
break; break;
case PROTMESSID_SERVER_FULL:
bRet = EvaluateServerFullMes();
break;
case PROTMESSID_CHANNEL_GAIN: case PROTMESSID_CHANNEL_GAIN:
bRet = EvaluateChanGainMes ( vecData ); bRet = EvaluateChanGainMes ( vecData );
break; break;
@ -471,6 +467,69 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
return bRet; return bRet;
} }
bool CProtocol::ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes )
{
/*
return code: false -> ok; true -> error
*/
bool bRet = false;
int iRecCounter, iRecID;
CVector<uint8_t> 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 -------------------------- // Access-functions for creating and parsing messages --------------------------
void CProtocol::CreateJitBufMes ( const int iJitBufSize ) void CProtocol::CreateJitBufMes ( const int iJitBufSize )
@ -512,7 +571,8 @@ bool CProtocol::EvaluateJitBufMes ( const CVector<uint8_t>& vecData )
void CProtocol::CreateReqJitBufMes() void CProtocol::CreateReqJitBufMes()
{ {
CreateAndSendMessage ( PROTMESSID_REQ_JITT_BUF_SIZE, CVector<uint8_t> ( 0 ) ); CreateAndSendMessage ( PROTMESSID_REQ_JITT_BUF_SIZE,
CVector<uint8_t> ( 0 ) );
} }
bool CProtocol::EvaluateReqJitBufMes() bool CProtocol::EvaluateReqJitBufMes()
@ -528,14 +588,6 @@ void CProtocol::CreateServerFullMes()
CreateAndSendMessage ( PROTMESSID_SERVER_FULL, CVector<uint8_t> ( 0 ) ); CreateAndSendMessage ( PROTMESSID_SERVER_FULL, CVector<uint8_t> ( 0 ) );
} }
bool CProtocol::EvaluateServerFullMes()
{
// invoke message action
emit ServerFull();
return false; // no error
}
void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain ) void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain )
{ {
CVector<uint8_t> vecData ( 3 ); // 3 bytes of data CVector<uint8_t> 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<uint8_t> ( 0 ) );
}
bool CProtocol::EvaluateServerFullMes()
{
// invoke message action
emit ServerFull();
return false; // no error
}
/******************************************************************************\ /******************************************************************************\
* Message generation (parsing) * * Message generation (parsing) *
\******************************************************************************/ \******************************************************************************/

View file

@ -97,11 +97,15 @@ public:
void CreateReqNetwTranspPropsMes(); void CreateReqNetwTranspPropsMes();
void CreateAndImmSendDisconnectionMes(); void CreateAndImmSendDisconnectionMes();
void CreateAndImmSendServerFullMes();
void CreateAndImmSendAcknMess ( const int& iID, const int& iCnt ); void CreateAndImmSendAcknMess ( const int& iID, const int& iCnt );
bool ParseMessage ( const CVector<uint8_t>& vecbyData, bool ParseMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes ); const int iNumBytes );
bool ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes );
bool IsProtocolMessage ( const CVector<uint8_t>& vecbyData, bool IsProtocolMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes ); const int iNumBytes );

View file

@ -861,12 +861,15 @@ bool CServer::PutData ( const CVector<uint8_t>& vecbyRecBuf,
if ( iCurChanID == INVALID_CHANNEL_ID ) 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 );
if ( ConnLessChannel.ParseConnectionLessMessage ( vecbyRecBuf,
// TODO at this point we have to check for connection less protocol messages! iNumBytesRead ) )
{
// a new client is calling, look for free channel // a new client is calling, look for free channel
iCurChanID = GetFreeChan(); iCurChanID = GetFreeChan();
@ -899,9 +902,8 @@ bool CServer::PutData ( const CVector<uint8_t>& vecbyRecBuf,
bChanOK = false; bChanOK = false;
// create and send "server full" message // create and send "server full" message
ConnLessChannel.CreateAndImmSendServerFullMes();
// TODO problem: if channel is not officially connected, we cannot send messages }
} }
} }