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; }
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:
// connection parameters
CHostAddress InetAddr;

View File

@ -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<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 --------------------------
void CProtocol::CreateJitBufMes ( const int iJitBufSize )
@ -512,7 +571,8 @@ bool CProtocol::EvaluateJitBufMes ( const CVector<uint8_t>& vecData )
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()
@ -528,14 +588,6 @@ void CProtocol::CreateServerFullMes()
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 )
{
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) *
\******************************************************************************/

View File

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

View File

@ -861,47 +861,49 @@ bool CServer::PutData ( const CVector<uint8_t>& 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();
}
}
}