From 5599420d92cd594c87db23f996b3ba51141e6971 Mon Sep 17 00:00:00 2001 From: LX3JL Date: Mon, 8 Feb 2016 22:55:47 +0100 Subject: [PATCH] version 1.2.2 Corrected keep alive timeout issue when multi-module repeater linked --- src/cclients.cpp | 41 +++++++++++++++++++++++++++++++++-------- src/cclients.h | 5 ++--- src/cdcsprotocol.cpp | 10 +++++----- src/cdextraprotocol.cpp | 14 +++++++------- src/cdplusprotocol.cpp | 8 +++++--- src/main.h | 2 +- 6 files changed, 53 insertions(+), 27 deletions(-) diff --git a/src/cclients.cpp b/src/cclients.cpp index e416531..efb029a 100644 --- a/src/cclients.cpp +++ b/src/cclients.cpp @@ -235,17 +235,42 @@ CClient *CClients::FindNextClient(int Protocol, int *index) return client; } -//////////////////////////////////////////////////////////////////////////////////////// -// reporting - -void CClients::WriteXml(std::ofstream &xmlFile) +CClient *CClients::FindNextClient(const CIp &Ip, int Protocol, int *index) { - xmlFile << "" << std::endl; - for ( int i = 0; i < m_Clients.size(); i++ ) + CClient *client = NULL; + + // find next client + bool found = false; + for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ ) { - m_Clients[i]->WriteXml(xmlFile); + if ( (m_Clients[i]->GetProtocol() == Protocol) && + (m_Clients[i]->GetIp() == Ip) ) + { + found = true; + client = m_Clients[i]; + *index = i; + } } - xmlFile << "" << std::endl; + return client; } +CClient *CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, int *index) +{ + CClient *client = NULL; + + // find next client + bool found = false; + for ( int i = *index+1; (i < m_Clients.size()) && !found; i++ ) + { + if ( (m_Clients[i]->GetProtocol() == Protocol) && + (m_Clients[i]->GetIp() == Ip) && + m_Clients[i]->GetCallsign().HasSameCallsign(Callsign) ) + { + found = true; + client = m_Clients[i]; + *index = i; + } + } + return client; +} diff --git a/src/cclients.h b/src/cclients.h index 328f323..66e6158 100644 --- a/src/cclients.h +++ b/src/cclients.h @@ -63,10 +63,9 @@ public: // iterate on clients CClient *FindNextClient(int, int*); + CClient *FindNextClient(const CIp &, int, int *); + CClient *FindNextClient(const CCallsign &, const CIp &, int, int *); - // reporting - void WriteXml(std::ofstream &); - protected: // data std::mutex m_Mutex; diff --git a/src/cdcsprotocol.cpp b/src/cdcsprotocol.cpp index d513d6a..21981d5 100644 --- a/src/cdcsprotocol.cpp +++ b/src/cdcsprotocol.cpp @@ -158,11 +158,11 @@ void CDcsProtocol::Task(void) { //std::cout << "DCS keepalive packet from " << Callsign << " at " << Ip << std::endl; - // find client & keep it alive - CClient *GetClient(const CCallsign &, const CIp &, char, int); - - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS); - if ( client != NULL ) + // find all clients with that callsign & ip and keep them alive + CClients *clients = g_Reflector.GetClients(); + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, &index)) != NULL ) { client->Alive(); } diff --git a/src/cdextraprotocol.cpp b/src/cdextraprotocol.cpp index 2b63cec..9ca8f2d 100644 --- a/src/cdextraprotocol.cpp +++ b/src/cdextraprotocol.cpp @@ -139,15 +139,15 @@ void CDextraProtocol::Task(void) } else if ( IsValidKeepAlivePacket(Buffer, &Callsign) ) { - //std::cout << "DExtra keepalive packet from " << Callsign << " at " << Ip << std::endl; + //std::cout << "DExtra keepalive packet from " << Callsign << " at " << Ip << std::endl; - // find client & keep it alive - CClient *GetClient(const CCallsign &, const CIp &, char, int); - - CClient *client = g_Reflector.GetClients()->FindClient(Callsign, Ip, PROTOCOL_DEXTRA); - if ( client != NULL ) + // find all clients with that callsign & ip and keep them alive + CClients *clients = g_Reflector.GetClients(); + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, &index)) != NULL ) { - client->Alive(); + client->Alive(); } g_Reflector.ReleaseClients(); } diff --git a/src/cdplusprotocol.cpp b/src/cdplusprotocol.cpp index 04fac6a..1854cf0 100644 --- a/src/cdplusprotocol.cpp +++ b/src/cdplusprotocol.cpp @@ -151,9 +151,11 @@ void CDplusProtocol::Task(void) { //std::cout << "DPlus keepalive packet from " << Ip << std::endl; - // find client & keep it alive - CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DPLUS); - if ( client != NULL ) + // find all clients with that callsign & ip and keep them alive + CClients *clients = g_Reflector.GetClients(); + int index = -1; + CClient *client = NULL; + while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, &index)) != NULL ) { client->Alive(); } diff --git a/src/main.h b/src/main.h index df6ab94..5a8ed5e 100644 --- a/src/main.h +++ b/src/main.h @@ -48,7 +48,7 @@ #define VERSION_MAJOR 1 #define VERSION_MINOR 1 -#define VERSION_REVISION 1 +#define VERSION_REVISION 2 // global ------------------------------------------------------