From fb785ce47a5a10f0a3111cdb3bcf794c6016a26e Mon Sep 17 00:00:00 2001 From: "Marius Petrescu, YO2LOJ" Date: Fri, 28 Jun 2019 18:01:01 +0300 Subject: [PATCH] Handle client IP change Dele and recreate client for the same callsign but different IP to prevent lingering connections on IP change. --- src/cg3protocol.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/cg3protocol.cpp b/src/cg3protocol.cpp index 768df7d..3466aee 100644 --- a/src/cg3protocol.cpp +++ b/src/cg3protocol.cpp @@ -177,8 +177,14 @@ void CG3Protocol::PresenceTask(void) Buffer.data()[2] = 0x80; // response Buffer.data()[3] = 0x00; // ok - // todo: handle reflector IP 0.0.0.0 - Buffer.Append(g_Reflector.GetListenIp().GetAddr()); + if (m_GwAddress == 0) + { + Buffer.Append(*(uint32 *)m_ConfigSocket.GetLocalAddr()); + } + else + { + Buffer.Append(m_GwAddress); + } CClients *clients = g_Reflector.GetClients(); @@ -195,7 +201,20 @@ void CG3Protocol::PresenceTask(void) if (extant == NULL) { - // create client + // do we already have a client with the same call (IP changed)? + while ( (extant = clients->FindNextClient(PROTOCOL_G3, &index)) != NULL ) + { + { + if (extant->GetCallsign().HasSameCallsign(Terminal)) + { + //delete old client + clients->RemoveClient(extant); + break; + } + } + } + + // create new client CG3Client *client = new CG3Client(Terminal, Ip); // and append @@ -203,6 +222,7 @@ void CG3Protocol::PresenceTask(void) } else { + // client changed callsign if (!extant->GetCallsign().HasSameCallsign(Terminal)) { //delete old client @@ -381,7 +401,7 @@ void CG3Protocol::IcmpTask(void) //////////////////////////////////////////////////////////////////////////////////////// -// task +// DV task void CG3Protocol::Task(void) {