connection less messages system requires the host address to always be available (not stored in channel object)

This commit is contained in:
Volker Fischer 2011-03-29 20:11:03 +00:00
parent e2f028eae7
commit 0cff6af6d8
9 changed files with 163 additions and 93 deletions

View file

@ -551,5 +551,8 @@ int CChannel::GetUploadRateKbps()
// CConnectionLessChannel implementation ***************************************
CConnectionLessChannel::CConnectionLessChannel()
{
// TODO
// connections -------------------------------------------------------------
QObject::connect ( &Protocol,
SIGNAL ( CLMessReadyForSending ( CHostAddress, CVector<uint8_t> ) ),
SIGNAL ( CLMessReadyForSending ( CHostAddress, CVector<uint8_t> ) ) );
}

View file

@ -119,7 +119,7 @@ public:
void CreateReqJitBufMes() { Protocol.CreateReqJitBufMes(); }
void CreateReqConnClientsList() { Protocol.CreateReqConnClientsList(); }
void CreateChatTextMes ( const QString& strChatText ) { Protocol.CreateChatTextMes ( strChatText ); }
void CreatePingMes ( const int iMs ) { Protocol.CreatePingMes ( iMs, false ); }
void CreatePingMes ( const int iMs ) { Protocol.CreatePingMes ( iMs ); }
void CreateConClientListMes ( const CVector<CChannelShortInfo>& vecChanInfo )
{
@ -199,23 +199,23 @@ public:
CConnectionLessChannel();
virtual ~CConnectionLessChannel() {}
void SetAddress ( const CHostAddress NAddr ) { InetAddr = NAddr; }
CHostAddress GetAddress() const { return InetAddr; }
bool ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes )
const int iNumBytes,
const CHostAddress& InetAddr )
{
return Protocol.ParseConnectionLessMessage ( vecbyData, iNumBytes );
return Protocol.ParseConnectionLessMessage ( vecbyData, iNumBytes, InetAddr );
}
void CreateAndImmSendServerFullMes() { Protocol.CreateAndImmSendServerFullMes(); }
void CreateCLServerFullMes ( const CHostAddress& InetAddr )
{ Protocol.CreateCLServerFullMes ( InetAddr ); }
protected:
// connection parameters
CHostAddress InetAddr;
// network protocol
CProtocol Protocol;
CProtocol Protocol;
signals:
void CLMessReadyForSending ( CHostAddress InetAddr,
CVector<uint8_t> vecMessage );
};

View file

