- bug fix for endless ping message loop causing a lot of network traffic

- implementation of empty message sending in slave server to keep NAT port open
This commit is contained in:
Volker Fischer 2012-07-09 12:52:23 +00:00
parent b625a77521
commit 8a167d844b

View file

@ -1,456 +1,478 @@
/******************************************************************************\ /******************************************************************************\
* Copyright (c) 2004-2011 * Copyright (c) 2004-2011
* *
* Author(s): * Author(s):
* Volker Fischer * Volker Fischer
* *
****************************************************************************** ******************************************************************************
* *
* This program is free software; you can redistribute it and/or modify it under * This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software * the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later * Foundation; either version 2 of the License, or (at your option) any later
* version. * version.
* *
* This program is distributed in the hope that it will be useful, but WITHOUT * This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. * details.
* *
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., * this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
\******************************************************************************/ \******************************************************************************/
#include "serverlist.h" #include "serverlist.h"
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CServerListManager::CServerListManager ( const quint16 iNPortNum, CServerListManager::CServerListManager ( const quint16 iNPortNum,
const QString& sNCentServAddr, const QString& sNCentServAddr,
const QString& strServerInfo, const QString& strServerInfo,
const int iNumChannels, const int iNumChannels,
CProtocol* pNConLProt ) CProtocol* pNConLProt )
: iPortNumber ( iNPortNum ), : iPortNumber ( iNPortNum ),
iNumPredefinedServers ( 0 ), iNumPredefinedServers ( 0 ),
bUseDefaultCentralServerAddress ( false ), bUseDefaultCentralServerAddress ( false ),
pConnLessProtocol ( pNConLProt ) pConnLessProtocol ( pNConLProt )
{ {
// set the central server address // set the central server address
SetCentralServerAddress ( sNCentServAddr ); SetCentralServerAddress ( sNCentServAddr );
// prepare the server info information // prepare the server info information
QStringList slServInfoSeparateParams; QStringList slServInfoSeparateParams;
int iServInfoNumSplitItems = 0; int iServInfoNumSplitItems = 0;
if ( !strServerInfo.isEmpty() ) if ( !strServerInfo.isEmpty() )
{ {
// split the different parameter strings // split the different parameter strings
slServInfoSeparateParams = strServerInfo.split ( ";" ); slServInfoSeparateParams = strServerInfo.split ( ";" );
// get the number of items in the split list // get the number of items in the split list
iServInfoNumSplitItems = slServInfoSeparateParams.count(); iServInfoNumSplitItems = slServInfoSeparateParams.count();
} }
// per definition, the very first entry is this server and this entry will // per definition, the very first entry is this server and this entry will
// never be deleted // never be deleted
ServerList.clear(); ServerList.clear();
// init server list entry (server info for this server) with defaults, per // init server list entry (server info for this server) with defaults, per
// definition the client substitudes the IP address of the central server // definition the client substitudes the IP address of the central server
// itself for his server list // itself for his server list
CServerListEntry ThisServerListEntry ( CHostAddress(), CServerListEntry ThisServerListEntry ( CHostAddress(),
iPortNumber, iPortNumber,
"", "",
"", "",
QLocale::system().country(), QLocale::system().country(),
"", "",
iNumChannels, iNumChannels,
true ); true );
// parse the server info string according to definition: // parse the server info string according to definition:
// [this server name];[this server city]; ... // [this server name];[this server city]; ...
// [this server country as QLocale ID]; ... // [this server country as QLocale ID]; ...
// per definition, we expect at least three parameters // per definition, we expect at least three parameters
if ( iServInfoNumSplitItems >= 3 ) if ( iServInfoNumSplitItems >= 3 )
{ {
// [this server name] // [this server name]
ThisServerListEntry.strName = slServInfoSeparateParams[0]; ThisServerListEntry.strName = slServInfoSeparateParams[0];
// [this server city] // [this server city]
ThisServerListEntry.strCity = slServInfoSeparateParams[1]; ThisServerListEntry.strCity = slServInfoSeparateParams[1];
// [this server country as QLocale ID] // [this server country as QLocale ID]
const int iCountry = slServInfoSeparateParams[2].toInt(); const int iCountry = slServInfoSeparateParams[2].toInt();
if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) ) if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) )
{ {
ThisServerListEntry.eCountry = static_cast<QLocale::Country> ( ThisServerListEntry.eCountry = static_cast<QLocale::Country> (
iCountry ); iCountry );
} }
} }
// per definition, the first entry in the server list is the own server // per definition, the first entry in the server list is the own server
ServerList.append ( ThisServerListEntry ); ServerList.append ( ThisServerListEntry );
// parse the predefined server infos (if any) according to definition: // parse the predefined server infos (if any) according to definition:
// [server1 address];[server1 name];[server1 city]; ... // [server1 address];[server1 name];[server1 city]; ...
// [server1 country as QLocale ID]; ... // [server1 country as QLocale ID]; ...
// [server2 address];[server2 name];[server2 city]; ... // [server2 address];[server2 name];[server2 city]; ...
// [server2 country as QLocale ID]; ... // [server2 country as QLocale ID]; ...
// ... // ...
int iCurUsedServInfoSplitItems = 3; // three items are used for this server int iCurUsedServInfoSplitItems = 3; // three items are used for this server
// we always expect four items per new server, also check for maximum // we always expect four items per new server, also check for maximum
// allowed number of servers in the server list // allowed number of servers in the server list
while ( ( iServInfoNumSplitItems - iCurUsedServInfoSplitItems >= 4 ) && while ( ( iServInfoNumSplitItems - iCurUsedServInfoSplitItems >= 4 ) &&
( iNumPredefinedServers <= MAX_NUM_SERVERS_IN_SERVER_LIST ) ) ( iNumPredefinedServers <= MAX_NUM_SERVERS_IN_SERVER_LIST ) )
{ {
// create a new server list entry // create a new server list entry
CServerListEntry NewServerListEntry ( CHostAddress(), CServerListEntry NewServerListEntry ( CHostAddress(),
0, // port number not used 0, // port number not used
"", "",
"", "",
QLocale::AnyCountry, QLocale::AnyCountry,
"", "",
iNumChannels, iNumChannels,
true ); true );
// [server n address] // [server n address]
LlconNetwUtil().ParseNetworkAddress ( LlconNetwUtil().ParseNetworkAddress (
slServInfoSeparateParams[iCurUsedServInfoSplitItems], slServInfoSeparateParams[iCurUsedServInfoSplitItems],
NewServerListEntry.HostAddr ); NewServerListEntry.HostAddr );
// [server n name] // [server n name]
NewServerListEntry.strName = NewServerListEntry.strName =
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 1]; slServInfoSeparateParams[iCurUsedServInfoSplitItems + 1];
// [server n city] // [server n city]
NewServerListEntry.strCity = NewServerListEntry.strCity =
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 2]; slServInfoSeparateParams[iCurUsedServInfoSplitItems + 2];
// [server n country as QLocale ID] // [server n country as QLocale ID]
const int iCountry = const int iCountry =
slServInfoSeparateParams[iCurUsedServInfoSplitItems + 3].toInt(); slServInfoSeparateParams[iCurUsedServInfoSplitItems + 3].toInt();
if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) ) if ( ( iCountry >= 0 ) && ( iCountry <= QLocale::LastCountry ) )
{ {
NewServerListEntry.eCountry = static_cast<QLocale::Country> ( NewServerListEntry.eCountry = static_cast<QLocale::Country> (
iCountry ); iCountry );
} }
// add the new server to the server list // add the new server to the server list
ServerList.append ( NewServerListEntry ); ServerList.append ( NewServerListEntry );
// we have used four items and have created one predefined server // we have used four items and have created one predefined server
// (adjust counters) // (adjust counters)
iCurUsedServInfoSplitItems += 4; iCurUsedServInfoSplitItems += 4;
iNumPredefinedServers++; iNumPredefinedServers++;
} }
// Connections ------------------------------------------------------------- // Connections -------------------------------------------------------------
QObject::connect ( &TimerPollList, SIGNAL ( timeout() ), QObject::connect ( &TimerPollList, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPollList() ) ); this, SLOT ( OnTimerPollList() ) );
QObject::connect ( &TimerPingServerInList, SIGNAL ( timeout() ), QObject::connect ( &TimerPingServerInList, SIGNAL ( timeout() ),
this, SLOT ( OnTimerPingServerInList() ) ); this, SLOT ( OnTimerPingServerInList() ) );
QObject::connect ( &TimerRegistering, SIGNAL ( timeout() ), QObject::connect ( &TimerPingCentralServer, SIGNAL ( timeout() ),
this, SLOT ( OnTimerRegistering() ) ); this, SLOT ( OnTimerPingCentralServer() ) );
}
QObject::connect ( &TimerRegistering, SIGNAL ( timeout() ),
void CServerListManager::SetCentralServerAddress ( const QString sNCentServAddr ) this, SLOT ( OnTimerRegistering() ) );
{ }
QMutexLocker locker ( &Mutex );
void CServerListManager::SetCentralServerAddress ( const QString sNCentServAddr )
strCentralServerAddress = sNCentServAddr; {
QMutexLocker locker ( &Mutex );
// per definition: If the central server address is empty, the server list
// is disabled. strCentralServerAddress = sNCentServAddr;
// per definition: If we are in server mode and the central server address
// is the localhost address, we are in central server mode. For the central // per definition: If the central server address is empty, the server list
// server, the server list is always enabled. // is disabled.
if ( !strCentralServerAddress.isEmpty() ) // per definition: If we are in server mode and the central server address
{ // is the localhost address, we are in central server mode. For the central
bIsCentralServer = // server, the server list is always enabled.
( !strCentralServerAddress.toLower().compare ( "localhost" ) || if ( !strCentralServerAddress.isEmpty() )
!strCentralServerAddress.compare ( "127.0.0.1" ) ); {
bIsCentralServer =
bEnabled = true; ( !strCentralServerAddress.toLower().compare ( "localhost" ) ||
} !strCentralServerAddress.compare ( "127.0.0.1" ) );
else
{ bEnabled = true;
bIsCentralServer = false; }
bEnabled = true; else
} {
} bIsCentralServer = false;
bEnabled = true;
void CServerListManager::Update() }
{ }
QMutexLocker locker ( &Mutex );
void CServerListManager::Update()
if ( bEnabled ) {
{ QMutexLocker locker ( &Mutex );
if ( bIsCentralServer )
{ if ( bEnabled )
// start timer for polling the server list if enabled {
// 1 minute = 60 * 1000 ms if ( bIsCentralServer )
TimerPollList.start ( SERVLIST_POLL_TIME_MINUTES * 60000 ); {
// start timer for polling the server list if enabled
// start timer for sending ping messages to servers in the list // 1 minute = 60 * 1000 ms
TimerPingServerInList.start ( SERVLIST_UPDATE_PING_SERVERS_MS ); TimerPollList.start ( SERVLIST_POLL_TIME_MINUTES * 60000 );
}
else // start timer for sending ping messages to servers in the list
{ TimerPingServerInList.start ( SERVLIST_UPDATE_PING_SERVERS_MS );
// initiate registration right away so that we do not have to wait }
// for the first time out of the timer until the slave server gets else
// registered at the central server, note that we have to unlock {
// the mutex before calling the function since inside this function // initiate registration right away so that we do not have to wait
// the mutex is locked, too // for the first time out of the timer until the slave server gets
locker.unlock(); // registered at the central server, note that we have to unlock
{ // the mutex before calling the function since inside this function
OnTimerRegistering(); // the mutex is locked, too
} locker.unlock();
locker.relock(); {
OnTimerRegistering();
// start timer for registering this server at the central server }
// 1 minute = 60 * 1000 ms locker.relock();
TimerRegistering.start ( SERVLIST_REGIST_INTERV_MINUTES * 60000 );
} // start timer for registering this server at the central server
} // 1 minute = 60 * 1000 ms
else TimerRegistering.start ( SERVLIST_REGIST_INTERV_MINUTES * 60000 );
{
// disable service -> stop timer // Start timer for ping the central server in short intervals to
if ( bIsCentralServer ) // keep the port open at the NAT router.
{ // If no NAT is used, we send the messages anyway since they do
TimerPollList.stop(); // not hurt (very low traffic). We also reuse the same update
TimerPingServerInList.stop(); // time as used in the central server for pinging the slave
} // servers.
else TimerPingCentralServer.start ( SERVLIST_UPDATE_PING_SERVERS_MS );
{ }
TimerRegistering.stop(); }
} else
} {
} // disable service -> stop timer
if ( bIsCentralServer )
{
/* Central server functionality ***********************************************/ TimerPollList.stop();
void CServerListManager::OnTimerPingServerInList() TimerPingServerInList.stop();
{ }
QMutexLocker locker ( &Mutex ); else
{
const int iCurServerListSize = ServerList.size(); TimerRegistering.stop();
TimerPingCentralServer.stop();
// send ping to list entries except of the very first one (which is the central }
// server entry) and the predefined servers }
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < iCurServerListSize; iIdx++ ) }
{
// send ping message to keep NAT port open at slave server
pConnLessProtocol->CreateCLPingMes ( /* Central server functionality ***********************************************/
ServerList[iIdx].HostAddr, void CServerListManager::OnTimerPingServerInList()
0 /* dummy */ ); {
} QMutexLocker locker ( &Mutex );
}
const int iCurServerListSize = ServerList.size();
void CServerListManager::OnTimerPollList()
{ // send ping to list entries except of the very first one (which is the central
QMutexLocker locker ( &Mutex ); // server entry) and the predefined servers
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < iCurServerListSize; iIdx++ )
// Check all list entries except of the very first one (which is the central {
// server entry) and the predefined servers if they are still valid. // send empty message to keep NAT port open at slave server
// Note that we have to use "ServerList.size()" function in the for loop pConnLessProtocol->CreateCLEmptyMes ( ServerList[iIdx].HostAddr );
// since we may remove elements from the server list inside the for loop. }
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < ServerList.size(); iIdx++ ) }
{
// 1 minute = 60 * 1000 ms void CServerListManager::OnTimerPollList()
if ( ServerList[iIdx].RegisterTime.elapsed() > {
( SERVLIST_TIME_OUT_MINUTES * 60000 ) ) QMutexLocker locker ( &Mutex );
{
// remove this list entry // Check all list entries except of the very first one (which is the central
ServerList.removeAt ( iIdx ); // server entry) and the predefined servers if they are still valid.
} // Note that we have to use "ServerList.size()" function in the for loop
} // since we may remove elements from the server list inside the for loop.
} for ( int iIdx = 1 + iNumPredefinedServers; iIdx < ServerList.size(); iIdx++ )
{
void CServerListManager::CentralServerRegisterServer ( const CHostAddress& InetAddr, // 1 minute = 60 * 1000 ms
const CServerCoreInfo& ServerInfo ) if ( ServerList[iIdx].RegisterTime.elapsed() >
{ ( SERVLIST_TIME_OUT_MINUTES * 60000 ) )
QMutexLocker locker ( &Mutex ); {
// remove this list entry
if ( bIsCentralServer && bEnabled ) ServerList.removeAt ( iIdx );
{ }
const int iCurServerListSize = ServerList.size(); }
}
// check for maximum allowed number of servers in the server list
if ( iCurServerListSize < MAX_NUM_SERVERS_IN_SERVER_LIST ) void CServerListManager::CentralServerRegisterServer ( const CHostAddress& InetAddr,
{ const CServerCoreInfo& ServerInfo )
// define invalid index used as a flag {
const int ciInvalidIdx = -1; QMutexLocker locker ( &Mutex );
// Check if server is already registered. Use address to identify if ( bIsCentralServer && bEnabled )
// a server. The very first list entry must not be checked since {
// this is per definition the central server (i.e., this server) const int iCurServerListSize = ServerList.size();
int iSelIdx = ciInvalidIdx; // initialize with an illegal value
for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ ) // check for maximum allowed number of servers in the server list
{ if ( iCurServerListSize < MAX_NUM_SERVERS_IN_SERVER_LIST )
if ( ServerList[iIdx].HostAddr == InetAddr ) {
{ // define invalid index used as a flag
// store entry index const int ciInvalidIdx = -1;
iSelIdx = iIdx;
// Check if server is already registered. Use address to identify
// entry found, leave for-loop // a server. The very first list entry must not be checked since
continue; // this is per definition the central server (i.e., this server)
} int iSelIdx = ciInvalidIdx; // initialize with an illegal value
} for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ )
{
// if server is not yet registered, we have to create a new entry if ( ServerList[iIdx].HostAddr == InetAddr )
if ( iSelIdx == ciInvalidIdx ) {
{ // store entry index
// create a new server list entry and init with received data iSelIdx = iIdx;
ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
} // entry found, leave for-loop
else continue;
{ }
// do not update the information in the predefined servers }
if ( iSelIdx > iNumPredefinedServers )
{ // if server is not yet registered, we have to create a new entry
// update all data and call update registration function if ( iSelIdx == ciInvalidIdx )
ServerList[iSelIdx].iLocalPortNumber = ServerInfo.iLocalPortNumber; {
ServerList[iSelIdx].strName = ServerInfo.strName; // create a new server list entry and init with received data
ServerList[iSelIdx].strTopic = ServerInfo.strTopic; ServerList.append ( CServerListEntry ( InetAddr, ServerInfo ) );
ServerList[iSelIdx].eCountry = ServerInfo.eCountry; }
ServerList[iSelIdx].strCity = ServerInfo.strCity; else
ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients; {
ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline; // do not update the information in the predefined servers
if ( iSelIdx > iNumPredefinedServers )
ServerList[iSelIdx].UpdateRegistration(); {
} // update all data and call update registration function
} ServerList[iSelIdx].iLocalPortNumber = ServerInfo.iLocalPortNumber;
} ServerList[iSelIdx].strName = ServerInfo.strName;
} ServerList[iSelIdx].strTopic = ServerInfo.strTopic;
} ServerList[iSelIdx].eCountry = ServerInfo.eCountry;
ServerList[iSelIdx].strCity = ServerInfo.strCity;
void CServerListManager::CentralServerUnregisterServer ( const CHostAddress& InetAddr ) ServerList[iSelIdx].iMaxNumClients = ServerInfo.iMaxNumClients;
{ ServerList[iSelIdx].bPermanentOnline = ServerInfo.bPermanentOnline;
QMutexLocker locker ( &Mutex );
ServerList[iSelIdx].UpdateRegistration();
if ( bIsCentralServer && bEnabled ) }
{ }
const int iCurServerListSize = ServerList.size(); }
}
// Find the server to unregister in the list. The very first list entry }
// must not be checked since this is per definition the central server
// (i.e., this server), also the predefined servers must not be checked. void CServerListManager::CentralServerUnregisterServer ( const CHostAddress& InetAddr )
for ( int iIdx = 1 + iNumPredefinedServers; iIdx < iCurServerListSize; iIdx++ ) {
{ QMutexLocker locker ( &Mutex );
if ( ServerList[iIdx].HostAddr == InetAddr )
{ if ( bIsCentralServer && bEnabled )
// remove this list entry {
ServerList.removeAt ( iIdx ); const int iCurServerListSize = ServerList.size();
// entry found, leave for-loop (it is important to exit the // Find the server to unregister in the list. The very first list entry
// for loop since when we remove an item from the server list, // must not be checked since this is per definition the central server
// "iCurServerListSize" is not correct anymore and we could get // (i.e., this server), also the predefined servers must not be checked.
// a segmentation fault) for ( int iIdx = 1 + iNumPredefinedServers; iIdx < iCurServerListSize; iIdx++ )
break; {
} if ( ServerList[iIdx].HostAddr == InetAddr )
} {
} // remove this list entry
} ServerList.removeAt ( iIdx );
void CServerListManager::CentralServerQueryServerList ( const CHostAddress& InetAddr ) // entry found, leave for-loop (it is important to exit the
{ // for loop since when we remove an item from the server list,
QMutexLocker locker ( &Mutex ); // "iCurServerListSize" is not correct anymore and we could get
// a segmentation fault)
if ( bIsCentralServer && bEnabled ) break;
{ }
const int iCurServerListSize = ServerList.size(); }
}
// allocate memory for the entire list }
CVector<CServerInfo> vecServerInfo ( iCurServerListSize );
void CServerListManager::CentralServerQueryServerList ( const CHostAddress& InetAddr )
// copy the list (we have to copy it since the message requires {
// a vector but the list is actually stored in a QList object and QMutexLocker locker ( &Mutex );
// not in a vector object
for ( int iIdx = 0; iIdx < iCurServerListSize; iIdx++ ) if ( bIsCentralServer && bEnabled )
{ {
// copy list item const int iCurServerListSize = ServerList.size();
vecServerInfo[iIdx] = ServerList[iIdx];
// allocate memory for the entire list
if ( iIdx > 0 ) CVector<CServerInfo> vecServerInfo ( iCurServerListSize );
{
// check if the address of the client which is requesting the // copy the list (we have to copy it since the message requires
// list is the same address as one server in the list -> in this // a vector but the list is actually stored in a QList object and
// case he has to connect to the local host address // not in a vector object
if ( vecServerInfo[iIdx].HostAddr.InetAddr == InetAddr.InetAddr ) for ( int iIdx = 0; iIdx < iCurServerListSize; iIdx++ )
{ {
vecServerInfo[iIdx].HostAddr.InetAddr = // copy list item
QHostAddress ( QHostAddress::LocalHost ); vecServerInfo[iIdx] = ServerList[iIdx];
// take the local port number instead of the received port if ( iIdx > 0 )
// number since some NAT (network address translation) might {
// have changed the port, note that the predefined servers // check if the address of the client which is requesting the
// are treated differently, for these we assume that the // list is the same address as one server in the list -> in this
// received port number is the same as the actual port // case he has to connect to the local host address
// number if ( vecServerInfo[iIdx].HostAddr.InetAddr == InetAddr.InetAddr )
if ( iIdx > iNumPredefinedServers ) {
{ vecServerInfo[iIdx].HostAddr.InetAddr =
vecServerInfo[iIdx].HostAddr.iPort = QHostAddress ( QHostAddress::LocalHost );
ServerList[iIdx].iLocalPortNumber;
} // take the local port number instead of the received port
} // number since some NAT (network address translation) might
else // have changed the port, note that the predefined servers
{ // are treated differently, for these we assume that the
// create "send empty message" for all registered servers // received port number is the same as the actual port
// (except of the very first list entry since this is this // number
// server (central server) per definition) and also it is if ( iIdx > iNumPredefinedServers )
// not required to send this message, if the server is on {
// the same computer vecServerInfo[iIdx].HostAddr.iPort =
pConnLessProtocol->CreateCLSendEmptyMesMes ( ServerList[iIdx].iLocalPortNumber;
vecServerInfo[iIdx].HostAddr, }
InetAddr ); }
} else
} {
} // create "send empty message" for all registered servers
// (except of the very first list entry since this is this
// send the server list to the client // server (central server) per definition) and also it is
pConnLessProtocol->CreateCLServerListMes ( InetAddr, vecServerInfo ); // not required to send this message, if the server is on
} // the same computer
} pConnLessProtocol->CreateCLSendEmptyMesMes (
vecServerInfo[iIdx].HostAddr,
InetAddr );
/* Slave server functionality *************************************************/ }
void CServerListManager::SlaveServerRegisterServer ( const bool bIsRegister ) }
{ }
// we need the lock since the user might change the server properties at
// any time // send the server list to the client
QMutexLocker locker ( &Mutex ); pConnLessProtocol->CreateCLServerListMes ( InetAddr, vecServerInfo );
}
// get the correct central server address }
const QString strCurCentrServAddr =
SELECT_SERVER_ADDRESS ( bUseDefaultCentralServerAddress,
strCentralServerAddress ); /* Slave server functionality *************************************************/
void CServerListManager::OnTimerPingCentralServer()
// For the slave server, the slave server properties are stored in the {
// very first item in the server list (which is actually no server list QMutexLocker locker ( &Mutex );
// but just one item long for the slave server).
// Note that we always have to parse the server address again since if // first check if central server address is valid
// it is an URL of a dynamic IP address, the IP address might have if ( !( SlaveCurCentServerHostAddress == CHostAddress() ) )
// changed in the meanwhile. {
CHostAddress HostAddress; // send empty message to central server to keep NAT port open -> we do
if ( LlconNetwUtil().ParseNetworkAddress ( strCurCentrServAddr, // not require any answer from the central server
HostAddress ) ) pConnLessProtocol->CreateCLEmptyMes ( SlaveCurCentServerHostAddress );
{ }
if ( bIsRegister ) }
{
// register server void CServerListManager::SlaveServerRegisterServer ( const bool bIsRegister )
pConnLessProtocol->CreateCLRegisterServerMes ( HostAddress, {
ServerList[0] ); // we need the lock since the user might change the server properties at
} // any time
else QMutexLocker locker ( &Mutex );
{
// unregister server // get the correct central server address
pConnLessProtocol->CreateCLUnregisterServerMes ( HostAddress ); const QString strCurCentrServAddr =
} SELECT_SERVER_ADDRESS ( bUseDefaultCentralServerAddress,
} strCentralServerAddress );
}
// For the slave server, the slave server properties are stored in the
// very first item in the server list (which is actually no server list
// but just one item long for the slave server).
// Note that we always have to parse the server address again since if
// it is an URL of a dynamic IP address, the IP address might have
// changed in the meanwhile.
if ( LlconNetwUtil().ParseNetworkAddress ( strCurCentrServAddr,
SlaveCurCentServerHostAddress ) )
{
if ( bIsRegister )
{
// register server
pConnLessProtocol->CreateCLRegisterServerMes ( SlaveCurCentServerHostAddress,
ServerList[0] );
}
else
{
// unregister server
pConnLessProtocol->CreateCLUnregisterServerMes ( SlaveCurCentServerHostAddress );
}
}
}