mirror of
https://github.com/ShaYmez/xlxd.git
synced 2025-07-29 11:52:26 -04:00
xlxd version 1.4.0
Fixed multiple concurrent streams in XLX interlink
This commit is contained in:
parent
189bb48cc6
commit
8e6f674d7d
@ -42,7 +42,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, c
|
|||||||
m_Ip = ip;
|
m_Ip = ip;
|
||||||
if ( modules != NULL )
|
if ( modules != NULL )
|
||||||
{
|
{
|
||||||
:: memset(m_Modules, 0, sizeof(m_Modules));
|
::memset(m_Modules, 0, sizeof(m_Modules));
|
||||||
if ( modules[0] == '*' )
|
if ( modules[0] == '*' )
|
||||||
{
|
{
|
||||||
for ( char i = 0; i < NB_OF_MODULES; i++ )
|
for ( char i = 0; i < NB_OF_MODULES; i++ )
|
||||||
@ -52,7 +52,15 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, c
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
::memcpy(m_Modules, modules, MIN(strlen(modules), sizeof(m_Modules)-1));
|
int n = MIN((int)::strlen(modules), sizeof(m_Modules)-1);
|
||||||
|
int j = 0;
|
||||||
|
for ( int i = 0; i < n; i++ )
|
||||||
|
{
|
||||||
|
if ( (modules[i] - 'A') < NB_OF_MODULES )
|
||||||
|
{
|
||||||
|
m_Modules[j++] = modules[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -64,7 +72,7 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const char *url,
|
|||||||
m_Ip = CIp(m_szUrl);
|
m_Ip = CIp(m_szUrl);
|
||||||
if ( modules != NULL )
|
if ( modules != NULL )
|
||||||
{
|
{
|
||||||
:: memset(m_Modules, 0, sizeof(m_Modules));
|
::memset(m_Modules, 0, sizeof(m_Modules));
|
||||||
if ( modules[0] == '*' )
|
if ( modules[0] == '*' )
|
||||||
{
|
{
|
||||||
for ( char i = 0; i < NB_OF_MODULES; i++ )
|
for ( char i = 0; i < NB_OF_MODULES; i++ )
|
||||||
@ -74,7 +82,15 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const char *url,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
::memcpy(m_Modules, modules, MIN(strlen(modules), sizeof(m_Modules)-1));
|
int n = MIN((int)::strlen(modules), sizeof(m_Modules)-1);
|
||||||
|
int j = 0;
|
||||||
|
for ( int i = 0; i < n; i++ )
|
||||||
|
{
|
||||||
|
if ( (modules[i] - 'A') < NB_OF_MODULES )
|
||||||
|
{
|
||||||
|
m_Modules[j++] = modules[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,8 @@ void CClient::Alive(void)
|
|||||||
bool CClient::operator ==(const CClient &client) const
|
bool CClient::operator ==(const CClient &client) const
|
||||||
{
|
{
|
||||||
return ((client.m_Callsign == m_Callsign) &&
|
return ((client.m_Callsign == m_Callsign) &&
|
||||||
(client.m_Ip == m_Ip));
|
(client.m_Ip == m_Ip) &&
|
||||||
|
(client.m_ReflectorModule == m_ReflectorModule));
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -56,7 +56,6 @@ public:
|
|||||||
bool HasModule(void) const { return m_Callsign.HasModule(); }
|
bool HasModule(void) const { return m_Callsign.HasModule(); }
|
||||||
char GetModule(void) const { return m_Callsign.GetModule(); }
|
char GetModule(void) const { return m_Callsign.GetModule(); }
|
||||||
char GetReflectorModule(void) const { return m_ReflectorModule; }
|
char GetReflectorModule(void) const { return m_ReflectorModule; }
|
||||||
virtual bool HasThisReflectorModule(char m) const { return (m_ReflectorModule == m); }
|
|
||||||
|
|
||||||
// set
|
// set
|
||||||
void SetModule(char c) { m_Callsign.SetModule(c); }
|
void SetModule(char c) { m_Callsign.SetModule(c); }
|
||||||
|
@ -85,11 +85,12 @@ void CClients::AddClient(CClient *client)
|
|||||||
// and append
|
// and append
|
||||||
m_Clients.push_back(client);
|
m_Clients.push_back(client);
|
||||||
std::cout << "New client " << client->GetCallsign() << " at " << client->GetIp()
|
std::cout << "New client " << client->GetCallsign() << " at " << client->GetIp()
|
||||||
<< " added with protocol " << client->GetProtocol() << std::endl;
|
<< " added with protocol " << client->GetProtocol()
|
||||||
|
<< " on module " << client->GetReflectorModule() << std::endl;
|
||||||
// notify
|
// notify
|
||||||
g_Reflector.OnClientsChanged();
|
g_Reflector.OnClientsChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CClients::RemoveClient(CClient *client)
|
void CClients::RemoveClient(CClient *client)
|
||||||
{
|
{
|
||||||
@ -105,7 +106,8 @@ void CClients::RemoveClient(CClient *client)
|
|||||||
{
|
{
|
||||||
// remove it
|
// remove it
|
||||||
std::cout << "Client " << m_Clients[i]->GetCallsign() << " at " << m_Clients[i]->GetIp()
|
std::cout << "Client " << m_Clients[i]->GetCallsign() << " at " << m_Clients[i]->GetIp()
|
||||||
<< " removed" << std::endl;
|
<< " removed with protocol " << client->GetProtocol()
|
||||||
|
<< " on module " << client->GetReflectorModule() << std::endl;
|
||||||
delete m_Clients[i];
|
delete m_Clients[i];
|
||||||
m_Clients.erase(m_Clients.begin()+i);
|
m_Clients.erase(m_Clients.begin()+i);
|
||||||
found = true;
|
found = true;
|
||||||
@ -175,6 +177,25 @@ CClient *CClients::FindClient(const CIp &Ip, int Protocol)
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CClient *CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule)
|
||||||
|
{
|
||||||
|
CClient *client = NULL;
|
||||||
|
|
||||||
|
// find client
|
||||||
|
for ( int i = 0; (i < m_Clients.size()) && (client == NULL); i++ )
|
||||||
|
{
|
||||||
|
if ( (m_Clients[i]->GetIp() == Ip) &&
|
||||||
|
(m_Clients[i]->GetReflectorModule() == ReflectorModule) &&
|
||||||
|
(m_Clients[i]->GetProtocol() == Protocol) )
|
||||||
|
{
|
||||||
|
client = m_Clients[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// done
|
||||||
|
return client;
|
||||||
|
}
|
||||||
|
|
||||||
CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol)
|
CClient *CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol)
|
||||||
{
|
{
|
||||||
CClient *client = NULL;
|
CClient *client = NULL;
|
||||||
@ -232,7 +253,6 @@ CClient *CClients::FindClient(const CCallsign &Callsign, int Protocol)
|
|||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// iterate on clients
|
// iterate on clients
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ public:
|
|||||||
// find clients
|
// find clients
|
||||||
CClient *FindClient(const CIp &);
|
CClient *FindClient(const CIp &);
|
||||||
CClient *FindClient(const CIp &, int);
|
CClient *FindClient(const CIp &, int);
|
||||||
|
CClient *FindClient(const CIp &, int, char);
|
||||||
CClient *FindClient(const CCallsign &, const CIp &, int);
|
CClient *FindClient(const CCallsign &, const CIp &, int);
|
||||||
CClient *FindClient(const CCallsign &, char, const CIp &, int);
|
CClient *FindClient(const CCallsign &, char, const CIp &, int);
|
||||||
CClient *FindClient(const CCallsign &, int);
|
CClient *FindClient(const CCallsign &, int);
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#define NOTIFICATION_USERS 2
|
#define NOTIFICATION_USERS 2
|
||||||
#define NOTIFICATION_STREAM_OPEN 3
|
#define NOTIFICATION_STREAM_OPEN 3
|
||||||
#define NOTIFICATION_STREAM_CLOSE 4
|
#define NOTIFICATION_STREAM_CLOSE 4
|
||||||
|
#define NOTIFICATION_PEERS 5
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// class
|
// class
|
||||||
|
172
src/cpeer.cpp
Normal file
172
src/cpeer.cpp
Normal file
@ -0,0 +1,172 @@
|
|||||||
|
//
|
||||||
|
// cpeer.cpp
|
||||||
|
// xlxd
|
||||||
|
//
|
||||||
|
// Created by Jean-Luc Deltombe (LX3JL) on 10/12/2016.
|
||||||
|
// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// This file is part of xlxd.
|
||||||
|
//
|
||||||
|
// xlxd 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 Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// xlxd is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include "creflector.h"
|
||||||
|
#include "cpeer.h"
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// constructor
|
||||||
|
|
||||||
|
|
||||||
|
CPeer::CPeer()
|
||||||
|
{
|
||||||
|
::memset(m_ReflectorModules, 0, sizeof(m_ReflectorModules));
|
||||||
|
m_Clients.reserve(100);
|
||||||
|
m_ConnectTime = std::time(NULL);
|
||||||
|
m_LastHeardTime = std::time(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
CPeer::CPeer(const CCallsign &callsign, const CIp &ip, char *modules)
|
||||||
|
{
|
||||||
|
m_Callsign = callsign;
|
||||||
|
m_Ip = ip;
|
||||||
|
::memset(m_ReflectorModules, 0, sizeof(m_ReflectorModules));
|
||||||
|
::strncpy(m_ReflectorModules, modules, sizeof(m_ReflectorModules)-1);
|
||||||
|
m_LastKeepaliveTime.Now();
|
||||||
|
m_ConnectTime = std::time(NULL);
|
||||||
|
m_LastHeardTime = std::time(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
CPeer::CPeer(const CPeer &peer)
|
||||||
|
{
|
||||||
|
m_Callsign = peer.m_Callsign;
|
||||||
|
m_Ip = peer.m_Ip;
|
||||||
|
::memcpy(m_ReflectorModules, peer.m_ReflectorModules, sizeof(m_ReflectorModules));
|
||||||
|
m_LastKeepaliveTime = peer.m_LastKeepaliveTime;
|
||||||
|
m_ConnectTime = peer.m_ConnectTime;
|
||||||
|
m_LastHeardTime = peer.m_LastHeardTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// destructors
|
||||||
|
|
||||||
|
CPeer::~CPeer()
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < m_Clients.size(); i++ )
|
||||||
|
{
|
||||||
|
delete m_Clients[i];
|
||||||
|
}
|
||||||
|
m_Clients.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// operators
|
||||||
|
|
||||||
|
bool CPeer::operator ==(const CPeer &peer) const
|
||||||
|
{
|
||||||
|
bool same = true;
|
||||||
|
|
||||||
|
same &= (peer.m_Callsign == m_Callsign);
|
||||||
|
same &= (peer.m_Ip == m_Ip);
|
||||||
|
for ( int i = 0; (i < m_Clients.size()) && same ; i++ )
|
||||||
|
{
|
||||||
|
same &= (peer.m_Clients[i] == m_Clients[i]);
|
||||||
|
}
|
||||||
|
return same;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// status
|
||||||
|
|
||||||
|
bool CPeer::IsAMaster(void) const
|
||||||
|
{
|
||||||
|
bool master = false;
|
||||||
|
for ( int i = 0; (i < m_Clients.size()) && !master ; i++ )
|
||||||
|
{
|
||||||
|
master |= m_Clients[i]->IsAMaster();
|
||||||
|
}
|
||||||
|
return master;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPeer::Alive(void)
|
||||||
|
{
|
||||||
|
m_LastKeepaliveTime.Now();;
|
||||||
|
for ( int i = 0; i < m_Clients.size(); i++ )
|
||||||
|
{
|
||||||
|
m_Clients[i]->Alive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// manage clients
|
||||||
|
|
||||||
|
CClient *CPeer::GetClient(int i)
|
||||||
|
{
|
||||||
|
if ( (i >= 0) && (i < m_Clients.size()) )
|
||||||
|
{
|
||||||
|
return m_Clients[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// reporting
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// reporting
|
||||||
|
|
||||||
|
void CPeer::WriteXml(std::ofstream &xmlFile)
|
||||||
|
{
|
||||||
|
xmlFile << "<PEER>" << std::endl;
|
||||||
|
xmlFile << "\t<Callsign>" << m_Callsign << "</Callsign>" << std::endl;
|
||||||
|
xmlFile << "\t<IP>" << m_Ip << "</IP>" << std::endl;
|
||||||
|
xmlFile << "\t<LinkedModule>" << m_ReflectorModules << "</LinkedModule>" << std::endl;
|
||||||
|
xmlFile << "\t<Protocol>" << GetProtocolName() << "</Protocol>" << std::endl;
|
||||||
|
char mbstr[100];
|
||||||
|
if (std::strftime(mbstr, sizeof(mbstr), "%A %c", std::localtime(&m_ConnectTime)))
|
||||||
|
{
|
||||||
|
xmlFile << "\t<ConnectTime>" << mbstr << "</ConnectTime>" << std::endl;
|
||||||
|
}
|
||||||
|
if (std::strftime(mbstr, sizeof(mbstr), "%A %c", std::localtime(&m_LastHeardTime)))
|
||||||
|
{
|
||||||
|
xmlFile << "\t<LastHeardTime>" << mbstr << "</LastHeardTime>" << std::endl;
|
||||||
|
}
|
||||||
|
xmlFile << "</PEER>" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPeer::GetJsonObject(char *Buffer)
|
||||||
|
{
|
||||||
|
char sz[512];
|
||||||
|
char mbstr[100];
|
||||||
|
char cs[16];
|
||||||
|
|
||||||
|
if (std::strftime(mbstr, sizeof(mbstr), "%A %c", std::localtime(&m_LastHeardTime)))
|
||||||
|
{
|
||||||
|
m_Callsign.GetCallsignString(cs);
|
||||||
|
|
||||||
|
::sprintf(sz, "{\"callsign\":\"%s\",\"linkedto\":\"%s\",\"time\":\"%s\"}",
|
||||||
|
cs,
|
||||||
|
m_ReflectorModules,
|
||||||
|
mbstr);
|
||||||
|
::strcat(Buffer, sz);
|
||||||
|
}
|
||||||
|
}
|
94
src/cpeer.h
Normal file
94
src/cpeer.h
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
//
|
||||||
|
// cpeer.h
|
||||||
|
// xlxd
|
||||||
|
//
|
||||||
|
// Created by Jean-Luc Deltombe (LX3JL) on 10/12/2016.
|
||||||
|
// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// This file is part of xlxd.
|
||||||
|
//
|
||||||
|
// xlxd 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 Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// xlxd is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef cpeer_h
|
||||||
|
#define cpeer_h
|
||||||
|
|
||||||
|
#include "ctimepoint.h"
|
||||||
|
#include "cip.h"
|
||||||
|
#include "ccallsign.h"
|
||||||
|
#include "cclient.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// class
|
||||||
|
|
||||||
|
class CPeer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
CPeer();
|
||||||
|
CPeer(const CCallsign &, const CIp &, char *);
|
||||||
|
CPeer(const CPeer &);
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
virtual ~CPeer();
|
||||||
|
|
||||||
|
// operators
|
||||||
|
bool operator ==(const CPeer &) const;
|
||||||
|
|
||||||
|
// get
|
||||||
|
const CCallsign &GetCallsign(void) const { return m_Callsign; }
|
||||||
|
const CIp &GetIp(void) const { return m_Ip; }
|
||||||
|
char *GetModulesModules(void) { return m_ReflectorModules; }
|
||||||
|
|
||||||
|
// set
|
||||||
|
|
||||||
|
// identity
|
||||||
|
virtual int GetProtocol(void) const { return PROTOCOL_NONE; }
|
||||||
|
virtual int GetProtocolRevision(void) const { return 0; }
|
||||||
|
virtual const char *GetProtocolName(void) const { return "none"; }
|
||||||
|
|
||||||
|
// status
|
||||||
|
virtual bool IsAMaster(void) const;
|
||||||
|
virtual void Alive(void);
|
||||||
|
virtual bool IsAlive(void) const { return false; }
|
||||||
|
virtual void Heard(void) { m_LastHeardTime = std::time(NULL); }
|
||||||
|
|
||||||
|
// clients access
|
||||||
|
int GetNbClients(void) const { return (int)m_Clients.size(); }
|
||||||
|
void ClearClients(void) { m_Clients.clear(); }
|
||||||
|
CClient *GetClient(int);
|
||||||
|
|
||||||
|
// reporting
|
||||||
|
virtual void WriteXml(std::ofstream &);
|
||||||
|
virtual void GetJsonObject(char *);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// data
|
||||||
|
CCallsign m_Callsign;
|
||||||
|
CIp m_Ip;
|
||||||
|
char m_ReflectorModules[NB_MODULES_MAX+1];
|
||||||
|
std::vector<CClient *> m_Clients;
|
||||||
|
|
||||||
|
// status
|
||||||
|
CTimePoint m_LastKeepaliveTime;
|
||||||
|
std::time_t m_ConnectTime;
|
||||||
|
std::time_t m_LastHeardTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#endif /* cpeer_h */
|
230
src/cpeers.cpp
Normal file
230
src/cpeers.cpp
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
//
|
||||||
|
// cpeers.cpp
|
||||||
|
// xlxd
|
||||||
|
//
|
||||||
|
// Created by Jean-Luc Deltombe (LX3JL) on 10/12/2016.
|
||||||
|
// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// This file is part of xlxd.
|
||||||
|
//
|
||||||
|
// xlxd 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 Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// xlxd is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include "creflector.h"
|
||||||
|
#include "cpeers.h"
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// constructor
|
||||||
|
|
||||||
|
|
||||||
|
CPeers::CPeers()
|
||||||
|
{
|
||||||
|
m_Peers.reserve(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// destructors
|
||||||
|
|
||||||
|
CPeers::~CPeers()
|
||||||
|
{
|
||||||
|
m_Mutex.lock();
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < m_Peers.size(); i++ )
|
||||||
|
{
|
||||||
|
delete m_Peers[i];
|
||||||
|
}
|
||||||
|
m_Peers.clear();
|
||||||
|
|
||||||
|
}
|
||||||
|
m_Mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// manage peers
|
||||||
|
|
||||||
|
void CPeers::AddPeer(CPeer *peer)
|
||||||
|
{
|
||||||
|
// first check if peer already exists
|
||||||
|
bool found = false;
|
||||||
|
for ( int i = 0; (i < m_Peers.size()) && !found; i++ )
|
||||||
|
{
|
||||||
|
found = (*peer == *m_Peers[i]);
|
||||||
|
// if found, just do nothing
|
||||||
|
// so *peer keep pointing on a valid object
|
||||||
|
// on function return
|
||||||
|
if ( found )
|
||||||
|
{
|
||||||
|
// delete new one
|
||||||
|
delete peer;
|
||||||
|
//std::cout << "Adding existing peer " << peer->GetCallsign() << " at " << peer->GetIp() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if not, append to the vector
|
||||||
|
if ( !found )
|
||||||
|
{
|
||||||
|
// grow vector capacity if needed
|
||||||
|
if ( m_Peers.capacity() == m_Peers.size() )
|
||||||
|
{
|
||||||
|
m_Peers.reserve(m_Peers.capacity()+10);
|
||||||
|
}
|
||||||
|
// append peer to reflector peer list
|
||||||
|
m_Peers.push_back(peer);
|
||||||
|
std::cout << "New peer " << peer->GetCallsign() << " at " << peer->GetIp()
|
||||||
|
<< " added with protocol " << peer->GetProtocol() << std::endl;
|
||||||
|
// and append all peer's client to reflector client list
|
||||||
|
// it is double lock safe to lock Clients list after Peers list
|
||||||
|
CClients *clients = g_Reflector.GetClients();
|
||||||
|
for ( int i = 0; i < peer->GetNbClients(); i++ )
|
||||||
|
{
|
||||||
|
clients->AddClient(peer->GetClient(i));
|
||||||
|
}
|
||||||
|
g_Reflector.ReleaseClients();
|
||||||
|
|
||||||
|
// notify
|
||||||
|
g_Reflector.OnPeersChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPeers::RemovePeer(CPeer *peer)
|
||||||
|
{
|
||||||
|
// look for the client
|
||||||
|
bool found = false;
|
||||||
|
for ( int i = 0; (i < m_Peers.size()) && !found; i++ )
|
||||||
|
{
|
||||||
|
// compare objetc pointers
|
||||||
|
if ( (m_Peers[i]) == peer )
|
||||||
|
{
|
||||||
|
// found it !
|
||||||
|
if ( !m_Peers[i]->IsAMaster() )
|
||||||
|
{
|
||||||
|
// remove all clients from reflector client list
|
||||||
|
// it is double lock safe to lock Clients list after Peers list
|
||||||
|
CClients *clients = g_Reflector.GetClients();
|
||||||
|
for ( int i = 0; i < peer->GetNbClients(); i++ )
|
||||||
|
{
|
||||||
|
// this also delete the client object
|
||||||
|
clients->RemoveClient(peer->GetClient(i));
|
||||||
|
}
|
||||||
|
// so clear it then
|
||||||
|
m_Peers[i]->ClearClients();
|
||||||
|
g_Reflector.ReleaseClients();
|
||||||
|
|
||||||
|
// remove it
|
||||||
|
std::cout << "Peer " << m_Peers[i]->GetCallsign() << " at " << m_Peers[i]->GetIp()
|
||||||
|
<< " removed" << std::endl;
|
||||||
|
delete m_Peers[i];
|
||||||
|
m_Peers.erase(m_Peers.begin()+i);
|
||||||
|
found = true;
|
||||||
|
// notify
|
||||||
|
g_Reflector.OnPeersChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CPeer *CPeers::GetPeer(int i)
|
||||||
|
{
|
||||||
|
if ( (i >= 0) && (i < m_Peers.size()) )
|
||||||
|
{
|
||||||
|
return m_Peers[i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// find peers
|
||||||
|
|
||||||
|
CPeer *CPeers::FindPeer(const CIp &Ip, int Protocol)
|
||||||
|
{
|
||||||
|
CPeer *peer = NULL;
|
||||||
|
|
||||||
|
// find peer
|
||||||
|
for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ )
|
||||||
|
{
|
||||||
|
if ( (m_Peers[i]->GetIp() == Ip) && (m_Peers[i]->GetProtocol() == Protocol))
|
||||||
|
{
|
||||||
|
peer = m_Peers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// done
|
||||||
|
return peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPeer *CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol)
|
||||||
|
{
|
||||||
|
CPeer *peer = NULL;
|
||||||
|
|
||||||
|
// find peer
|
||||||
|
for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ )
|
||||||
|
{
|
||||||
|
if ( m_Peers[i]->GetCallsign().HasSameCallsign(Callsign) &&
|
||||||
|
(m_Peers[i]->GetIp() == Ip) &&
|
||||||
|
(m_Peers[i]->GetProtocol() == Protocol) )
|
||||||
|
{
|
||||||
|
peer = m_Peers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// done
|
||||||
|
return peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
CPeer *CPeers::FindPeer(const CCallsign &Callsign, int Protocol)
|
||||||
|
{
|
||||||
|
CPeer *peer = NULL;
|
||||||
|
|
||||||
|
// find peer
|
||||||
|
for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ )
|
||||||
|
{
|
||||||
|
if ( (m_Peers[i]->GetProtocol() == Protocol) &&
|
||||||
|
m_Peers[i]->GetCallsign().HasSameCallsign(Callsign) )
|
||||||
|
{
|
||||||
|
peer = m_Peers[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// done
|
||||||
|
return peer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// iterate on peers
|
||||||
|
|
||||||
|
CPeer *CPeers::FindNextPeer(int Protocol, int *index)
|
||||||
|
{
|
||||||
|
CPeer *peer = NULL;
|
||||||
|
|
||||||
|
// find next peer
|
||||||
|
bool found = false;
|
||||||
|
for ( int i = *index+1; (i < m_Peers.size()) && !found; i++ )
|
||||||
|
{
|
||||||
|
if ( m_Peers[i]->GetProtocol() == Protocol )
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
peer = m_Peers[i];
|
||||||
|
*index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return peer;
|
||||||
|
}
|
||||||
|
|
73
src/cpeers.h
Normal file
73
src/cpeers.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
//
|
||||||
|
// cpeers.h
|
||||||
|
// xlxd
|
||||||
|
//
|
||||||
|
// Created by Jean-Luc Deltombe (LX3JL) on 10/12/2016.
|
||||||
|
// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// This file is part of xlxd.
|
||||||
|
//
|
||||||
|
// xlxd 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 Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// xlxd is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef cpeers_h
|
||||||
|
#define cpeers_h
|
||||||
|
|
||||||
|
#include "cpeer.h"
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// define
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// class
|
||||||
|
|
||||||
|
class CPeers
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
CPeers();
|
||||||
|
|
||||||
|
// destructors
|
||||||
|
virtual ~CPeers();
|
||||||
|
|
||||||
|
// locks
|
||||||
|
void Lock(void) { m_Mutex.lock(); }
|
||||||
|
void Unlock(void) { m_Mutex.unlock(); }
|
||||||
|
|
||||||
|
// manage peers
|
||||||
|
int GetSize(void) const { return (int)m_Peers.size(); }
|
||||||
|
void AddPeer(CPeer *);
|
||||||
|
void RemovePeer(CPeer *);
|
||||||
|
CPeer *GetPeer(int);
|
||||||
|
|
||||||
|
// find peers
|
||||||
|
CPeer *FindPeer(const CIp &, int);
|
||||||
|
CPeer *FindPeer(const CCallsign &, const CIp &, int);
|
||||||
|
CPeer *FindPeer(const CCallsign &, int);
|
||||||
|
|
||||||
|
// iterate on peers
|
||||||
|
CPeer *FindNextPeer(int, int*);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// data
|
||||||
|
std::mutex m_Mutex;
|
||||||
|
std::vector<CPeer *> m_Peers;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#endif /* cpeers_h */
|
@ -421,6 +421,7 @@ void CReflector::JsonReportThread(CReflector *This)
|
|||||||
switch ( notification.GetId() )
|
switch ( notification.GetId() )
|
||||||
{
|
{
|
||||||
case NOTIFICATION_CLIENTS:
|
case NOTIFICATION_CLIENTS:
|
||||||
|
case NOTIFICATION_PEERS:
|
||||||
//std::cout << "Monitor updating nodes table" << std::endl;
|
//std::cout << "Monitor updating nodes table" << std::endl;
|
||||||
This->SendJsonNodesObject(Socket, Ip);
|
This->SendJsonNodesObject(Socket, Ip);
|
||||||
break;
|
break;
|
||||||
@ -455,6 +456,15 @@ void CReflector::JsonReportThread(CReflector *This)
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// notifications
|
// notifications
|
||||||
|
|
||||||
|
void CReflector::OnPeersChanged(void)
|
||||||
|
{
|
||||||
|
CNotification notification(NOTIFICATION_PEERS);
|
||||||
|
|
||||||
|
m_Notifications.Lock();
|
||||||
|
m_Notifications.push(notification);
|
||||||
|
m_Notifications.Unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void CReflector::OnClientsChanged(void)
|
void CReflector::OnClientsChanged(void)
|
||||||
{
|
{
|
||||||
CNotification notification(NOTIFICATION_CLIENTS);
|
CNotification notification(NOTIFICATION_CLIENTS);
|
||||||
@ -544,23 +554,20 @@ void CReflector::WriteXmlFile(std::ofstream &xmlFile)
|
|||||||
// linked peers
|
// linked peers
|
||||||
xmlFile << "<" << m_Callsign << "linked peers>" << std::endl;
|
xmlFile << "<" << m_Callsign << "linked peers>" << std::endl;
|
||||||
// lock
|
// lock
|
||||||
CClients *clients = GetClients();
|
CPeers *peers = GetPeers();
|
||||||
// iterate on clients
|
// iterate on peers
|
||||||
for ( int i = 0; i < clients->GetSize(); i++ )
|
for ( int i = 0; i < peers->GetSize(); i++ )
|
||||||
{
|
{
|
||||||
if ( clients->GetClient(i)->IsPeer() )
|
peers->GetPeer(i)->WriteXml(xmlFile);
|
||||||
{
|
|
||||||
clients->GetClient(i)->WriteXml(xmlFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// unlock
|
// unlock
|
||||||
ReleaseClients();
|
ReleasePeers();
|
||||||
xmlFile << "</" << m_Callsign << "linked peers>" << std::endl;
|
xmlFile << "</" << m_Callsign << "linked peers>" << std::endl;
|
||||||
|
|
||||||
// linked nodes
|
// linked nodes
|
||||||
xmlFile << "<" << m_Callsign << "linked nodes>" << std::endl;
|
xmlFile << "<" << m_Callsign << "linked nodes>" << std::endl;
|
||||||
// lock
|
// lock
|
||||||
clients = GetClients();
|
CClients *clients = GetClients();
|
||||||
// iterate on clients
|
// iterate on clients
|
||||||
for ( int i = 0; i < clients->GetSize(); i++ )
|
for ( int i = 0; i < clients->GetSize(); i++ )
|
||||||
{
|
{
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "cusers.h"
|
#include "cusers.h"
|
||||||
#include "cclients.h"
|
#include "cclients.h"
|
||||||
|
#include "cpeers.h"
|
||||||
#include "cprotocols.h"
|
#include "cprotocols.h"
|
||||||
#include "cpacketstream.h"
|
#include "cpacketstream.h"
|
||||||
#include "cnotificationqueue.h"
|
#include "cnotificationqueue.h"
|
||||||
@ -67,6 +68,10 @@ public:
|
|||||||
CClients *GetClients(void) { m_Clients.Lock(); return &m_Clients; }
|
CClients *GetClients(void) { m_Clients.Lock(); return &m_Clients; }
|
||||||
void ReleaseClients(void) { m_Clients.Unlock(); }
|
void ReleaseClients(void) { m_Clients.Unlock(); }
|
||||||
|
|
||||||
|
// peers
|
||||||
|
CPeers *GetPeers(void) { m_Peers.Lock(); return &m_Peers; }
|
||||||
|
void ReleasePeers(void) { m_Peers.Unlock(); }
|
||||||
|
|
||||||
// stream opening & closing
|
// stream opening & closing
|
||||||
CPacketStream *OpenStream(CDvHeaderPacket *, CClient *);
|
CPacketStream *OpenStream(CDvHeaderPacket *, CClient *);
|
||||||
bool IsStreaming(char);
|
bool IsStreaming(char);
|
||||||
@ -82,6 +87,7 @@ public:
|
|||||||
char GetModuleLetter(int i) const { return 'A' + (char)i; }
|
char GetModuleLetter(int i) const { return 'A' + (char)i; }
|
||||||
|
|
||||||
// notifications
|
// notifications
|
||||||
|
void OnPeersChanged(void);
|
||||||
void OnClientsChanged(void);
|
void OnClientsChanged(void);
|
||||||
void OnUsersChanged(void);
|
void OnUsersChanged(void);
|
||||||
void OnStreamOpen(const CCallsign &);
|
void OnStreamOpen(const CCallsign &);
|
||||||
@ -114,7 +120,8 @@ protected:
|
|||||||
|
|
||||||
// objects
|
// objects
|
||||||
CUsers m_Users; // sorted list of lastheard stations
|
CUsers m_Users; // sorted list of lastheard stations
|
||||||
CClients m_Clients; // list of linked repeaters/nodes
|
CClients m_Clients; // list of linked repeaters/nodes/peers's modules
|
||||||
|
CPeers m_Peers; // list of linked peers
|
||||||
CProtocols m_Protocols; // list of supported protocol handlers
|
CProtocols m_Protocols; // list of supported protocol handlers
|
||||||
|
|
||||||
// queues
|
// queues
|
||||||
|
@ -32,31 +32,16 @@
|
|||||||
|
|
||||||
CXlxClient::CXlxClient()
|
CXlxClient::CXlxClient()
|
||||||
{
|
{
|
||||||
::memset(m_ReflectorModules, 0, sizeof(m_ReflectorModules));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CXlxClient::CXlxClient(const CCallsign &callsign, const CIp &ip, char *reflectorModules)
|
CXlxClient::CXlxClient(const CCallsign &callsign, const CIp &ip, char reflectorModule)
|
||||||
: CClient(callsign, ip)
|
: CClient(callsign, ip, reflectorModule)
|
||||||
{
|
{
|
||||||
::memset(m_ReflectorModules, 0, sizeof(m_ReflectorModules));
|
|
||||||
if ( reflectorModules != NULL )
|
|
||||||
{
|
|
||||||
while ( *reflectorModules != 0x00 )
|
|
||||||
{
|
|
||||||
if ( (*reflectorModules >= 'A') && (*reflectorModules < ('A'+ NB_OF_MODULES)) )
|
|
||||||
{
|
|
||||||
::strncat(m_ReflectorModules, reflectorModules, 1);
|
|
||||||
}
|
|
||||||
reflectorModules++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CXlxClient::CXlxClient(const CXlxClient &client)
|
CXlxClient::CXlxClient(const CXlxClient &client)
|
||||||
: CClient(client)
|
: CClient(client)
|
||||||
{
|
{
|
||||||
::strcpy(m_ReflectorModules, client.m_ReflectorModules);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -67,34 +52,3 @@ bool CXlxClient::IsAlive(void) const
|
|||||||
return (m_LastKeepaliveTime.DurationSinceNow() < XLX_KEEPALIVE_TIMEOUT);
|
return (m_LastKeepaliveTime.DurationSinceNow() < XLX_KEEPALIVE_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// get
|
|
||||||
|
|
||||||
bool CXlxClient::HasThisReflectorModule(char module) const
|
|
||||||
{
|
|
||||||
return (::strchr(m_ReflectorModules, module) != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// reporting
|
|
||||||
|
|
||||||
void CXlxClient::WriteXml(std::ofstream &xmlFile)
|
|
||||||
{
|
|
||||||
xmlFile << "<PEER>" << std::endl;
|
|
||||||
xmlFile << "\t<Callsign>" << m_Callsign << "</Callsign>" << std::endl;
|
|
||||||
xmlFile << "\t<IP>" << m_Ip << "</IP>" << std::endl;
|
|
||||||
xmlFile << "\t<LinkedModule>" << m_ReflectorModules << "</LinkedModule>" << std::endl;
|
|
||||||
xmlFile << "\t<Protocol>" << GetProtocolName() << "</Protocol>" << std::endl;
|
|
||||||
char mbstr[100];
|
|
||||||
if (std::strftime(mbstr, sizeof(mbstr), "%A %c", std::localtime(&m_ConnectTime)))
|
|
||||||
{
|
|
||||||
xmlFile << "\t<ConnectTime>" << mbstr << "</ConnectTime>" << std::endl;
|
|
||||||
}
|
|
||||||
if (std::strftime(mbstr, sizeof(mbstr), "%A %c", std::localtime(&m_LastHeardTime)))
|
|
||||||
{
|
|
||||||
xmlFile << "\t<LastHeardTime>" << mbstr << "</LastHeardTime>" << std::endl;
|
|
||||||
}
|
|
||||||
xmlFile << "</PEER>" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class CXlxClient : public CClient
|
|||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
CXlxClient();
|
CXlxClient();
|
||||||
CXlxClient(const CCallsign &, const CIp &, char * = NULL);
|
CXlxClient(const CCallsign &, const CIp &, char = ' ');
|
||||||
CXlxClient(const CXlxClient &);
|
CXlxClient(const CXlxClient &);
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
@ -54,16 +54,8 @@ public:
|
|||||||
// status
|
// status
|
||||||
bool IsAlive(void) const;
|
bool IsAlive(void) const;
|
||||||
|
|
||||||
// get
|
|
||||||
bool HasThisReflectorModule(char) const;
|
|
||||||
|
|
||||||
// reporting
|
// reporting
|
||||||
void WriteXml(std::ofstream &);
|
void WriteXml(std::ofstream &) {}
|
||||||
|
|
||||||
protected:
|
|
||||||
// linked to
|
|
||||||
char m_ReflectorModules[NB_OF_MODULES+1];
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
84
src/cxlxpeer.cpp
Normal file
84
src/cxlxpeer.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
//
|
||||||
|
// cxlxpeer.cpp
|
||||||
|
// xlxd
|
||||||
|
//
|
||||||
|
// Created by Jean-Luc Deltombe (LX3JL) on 10/12/2016.
|
||||||
|
// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// This file is part of xlxd.
|
||||||
|
//
|
||||||
|
// xlxd 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 Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// xlxd is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include <string.h>
|
||||||
|
#include "creflector.h"
|
||||||
|
#include "cxlxpeer.h"
|
||||||
|
#include "cxlxclient.h"
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// constructor
|
||||||
|
|
||||||
|
|
||||||
|
CXlxPeer::CXlxPeer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CXlxPeer::CXlxPeer(const CCallsign &callsign, const CIp &ip, char *modules)
|
||||||
|
: CPeer(callsign, ip, modules)
|
||||||
|
{
|
||||||
|
// and construct all xlx clients
|
||||||
|
for ( int i = 0; i < ::strlen(modules); i++ )
|
||||||
|
{
|
||||||
|
// create
|
||||||
|
CXlxClient *client = new CXlxClient(callsign, ip, modules[i]);
|
||||||
|
// and append to vector
|
||||||
|
m_Clients.push_back(client);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CXlxPeer::CXlxPeer(const CXlxPeer &peer)
|
||||||
|
: CPeer(peer)
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < peer.m_Clients.size(); i++ )
|
||||||
|
{
|
||||||
|
CXlxClient *client = new CXlxClient((const CXlxClient &)*(peer.m_Clients[i]));
|
||||||
|
// grow vector capacity if needed
|
||||||
|
if ( m_Clients.capacity() == m_Clients.size() )
|
||||||
|
{
|
||||||
|
m_Clients.reserve(m_Clients.capacity()+10);
|
||||||
|
}
|
||||||
|
// and append
|
||||||
|
m_Clients.push_back(client);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// destructors
|
||||||
|
|
||||||
|
CXlxPeer::~CXlxPeer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// status
|
||||||
|
|
||||||
|
bool CXlxPeer::IsAlive(void) const
|
||||||
|
{
|
||||||
|
return (m_LastKeepaliveTime.DurationSinceNow() < XLX_KEEPALIVE_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
55
src/cxlxpeer.h
Normal file
55
src/cxlxpeer.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
//
|
||||||
|
// cxlxpeer.h
|
||||||
|
// xlxd
|
||||||
|
//
|
||||||
|
// Created by Jean-Luc Deltombe (LX3JL) on 10/12/2016.
|
||||||
|
// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
||||||
|
//
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// This file is part of xlxd.
|
||||||
|
//
|
||||||
|
// xlxd 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 Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// xlxd is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef cxlxpeer_h
|
||||||
|
#define cxlxpeer_h
|
||||||
|
|
||||||
|
#include "cpeer.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// class
|
||||||
|
|
||||||
|
class CXlxPeer : public CPeer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// constructors
|
||||||
|
CXlxPeer();
|
||||||
|
CXlxPeer(const CCallsign &, const CIp &, char *);
|
||||||
|
CXlxPeer(const CXlxPeer &);
|
||||||
|
|
||||||
|
// destructor
|
||||||
|
~CXlxPeer();
|
||||||
|
|
||||||
|
// status
|
||||||
|
bool IsAlive(void) const;
|
||||||
|
// identity
|
||||||
|
int GetProtocol(void) const { return PROTOCOL_XLX; }
|
||||||
|
const char *GetProtocolName(void) const { return "XLX"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#endif /* cxlxpeer_h */
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "cxlxclient.h"
|
#include "cxlxpeer.h"
|
||||||
#include "cxlxprotocol.h"
|
#include "cxlxprotocol.h"
|
||||||
#include "creflector.h"
|
#include "creflector.h"
|
||||||
#include "cgatekeeper.h"
|
#include "cgatekeeper.h"
|
||||||
@ -52,6 +52,7 @@ bool CXlxProtocol::Init(void)
|
|||||||
|
|
||||||
// update time
|
// update time
|
||||||
m_LastKeepaliveTime.Now();
|
m_LastKeepaliveTime.Now();
|
||||||
|
m_LastPeersLinkTime.Now();
|
||||||
|
|
||||||
// done
|
// done
|
||||||
return ok;
|
return ok;
|
||||||
@ -69,6 +70,7 @@ void CXlxProtocol::Task(void)
|
|||||||
CDvHeaderPacket *Header;
|
CDvHeaderPacket *Header;
|
||||||
CDvFramePacket *Frame;
|
CDvFramePacket *Frame;
|
||||||
CDvLastFramePacket *LastFrame;
|
CDvLastFramePacket *LastFrame;
|
||||||
|
uint8 Major, Minor, Revision;
|
||||||
|
|
||||||
// any incoming packet ?
|
// any incoming packet ?
|
||||||
if ( m_Socket.Receive(&Buffer, &Ip, 20) != -1 )
|
if ( m_Socket.Receive(&Buffer, &Ip, 20) != -1 )
|
||||||
@ -84,6 +86,7 @@ void CXlxProtocol::Task(void)
|
|||||||
else if ( (Header = IsValidDvHeaderPacket(Buffer)) != NULL )
|
else if ( (Header = IsValidDvHeaderPacket(Buffer)) != NULL )
|
||||||
{
|
{
|
||||||
//std::cout << "XLX (DExtra) DV header:" << std::endl << *Header << std::endl;
|
//std::cout << "XLX (DExtra) DV header:" << std::endl << *Header << std::endl;
|
||||||
|
//std::cout << "XLX (DExtra) DV header on module " << Header->GetRpt2Module() << std::endl;
|
||||||
|
|
||||||
// callsign muted?
|
// callsign muted?
|
||||||
if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip) )
|
if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip) )
|
||||||
@ -103,26 +106,35 @@ void CXlxProtocol::Task(void)
|
|||||||
// handle it
|
// handle it
|
||||||
OnDvLastFramePacketIn(LastFrame);
|
OnDvLastFramePacketIn(LastFrame);
|
||||||
}
|
}
|
||||||
else if ( IsValidConnectPacket(Buffer, &Callsign, Modules) || IsValidAckPacket(Buffer, &Callsign, Modules) )
|
else if ( IsValidConnectPacket(Buffer, &Callsign, Modules, &Major, &Minor, &Revision) )
|
||||||
{
|
{
|
||||||
std::cout << "XLX connect/ack packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl;
|
std::cout << "XLX (" << (int)Major << "." << (int)Minor << "." << (int)Revision
|
||||||
|
<< ") connect packet for modules " << Modules
|
||||||
|
<< " from " << Callsign << " at " << Ip << std::endl;
|
||||||
|
|
||||||
// already connected ?
|
|
||||||
CClients *clients = g_Reflector.GetClients();
|
|
||||||
if ( clients->FindClient(Callsign, Ip, PROTOCOL_XLX) == NULL )
|
|
||||||
{
|
|
||||||
// callsign authorized?
|
// callsign authorized?
|
||||||
if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_XLX, Modules) )
|
if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_XLX, Modules) )
|
||||||
|
{
|
||||||
|
// following is version dependent
|
||||||
|
// for backward compatibility, only send ACK once
|
||||||
|
if ( (Major == 1) && (Minor < 4) )
|
||||||
|
{
|
||||||
|
// already connected ?
|
||||||
|
CPeers *peers = g_Reflector.GetPeers();
|
||||||
|
if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == NULL )
|
||||||
{
|
{
|
||||||
// acknowledge the request
|
// acknowledge the request
|
||||||
EncodeConnectAckPacket(&Buffer, Modules);
|
EncodeConnectAckPacket(&Buffer, Modules);
|
||||||
m_Socket.Send(Buffer, Ip);
|
m_Socket.Send(Buffer, Ip);
|
||||||
|
}
|
||||||
// create the client
|
g_Reflector.ReleasePeers();
|
||||||
CXlxClient *client = new CXlxClient(Callsign, Ip, Modules);
|
}
|
||||||
|
else
|
||||||
// and append
|
{
|
||||||
clients->AddClient(client);
|
// acknowledge the request
|
||||||
|
EncodeConnectAckPacket(&Buffer, Modules);
|
||||||
|
m_Socket.Send(Buffer, Ip);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -131,21 +143,43 @@ void CXlxProtocol::Task(void)
|
|||||||
m_Socket.Send(Buffer, Ip);
|
m_Socket.Send(Buffer, Ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// done
|
else if ( IsValidAckPacket(Buffer, &Callsign, Modules) )
|
||||||
g_Reflector.ReleaseClients();
|
{
|
||||||
|
std::cout << "XLX ack packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl;
|
||||||
|
|
||||||
|
// callsign authorized?
|
||||||
|
if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_XLX, Modules) )
|
||||||
|
{
|
||||||
|
// already connected ?
|
||||||
|
CPeers *peers = g_Reflector.GetPeers();
|
||||||
|
if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == NULL )
|
||||||
|
{
|
||||||
|
// create the new peer
|
||||||
|
// this also create one client per module
|
||||||
|
CXlxPeer *peer = new CXlxPeer(Callsign, Ip, Modules);
|
||||||
|
|
||||||
|
// append the peer to reflector peer list
|
||||||
|
// this also add all new clients to reflector client list
|
||||||
|
peers->AddPeer(peer);
|
||||||
|
}
|
||||||
|
g_Reflector.ReleasePeers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ( IsValidDisconnectPacket(Buffer, &Callsign) )
|
else if ( IsValidDisconnectPacket(Buffer, &Callsign) )
|
||||||
{
|
{
|
||||||
std::cout << "XLX disconnect packet from " << Callsign << " at " << Ip << std::endl;
|
std::cout << "XLX disconnect packet from " << Callsign << " at " << Ip << std::endl;
|
||||||
|
|
||||||
// find client & remove it
|
// find peer
|
||||||
CClients *clients = g_Reflector.GetClients();
|
CPeers *peers = g_Reflector.GetPeers();
|
||||||
CClient *client = clients->FindClient(Callsign, Ip, PROTOCOL_XLX);
|
CPeer *peer = peers->FindPeer(Ip, PROTOCOL_XLX);
|
||||||
if ( client != NULL )
|
if ( peer != NULL )
|
||||||
{
|
{
|
||||||
clients->RemoveClient(client);
|
// remove it from reflector peer list
|
||||||
|
// this also remove all concerned clients from reflector client list
|
||||||
|
// and delete them
|
||||||
|
peers->RemovePeer(peer);
|
||||||
}
|
}
|
||||||
g_Reflector.ReleaseClients();
|
g_Reflector.ReleasePeers();
|
||||||
}
|
}
|
||||||
else if ( IsValidNackPacket(Buffer, &Callsign) )
|
else if ( IsValidNackPacket(Buffer, &Callsign) )
|
||||||
{
|
{
|
||||||
@ -155,15 +189,15 @@ void CXlxProtocol::Task(void)
|
|||||||
{
|
{
|
||||||
//std::cout << "XLX keepalive packet from " << Callsign << " at " << Ip << std::endl;
|
//std::cout << "XLX keepalive packet from " << Callsign << " at " << Ip << std::endl;
|
||||||
|
|
||||||
// find client & keep it alive
|
// find peer
|
||||||
CClient *GetClient(const CCallsign &, const CIp &, char, int);
|
CPeers *peers = g_Reflector.GetPeers();
|
||||||
|
CPeer *peer = peers->FindPeer(Ip, PROTOCOL_XLX);
|
||||||
CClient *client = g_Reflector.GetClients()->FindClient(Callsign, Ip, PROTOCOL_XLX);
|
if ( peer != NULL )
|
||||||
if ( client != NULL )
|
|
||||||
{
|
{
|
||||||
client->Alive();
|
// keep it alive
|
||||||
|
peer->Alive();
|
||||||
}
|
}
|
||||||
g_Reflector.ReleaseClients();
|
g_Reflector.ReleasePeers();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -183,11 +217,18 @@ void CXlxProtocol::Task(void)
|
|||||||
// handle keep alives
|
// handle keep alives
|
||||||
HandleKeepalives();
|
HandleKeepalives();
|
||||||
|
|
||||||
|
// update time
|
||||||
|
m_LastKeepaliveTime.Now();
|
||||||
|
}
|
||||||
|
|
||||||
|
// peer connections
|
||||||
|
if ( m_LastPeersLinkTime.DurationSinceNow() > XLX_RECONNECT_PERIOD )
|
||||||
|
{
|
||||||
// handle remote peers connections
|
// handle remote peers connections
|
||||||
HandlePeerLinks();
|
HandlePeerLinks();
|
||||||
|
|
||||||
// update time
|
// update time
|
||||||
m_LastKeepaliveTime.Now();
|
m_LastPeersLinkTime.Now();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,8 +260,7 @@ void CXlxProtocol::HandleQueue(void)
|
|||||||
while ( (client = clients->FindNextClient(PROTOCOL_XLX, &index)) != NULL )
|
while ( (client = clients->FindNextClient(PROTOCOL_XLX, &index)) != NULL )
|
||||||
{
|
{
|
||||||
// is this client busy ?
|
// is this client busy ?
|
||||||
// here check that origin module of the stream is listed in client xlx
|
if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) )
|
||||||
if ( !client->IsAMaster() && client->HasThisReflectorModule(packet->GetModuleId()) )
|
|
||||||
{
|
{
|
||||||
// no, send the packet
|
// no, send the packet
|
||||||
m_Socket.Send(buffer, client->GetIp());
|
m_Socket.Send(buffer, client->GetIp());
|
||||||
@ -247,35 +287,35 @@ void CXlxProtocol::HandleKeepalives(void)
|
|||||||
CBuffer keepalive;
|
CBuffer keepalive;
|
||||||
EncodeKeepAlivePacket(&keepalive);
|
EncodeKeepAlivePacket(&keepalive);
|
||||||
|
|
||||||
// iterate on clients
|
// iterate on peers
|
||||||
CClients *clients = g_Reflector.GetClients();
|
CPeers *peers = g_Reflector.GetPeers();
|
||||||
int index = -1;
|
int index = -1;
|
||||||
CClient *client = NULL;
|
CPeer *peer = NULL;
|
||||||
while ( (client = clients->FindNextClient(PROTOCOL_XLX, &index)) != NULL )
|
while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, &index)) != NULL )
|
||||||
{
|
{
|
||||||
// send keepalive
|
// send keepalive
|
||||||
m_Socket.Send(keepalive, client->GetIp());
|
m_Socket.Send(keepalive, peer->GetIp());
|
||||||
|
|
||||||
// client busy ?
|
// client busy ?
|
||||||
if ( client->IsAMaster() )
|
if ( peer->IsAMaster() )
|
||||||
{
|
{
|
||||||
// yes, just tickle it
|
// yes, just tickle it
|
||||||
client->Alive();
|
peer->Alive();
|
||||||
}
|
}
|
||||||
// otherwise check if still with us
|
// otherwise check if still with us
|
||||||
else if ( !client->IsAlive() )
|
else if ( !peer->IsAlive() )
|
||||||
{
|
{
|
||||||
// no, disconnect
|
// no, disconnect
|
||||||
CBuffer disconnect;
|
CBuffer disconnect;
|
||||||
EncodeDisconnectPacket(&disconnect);
|
EncodeDisconnectPacket(&disconnect);
|
||||||
m_Socket.Send(disconnect, client->GetIp());
|
m_Socket.Send(disconnect, peer->GetIp());
|
||||||
|
|
||||||
// remove it
|
// remove it
|
||||||
std::cout << "XLX peer " << client->GetCallsign() << " keepalive timeout" << std::endl;
|
std::cout << "XLX peer " << peer->GetCallsign() << " keepalive timeout" << std::endl;
|
||||||
clients->RemoveClient(client);
|
peers->RemovePeer(peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_Reflector.ReleaseClients();
|
g_Reflector.ReleasePeers();
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -287,23 +327,22 @@ void CXlxProtocol::HandlePeerLinks(void)
|
|||||||
|
|
||||||
// get the list of peers
|
// get the list of peers
|
||||||
CPeerCallsignList *list = g_GateKeeper.GetPeerList();
|
CPeerCallsignList *list = g_GateKeeper.GetPeerList();
|
||||||
// todo: analyse possibility of double-lock hang-up
|
CPeers *peers = g_Reflector.GetPeers();
|
||||||
CClients *clients = g_Reflector.GetClients();
|
|
||||||
|
|
||||||
// check if all our connected client are still listed by gatekeeper
|
// check if all our connected peers are still listed by gatekeeper
|
||||||
// if not, disconnect
|
// if not, disconnect
|
||||||
int index = -1;
|
int index = -1;
|
||||||
CClient *client = NULL;
|
CPeer *peer = NULL;
|
||||||
while ( (client = clients->FindNextClient(PROTOCOL_XLX, &index)) != NULL )
|
while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, &index)) != NULL )
|
||||||
{
|
{
|
||||||
if ( list->FindListItem(client->GetCallsign()) == NULL )
|
if ( list->FindListItem(peer->GetCallsign()) == NULL )
|
||||||
{
|
{
|
||||||
// send disconnect packet
|
// send disconnect packet
|
||||||
EncodeDisconnectPacket(&buffer);
|
EncodeDisconnectPacket(&buffer);
|
||||||
m_Socket.Send(buffer, client->GetIp());
|
m_Socket.Send(buffer, peer->GetIp());
|
||||||
std::cout << "Sending disconnect packet to XLX peer " << client->GetCallsign() << std::endl;
|
std::cout << "Sending disconnect packet to XLX peer " << peer->GetCallsign() << std::endl;
|
||||||
// remove client
|
// remove client
|
||||||
clients->RemoveClient(client);
|
peers->RemovePeer(peer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +351,7 @@ void CXlxProtocol::HandlePeerLinks(void)
|
|||||||
for ( int i = 0; i < list->size(); i++ )
|
for ( int i = 0; i < list->size(); i++ )
|
||||||
{
|
{
|
||||||
CCallsignListItem *item = &((list->data())[i]);
|
CCallsignListItem *item = &((list->data())[i]);
|
||||||
if ( clients->FindClient(item->GetCallsign(), PROTOCOL_XLX) == NULL )
|
if ( peers->FindPeer(item->GetCallsign(), PROTOCOL_XLX) == NULL )
|
||||||
{
|
{
|
||||||
// resolve again peer's IP in case it's a dynamic IP
|
// resolve again peer's IP in case it's a dynamic IP
|
||||||
item->ResolveIp();
|
item->ResolveIp();
|
||||||
@ -324,7 +363,7 @@ void CXlxProtocol::HandlePeerLinks(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// done
|
// done
|
||||||
g_Reflector.ReleaseClients();
|
g_Reflector.ReleasePeers();
|
||||||
g_GateKeeper.ReleasePeerList();
|
g_GateKeeper.ReleasePeerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +388,7 @@ bool CXlxProtocol::OnDvHeaderPacketIn(CDvHeaderPacket *Header, const CIp &Ip)
|
|||||||
{
|
{
|
||||||
// no stream open yet, open a new one
|
// no stream open yet, open a new one
|
||||||
// find this client
|
// find this client
|
||||||
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX);
|
CClient *client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX, Header->GetRpt2Module());
|
||||||
if ( client != NULL )
|
if ( client != NULL )
|
||||||
{
|
{
|
||||||
// and try to open the stream
|
// and try to open the stream
|
||||||
@ -414,7 +453,7 @@ bool CXlxProtocol::IsValidKeepAlivePacket(const CBuffer &Buffer, CCallsign *call
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CXlxProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsign, char *modules)
|
bool CXlxProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsign, char *modules, uint8 *major, uint8 *minor, uint8 *rev)
|
||||||
{
|
{
|
||||||
bool valid = false;
|
bool valid = false;
|
||||||
if ((Buffer.size() == 39) && (Buffer.data()[0] == 'L') && (Buffer.data()[38] == 0))
|
if ((Buffer.size() == 39) && (Buffer.data()[0] == 'L') && (Buffer.data()[38] == 0))
|
||||||
@ -422,6 +461,9 @@ bool CXlxProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsi
|
|||||||
callsign->SetCallsign((const uint8 *)&(Buffer.data()[1]), 8);
|
callsign->SetCallsign((const uint8 *)&(Buffer.data()[1]), 8);
|
||||||
::strcpy(modules, (const char *)&(Buffer.data()[12]));
|
::strcpy(modules, (const char *)&(Buffer.data()[12]));
|
||||||
valid = callsign->IsValid();
|
valid = callsign->IsValid();
|
||||||
|
*major = Buffer.data()[9];
|
||||||
|
*minor = Buffer.data()[10];
|
||||||
|
*rev = Buffer.data()[11];
|
||||||
for ( int i = 0; i < ::strlen(modules); i++ )
|
for ( int i = 0; i < ::strlen(modules); i++ )
|
||||||
{
|
{
|
||||||
valid &= IsLetter(modules[i]);
|
valid &= IsLetter(modules[i]);
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "ctimepoint.h"
|
#include "ctimepoint.h"
|
||||||
#include "cdextraprotocol.h"
|
#include "cdextraprotocol.h"
|
||||||
|
#include "cclients.h"
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ protected:
|
|||||||
|
|
||||||
// packet decoding helpers
|
// packet decoding helpers
|
||||||
bool IsValidKeepAlivePacket(const CBuffer &, CCallsign *);
|
bool IsValidKeepAlivePacket(const CBuffer &, CCallsign *);
|
||||||
bool IsValidConnectPacket(const CBuffer &, CCallsign *, char *);
|
bool IsValidConnectPacket(const CBuffer &, CCallsign *, char *, uint8 *, uint8 *, uint8 *);
|
||||||
bool IsValidDisconnectPacket(const CBuffer &, CCallsign *);
|
bool IsValidDisconnectPacket(const CBuffer &, CCallsign *);
|
||||||
bool IsValidAckPacket(const CBuffer &, CCallsign *, char *);
|
bool IsValidAckPacket(const CBuffer &, CCallsign *, char *);
|
||||||
bool IsValidNackPacket(const CBuffer &, CCallsign *);
|
bool IsValidNackPacket(const CBuffer &, CCallsign *);
|
||||||
@ -80,6 +81,7 @@ protected:
|
|||||||
protected:
|
protected:
|
||||||
// time
|
// time
|
||||||
CTimePoint m_LastKeepaliveTime;
|
CTimePoint m_LastKeepaliveTime;
|
||||||
|
CTimePoint m_LastPeersLinkTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -47,8 +47,8 @@
|
|||||||
// version -----------------------------------------------------
|
// version -----------------------------------------------------
|
||||||
|
|
||||||
#define VERSION_MAJOR 1
|
#define VERSION_MAJOR 1
|
||||||
#define VERSION_MINOR 3
|
#define VERSION_MINOR 4
|
||||||
#define VERSION_REVISION 9
|
#define VERSION_REVISION 0
|
||||||
|
|
||||||
// global ------------------------------------------------------
|
// global ------------------------------------------------------
|
||||||
|
|
||||||
@ -90,6 +90,7 @@
|
|||||||
#define XLX_PORT 10002 // UDP port
|
#define XLX_PORT 10002 // UDP port
|
||||||
#define XLX_KEEPALIVE_PERIOD 1 // in seconds
|
#define XLX_KEEPALIVE_PERIOD 1 // in seconds
|
||||||
#define XLX_KEEPALIVE_TIMEOUT (XLX_KEEPALIVE_PERIOD*30) // in seconds
|
#define XLX_KEEPALIVE_TIMEOUT (XLX_KEEPALIVE_PERIOD*30) // in seconds
|
||||||
|
#define XLX_RECONNECT_PERIOD 5 // in seconds
|
||||||
|
|
||||||
// xml & json reporting -----------------------------------------
|
// xml & json reporting -----------------------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user