@ -89,6 +89,10 @@ CClient::CClient ( const quint16 iPortNumber ) :
SIGNAL ( MessReadyForSending ( CVector<uint8_t> ) ),
this, SLOT ( OnSendProtMessage ( CVector<uint8_t> ) ) );
QObject::connect ( &ConnLessChannel,
SIGNAL ( CLMessReadyForSending ( CHostAddress, CVector<uint8_t> ) ),
this, SLOT ( OnSendCLProtMessage ( CHostAddress, CVector<uint8_t> ) ) );
QObject::connect ( &Channel, SIGNAL ( ReqJittBufSize() ),
this, SLOT ( OnReqJittBufSize() ) );
@ -123,6 +127,14 @@ void CClient::OnSendProtMessage ( CVector<uint8_t> vecMessage )
Socket.SendPacket ( vecMessage, Channel.GetAddress() );
}
void CClient::OnSendCLProtMessage ( CHostAddress InetAddr,
CVector<uint8_t> vecMessage )
{
// the protocol queries me to call the function to send the message
// send it through the network
Socket.SendPacket ( vecMessage, InetAddr );
}
void CClient::OnNewConnection()
{
// a new connection was successfully initiated, send name and request

View file

@ -293,6 +293,7 @@ protected:
public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
void OnReqJittBufSize() { Channel.CreateJitBufMes ( Channel.GetSockBufNumFrames() ); }
void OnReqChanName() { Channel.SetRemoteName ( strName ); }
void OnNewConnection();

View file

@ -8,7 +8,8 @@
Protocol message definition
---------------------------
- All messages received need to be acknowledged by an acknowledge packet
- All messages received need to be acknowledged by an acknowledge packet (except
of connection less messages)
@ -18,9 +19,9 @@ MAIN FRAME
+-------------+------------+------------+------------------+ ...
| 2 bytes TAG | 2 bytes ID | 1 byte cnt | 2 bytes length n | ...
+-------------+------------+------------+------------------+ ...
... --------------+-------------+
... n bytes data | 2 bytes CRC |
... --------------+-------------+
... --------------+-------------+
... n bytes data | 2 bytes CRC |
... --------------+-------------+
- TAG is an all zero bit word to identify protocol messages
- message ID defined by the defines PROTMESSID_x
@ -31,10 +32,11 @@ MAIN FRAME
Generator polynom: G_16(x) = x^16 + x^12 + x^5 + 1, initial state: all ones
MESSAGES
--------
- Acknowledgement message: PROTMESSID_ACKN
- PROTMESSID_ACKN: Acknowledgement message
+-----------------------------------+
| 2 bytes ID of message to be ackn. |
@ -43,47 +45,43 @@ MESSAGES
note: the cnt value is the same as of the message to be acknowledged
- Jitter buffer size: PROTMESSID_JITT_BUF_SIZE
- PROTMESSID_JITT_BUF_SIZE: Jitter buffer size
+--------------------------+
| 2 bytes number of blocks |
+--------------------------+
- Request jitter buffer size: PROTMESSID_REQ_JITT_BUF_SIZE
- PROTMESSID_REQ_JITT_BUF_SIZE: Request jitter buffer size
note: does not have any data -> n = 0
- Server full message: PROTMESSID_SERVER_FULL
note: does not have any data -> n = 0
- Gain of channel: PROTMESSID_CHANNEL_GAIN
- PROTMESSID_CHANNEL_GAIN: Gain of channel
+-------------------+--------------+
| 1 byte channel ID | 2 bytes gain |
+-------------------+--------------+
- IP number and name of connected clients: PROTMESSID_CONN_CLIENTS_LIST
- PROTMESSID_CONN_CLIENTS_LIST: IP number and name of connected clients
for each connected client append following data:
+-------------------+--------------------+------------------+ ...
| 1 byte channel ID | 4 bytes IP address | 2 bytes number n | ...
+-------------------+--------------------+------------------+ ...
... ----------------------+
... n bytes UTF-8 string |
... ----------------------+
... ----------------------+
... n bytes UTF-8 string |
... ----------------------+
- Request connected clients list: PROTMESSID_REQ_CONN_CLIENTS_LIST
- PROTMESSID_REQ_CONN_CLIENTS_LIST: Request connected clients list
note: does not have any data -> n = 0
- Name of channel: PROTMESSID_CHANNEL_NAME
- PROTMESSID_CHANNEL_NAME: Name of channel
for each connected client append following data:
@ -91,33 +89,37 @@ MESSAGES
| 2 bytes number n | n bytes UTF-8 string |
+------------------+----------------------+
- Request name of channel: PROTMESSID_REQ_CHANNEL_NAME
- Chat text: PROTMESSID_CHAT_TEXT
- PROTMESSID_REQ_CHANNEL_NAME: Request name of channel
note: does not have any data -> n = 0
- PROTMESSID_CHAT_TEXT: Chat text
+------------------+----------------------+
| 2 bytes number n | n bytes UTF-8 string |
+------------------+----------------------+
- Ping message (for measuring the ping time): PROTMESSID_PING_MS
- PROTMESSID_PING_MS: Ping message (for measuring the ping time)
+-----------------------------+
| 4 bytes transmit time in ms |
+-----------------------------+
- Properties for network transport: PROTMESSID_NETW_TRANSPORT_PROPS
- PROTMESSID_NETW_TRANSPORT_PROPS: Properties for network transport
+------------------------+-------------------------+-----------------+ ...
| 4 bytes base netw size | 2 bytes block size fact | 1 byte num chan | ...
+------------------------+-------------------------+-----------------+ ...
... ------------------+-----------------------+ ...
... 4 bytes sam rate | 2 bytes audiocod type | ...
... ------------------+-----------------------+ ...
... -----------------+----------------------+
... 2 bytes version | 4 bytes audiocod arg |
... -----------------+----------------------+
... ------------------+-----------------------+ ...
... 4 bytes sam rate | 2 bytes audiocod type | ...
... ------------------+-----------------------+ ...
... -----------------+----------------------+
... 2 bytes version | 4 bytes audiocod arg |
... -----------------+----------------------+
- "base netw size": length of the base network packet (frame) in bytes
- "block size fact": block size factor
@ -130,12 +132,26 @@ MESSAGES
- "audiocod arg": argument for the audio coder, if not used this value shall be set to 0
- Request properties for network transport: PROTMESSID_REQ_NETW_TRANSPORT_PROPS
- PROTMESSID_REQ_NETW_TRANSPORT_PROPS: Request properties for network transport
note: does not have any data -> n = 0
- Disconnect message: PROTMESSID_DISCONNECTION
- PROTMESSID_DISCONNECTION: Disconnect message
note: does not have any data -> n = 0
CONNECTION LESS MESSAGES
------------------------
- PROTMESSID_CLM_PING_MS: Connection less ping message (for measuring the ping time)
note: same definition as PROTMESSID_PING_MS
- PROTMESSID_SERVER_FULL: Connection less server full message
note: does not have any data -> n = 0
@ -288,7 +304,8 @@ void CProtocol::CreateAndImmSendAcknMess ( const int& iID,
}
void CProtocol::CreateAndImmSendConLessMessage ( const int iID,
const CVector<uint8_t>& vecData )
const CVector<uint8_t>& vecData,
const CHostAddress& InetAddr )
{
CVector<uint8_t> vecNewMessage;
@ -297,7 +314,7 @@ void CProtocol::CreateAndImmSendConLessMessage ( const int iID,
GenMessageFrame ( vecNewMessage, 0, iID, vecData );
// immediately send message
emit MessReadyForSending ( vecNewMessage );
emit CLMessReadyForSending ( InetAddr, vecNewMessage );
}
bool CProtocol::IsProtocolMessage ( const CVector<uint8_t>& vecbyData,
@ -468,7 +485,8 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
}
bool CProtocol::ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes )
const int iNumBytes,
const CHostAddress& InetAddr )
{
/*
return code: false -> ok; true -> error
@ -485,11 +503,11 @@ bool CProtocol::ParseConnectionLessMessage ( const CVector<uint8_t>& vecbyData,
switch ( iRecID )
{
case PROTMESSID_CLM_PING_MS:
bRet = EvaluatePingMes ( vecData );
bRet = EvaluateCLPingMes ( InetAddr, vecData );
break;
case PROTMESSID_CLM_SERVER_FULL:
bRet = EvaluateServerFullMes();
bRet = EvaluateCLServerFullMes();
break;
case PROTMESSID_CLM_SERVER_LIST:
@ -583,11 +601,6 @@ bool CProtocol::EvaluateReqJitBufMes()
return false; // no error
}
void CProtocol::CreateServerFullMes()
{
CreateAndSendMessage ( PROTMESSID_SERVER_FULL, CVector<uint8_t> ( 0 ) );
}
void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain )
{
CVector<uint8_t> vecData ( 3 ); // 3 bytes of data
@ -871,8 +884,7 @@ bool CProtocol::EvaluateChatTextMes ( const CVector<uint8_t>& vecData )
return false; // no error
}
void CProtocol::CreatePingMes ( const int iMs,
const bool bIsConnectionLess )
void CProtocol::CreatePingMes ( const int iMs )
{
unsigned int iPos = 0; // init position pointer
@ -882,15 +894,7 @@ void CProtocol::CreatePingMes ( const int iMs,
// byte-by-byte copying of the string data
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iMs ), 4 );
// distinguish between connection less and with connection transmission
if ( bIsConnectionLess )
{
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_PING_MS, vecData );
}
else
{
CreateAndSendMessage ( PROTMESSID_PING_MS, vecData );
}
CreateAndSendMessage ( PROTMESSID_PING_MS, vecData );
}
bool CProtocol::EvaluatePingMes ( const CVector<uint8_t>& vecData )
@ -1076,13 +1080,46 @@ bool CProtocol::EvaluateDisconnectionMes()
// Connection less messages ----------------------------------------------------
void CProtocol::CreateAndImmSendServerFullMes()
void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs )
{
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_FULL,
CVector<uint8_t> ( 0 ) );
unsigned int iPos = 0; // init position pointer
// build data vector (4 bytes long)
CVector<uint8_t> vecData ( 4 );
// byte-by-byte copying of the string data
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iMs ), 4 );
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_PING_MS,
vecData,
InetAddr );
}
bool CProtocol::EvaluateServerFullMes()
bool CProtocol::EvaluateCLPingMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData )
{
unsigned int iPos = 0; // init position pointer
// check size
if ( vecData.Size() != 4 )
{
return true;
}
emit CLPingReceived ( InetAddr,
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) ) );
return false; // no error
}
void CProtocol::CreateCLServerFullMes ( const CHostAddress& InetAddr )
{
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_FULL,
CVector<uint8_t> ( 0 ),
InetAddr );
}
bool CProtocol::EvaluateCLServerFullMes()
{
// invoke message action
emit ServerFull();

View file

@ -87,24 +87,26 @@ public:
void CreateReqJitBufMes();
void CreateChanGainMes ( const int iChanID, const double dGain );
void CreateConClientListMes ( const CVector<CChannelShortInfo>& vecChanInfo );
void CreateServerFullMes();
void CreateReqConnClientsList();
void CreateChanNameMes ( const QString strName );
void CreateReqChanNameMes();
void CreateChatTextMes ( const QString strChatText );
void CreatePingMes ( const int iMs, const bool bIsConnectionLess );
void CreatePingMes ( const int iMs );
void CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps );
void CreateReqNetwTranspPropsMes();
void CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs );
void CreateCLServerFullMes ( const CHostAddress& InetAddr );
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 );
const int iNumBytes,
const CHostAddress& InetAddr );
bool IsProtocolMessage ( const CVector<uint8_t>& vecbyData,
const int iNumBytes );
@ -165,7 +167,8 @@ protected:
void CreateAndSendMessage ( const int iID, const CVector<uint8_t>& vecData );
void CreateAndImmSendConLessMessage ( const int iID,
const CVector<uint8_t>& vecData );
const CVector<uint8_t>& vecData,
const CHostAddress& InetAddr );
bool EvaluateJitBufMes ( const CVector<uint8_t>& vecData );
bool EvaluateReqJitBufMes();
@ -181,6 +184,10 @@ protected:
bool EvaluateReqNetwTranspPropsMes();
bool EvaluateDisconnectionMes();
bool EvaluateCLPingMes ( const CHostAddress& InetAddr,
const CVector<uint8_t>& vecData );
bool EvaluateCLServerFullMes();
int iOldRecID, iOldRecCnt;
// these two objects must be sequred by a mutex
@ -196,6 +203,8 @@ public slots:
signals:
// transmitting
void MessReadyForSending ( CVector<uint8_t> vecMessage );
void CLMessReadyForSending ( CHostAddress InetAddr,
CVector<uint8_t> vecMessage );
// receiving
void ChangeJittBufSize ( int iNewJitBufSize );
@ -212,6 +221,8 @@ signals:
void NetTranspPropsReceived ( CNetworkTransportProps NetworkTransportProps );
void ReqNetTranspProps();
void Disconnection();
void CLPingReceived ( CHostAddress InetAddr, int iMs );
};
#endif /* !defined ( PROTOCOL_H__3B123453_4344_BB2392354455IUHF1912__INCLUDED_ ) */

View file

@ -272,6 +272,10 @@ CServer::CServer ( const QString& strLoggingFileName,
QObject::connect ( &HighPrecisionTimer, SIGNAL ( timeout() ),
this, SLOT ( OnTimer() ) );
QObject::connect ( &ConnLessChannel,
SIGNAL ( CLMessReadyForSending ( CHostAddress, CVector<uint8_t> ) ),
this, SLOT ( OnSendCLProtMessage ( CHostAddress, CVector<uint8_t> ) ) );
// CODE TAG: MAX_NUM_CHANNELS_TAG
// make sure we have MAX_NUM_CHANNELS connections!!!
// send message
@ -354,6 +358,14 @@ void CServer::OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
Socket.SendPacket ( vecMessage, vecChannels[iChID].GetAddress() );
}
void CServer::OnSendCLProtMessage ( CHostAddress InetAddr,
CVector<uint8_t> vecMessage )
{
// the protocol queries me to call the function to send the message
// send it through the network
Socket.SendPacket ( vecMessage, InetAddr );
}
void CServer::Start()
{
// only start if not already running
@ -862,13 +874,10 @@ 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 );
// less message before we create a new official channel
if ( ConnLessChannel.ParseConnectionLessMessage ( vecbyRecBuf,
iNumBytesRead ) )
iNumBytesRead,
HostAdr ) )
{
// a new client is calling, look for free channel
iCurChanID = GetFreeChan();
@ -902,7 +911,7 @@ bool CServer::PutData ( const CVector<uint8_t>& vecbyRecBuf,
bChanOK = false;
// create and send "server full" message
ConnLessChannel.CreateAndImmSendServerFullMes();
ConnLessChannel.CreateCLServerFullMes ( HostAdr );
}
}
}

View file

@ -181,6 +181,7 @@ protected:
public slots:
void OnTimer();
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
void OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecMessage );
// CODE TAG: MAX_NUM_CHANNELS_TAG
// make sure we have MAX_NUM_CHANNELS connections!!!

View file

@ -75,7 +75,7 @@ public slots:
void OnTimer()
{
// generate random protocol message
switch ( GenRandomIntInRange ( 0, 11 ) )
switch ( GenRandomIntInRange ( 0, 10 ) )
{
case 0:
Protocol.CreateJitBufMes ( GenRandomIntInRange ( 0, 10 ) );
@ -91,41 +91,37 @@ public slots:
break;
case 3:
Protocol.CreateServerFullMes();
break;
case 4:
Protocol.CreateReqConnClientsList();
break;
case 5:
case 4:
Protocol.CreateChanNameMes ( QString ( "test%1" ).arg (
GenRandomIntInRange ( 0, 1000 ) ) );
break;
case 6:
case 5:
Protocol.CreateChatTextMes ( QString ( "test%1" ).arg (
GenRandomIntInRange ( 0, 1000 ) ) );
break;
case 7:
Protocol.CreatePingMes ( GenRandomIntInRange ( 0, 100000 ), false );
case 6:
Protocol.CreatePingMes ( GenRandomIntInRange ( 0, 100000 ) );
break;
case 8:
case 7:
Protocol.CreateReqNetwTranspPropsMes();
break;
case 9:
case 8:
Protocol.CreateAndImmSendAcknMess ( GenRandomIntInRange ( -10, 100 ),
GenRandomIntInRange ( -100, 100 ) );
break;
case 10:
case 9:
Protocol.CreateAndImmSendDisconnectionMes();
break;
case 11:
case 10:
// arbitrary "audio" packet (with random sizes)
CVector<uint8_t> vecMessage ( GenRandomIntInRange ( 1, 1000 ) );
OnSendProtMessage ( vecMessage );