diff --git a/config/urfd.interlink b/config/urfd.interlink index b895a7d..3232cc2 100644 --- a/config/urfd.interlink +++ b/config/urfd.interlink @@ -5,12 +5,10 @@ # each entry specifies a remote XLX or XRF to peer with # format: # -# # example: # URF270 158.64.26.132 ACD -# XRF270 158.64.26.132 BB # -# note: the remote XLX must list this XLX in its interlink file +# note: the remote URFD must list this in its interlink file # for the link to be established # ############################################################################# diff --git a/reflector/BMClient.cpp b/reflector/BMClient.cpp index 59b037c..9e621da 100644 --- a/reflector/BMClient.cpp +++ b/reflector/BMClient.cpp @@ -43,5 +43,5 @@ CBmClient::CBmClient(const CBmClient &client) bool CBmClient::IsAlive(void) const { - return (m_LastKeepaliveTime.time() < XLX_KEEPALIVE_TIMEOUT); + return (m_LastKeepaliveTime.time() < BM_KEEPALIVE_TIMEOUT); } diff --git a/reflector/BMClient.h b/reflector/BMClient.h index 1708bf6..4328afc 100644 --- a/reflector/BMClient.h +++ b/reflector/BMClient.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Client.h" class CBmClient : public CClient diff --git a/reflector/BMPeer.cpp b/reflector/BMPeer.cpp index 6bcd756..fa03e3c 100644 --- a/reflector/BMPeer.cpp +++ b/reflector/BMPeer.cpp @@ -50,7 +50,7 @@ CBmPeer::CBmPeer(const CCallsign &callsign, const CIp &ip, const char *modules, bool CBmPeer::IsAlive(void) const { - return (m_LastKeepaliveTime.time() < XLX_KEEPALIVE_TIMEOUT); + return (m_LastKeepaliveTime.time() < BM_KEEPALIVE_TIMEOUT); } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/reflector/BMProtocol.cpp b/reflector/BMProtocol.cpp index dae8b90..3d848ce 100644 --- a/reflector/BMProtocol.cpp +++ b/reflector/BMProtocol.cpp @@ -18,12 +18,9 @@ #include - #include "BMPeer.h" #include "BMProtocol.h" -#include "Reflector.h" -#include "GateKeeper.h" - +#include "Global.h" //////////////////////////////////////////////////////////////////////////////////////// // operation @@ -104,7 +101,7 @@ void CBMProtocol::Task(void) if ( g_Gate.MayLink(Callsign, Ip, EProtocol::bm, Modules) ) { // already connected ? - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); if ( peers->FindPeer(Callsign, Ip, EProtocol::bm) == nullptr ) { // create the new peer @@ -115,7 +112,7 @@ void CBMProtocol::Task(void) // this also add all new clients to reflector client list peers->AddPeer(peer); } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } } else if ( IsValidDisconnectPacket(Buffer, &Callsign) ) @@ -123,7 +120,7 @@ void CBMProtocol::Task(void) std::cout << "XLX disconnect packet from " << Callsign << " at " << Ip << std::endl; // find peer - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); std::shared_ptrpeer = peers->FindPeer(Ip, EProtocol::bm); if ( peer != nullptr ) { @@ -132,7 +129,7 @@ void CBMProtocol::Task(void) // and delete them peers->RemovePeer(peer); } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } else if ( IsValidNackPacket(Buffer, &Callsign) ) { @@ -143,14 +140,14 @@ void CBMProtocol::Task(void) //std::cout << "XLX keepalive packet from " << Callsign << " at " << Ip << std::endl; // find peer - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); std::shared_ptrpeer = peers->FindPeer(Ip, EProtocol::bm); if ( peer != nullptr ) { // keep it alive peer->Alive(); } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } else { @@ -167,7 +164,7 @@ void CBMProtocol::Task(void) HandleQueue(); // keep alive - if ( m_LastKeepaliveTime.time() > XLX_KEEPALIVE_PERIOD ) + if ( m_LastKeepaliveTime.time() > BM_KEEPALIVE_PERIOD ) { // handle keep alives HandleKeepalives(); @@ -177,7 +174,7 @@ void CBMProtocol::Task(void) } // peer connections - if ( m_LastPeersLinkTime.time() > XLX_RECONNECT_PERIOD ) + if ( m_LastPeersLinkTime.time() > BM_RECONNECT_PERIOD ) { // handle remote peers connections HandlePeerLinks(); @@ -210,7 +207,7 @@ void CBMProtocol::HandleQueue(void) } // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::bm, it)) != nullptr ) @@ -237,7 +234,7 @@ void CBMProtocol::HandleQueue(void) } } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } m_Queue.Unlock(); @@ -255,7 +252,7 @@ void CBMProtocol::HandleKeepalives(void) EncodeKeepAlivePacket(&keepalive); // iterate on peers - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); auto pit = peers->begin(); std::shared_ptrpeer = nullptr; while ( (peer = peers->FindNextPeer(EProtocol::bm, pit)) != nullptr ) @@ -282,7 +279,7 @@ void CBMProtocol::HandleKeepalives(void) peers->RemovePeer(peer); } } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -294,7 +291,7 @@ void CBMProtocol::HandlePeerLinks(void) // get the list of peers CPeerCallsignList *list = g_Gate.GetPeerList(); - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); // check if all our connected peers are still listed by gatekeeper // if not, disconnect @@ -324,13 +321,13 @@ void CBMProtocol::HandlePeerLinks(void) it->ResolveIp(); // send connect packet to re-initiate peer link EncodeConnectPacket(&buffer, it->GetModules()); - Send(buffer, it->GetIp(), XLX_PORT); + Send(buffer, it->GetIp(), m_Port); std::cout << "Sending connect packet to BM peer " << cs << " @ " << it->GetIp() << " for modules " << it->GetModules() << std::endl; } } // done - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); g_Gate.ReleasePeerList(); } @@ -360,11 +357,11 @@ void CBMProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c CCallsign rpt2(Header->GetRpt2Callsign()); // no stream open yet, open a new one // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::bm, Header->GetRpt2Module()); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::bm, Header->GetRpt2Module()); if ( client ) { // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; @@ -373,10 +370,10 @@ void CBMProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c peer = client->GetCallsign(); } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2, peer); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2, peer); + g_Refl.ReleaseUsers(); } } diff --git a/reflector/BMProtocol.h b/reflector/BMProtocol.h index fa36b2d..74dfe15 100644 --- a/reflector/BMProtocol.h +++ b/reflector/BMProtocol.h @@ -18,6 +18,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "Defines.h" #include "Version.h" #include "Timer.h" #include "SEProtocol.h" diff --git a/reflector/Buffer.cpp b/reflector/Buffer.cpp index 544ba84..8aa57a5 100644 --- a/reflector/Buffer.cpp +++ b/reflector/Buffer.cpp @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include #include #include "Buffer.h" diff --git a/reflector/CNotificationQueue.h b/reflector/CNotificationQueue.h index 57839ad..f0bc210 100644 --- a/reflector/CNotificationQueue.h +++ b/reflector/CNotificationQueue.h @@ -23,12 +23,6 @@ #include "Notification.h" - -//////////////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////////////// -// class - class CNotificationQueue { public: diff --git a/reflector/Callsign.cpp b/reflector/Callsign.cpp index c8749b3..b0312e3 100644 --- a/reflector/Callsign.cpp +++ b/reflector/Callsign.cpp @@ -19,10 +19,7 @@ #include #include -#include "DMRIdDirFile.h" -#include "DMRIdDirHttp.h" -#include "NXDNIdDirFile.h" -#include "NXDNIdDirHttp.h" +#include "Global.h" #include "Callsign.h" // if a client is using special characters '.', '-' or '/', he's out of luck! @@ -277,7 +274,7 @@ void CCallsign::SetNXDNid(uint16_t nxdnid, bool UpdateCallsign) m_uiNXDNid = nxdnid; if ( UpdateCallsign ) { - g_LDid.Lock(); + g_LNid.Lock(); { const CCallsign *callsign = g_LNid.FindCallsign(nxdnid); if ( callsign != nullptr ) diff --git a/reflector/CallsignList.cpp b/reflector/CallsignList.cpp index 2fff96b..e1d4a0d 100644 --- a/reflector/CallsignList.cpp +++ b/reflector/CallsignList.cpp @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include #include #include #include @@ -34,7 +35,7 @@ CCallsignList::CCallsignList() //////////////////////////////////////////////////////////////////////////////////////// // file io -bool CCallsignList::LoadFromFile(const char *filename) +bool CCallsignList::LoadFromFile(const std::string &filename) { bool ok = false; char sz[256]; @@ -77,7 +78,7 @@ bool CCallsignList::LoadFromFile(const char *filename) file.close(); // keep file path - m_Filename = filename; + m_Filename.assign(filename); // update time GetLastModTime(&m_LastModTime); @@ -99,7 +100,7 @@ bool CCallsignList::ReloadFromFile(void) { bool ok = false; - if ( m_Filename != nullptr ) + if (! m_Filename.empty()) { ok = LoadFromFile(m_Filename); } @@ -210,10 +211,10 @@ bool CCallsignList::GetLastModTime(time_t *time) { bool ok = false; - if ( m_Filename != nullptr ) + if (! m_Filename.empty()) { struct stat fileStat; - if( ::stat(m_Filename, &fileStat) != -1 ) + if( ::stat(m_Filename.c_str(), &fileStat) != -1 ) { *time = fileStat.st_mtime; ok = true; diff --git a/reflector/CallsignList.h b/reflector/CallsignList.h index c9ba29a..df1d153 100644 --- a/reflector/CallsignList.h +++ b/reflector/CallsignList.h @@ -18,6 +18,9 @@ #pragma once +#include +#include + #include "CallsignListItem.h" //////////////////////////////////////////////////////////////////////////////////////// @@ -29,15 +32,12 @@ public: // constructor CCallsignList(); - // destructor - virtual ~CCallsignList() {} - // locks void Lock(void) { m_Mutex.lock(); } void Unlock(void) { m_Mutex.unlock(); } // file io - virtual bool LoadFromFile(const char *); + virtual bool LoadFromFile(const std::string &str); bool ReloadFromFile(void); bool NeedReload(void); @@ -61,7 +61,7 @@ protected: // data std::mutex m_Mutex; - const char * m_Filename; + std::string m_Filename; time_t m_LastModTime; std::list m_Callsigns; }; diff --git a/reflector/CallsignListItem.cpp b/reflector/CallsignListItem.cpp index c6a5808..01bebab 100644 --- a/reflector/CallsignListItem.cpp +++ b/reflector/CallsignListItem.cpp @@ -18,6 +18,8 @@ #include +#include "Global.h" + #include "CallsignListItem.h" //////////////////////////////////////////////////////////////////////////////////////// @@ -31,6 +33,7 @@ CCallsignListItem::CCallsignListItem() CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, const char *modules) { + const std::string mods(g_Conf.GetString(g_Conf.j.modules.modules)); m_Callsign = callsign; memset(m_szUrl, 0, sizeof(m_szUrl)); m_Ip = ip; @@ -39,14 +42,14 @@ CCallsignListItem::CCallsignListItem(const CCallsign &callsign, const CIp &ip, c memset(m_Modules, 0, sizeof(m_Modules)); if ( modules[0] == '*' ) { - memcpy(m_Modules, ACTIVE_MODULES, sizeof(ACTIVE_MODULES)); + memcpy(m_Modules, mods.c_str(), mods.size()); } else { int n = MIN(::strlen(modules), sizeof(m_Modules)-1); for (int i=0, j=0; i. -#include "Reflector.h" +#include "Global.h" #include "Clients.h" - //////////////////////////////////////////////////////////////////////////////////////// // constructor - CClients::CClients() { } @@ -66,7 +64,7 @@ void CClients::AddClient(std::shared_ptr client) } std::cout << std::endl; // notify - g_Refl..OnClientsChanged(); + g_Refl.OnClientsChanged(); } void CClients::RemoveClient(std::shared_ptr client) @@ -90,7 +88,7 @@ void CClients::RemoveClient(std::shared_ptr client) std::cout << std::endl; m_Clients.erase(it); // notify - g_Refl..OnClientsChanged(); + g_Refl.OnClientsChanged(); break; } } diff --git a/reflector/Configure.cpp b/reflector/Configure.cpp index 968c722..de6b31f 100644 --- a/reflector/Configure.cpp +++ b/reflector/Configure.cpp @@ -441,7 +441,7 @@ bool CConfigure::ReadData(const std::string &path) data[j.usrp.defaultcallsign] = cs; } else if (0 == key.compare(JCLIENTSPATH)) - data[j.usrp.clientfilepath] == value; + data[j.usrp.clientfilepath] = value; else badParam(key); break; @@ -915,14 +915,14 @@ bool CConfigure::IsString(const std::string &key) const #ifdef INICHECK int main(int argc, char *argv[]) { - if (argc == 2) + if (argc == 2 || argc == 3) { CConfigure d; - auto rval = d.ReadData(argv[1]); - d.Dump(true); + auto rval = d.ReadData(argv[argc-1]); + d.Dump((2==argc) ? false : true); return rval ? EXIT_FAILURE : EXIT_SUCCESS; } - std::cerr << "Usage: " << argv[0] << " FILENAME" << std::endl; + std::cerr << "Usage: " << argv[0] << " FILENAME\nWhere is anything.\nThis option only shows values whose key begins with an uppercase letter." << std::endl; return EXIT_SUCCESS; } #endif diff --git a/reflector/DCSClient.h b/reflector/DCSClient.h index 09d00dd..d22cd04 100644 --- a/reflector/DCSClient.h +++ b/reflector/DCSClient.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Client.h" class CDcsClient : public CClient diff --git a/reflector/DCSProtocol.cpp b/reflector/DCSProtocol.cpp index 0a3f5b6..90eb419 100644 --- a/reflector/DCSProtocol.cpp +++ b/reflector/DCSProtocol.cpp @@ -16,12 +16,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - #include + +#include "Global.h" #include "DCSClient.h" #include "DCSProtocol.h" -#include "Reflector.h" -#include "GateKeeper.h" //////////////////////////////////////////////////////////////////////////////////////// // operation @@ -80,18 +79,18 @@ void CDcsProtocol::Task(void) std::cout << "DCS connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_Gate.MayLink(Callsign, Ip, EProtocol::dcs) && g_Refl..IsValidModule(ToLinkModule) ) + if ( g_Gate.MayLink(Callsign, Ip, EProtocol::dcs) && g_Refl.IsValidModule(ToLinkModule) ) { // valid module ? - if ( g_Refl..IsValidModule(ToLinkModule) ) + if ( g_Refl.IsValidModule(ToLinkModule) ) { // acknowledge the request EncodeConnectAckPacket(Callsign, ToLinkModule, &Buffer); Send(Buffer, Ip); // create the client and append - g_Refl..GetClients()->AddClient(std::make_shared(Callsign, Ip, ToLinkModule)); - g_Refl..ReleaseClients(); + g_Refl.GetClients()->AddClient(std::make_shared(Callsign, Ip, ToLinkModule)); + g_Refl.ReleaseClients(); } else { @@ -115,7 +114,7 @@ void CDcsProtocol::Task(void) std::cout << "DCS disconnect packet from " << Callsign << " at " << Ip << std::endl; // find client - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dcs); if ( client != nullptr ) { @@ -125,21 +124,21 @@ void CDcsProtocol::Task(void) EncodeConnectNackPacket(Callsign, ' ', &Buffer); Send(Buffer, Ip); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else if ( IsValidKeepAlivePacket(Buffer, &Callsign) ) { //std::cout << "DCS keepalive packet from " << Callsign << " at " << Ip << std::endl; // find all clients with that callsign & ip and keep them alive - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(Callsign, Ip, EProtocol::dcs, it)) != nullptr ) { client->Alive(); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else if ( IsIgnorePacket(Buffer) ) { @@ -193,24 +192,24 @@ void CDcsProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::dcs); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::dcs); if ( client ) { // get client callsign rpt1 = client->GetCallsign(); // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } @@ -253,7 +252,7 @@ void CDcsProtocol::HandleQueue(void) if ( buffer.size() > 0 ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dcs, it)) != nullptr ) @@ -266,7 +265,7 @@ void CDcsProtocol::HandleQueue(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } } @@ -285,7 +284,7 @@ void CDcsProtocol::HandleKeepalives(void) EncodeKeepAlivePacket(&keepalive1); // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dcs, it)) != nullptr ) @@ -318,7 +317,7 @@ void CDcsProtocol::HandleKeepalives(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/reflector/DCSProtocol.h b/reflector/DCSProtocol.h index d064dc1..49bbfbc 100644 --- a/reflector/DCSProtocol.h +++ b/reflector/DCSProtocol.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "Protocol.h" #include "DVHeaderPacket.h" diff --git a/reflector/DExtraClient.cpp b/reflector/DExtraClient.cpp index fc6b008..560ff66 100644 --- a/reflector/DExtraClient.cpp +++ b/reflector/DExtraClient.cpp @@ -16,10 +16,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - #include "DExtraClient.h" - //////////////////////////////////////////////////////////////////////////////////////// // constructors diff --git a/reflector/DExtraClient.h b/reflector/DExtraClient.h index dd6dab1..f91f941 100644 --- a/reflector/DExtraClient.h +++ b/reflector/DExtraClient.h @@ -18,15 +18,9 @@ #pragma once +#include "Defines.h" #include "Client.h" -//////////////////////////////////////////////////////////////////////////////////////// -// define - - -//////////////////////////////////////////////////////////////////////////////////////// -// class - class CDextraClient : public CClient { public: diff --git a/reflector/DExtraPeer.cpp b/reflector/DExtraPeer.cpp deleted file mode 100644 index 1a72a60..0000000 --- a/reflector/DExtraPeer.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// Created by Antony Chazapis (SV9OAN) on 25/2/2018. -// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved. - -// urfd -- The universal reflector -// Copyright © 2021 Thomas A. Early N7TAE -// -// 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 Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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 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 this program. If not, see . - - -#include -#include "Reflector.h" -#include "DExtraPeer.h" -#include "DExtraClient.h" - - -//////////////////////////////////////////////////////////////////////////////////////// -// constructor - - -CDextraPeer::CDextraPeer() -{ -} - -CDextraPeer::CDextraPeer(const CCallsign &callsign, const CIp &ip, const char *modules, const CVersion &version) - : CPeer(callsign, ip, modules, version) -{ - std::cout << "Adding DExtra peer" << std::endl; - - // and construct the DExtra clients - for ( unsigned i = 0; i < ::strlen(modules); i++ ) - { - // create and append to list - m_Clients.push_back(std::make_shared(callsign, ip, modules[i], EProtoRev::ambe)); - } -} - -//////////////////////////////////////////////////////////////////////////////////////// -// status - -bool CDextraPeer::IsAlive(void) const -{ - for ( auto it=cbegin(); it!=cend(); it++ ) - { - if (! (*it)->IsAlive()) - return false; - } - return true; -} - -//////////////////////////////////////////////////////////////////////////////////////// -// revision helper - -int CDextraPeer::GetProtocolRevision(const CVersion &version) -{ - return version.GetMajor(); -} diff --git a/reflector/DExtraPeer.h b/reflector/DExtraPeer.h deleted file mode 100644 index ac6d538..0000000 --- a/reflector/DExtraPeer.h +++ /dev/null @@ -1,42 +0,0 @@ -// Created by Antony Chazapis (SV9OAN) on 25/2/2018. -// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved. - -// urfd -- The universal reflector -// Copyright © 2021 Thomas A. Early N7TAE -// -// 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 Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// 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 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 this program. If not, see . - -#pragma once - -#include "Peer.h" -#include "DExtraClient.h" - -class CDextraPeer : public CPeer -{ -public: - // constructors - CDextraPeer(); - CDextraPeer(const CCallsign &, const CIp &, const char *, const CVersion &); - CDextraPeer(const CDextraPeer &) = delete; - - // status - bool IsAlive(void) const; - - // identity - EProtocol GetProtocol(void) const { return EProtocol::dextra; } - const char *GetProtocolName(void) const { return "DExtra"; } - - // revision helper - static int GetProtocolRevision(const CVersion &); -}; diff --git a/reflector/DExtraProtocol.cpp b/reflector/DExtraProtocol.cpp index 9b47e2b..8a4b046 100644 --- a/reflector/DExtraProtocol.cpp +++ b/reflector/DExtraProtocol.cpp @@ -18,12 +18,11 @@ #include -#include "DExtraPeer.h" + +#include "Global.h" #include "DExtraClient.h" #include "DExtraProtocol.h" -#include "Reflector.h" -#include "GateKeeper.h" - +# //////////////////////////////////////////////////////////////////////////////////////// // operation @@ -36,7 +35,6 @@ bool CDextraProtocol::Initialize(const char *type, const EProtocol ptype, const // update time m_LastKeepaliveTime.start(); - m_LastPeersLinkTime.start(); // done return true; @@ -101,38 +99,15 @@ void CDextraProtocol::Task(void) if ( g_Gate.MayLink(Callsign, Ip, EProtocol::dextra) ) { // valid module ? - if ( g_Refl..IsValidModule(ToLinkModule) ) + if ( g_Refl.IsValidModule(ToLinkModule) ) { - // is this an ack for a link request? - CPeerCallsignList *list = g_Gate.GetPeerList(); - CCallsignListItem *item = list->FindListItem(Callsign); - if ( item != nullptr && Callsign.GetCSModule() == item->GetModules()[1] && ToLinkModule == item->GetModules()[0] ) - { - std::cout << "DExtra ack packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; - - // already connected ? - CPeers *peers = g_Refl..GetPeers(); - if ( peers->FindPeer(Callsign, Ip, EProtocol::dextra) == nullptr ) - { - // create the new peer - // this also create one client per module - // append the peer to reflector peer list - // this also add all new clients to reflector client list - peers->AddPeer(std::make_shared(Callsign, Ip, std::string(1, ToLinkModule).c_str(), CVersion(2, 0, 0))); - } - g_Refl..ReleasePeers(); - } - else - { - // acknowledge the request - EncodeConnectAckPacket(&Buffer, ProtRev); - Send(Buffer, Ip); + // acknowledge the request + EncodeConnectAckPacket(&Buffer, ProtRev); + Send(Buffer, Ip); - // create the client and append - g_Refl..GetClients()->AddClient(std::make_shared(Callsign, Ip, ToLinkModule, ProtRev)); - g_Refl..ReleaseClients(); - } - g_Gate.ReleasePeerList(); + // create the client and append + g_Refl.GetClients()->AddClient(std::make_shared(Callsign, Ip, ToLinkModule, ProtRev)); + g_Refl.ReleaseClients(); } else { @@ -155,7 +130,7 @@ void CDextraProtocol::Task(void) std::cout << "DExtra disconnect packet from " << Callsign << " at " << Ip << std::endl; // find client & remove it - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dextra); if ( client != nullptr ) { @@ -172,21 +147,21 @@ void CDextraProtocol::Task(void) // and remove it clients->RemoveClient(client); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else if ( IsValidKeepAlivePacket(Buffer, &Callsign) ) { //std::cout << "DExtra keepalive packet from " << Callsign << " at " << Ip << std::endl; // find all clients with that callsign & ip and keep them alive - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(Callsign, Ip, EProtocol::dextra, it)) != nullptr ) { client->Alive(); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -211,16 +186,6 @@ void CDextraProtocol::Task(void) // update time m_LastKeepaliveTime.start(); } - - // peer connections - if ( m_LastPeersLinkTime.time() > DEXTRA_RECONNECT_PERIOD ) - { - // handle remote peers connections - HandlePeerLinks(); - - // update time - m_LastPeersLinkTime.start(); - } } //////////////////////////////////////////////////////////////////////////////////////// @@ -239,7 +204,7 @@ void CDextraProtocol::HandleQueue(void) if ( EncodeDvPacket(*packet, buffer) ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dextra, it)) != nullptr ) @@ -255,7 +220,7 @@ void CDextraProtocol::HandleQueue(void) } } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } m_Queue.Unlock(); @@ -273,7 +238,7 @@ void CDextraProtocol::HandleKeepalives(void) EncodeKeepAlivePacket(&keepalive); // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dextra, it)) != nullptr ) @@ -290,7 +255,7 @@ void CDextraProtocol::HandleKeepalives(void) // otherwise check if still with us else if ( !client->IsAlive() ) { - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); std::shared_ptrpeer = peers->FindPeer(client->GetCallsign(), client->GetIp(), EProtocol::dextra); if ( peer != nullptr && peer->GetReflectorModules()[0] == client->GetReflectorModule() ) { @@ -307,14 +272,14 @@ void CDextraProtocol::HandleKeepalives(void) std::cout << "DExtra client " << client->GetCallsign() << " keepalive timeout" << std::endl; clients->RemoveClient(client); } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // iterate on peers - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); auto pit = peers->begin(); std::shared_ptrpeer = nullptr; while ( (peer = peers->FindNextPeer(EProtocol::dextra, pit)) != nullptr ) @@ -327,71 +292,19 @@ void CDextraProtocol::HandleKeepalives(void) // no, disconnect all clients CBuffer disconnect; EncodeDisconnectPacket(&disconnect, peer->GetReflectorModules()[0]); - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); for ( auto cit=peer->cbegin(); cit!=peer->cend(); cit++ ) { Send(disconnect, (*cit)->GetIp()); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // remove it std::cout << "DExtra peer " << peer->GetCallsign() << " keepalive timeout" << std::endl; peers->RemovePeer(peer); } } - g_Refl..ReleasePeers(); -} - -//////////////////////////////////////////////////////////////////////////////////////// -// Peers helpers - -void CDextraProtocol::HandlePeerLinks(void) -{ - CBuffer buffer; - - // get the list of peers - CPeerCallsignList *list = g_Gate.GetPeerList(); - CPeers *peers = g_Refl..GetPeers(); - - // check if all our connected peers are still listed by gatekeeper - // if not, disconnect - auto pit = peers->begin(); - std::shared_ptrpeer = nullptr; - while ( (peer = peers->FindNextPeer(EProtocol::dextra, pit)) != nullptr ) - { - if ( list->FindListItem(peer->GetCallsign()) == nullptr ) - { - // send disconnect packet - EncodeDisconnectPacket(&buffer, peer->GetReflectorModules()[0]); - Send(buffer, peer->GetIp()); - std::cout << "Sending disconnect packet to XRF peer " << peer->GetCallsign() << " at " << peer->GetIp() << std::endl; - // remove client - peers->RemovePeer(peer); - } - } - - // check if all ours peers listed by gatekeeper are connected - // if not, connect or reconnect - for ( auto it=list->begin(); it!=list->end(); it++ ) - { - if ( !it->GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) - continue; - if ( strlen(it->GetModules()) != 2 ) - continue; - if ( peers->FindPeer(it->GetCallsign(), EProtocol::dextra) == nullptr ) - { - // resolve again peer's IP in case it's a dynamic IP - it->ResolveIp(); - // send connect packet to re-initiate peer link - EncodeConnectPacket(&buffer, it->GetModules()); - Send(buffer, it->GetIp(), DEXTRA_PORT); - std::cout << "Sending connect packet to XRF peer " << it->GetCallsign() << " @ " << it->GetIp() << " for module " << it->GetModules()[1] << " (module " << it->GetModules()[0] << ")" << std::endl; - } - } - - // done - g_Refl..ReleasePeers(); - g_Gate.ReleasePeerList(); + g_Refl.ReleasePeers(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -415,7 +328,7 @@ void CDextraProtocol::OnDvHeaderPacketIn(std::unique_ptr &Heade CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::dextra); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::dextra); if ( client ) { // get client callsign @@ -430,18 +343,18 @@ void CDextraProtocol::OnDvHeaderPacketIn(std::unique_ptr &Heade rpt2.SetCSModule(m); } // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } diff --git a/reflector/DExtraProtocol.h b/reflector/DExtraProtocol.h index 69f329d..4434ddd 100644 --- a/reflector/DExtraProtocol.h +++ b/reflector/DExtraProtocol.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "SEProtocol.h" #include "DVHeaderPacket.h" @@ -61,7 +62,6 @@ protected: void HandleQueue(void); // keepalive helpers - void HandlePeerLinks(void); void HandleKeepalives(void); // stream helpers @@ -84,8 +84,6 @@ protected: bool EncodeDvHeaderPacket(const CDvHeaderPacket &, CBuffer &) const; bool EncodeDvFramePacket(const CDvFramePacket &, CBuffer &) const; -protected: // time CTimer m_LastKeepaliveTime; - CTimer m_LastPeersLinkTime; }; diff --git a/reflector/DMRMMDVMClient.h b/reflector/DMRMMDVMClient.h index d3c7cec..31c7fac 100644 --- a/reflector/DMRMMDVMClient.h +++ b/reflector/DMRMMDVMClient.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Client.h" class CDmrmmdvmClient : public CClient diff --git a/reflector/DMRMMDVMProtocol.cpp b/reflector/DMRMMDVMProtocol.cpp index c3f8acd..ec0b60e 100644 --- a/reflector/DMRMMDVMProtocol.cpp +++ b/reflector/DMRMMDVMProtocol.cpp @@ -18,16 +18,15 @@ #include + +#include "Global.h" #include "DMRMMDVMClient.h" #include "DMRMMDVMProtocol.h" -#include "Reflector.h" -#include "GateKeeper.h" #include "BPTC19696.h" #include "RS129.h" #include "Golay2087.h" #include "QR1676.h" - //////////////////////////////////////////////////////////////////////////////////////// // define @@ -49,6 +48,7 @@ static uint8_t g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; bool CDmrmmdvmProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { + m_DefaultId = g_Conf.GetUnsigned(g_Conf.j.mmdvm.defaultid); // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) return false; @@ -93,7 +93,7 @@ void CDmrmmdvmProtocol::Task(void) if ( Receive4(Buffer, Ip, 20) ) #endif { - //Buffer.DebugDump(g_Refl..m_DebugFile); + //Buffer.DebugDump(g_Refl.m_DebugFile); // crack the packet if ( IsValidDvFramePacket(Buffer, Frames) ) { @@ -146,7 +146,7 @@ void CDmrmmdvmProtocol::Task(void) Send(Buffer, Ip); // add client if needed - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Callsign, Ip, EProtocol::dmrmmdvm); // client already connected ? if ( client == nullptr ) @@ -161,7 +161,7 @@ void CDmrmmdvmProtocol::Task(void) client->Alive(); } // and done - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -176,13 +176,13 @@ void CDmrmmdvmProtocol::Task(void) std::cout << "DMRmmdvm disconnect packet from " << Callsign << " at " << Ip << std::endl; // find client & remove it - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dmrmmdvm); if ( client != nullptr ) { clients->RemoveClient(client); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else if ( IsValidConfigPacket(Buffer, &Callsign, Ip) ) { @@ -197,7 +197,7 @@ void CDmrmmdvmProtocol::Task(void) //std::cout << "DMRmmdvm keepalive packet from " << Callsign << " at " << Ip << std::endl; // find all clients with that callsign & ip and keep them alive - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(Callsign, Ip, EProtocol::dmrmmdvm, it)) != nullptr ) @@ -209,7 +209,7 @@ void CDmrmmdvmProtocol::Task(void) // and mark as alive client->Alive(); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else if ( IsValidRssiPacket(Buffer, &Callsign, &iRssi) ) { @@ -273,7 +273,7 @@ void CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Hea CCallsign rpt2(Header->GetRpt2Callsign()); // no stream open yet, open a new one // firstfind this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::dmrmmdvm); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::dmrmmdvm); if ( client ) { // process cmd if any @@ -282,7 +282,7 @@ void CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Hea // not linked yet if ( cmd == CMD_LINK ) { - if ( g_Refl..IsValidModule(rpt2.GetCSModule()) ) + if ( g_Refl.IsValidModule(rpt2.GetCSModule()) ) { std::cout << "DMRmmdvm client " << client->GetCallsign() << " linking on module " << rpt2.GetCSModule() << std::endl; // link @@ -313,10 +313,10 @@ void CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Hea } // and now, re-check module is valid && that it's not a private call - if ( g_Refl..IsValidModule(rpt2.GetCSModule()) && (CallType == DMR_GROUP_CALL) ) + if ( g_Refl.IsValidModule(rpt2.GetCSModule()) && (CallType == DMR_GROUP_CALL) ) { // yes, try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; @@ -330,13 +330,13 @@ void CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Hea } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard if ( lastheard ) { - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } } @@ -403,7 +403,7 @@ void CDmrmmdvmProtocol::HandleQueue(void) if ( buffer.size() > 0 ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dmrmmdvm, it)) != nullptr ) @@ -416,7 +416,7 @@ void CDmrmmdvmProtocol::HandleQueue(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } m_Queue.Unlock(); @@ -432,7 +432,7 @@ void CDmrmmdvmProtocol::HandleKeepalives(void) // and disconnect them if not // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dmrmmdvm, it)) != nullptr ) @@ -456,7 +456,7 @@ void CDmrmmdvmProtocol::HandleKeepalives(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -696,7 +696,7 @@ bool CDmrmmdvmProtocol::IsValidDvFramePacket(const CBuffer &Buffer, std::arraydata()[33]), 7); - //dump.DebugDump(g_Refl..m_DebugFile); + //dump.DebugDump(g_Refl.m_DebugFile); // BER Buffer->Append((uint8_t)0); @@ -982,7 +982,7 @@ char CDmrmmdvmProtocol::DmrDstIdToModule(uint32_t tg) const if (tg > 4000 && tg < 4027) { const char mod = 'A' + (tg - 4001U); - if (strchr(ACTIVE_MODULES, mod)) + if (g_Refl.IsValidModule(mod)) { return mod; } diff --git a/reflector/DMRMMDVMProtocol.h b/reflector/DMRMMDVMProtocol.h index da8086b..17864c7 100644 --- a/reflector/DMRMMDVMProtocol.h +++ b/reflector/DMRMMDVMProtocol.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "Protocol.h" #include "DVHeaderPacket.h" @@ -117,4 +118,7 @@ protected: // for authentication uint32_t m_uiAuthSeed; + + // config data + unsigned m_DefaultId; }; diff --git a/reflector/DMRPlusClient.h b/reflector/DMRPlusClient.h index e0e284c..6cf6868 100644 --- a/reflector/DMRPlusClient.h +++ b/reflector/DMRPlusClient.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Client.h" class CDmrplusClient : public CClient diff --git a/reflector/DMRPlusProtocol.cpp b/reflector/DMRPlusProtocol.cpp index db96a50..224635f 100644 --- a/reflector/DMRPlusProtocol.cpp +++ b/reflector/DMRPlusProtocol.cpp @@ -18,11 +18,10 @@ #include + +#include "Global.h" #include "DMRPlusClient.h" #include "DMRPlusProtocol.h" -#include "Reflector.h" -#include "GateKeeper.h" -#include "DMRIdDir.h" #include "BPTC19696.h" #include "RS129.h" #include "Golay2087.h" @@ -111,7 +110,7 @@ void CDmrplusProtocol::Task(void) Send(Buffer, Ip); // add client if needed - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Callsign, Ip, EProtocol::dmrplus); // client already connected ? if ( client == nullptr ) @@ -126,7 +125,7 @@ void CDmrplusProtocol::Task(void) client->Alive(); } // and done - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -141,13 +140,13 @@ void CDmrplusProtocol::Task(void) std::cout << "DMRplus disconnect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; // find client & remove it - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dmrplus); if ( client != nullptr ) { clients->RemoveClient(client); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -196,21 +195,21 @@ void CDmrplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Head // no stream open yet, open a new one // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::dmrplus); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::dmrplus); if ( client ) { // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } @@ -268,7 +267,7 @@ void CDmrplusProtocol::HandleQueue(void) if ( buffer.size() > 0 ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dmrplus, it)) != nullptr ) @@ -280,10 +279,10 @@ void CDmrplusProtocol::HandleQueue(void) Send(buffer, client->GetIp()); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // debug - //buffer.DebugDump(g_Refl..m_DebugFile); + //buffer.DebugDump(g_Refl.m_DebugFile); } } m_Queue.Unlock(); @@ -294,7 +293,7 @@ void CDmrplusProtocol::SendBufferToClients(const CBuffer &buffer, uint8_t module if ( buffer.size() > 0 ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dmrplus, it)) != nullptr ) @@ -306,10 +305,10 @@ void CDmrplusProtocol::SendBufferToClients(const CBuffer &buffer, uint8_t module Send(buffer, client->GetIp()); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // debug - //buffer.DebugDump(g_Refl..m_DebugFile); + //buffer.DebugDump(g_Refl.m_DebugFile); } } @@ -324,7 +323,7 @@ void CDmrplusProtocol::HandleKeepalives(void) // and disconnect them if not // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dmrplus, it)) != nullptr ) @@ -349,7 +348,7 @@ void CDmrplusProtocol::HandleKeepalives(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -642,7 +641,7 @@ char CDmrplusProtocol::DmrDstIdToModule(uint32_t tg) const // is it a 4xxx ? if (tg > 4000 && tg < 4027) { char mod = 'A' + (tg - 4001U); - if (strchr(ACTIVE_MODULES, mod)) + if (g_Refl.IsValidModule(mod)) { return mod; } diff --git a/reflector/DMRPlusProtocol.h b/reflector/DMRPlusProtocol.h index 83113d9..bf0cca9 100644 --- a/reflector/DMRPlusProtocol.h +++ b/reflector/DMRPlusProtocol.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "Protocol.h" #include "DVHeaderPacket.h" diff --git a/reflector/DPlusClient.h b/reflector/DPlusClient.h index 4c7bb6e..5e68171 100644 --- a/reflector/DPlusClient.h +++ b/reflector/DPlusClient.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Client.h" class CDplusClient : public CClient diff --git a/reflector/DPlusProtocol.cpp b/reflector/DPlusProtocol.cpp index a162229..bf00561 100644 --- a/reflector/DPlusProtocol.cpp +++ b/reflector/DPlusProtocol.cpp @@ -18,11 +18,10 @@ #include + +#include "Global.h" #include "DPlusClient.h" #include "DPlusProtocol.h" -#include "Reflector.h" -#include "GateKeeper.h" - //////////////////////////////////////////////////////////////////////////////////////// // operation @@ -97,8 +96,8 @@ void CDplusProtocol::Task(void) Send(Buffer, Ip); // create the client and append - g_Refl..GetClients()->AddClient(std::make_shared(Callsign, Ip)); - g_Refl..ReleaseClients(); + g_Refl.GetClients()->AddClient(std::make_shared(Callsign, Ip)); + g_Refl.ReleaseClients(); } else { @@ -113,7 +112,7 @@ void CDplusProtocol::Task(void) std::cout << "DPlus disconnect packet from " << Ip << std::endl; // find client - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dplus); if ( client != nullptr ) { @@ -123,21 +122,21 @@ void CDplusProtocol::Task(void) EncodeDisconnectPacket(&Buffer); Send(Buffer, Ip); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else if ( IsValidKeepAlivePacket(Buffer) ) { //std::cout << "DPlus keepalive packet from " << Ip << std::endl; // find all clients with that callsign & ip and keep them alive - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(Ip, EProtocol::dplus, it)) != nullptr ) { client->Alive(); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -185,10 +184,10 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header CCallsign rpt2(Header->GetRpt2Callsign()); // first, check module is valid - if ( g_Refl..IsValidModule(rpt2.GetCSModule()) ) + if ( g_Refl.IsValidModule(rpt2.GetCSModule()) ) { // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::dplus); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::dplus); if ( client ) { // now we know if it's a dextra dongle or a genuine dplus node @@ -204,18 +203,18 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header // get client callsign rpt1 = client->GetCallsign(); // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } else { @@ -253,7 +252,7 @@ void CDplusProtocol::HandleQueue(void) // and push it to all our clients who are not streaming in // note that for dplus protocol, all stream of all modules are push to all clients // it's client who decide which stream he's interrrested in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dplus, it)) != nullptr ) @@ -290,7 +289,7 @@ void CDplusProtocol::HandleQueue(void) } } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } m_Queue.Unlock(); @@ -343,7 +342,7 @@ void CDplusProtocol::HandleKeepalives(void) EncodeKeepAlivePacket(&keepalive); // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::dplus, it)) != nullptr ) @@ -371,7 +370,7 @@ void CDplusProtocol::HandleKeepalives(void) clients->RemoveClient(client); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/reflector/DPlusProtocol.h b/reflector/DPlusProtocol.h index 8b151e5..47a3ff1 100644 --- a/reflector/DPlusProtocol.h +++ b/reflector/DPlusProtocol.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "SEProtocol.h" #include "DVHeaderPacket.h" diff --git a/reflector/DVFramePacket.cpp b/reflector/DVFramePacket.cpp index 86f1d61..3bf7a94 100644 --- a/reflector/DVFramePacket.cpp +++ b/reflector/DVFramePacket.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - +#include #include #include "DVFramePacket.h" diff --git a/reflector/DVHeaderPacket.cpp b/reflector/DVHeaderPacket.cpp index 7bf6082..0e09db0 100644 --- a/reflector/DVHeaderPacket.cpp +++ b/reflector/DVHeaderPacket.cpp @@ -18,10 +18,10 @@ #include -#include -#include "DMRIdDir.h" -#include "DVHeaderPacket.h" +#include +#include "Defines.h" +#include "DVHeaderPacket.h" //////////////////////////////////////////////////////////////////////////////////////// // constructor diff --git a/reflector/Defines.h b/reflector/Defines.h index 690b01f..862451d 100644 --- a/reflector/Defines.h +++ b/reflector/Defines.h @@ -46,25 +46,31 @@ #define DSTAR_IPV4 true #define DMR_IPV4 true #define YSF_IPV4 true -#define BM_IPV4 true +#define XLX_IPV4 true #define M17_IPV4 true +#define P25_IPV4 true +#define NXDN_IPV4 true +#define USRP_IPV4 true #define URF_IPV4 true -#define DSTAR_IPV6 true + +#define DSTAR_IPV6 true // QnetGateway can use IPv6 #define DMR_IPV6 false #define YSF_IPV6 false -#define BM_IPV6 false +#define XLX_IPV6 false #define M17_IPV6 true +#define P25_IPV6 false +#define NXDN_IPV6 false +#define USRP_IPV6 false #define URF_IPV6 true // protocols --------------------------------------------------- -enum class EProtocol { any, none, dextra, dplus, dcs, bm, urf, dmrplus, dmrmmdvm, ysf, m17 }; +enum class EProtocol { any, none, dextra, dplus, dcs, g3, bm, urf, dmrplus, dmrmmdvm, nxdn, p25, usrp, ysf, m17 }; // DExtra #define DEXTRA_KEEPALIVE_PERIOD 3 // in seconds #define DEXTRA_KEEPALIVE_TIMEOUT (DEXTRA_KEEPALIVE_PERIOD*10) // in seconds -#define DEXTRA_RECONNECT_PERIOD 5 // in seconds // DPlus #define DPLUS_KEEPALIVE_PERIOD 1 // in seconds @@ -77,7 +83,7 @@ enum class EProtocol { any, none, dextra, dplus, dcs, bm, urf, dmrplus, dmrmmdvm // XLX, used for BM #define BM_KEEPALIVE_PERIOD 1 // in seconds -#define BM_KEEPALIVE_TIMEOUT (XLX_KEEPALIVE_PERIOD*30) // in seconds +#define BM_KEEPALIVE_TIMEOUT (BM_KEEPALIVE_PERIOD*30) // in seconds #define BM_RECONNECT_PERIOD 5 // in seconds // URF @@ -89,6 +95,7 @@ enum class EProtocol { any, none, dextra, dplus, dcs, bm, urf, dmrplus, dmrmmdvm #define DMRPLUS_KEEPALIVE_PERIOD 1 // in seconds #define DMRPLUS_KEEPALIVE_TIMEOUT (DMRPLUS_KEEPALIVE_PERIOD*10) // in seconds #define DMRPLUS_REFLECTOR_SLOT DMR_SLOT2 +#define DMRPLUS_REFLECTOR_COLOUR 1 // DMRMmdvm #define DMRMMDVM_KEEPALIVE_PERIOD 10 // in seconds @@ -104,6 +111,18 @@ enum class EProtocol { any, none, dextra, dplus, dcs, bm, urf, dmrplus, dmrmmdvm #define M17_KEEPALIVE_PERIOD 3 #define M17_KEEPALIVE_TIMEOUT (M17_KEEPALIVE_PERIOD*10) +// P25 +#define P25_KEEPALIVE_PERIOD 3 // in seconds +#define P25_KEEPALIVE_TIMEOUT (P25_KEEPALIVE_PERIOD*10) // in seconds + +// NXDN +#define NXDN_KEEPALIVE_PERIOD 3 // in seconds +#define NXDN_KEEPALIVE_TIMEOUT (NXDN_KEEPALIVE_PERIOD*10) // in seconds + +// USRP +#define USRP_KEEPALIVE_PERIOD 1 // in seconds +#define USRP_KEEPALIVE_TIMEOUT (USRP_KEEPALIVE_PERIOD*10) // in seconds + // G3 Terminal #define G3_PRESENCE_PORT 12346 // UDP port #define G3_CONFIG_PORT 12345 // UDP port diff --git a/reflector/G3Client.h b/reflector/G3Client.h index d5c313d..07b2454 100644 --- a/reflector/G3Client.h +++ b/reflector/G3Client.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Client.h" class CG3Client : public CClient diff --git a/reflector/G3Protocol.cpp b/reflector/G3Protocol.cpp index 0d5f62c..46bcb0f 100644 --- a/reflector/G3Protocol.cpp +++ b/reflector/G3Protocol.cpp @@ -16,16 +16,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - +#include +#include #include #include + +#include "Global.h" #include "G3Client.h" #include "G3Protocol.h" -#include "Reflector.h" -#include "GateKeeper.h" - -#include -#include //////////////////////////////////////////////////////////////////////////////////////// @@ -34,10 +32,14 @@ bool CG3Protocol::Initialize(const char */*type*/, const EProtocol /*type*/, const uint16_t /*port*/, const bool /*has_ipv4*/, const bool /*has_ipv6*/) // everything is hard coded until ICOM gets their act together and start supporting IPv6 { + //config data + m_TerminalPath.assign(g_Conf.GetString(g_Conf.j.files.terminal)); + const std::string ipv4address(g_Conf.GetString(g_Conf.j.ip.ipv4bind)); + ReadOptions(); // init reflector apparent callsign - m_ReflectorCallsign = g_Refl..GetCallsign(); + m_ReflectorCallsign = g_Refl.GetCallsign(); // reset stop flag keep_running = true; @@ -46,7 +48,7 @@ bool CG3Protocol::Initialize(const char */*type*/, const EProtocol /*type*/, con //m_ReflectorCallsign.PatchCallsign(0, "XLX", 3); // create our sockets - CIp ip(AF_INET, G3_DV_PORT, LISTEN_IPV4); + CIp ip(AF_INET, G3_DV_PORT, ipv4address.c_str()); if ( ip.IsSet() ) { if (! m_Socket4.Open(ip)) @@ -177,7 +179,7 @@ void CG3Protocol::PresenceTask(void) Buffer.Append(m_GwAddress); } - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrextant = nullptr; while ( (extant = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) @@ -219,7 +221,7 @@ void CG3Protocol::PresenceTask(void) clients->AddClient(std::make_shared(Terminal, Ip)); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); m_PresenceSocket.Send(Buffer, ReqIp); } @@ -260,7 +262,7 @@ void CG3Protocol::ConfigTask(void) if (isRepeaterCall) { - if ((Call.HasSameCallsign(GetReflectorCallsign())) && (g_Refl..IsValidModule(Call.GetCSModule()))) + if ((Call.HasSameCallsign(GetReflectorCallsign())) && (g_Refl.IsValidModule(Call.GetCSModule()))) { Buffer.data()[3] = 0x00; // ok } @@ -343,7 +345,7 @@ void CG3Protocol::IcmpTask(void) { if (iIcmpType == ICMP_DEST_UNREACH) { - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) @@ -354,7 +356,7 @@ void CG3Protocol::IcmpTask(void) clients->RemoveClient(client); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } } @@ -378,7 +380,7 @@ void CG3Protocol::Task(void) { CIp ClIp; CIp *BaseIp = nullptr; - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) @@ -394,7 +396,7 @@ void CG3Protocol::Task(void) break; } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); if (BaseIp != nullptr) { @@ -454,7 +456,7 @@ void CG3Protocol::HandleQueue(void) if ( EncodeDvPacket(*packet, buffer) ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) @@ -470,7 +472,7 @@ void CG3Protocol::HandleQueue(void) } } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } m_Queue.Unlock(); @@ -487,7 +489,7 @@ void CG3Protocol::HandleKeepalives(void) CBuffer keepalive((uint8_t *)"PING", 4); // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) @@ -502,7 +504,7 @@ void CG3Protocol::HandleKeepalives(void) Send(keepalive, client->GetIp()); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -527,7 +529,7 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) @@ -554,7 +556,7 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c } else { - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); return; } } @@ -563,19 +565,19 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c rpt1 = client->GetCallsign(); // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } @@ -672,14 +674,14 @@ void CG3Protocol::NeedReload(void) { struct stat fileStat; - if (::stat(TERMINALOPTIONS_PATH, &fileStat) != -1) + if (::stat(m_TerminalPath.c_str(), &fileStat) != -1) { if (m_LastModTime != fileStat.st_mtime) { ReadOptions(); // we have new options - iterate on clients for potential removal - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) @@ -690,7 +692,7 @@ void CG3Protocol::NeedReload(void) clients->RemoveClient(client); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } } @@ -701,7 +703,7 @@ void CG3Protocol::ReadOptions(void) int opts = 0; - std::ifstream file(TERMINALOPTIONS_PATH); + std::ifstream file(m_TerminalPath.c_str()); if (file.is_open()) { m_GwAddress = 0u; @@ -742,12 +744,12 @@ void CG3Protocol::ReadOptions(void) } } } - std::cout << "G3 handler loaded " << opts << " options from file " << TERMINALOPTIONS_PATH << std::endl; + std::cout << "G3 handler loaded " << opts << " options from file " << m_TerminalPath << std::endl; file.close(); struct stat fileStat; - if (::stat(TERMINALOPTIONS_PATH, &fileStat) != -1) + if (::stat(m_TerminalPath.c_str(), &fileStat) != -1) { m_LastModTime = fileStat.st_mtime; } diff --git a/reflector/G3Protocol.h b/reflector/G3Protocol.h index 193e529..d9c6b73 100644 --- a/reflector/G3Protocol.h +++ b/reflector/G3Protocol.h @@ -19,6 +19,8 @@ #pragma once #include + +#include "Defines.h" #include "Timer.h" #include "SEProtocol.h" #include "DVHeaderPacket.h" @@ -117,4 +119,5 @@ protected: uint32_t m_GwAddress; std::string m_Modules; time_t m_LastModTime; + std::string m_TerminalPath; }; diff --git a/reflector/GateKeeper.cpp b/reflector/GateKeeper.cpp index 2e96e04..ce357dd 100644 --- a/reflector/GateKeeper.cpp +++ b/reflector/GateKeeper.cpp @@ -18,7 +18,7 @@ #include "Timer.h" -#include "GateKeeper.h" +#include "Global.h" //////////////////////////////////////////////////////////////////////////////////////// @@ -49,9 +49,9 @@ bool CGateKeeper::Init(void) { // load lists from files - m_NodeWhiteList.LoadFromFile(WHITELIST_PATH); - m_NodeBlackList.LoadFromFile(BLACKLIST_PATH); - m_PeerList.LoadFromFile(INTERLINKLIST_PATH); + m_NodeWhiteList.LoadFromFile(g_Conf.GetString(g_Conf.j.files.white)); + m_NodeBlackList.LoadFromFile(g_Conf.GetString(g_Conf.j.files.black)); + m_PeerList.LoadFromFile(g_Conf.GetString(g_Conf.j.files.interlink)); // reset run flag keep_running = true; diff --git a/reflector/LookupDmr.cpp b/reflector/LookupDmr.cpp index af61349..2e64812 100644 --- a/reflector/LookupDmr.cpp +++ b/reflector/LookupDmr.cpp @@ -21,11 +21,7 @@ #include #include -#include "Reflector.h" -#include "LookupDmr.h" - -extern CReflector g_ref; -extern CConfigure g_cfg; +#include "Global.h" void CLookupDmr::ClearContents() { @@ -35,11 +31,11 @@ void CLookupDmr::ClearContents() void CLookupDmr::LoadParameters() { - g_cfg.GetRefreshType(g_cfg.j.dmriddb.mode, m_Type); - g_cfg.GetUnsigned(g_cfg.j.dmriddb.refreshmin, m_Refresh); - g_cfg.GetString(g_cfg.j.dmriddb.filepath, m_Path); - g_cfg.GetString(g_cfg.j.dmriddb.hostname, m_Host); - g_cfg.GetString(g_cfg.j.dmriddb.suffix, m_Suffix); + m_Type = g_Conf.GetRefreshType(g_Conf.j.dmriddb.mode); + m_Refresh = g_Conf.GetUnsigned(g_Conf.j.dmriddb.refreshmin); + m_Path.assign(g_Conf.GetString(g_Conf.j.dmriddb.filepath)); + m_Host.assign(g_Conf.GetString(g_Conf.j.dmriddb.hostname)); + m_Suffix.assign(g_Conf.GetString(g_Conf.j.dmriddb.suffix)); } uint32_t CLookupDmr::FindDmrid(const CCallsign &callsign) @@ -204,7 +200,7 @@ bool CLookupDmr::HttpGet(const char *hostname, const char *filename, int port, C { // send the GET request char request[DMRID_HTTPGET_SIZEMAX]; - ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_ref.GetCallsign().GetCS().c_str()); + ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Conf.j.names.cs).c_str()); ::write(sock_id, request, strlen(request)); // config receive timeouts diff --git a/reflector/LookupNxdn.cpp b/reflector/LookupNxdn.cpp index 624cdbd..ee0da2a 100644 --- a/reflector/LookupNxdn.cpp +++ b/reflector/LookupNxdn.cpp @@ -21,11 +21,7 @@ #include #include -#include "Reflector.h" -#include "LookupNxdn.h" - -extern CReflector g_ref; -extern CConfigure g_cfg; +#include "Global.h" void CLookupNxdn::ClearContents() { @@ -35,11 +31,11 @@ void CLookupNxdn::ClearContents() void CLookupNxdn::LoadParameters() { - g_cfg.GetRefreshType(g_cfg.j.nxdniddb.mode, m_Type); - g_cfg.GetUnsigned(g_cfg.j.nxdniddb.refreshmin, m_Refresh); - g_cfg.GetString(g_cfg.j.nxdniddb.filepath, m_Path); - g_cfg.GetString(g_cfg.j.dmriddb.hostname, m_Host); - g_cfg.GetString(g_cfg.j.nxdniddb.suffix, m_Suffix); + m_Type = g_Conf.GetRefreshType(g_Conf.j.nxdniddb.mode); + m_Refresh = g_Conf.GetUnsigned(g_Conf.j.nxdniddb.refreshmin); + m_Path.assign(g_Conf.GetString(g_Conf.j.nxdniddb.filepath)); + m_Host.assign(g_Conf.GetString(g_Conf.j.nxdniddb.hostname)); + m_Suffix.assign(g_Conf.GetString(g_Conf.j.nxdniddb.suffix)); } const CCallsign *CLookupNxdn::FindCallsign(uint16_t nxdnid) @@ -206,7 +202,7 @@ bool CLookupNxdn::HttpGet(const char *hostname, const char *filename, int port, { // send the GET request char request[NXDNID_HTTPGET_SIZEMAX]; - ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, (const char *)g_ref.GetCallsign()); + ::sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Conf.j.names.cs).c_str()); ::write(sock_id, request, strlen(request)); // config receive timeouts diff --git a/reflector/LookupYsf.cpp b/reflector/LookupYsf.cpp index 96e556c..7b389e4 100644 --- a/reflector/LookupYsf.cpp +++ b/reflector/LookupYsf.cpp @@ -22,11 +22,7 @@ #include #include -#include "Reflector.h" -#include "LookupYsf.h" - -extern CReflector g_ref; -extern CConfigure g_cfg; +#include "Global.h" void CLookupYsf::ClearContents() { @@ -35,13 +31,13 @@ void CLookupYsf::ClearContents() void CLookupYsf::LoadParameters() { - g_cfg.GetRefreshType(g_cfg.j.ysftxrxdb.mode, m_Type); - g_cfg.GetUnsigned(g_cfg.j.ysftxrxdb.refreshmin, m_Refresh); - g_cfg.GetString(g_cfg.j.ysftxrxdb.filepath, m_Path); - g_cfg.GetString(g_cfg.j.ysftxrxdb.hostname, m_Host); - g_cfg.GetString(g_cfg.j.ysftxrxdb.suffix, m_Suffix); - g_cfg.GetUnsigned(g_cfg.j.ysf.defaulttxfreq, m_DefaultTx); - g_cfg.GetUnsigned(g_cfg.j.ysf.defaultrxfreq, m_DefaultRx); + m_Type = g_Conf.GetRefreshType(g_Conf.j.ysftxrxdb.mode); + m_Refresh = g_Conf.GetUnsigned(g_Conf.j.ysftxrxdb.refreshmin); + m_Path.assign(g_Conf.GetString(g_Conf.j.ysftxrxdb.filepath)); + m_Host.assign(g_Conf.GetString(g_Conf.j.ysftxrxdb.hostname)); + m_Suffix.assign(g_Conf.GetString(g_Conf.j.ysftxrxdb.suffix)); + m_DefaultTx = g_Conf.GetUnsigned(g_Conf.j.ysf.defaulttxfreq); + m_DefaultRx = g_Conf.GetUnsigned(g_Conf.j.ysf.defaultrxfreq); } bool CLookupYsf::LoadContentFile(CBuffer &buffer) @@ -182,7 +178,7 @@ bool CLookupYsf::HttpGet(const char *hostname, const char *filename, int port, C { // send the GET request char request[YSFNODE_HTTPGET_SIZEMAX]; - sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_ref.GetCallsign().GetCS().c_str()); + sprintf(request, "GET /%s HTTP/1.0\r\nFrom: %s\r\nUser-Agent: urfd\r\n\r\n", filename, g_Conf.GetString(g_Conf.j.names.cs).c_str()); write(sock_id, request, strlen(request)); // config receive timeouts diff --git a/reflector/LookupYsf.h b/reflector/LookupYsf.h index 3501309..265511a 100644 --- a/reflector/LookupYsf.h +++ b/reflector/LookupYsf.h @@ -40,4 +40,6 @@ private: CsNodeMap m_map; bool HttpGet(const char *, const char *, int, CBuffer &); + + unsigned m_DefaultTx, m_DefaultRx; }; diff --git a/reflector/M17Client.h b/reflector/M17Client.h index 407090e..2186fa0 100644 --- a/reflector/M17Client.h +++ b/reflector/M17Client.h @@ -16,15 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "Defines.h" #include "Client.h" -//////////////////////////////////////////////////////////////////////////////////////// -// define - - -//////////////////////////////////////////////////////////////////////////////////////// -// class - class CM17Client : public CClient { public: diff --git a/reflector/M17Protocol.cpp b/reflector/M17Protocol.cpp index ce3b1b8..fcbfce9 100644 --- a/reflector/M17Protocol.cpp +++ b/reflector/M17Protocol.cpp @@ -21,8 +21,7 @@ #include "M17Client.h" #include "M17Protocol.h" #include "M17Packet.h" -#include "Reflector.h" -#include "GateKeeper.h" +#include "Global.h" //////////////////////////////////////////////////////////////////////////////////////// // operation @@ -93,17 +92,17 @@ void CM17Protocol::Task(void) std::cout << "M17 connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_Gate.MayLink(Callsign, Ip, EProtocol::m17) && g_Refl..IsValidModule(ToLinkModule) ) + if ( g_Gate.MayLink(Callsign, Ip, EProtocol::m17) && g_Refl.IsValidModule(ToLinkModule) ) { // valid module ? - if ( g_Refl..IsValidModule(ToLinkModule) ) + if ( g_Refl.IsValidModule(ToLinkModule) ) { // acknowledge the request Send("ACKN", Ip); // create the client and append - g_Refl..GetClients()->AddClient(std::make_shared(Callsign, Ip, ToLinkModule)); - g_Refl..ReleaseClients(); + g_Refl.GetClients()->AddClient(std::make_shared(Callsign, Ip, ToLinkModule)); + g_Refl.ReleaseClients(); } else { @@ -125,7 +124,7 @@ void CM17Protocol::Task(void) std::cout << "M17 disconnect packet from " << Callsign << " at " << Ip << std::endl; // find client - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::m17); if ( client != nullptr ) { @@ -134,19 +133,19 @@ void CM17Protocol::Task(void) // and acknowledge the disconnect Send("DISC", Ip); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else if ( IsValidKeepAlivePacket(Buffer, Callsign) ) { // find all clients with that callsign & ip and keep them alive - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(Callsign, Ip, EProtocol::m17, it)) != nullptr ) { client->Alive(); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -196,24 +195,24 @@ void CM17Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::m17); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::m17); if ( client ) { // get client callsign rpt1 = client->GetCallsign(); // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } @@ -249,7 +248,7 @@ void CM17Protocol::HandleQueue(void) EncodeM17Packet(frame, m_StreamsCache[module].m_dvHeader, (CDvFramePacket *)packet.get(), m_StreamsCache[module].m_iSeqCounter); // push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::m17, it)) != nullptr ) @@ -266,7 +265,7 @@ void CM17Protocol::HandleQueue(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } m_StreamsCache[module].m_iSeqCounter++; } @@ -286,7 +285,7 @@ void CM17Protocol::HandleKeepalives(void) EncodeKeepAlivePacket(keepalive); // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::m17, it)) != nullptr ) @@ -312,7 +311,7 @@ void CM17Protocol::HandleKeepalives(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -389,7 +388,7 @@ void CM17Protocol::EncodeKeepAlivePacket(CBuffer &Buffer) { Buffer.resize(10); memcpy(Buffer.data(), "PING", 4); - g_Refl..GetCallsign().CodeOut(Buffer.data() + 4); + g_Refl.GetCallsign().CodeOut(Buffer.data() + 4); } void CM17Protocol::EncodeM17Packet(SM17Frame &frame, const CDvHeaderPacket &Header, const CDvFramePacket *DvFrame, uint32_t iSeq) const diff --git a/reflector/M17Protocol.h b/reflector/M17Protocol.h index 5e9e2c7..61c21ea 100644 --- a/reflector/M17Protocol.h +++ b/reflector/M17Protocol.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "Protocol.h" #include "DVHeaderPacket.h" diff --git a/reflector/Makefile b/reflector/Makefile index ea751fa..8a2a1f8 100644 --- a/reflector/Makefile +++ b/reflector/Makefile @@ -18,55 +18,37 @@ # if you change these locations, make sure the sgs.service file is updated! # you will also break hard coded paths in the dashboard file, index.php. -include configure.mk +EXE = urfd -# if you make changed in these two variable, you'll need to change things -# in the main.h file as well as the systemd service file. -BINDIR = /usr/local/bin -CFGDIR = /usr/local/etc +INICHECK = inicheck -CC = g++ +include configure.mk ifeq ($(debug), true) -CFLAGS = -ggdb3 -W -Werror -Wno-psabi -c -std=c++11 -MMD -MD -c +CFLAGS = -ggdb3 -W -Werror -c -std=c++11 -MMD -MD else -CFLAGS = -c -W -Werror -Wno-psabi -std=c++11 -MMD -MD -c +CFLAGS = -W -Werror -std=c++11 -MMD -MD endif -LDFLAGS=-pthread - -URFSRCS = Buffer.cpp Callsign.cpp CallsignList.cpp CallsignListItem.cpp Client.cpp Clients.cpp DCSClient.cpp DCSProtocol.cpp DExtraClient.cpp DExtraPeer.cpp DExtraProtocol.cpp DPlusClient.cpp DPlusProtocol.cpp DVFramePacket.cpp DVHeaderPacket.cpp GateKeeper.cpp IP.cpp Notification.cpp Packet.cpp PacketStream.cpp PeerCallsignList.cpp Peer.cpp Peers.cpp Protocol.cpp Protocols.cpp Reflector.cpp SEProtocol.cpp UDPSocket.cpp User.cpp Users.cpp Version.cpp Main.cpp BMClient.cpp BMPeer.cpp BMProtocol.cpp BPTC19696.cpp CRC.cpp DMRIdDir.cpp DMRIdDirFile.cpp DMRIdDirHttp.cpp NXDNIdDir.cpp NXDNIdDirFile.cpp NXDNIdDirHttp.cpp DMRMMDVMClient.cpp DMRMMDVMProtocol.cpp DMRPlusClient.cpp DMRPlusProtocol.cpp Golay2087.cpp Golay24128.cpp Hamming.cpp M17Client.cpp M17CRC.cpp M17Packet.cpp M17Client.cpp M17Protocol.cpp NXDNClient.cpp NXDNProtocol.cpp P25Client.cpp P25Protocol.cpp QR1676.cpp RS129.cpp Semaphore.cpp USRPClient.cpp USRPProtocol.cpp Utils.cpp WiresXCmd.cpp WiresXCmdHandler.cpp WiresXInfo.cpp URFClient.cpp URFProtocol.cpp URFPeer.cpp YSFClient.cpp YSFConvolution.cpp YSFFich.cpp YSFNode.cpp YSFNodeDir.cpp YSFNodeDirFile.cpp YSFNodeDirHttp.cpp YSFPayload.cpp YSFProtocol.cpp YSFUtils.cpp - -G3SRCS = G3Client.cpp G3Protocol.cpp RawSocket.cpp UDPMsgSocket.cpp - -SRCS = $(URFSRCS) -ifeq ($(use_g3), true) -SRCS += $(G3SRCS) -endif - -ifeq ($(ysf_db), true) -LDFLAGS += `mysql_config --libs` -endif - -ifdef tc_ip -SRCS += CodecStream.cpp UnixDgramSocket.cpp -endif +LDFLAGS=-pthread -lcurl +SRCS = $(wildcard *.cpp) OBJS = $(SRCS:.cpp=.o) DEPS = $(SRCS:.cpp=.d) -EXE=urfd - -all : $(EXE) +all : $(EXE) $(INICHECK) $(EXE) : $(OBJS) - $(CC) $^ -o $@ $(LDFLAGS) + $(CXX) $^ -o $@ $(LDFLAGS) + +$(INICHECK) : Configure.cpp Configure.h + $(CXX) -DINICHECK $(CFLAGS) $< -o $(INICHECK) -lcurl %.o : %.cpp - g++ $(CFLAGS) $< -o $@ + $(CXX) $(CFLAGS) -c $< -o $@ clean : - $(RM) *.o *.d urfd + $(RM) *.o *.d $(EXE) $(INICHECK) -include $(DEPS) @@ -74,9 +56,7 @@ install : ln -f -s $(shell pwd)/$(EXE).blacklist $(CFGDIR)/$(EXE).blacklist ln -f -s $(shell pwd)/$(EXE).whitelist $(CFGDIR)/$(EXE).whitelist ln -f -s $(shell pwd)/$(EXE).interlink $(CFGDIR)/$(EXE).interlink -ifeq ($(use_g3), true) ln -f -s $(shell pwd)/$(EXE).terminal $(CFGDIR)/$(EXE).terminal -endif cp -f ../systemd/$(EXE).service /etc/systemd/system/ cp -f $(EXE) $(BINDIR) systemctl enable $(EXE).service diff --git a/reflector/NXDNClient.h b/reflector/NXDNClient.h index e75c118..fb809cb 100644 --- a/reflector/NXDNClient.h +++ b/reflector/NXDNClient.h @@ -19,7 +19,9 @@ #pragma once +#include "Defines.h" #include "Client.h" + class CNXDNClient : public CClient { public: diff --git a/reflector/NXDNProtocol.cpp b/reflector/NXDNProtocol.cpp index 8b2fcfc..66f43ce 100644 --- a/reflector/NXDNProtocol.cpp +++ b/reflector/NXDNProtocol.cpp @@ -22,9 +22,8 @@ #include "NXDNClient.h" #include "NXDNProtocol.h" #include "YSFDefines.h" -#include "Reflector.h" -#include "GateKeeper.h" #include "Golay24128.h" +#include "Global.h" const uint8_t NXDN_LICH_RFCT_RDCH = 2U; const uint8_t NXDN_LICH_USC_SACCH_NS = 0U; @@ -53,6 +52,10 @@ CNXDNProtocol::CNXDNProtocol() bool CNXDNProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { + // config value + m_ReflectorId = g_Conf.GetUnsigned(g_Conf.j.nxdn.reflectorid); + m_AutolinkModule = g_Conf.GetAutolinkModule(g_Conf.j.nxdn.autolinkmod); + // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) return false; @@ -119,7 +122,7 @@ void CNXDNProtocol::Task(void) if ( g_Gate.MayLink(Callsign, Ip, EProtocol::nxdn) ) { // add client if needed - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Callsign, Ip, EProtocol::nxdn); // client already connected ? if ( client == nullptr ) @@ -130,9 +133,8 @@ void CNXDNProtocol::Task(void) auto newclient = std::make_shared(Callsign, Ip); // aautolink, if enabled -#if NXDN_AUTOLINK_ENABLE - newclient->SetReflectorModule(NXDN_AUTOLINK_MODULE); -#endif + if (m_AutolinkModule) + newclient->SetReflectorModule(m_AutolinkModule); // and append clients->AddClient(newclient); @@ -145,7 +147,7 @@ void CNXDNProtocol::Task(void) // acknowledge the request -- NXDNReflector simply echoes the packet Send(Buffer, Ip); // and done - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } else if ( IsValidDisconnectPacket(Buffer) ) @@ -153,14 +155,14 @@ void CNXDNProtocol::Task(void) std::cout << "NXDN disconnect packet from " << Ip << std::endl; // find client - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::nxdn); if ( client != nullptr ) { // remove it clients->RemoveClient(client); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -210,7 +212,7 @@ void CNXDNProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::nxdn); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::nxdn); if ( client ) { // get client callsign @@ -221,20 +223,20 @@ void CNXDNProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, rpt2.SetCSModule(m); // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - if ( g_Refl..IsValidModule(rpt2.GetCSModule()) ) + if ( g_Refl.IsValidModule(rpt2.GetCSModule()) ) { - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } } @@ -292,7 +294,7 @@ void CNXDNProtocol::HandleQueue(void) if ( buffer.size() > 0 ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::nxdn, it)) != nullptr ) @@ -305,7 +307,7 @@ void CNXDNProtocol::HandleQueue(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } m_Queue.Unlock(); @@ -321,7 +323,7 @@ void CNXDNProtocol::HandleKeepalives(void) // and disconnect them if not // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::nxdn, it)) != nullptr ) @@ -341,7 +343,7 @@ void CNXDNProtocol::HandleKeepalives(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -479,7 +481,7 @@ bool CNXDNProtocol::EncodeNXDNHeaderPacket(const CDvHeaderPacket &Header, CBuffe { Buffer.resize(43); uint16_t NXDNId = Header.GetMyCallsign().GetNXDNid(); - uint16_t RptrId = NXDN_REFID; + uint16_t RptrId = m_ReflectorId; memcpy(Buffer.data(), "NXDND", 5); Buffer.data()[5U] = (NXDNId >> 8) & 0xFFU; @@ -535,7 +537,7 @@ bool CNXDNProtocol::EncodeNXDNPacket(const CDvHeaderPacket &Header, uint32_t seq uint8_t ambe[28]; Buffer.resize(43); uint16_t NXDNId = Header.GetMyCallsign().GetNXDNid(); - uint16_t RptrId = NXDN_REFID; + uint16_t RptrId = m_ReflectorId; memcpy(Buffer.data(), "NXDND", 5); Buffer.data()[5U] = (NXDNId >> 8) & 0xFFU; diff --git a/reflector/NXDNProtocol.h b/reflector/NXDNProtocol.h index 66c6896..ceb5dd6 100644 --- a/reflector/NXDNProtocol.h +++ b/reflector/NXDNProtocol.h @@ -19,6 +19,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "Protocol.h" #include "DVHeaderPacket.h" @@ -80,10 +81,10 @@ protected: // uiStreamId helpers uint32_t IpToStreamId(const CIp &) const; - + void encode(const unsigned char*, unsigned char*) const; void decode(const unsigned char*, unsigned char*) const; - + uint8_t get_lich_fct(uint8_t); void set_lich_rfct(uint8_t); void set_lich_fct(uint8_t); @@ -121,4 +122,7 @@ protected: uint8_t m_lich; uint8_t m_sacch[5]; uint8_t m_layer3[22]; + + uint16_t m_ReflectorId; + char m_AutolinkModule; }; diff --git a/reflector/NotificationQueue.h b/reflector/NotificationQueue.h index 57839ad..70b894a 100644 --- a/reflector/NotificationQueue.h +++ b/reflector/NotificationQueue.h @@ -32,12 +32,6 @@ class CNotificationQueue { public: - // constructor - CNotificationQueue() {} - - // destructor - ~CNotificationQueue() {} - // lock void Lock() { m_Mutex.lock(); } void Unlock() { m_Mutex.unlock(); } diff --git a/reflector/P25Client.h b/reflector/P25Client.h index 7532a92..aafce95 100644 --- a/reflector/P25Client.h +++ b/reflector/P25Client.h @@ -18,8 +18,9 @@ // along with this program. If not, see . #pragma once - +#include "Defines.h" #include "Client.h" + class CP25Client : public CClient { public: diff --git a/reflector/P25Protocol.cpp b/reflector/P25Protocol.cpp index e50e007..38f86b6 100644 --- a/reflector/P25Protocol.cpp +++ b/reflector/P25Protocol.cpp @@ -22,8 +22,7 @@ #include "P25Client.h" #include "P25Protocol.h" -#include "Reflector.h" -#include "GateKeeper.h" +#include "Global.h" const uint8_t REC62[] = {0x62U, 0x02U, 0x02U, 0x0CU, 0x0BU, 0x12U, 0x64U, 0x00U, 0x00U, 0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U,0x00U, 0x00U, 0x00U, 0x00U, 0x00U}; const uint8_t REC63[] = {0x63U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x02U}; @@ -50,6 +49,11 @@ const uint8_t REC80[] = {0x80U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, bool CP25Protocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { + // config data + m_ReflectorId = g_Conf.GetUnsigned(g_Conf.j.p25.reflectorid); + m_DefaultId = g_Conf.GetUnsigned(g_Conf.j.mmdvm.defaultid); + m_AutolinkModule = g_Conf.GetAutolinkModule(g_Conf.j.p25.autolinkmod); + m_uiStreamId = 0; // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) @@ -107,7 +111,7 @@ void CP25Protocol::Task(void) if ( g_Gate.MayLink(Callsign, Ip, EProtocol::p25) ) { // add client if needed - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Callsign, Ip, EProtocol::p25); // client already connected ? if ( client == nullptr ) @@ -118,9 +122,8 @@ void CP25Protocol::Task(void) auto newclient = std::make_shared(Callsign, Ip); // aautolink, if enabled -#if P25_AUTOLINK_ENABLE - newclient->SetReflectorModule(P25_AUTOLINK_MODULE); -#endif + if (m_AutolinkModule) + newclient->SetReflectorModule(m_AutolinkModule); // and append clients->AddClient(newclient); @@ -133,7 +136,7 @@ void CP25Protocol::Task(void) // acknowledge the request -- P25Reflector simply echoes the packet Send(Buffer, Ip); // and done - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } else if ( IsValidDisconnectPacket(Buffer, &Callsign) ) @@ -141,14 +144,14 @@ void CP25Protocol::Task(void) std::cout << "P25 disconnect packet from " << Callsign << " at " << Ip << std::endl; // find client - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::p25); if ( client != nullptr ) { // remove it clients->RemoveClient(client); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -197,7 +200,7 @@ void CP25Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::p25); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::p25); if ( client ) { // get client callsign @@ -206,18 +209,18 @@ void CP25Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, Header->SetRpt2Module(m); rpt2.SetCSModule(m); // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } @@ -256,7 +259,7 @@ void CP25Protocol::HandleQueue(void) if ( buffer.size() > 0 ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::p25, it)) != nullptr ) @@ -269,7 +272,7 @@ void CP25Protocol::HandleQueue(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } } @@ -387,10 +390,9 @@ bool CP25Protocol::IsValidDvHeaderPacket(const CIp &Ip, const CBuffer &Buffer, s void CP25Protocol::EncodeP25Packet(const CDvHeaderPacket &Header, const CDvFramePacket &DvFrame, uint32_t iSeq, CBuffer &Buffer, bool islast) const { uint32_t uiSrcId = Header.GetMyCallsign().GetDmrid(); - uint32_t uiRptrId = P25_REFID; if(uiSrcId == 0){ - uiSrcId = DMRMMDVM_DEFAULTID; + uiSrcId = m_DefaultId; } if(islast) @@ -420,9 +422,9 @@ void CP25Protocol::EncodeP25Packet(const CDvHeaderPacket &Header, const CDvFrame Buffer.resize(17); ::memcpy(Buffer.data(), REC65, 17U); ::memcpy(Buffer.data() + 5U, DvFrame.GetCodecData(ECodecType::p25), 11U); - Buffer.data()[1U] = (uiRptrId >> 16) & 0xFFU; - Buffer.data()[2U] = (uiRptrId >> 8) & 0xFFU; - Buffer.data()[3U] = (uiRptrId >> 0) & 0xFFU; + Buffer.data()[1U] = (m_ReflectorId >> 16) & 0xFFU; + Buffer.data()[2U] = (m_ReflectorId >> 8) & 0xFFU; + Buffer.data()[3U] = (m_ReflectorId >> 0) & 0xFFU; break; case 0x04U: Buffer.resize(17); @@ -506,7 +508,7 @@ void CP25Protocol::EncodeP25Packet(const CDvHeaderPacket &Header, const CDvFrame void CP25Protocol::HandleKeepalives(void) { // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::p25, it)) != nullptr ) @@ -526,5 +528,5 @@ void CP25Protocol::HandleKeepalives(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } diff --git a/reflector/P25Protocol.h b/reflector/P25Protocol.h index 38f7a36..7829fe9 100644 --- a/reflector/P25Protocol.h +++ b/reflector/P25Protocol.h @@ -19,6 +19,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "Protocol.h" #include "DVHeaderPacket.h" @@ -53,7 +54,7 @@ protected: // queue helper void HandleQueue(void); void HandleKeepalives(void); - + // stream helpers void OnDvHeaderPacketIn(std::unique_ptr &, const CIp &); @@ -72,4 +73,9 @@ protected: // for queue header caches std::unordered_map m_StreamsCache; uint32_t m_uiStreamId; + + // config data + uint32_t m_ReflectorId; + uint32_t m_DefaultId; + char m_AutolinkModule; }; diff --git a/reflector/Packet.cpp b/reflector/Packet.cpp index c77208b..ed4d3a1 100644 --- a/reflector/Packet.cpp +++ b/reflector/Packet.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - +#include #include "Packet.h" // default constructor diff --git a/reflector/PacketQueue.h b/reflector/PacketQueue.h index 8851cd5..e53881c 100644 --- a/reflector/PacketQueue.h +++ b/reflector/PacketQueue.h @@ -18,6 +18,8 @@ #pragma once +#include +#include #include "Packet.h" class CClient; diff --git a/reflector/PacketStream.cpp b/reflector/PacketStream.cpp index 7253218..a5df4a8 100644 --- a/reflector/PacketStream.cpp +++ b/reflector/PacketStream.cpp @@ -60,7 +60,8 @@ bool CPacketStream::OpenPacketStream(const CDvHeaderPacket &DvHeader, std::share m_LastPacketTime.start(); return true; } - + if (m_CodecStream) + m_CodecStream->ResetStats(m_uiStreamId, m_DvHeader.GetCodecIn()); return false; } @@ -71,7 +72,7 @@ void CPacketStream::ClosePacketStream(void) m_uiStreamId = 0; m_OwnerClient.reset(); if (m_CodecStream) - m_CodecStream.reset(); + m_CodecStream->ReportStats(); } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/reflector/PeerCallsignList.cpp b/reflector/PeerCallsignList.cpp index af07d5d..5729d0a 100644 --- a/reflector/PeerCallsignList.cpp +++ b/reflector/PeerCallsignList.cpp @@ -16,11 +16,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include #include #include "PeerCallsignList.h" -bool CPeerCallsignList::LoadFromFile(const char *filename) +bool CPeerCallsignList::LoadFromFile(const std::string &filename) { bool ok = false; char sz[256]; diff --git a/reflector/PeerCallsignList.h b/reflector/PeerCallsignList.h index 8ef827e..b4cd2b9 100644 --- a/reflector/PeerCallsignList.h +++ b/reflector/PeerCallsignList.h @@ -34,5 +34,5 @@ public: virtual ~CPeerCallsignList() {} // file io - bool LoadFromFile(const char *); + bool LoadFromFile(const std::string &filename); }; diff --git a/reflector/Peers.cpp b/reflector/Peers.cpp index a371c8f..df3497b 100644 --- a/reflector/Peers.cpp +++ b/reflector/Peers.cpp @@ -16,11 +16,9 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - -#include "Reflector.h" +#include "Global.h" #include "Peers.h" - //////////////////////////////////////////////////////////////////////////////////////// // constructor @@ -60,15 +58,15 @@ void CPeers::AddPeer(std::shared_ptr peer) std::cout << "New peer " << peer->GetCallsign() << " at " << peer->GetIp() << " added with protocol " << peer->GetProtocolName() << 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_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); for ( auto cit=peer->cbegin(); cit!=peer->cend(); cit++ ) { clients->AddClient(*cit); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // notify - g_Refl..OnPeersChanged(); + g_Refl.OnPeersChanged(); } void CPeers::RemovePeer(std::shared_ptr peer) @@ -81,7 +79,7 @@ void CPeers::RemovePeer(std::shared_ptr peer) { // remove all clients from reflector client list // it is double lock safe to lock Clients list after Peers list - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); for ( auto cit=peer->begin(); cit!=peer->end(); cit++ ) { // this also delete the client object @@ -89,13 +87,13 @@ void CPeers::RemovePeer(std::shared_ptr peer) } // so clear it then (*pit)->ClearClients(); - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // remove it std::cout << "Peer " << (*pit)->GetCallsign() << " at " << (*pit)->GetIp() << " removed" << std::endl; pit = m_Peers.erase(pit); // notify - g_Refl..OnPeersChanged(); + g_Refl.OnPeersChanged(); } else { diff --git a/reflector/Protocol.cpp b/reflector/Protocol.cpp index 817f5b5..7792901 100644 --- a/reflector/Protocol.cpp +++ b/reflector/Protocol.cpp @@ -16,11 +16,10 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - +#include "Defines.h" +#include "Global.h" #include "Protocol.h" #include "Clients.h" -#include "Reflector.h" - //////////////////////////////////////////////////////////////////////////////////////// // constructor @@ -51,8 +50,9 @@ CProtocol::~CProtocol() bool CProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { + m_Port = port; // init reflector apparent callsign - m_ReflectorCallsign = g_Refl..GetCallsign(); + m_ReflectorCallsign = g_Refl.GetCallsign(); // reset stop flag keep_running = true; @@ -62,10 +62,10 @@ bool CProtocol::Initialize(const char *type, const EProtocol ptype, const uint16 m_ReflectorCallsign.PatchCallsign(0, type, 3); // create our sockets -#ifdef LISTEN_IPV4 if (has_ipv4) { - CIp ip4(AF_INET, port, LISTEN_IPV4); + const std::string ipv4binding(g_Conf.GetString(g_Conf.j.ip.ipv4bind)); + CIp ip4(AF_INET, port, ipv4binding.c_str()); if ( ip4.IsSet() ) { if (! m_Socket4.Open(ip4)) @@ -73,25 +73,27 @@ bool CProtocol::Initialize(const char *type, const EProtocol ptype, const uint16 } std::cout << "Listening on " << ip4 << std::endl; } -#endif -#ifdef LISTEN_IPV6 - if (has_ipv6) + if (g_Conf.IsString(g_Conf.j.ip.ipv6bind)) { - CIp ip6(AF_INET6, port, LISTEN_IPV6); - if ( ip6.IsSet() ) + if (has_ipv6) { - if (! m_Socket6.Open(ip6)) + const std::string ipv6binding(g_Conf.j.ip.ipv6bind); + CIp ip6(AF_INET6, port, ipv6binding.c_str()); + if ( ip6.IsSet() ) { - m_Socket4.Close(); - return false; + if (! m_Socket6.Open(ip6)) + { + m_Socket4.Close(); + return false; + } + std::cout << "Listening on " << ip6 << std::endl; } - std::cout << "Listening on " << ip6 << std::endl; } } -#endif - try { + try + { m_Future = std::async(std::launch::async, &CProtocol::Thread, this); } catch (const std::exception &e) @@ -179,7 +181,7 @@ void CProtocol::CheckStreamsTimeout(void) { // yes, close it it->second->Unlock(); - g_Refl..CloseStream(it->second); + g_Refl.CloseStream(it->second); // and remove it from the m_Streams map it = m_Streams.erase(it); } diff --git a/reflector/Protocol.h b/reflector/Protocol.h index 6d0c37c..799ca76 100644 --- a/reflector/Protocol.h +++ b/reflector/Protocol.h @@ -132,10 +132,8 @@ protected: // identity CCallsign m_ReflectorCallsign; + // data + uint8_t m_Port; // debug CTimer m_DebugTimer; - -#ifdef DEBUG - void Dump(const char *title, const uint8_t *pointer, int length); -#endif }; diff --git a/reflector/Protocols.cpp b/reflector/Protocols.cpp index 6dec2ff..b52c801 100644 --- a/reflector/Protocols.cpp +++ b/reflector/Protocols.cpp @@ -29,10 +29,9 @@ #include "P25Protocol.h" #include "NXDNProtocol.h" #include "USRPProtocol.h" -#ifndef NO_G3 #include "G3Protocol.h" -#endif #include "Protocols.h" +#include "Global.h" //////////////////////////////////////////////////////////////////////////////////////// // destructor @@ -50,58 +49,56 @@ bool CProtocols::Init(void) m_Mutex.lock(); { m_Protocols.emplace_back(std::unique_ptr(new CDextraProtocol)); - if (! m_Protocols.back()->Initialize("XRF", EProtocol::dextra, DEXTRA_PORT, DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("XRF", EProtocol::dextra, uint16_t(g_Conf.GetUnsigned(g_Conf.j.dextra.port)), DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDplusProtocol)); - if (! m_Protocols.back()->Initialize("REF", EProtocol::dplus, DPLUS_PORT, DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("REF", EProtocol::dplus, uint16_t(g_Conf.GetUnsigned(g_Conf.j.dplus.port)), DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDcsProtocol)); - if (! m_Protocols.back()->Initialize("DCS", EProtocol::dcs, DCS_PORT, DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("DCS", EProtocol::dcs, uint16_t(g_Conf.GetUnsigned(g_Conf.j.dcs.port)), DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDmrmmdvmProtocol)); - if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrmmdvm, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrmmdvm, uint16_t(g_Conf.GetUnsigned(g_Conf.j.mmdvm.port)), DMR_IPV4, DMR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CBMProtocol)); - if (! m_Protocols.back()->Initialize("XLX", EProtocol::bm, XLX_PORT, DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize("XLX", EProtocol::bm, uint16_t(g_Conf.GetUnsigned(g_Conf.j.bm.port)), DMR_IPV4, DMR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDmrplusProtocol)); - if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrplus, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrplus, uint16_t(g_Conf.GetUnsigned(g_Conf.j.dmrplus.port)), DMR_IPV4, DMR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CYsfProtocol)); - if (! m_Protocols.back()->Initialize("YSF", EProtocol::ysf, YSF_PORT, YSF_IPV4, YSF_IPV6)) + if (! m_Protocols.back()->Initialize("YSF", EProtocol::ysf, uint16_t(g_Conf.GetUnsigned(g_Conf.j.ysf.port)), YSF_IPV4, YSF_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CM17Protocol)); - if (! m_Protocols.back()->Initialize("URF", EProtocol::m17, M17_PORT, M17_IPV4, M17_IPV6)) + if (! m_Protocols.back()->Initialize("URF", EProtocol::m17, uint16_t(g_Conf.GetUnsigned(g_Conf.j.m17.port)), M17_IPV4, M17_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CP25Protocol)); - if (! m_Protocols.back()->Initialize("P25", EProtocol::p25, P25_PORT, P25_IPV4, P25_IPV6)) + if (! m_Protocols.back()->Initialize("P25", EProtocol::p25, uint16_t(g_Conf.GetUnsigned(g_Conf.j.p25.port)), P25_IPV4, P25_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CNXDNProtocol)); - if (! m_Protocols.back()->Initialize("NXDN", EProtocol::nxdn, NXDN_PORT, NXDN_IPV4, NXDN_IPV6)) + if (! m_Protocols.back()->Initialize("NXDN", EProtocol::nxdn, uint16_t(g_Conf.GetUnsigned(g_Conf.j.nxdn.port)), NXDN_IPV4, NXDN_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CUSRPProtocol)); - if (! m_Protocols.back()->Initialize("USRP", EProtocol::usrp, USRP_PORT, USRP_IPV4, USRP_IPV6)) + if (! m_Protocols.back()->Initialize("USRP", EProtocol::usrp, uint16_t(g_Conf.GetUnsigned(g_Conf.j.usrp.port)), USRP_IPV4, USRP_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CURFProtocol)); - if (! m_Protocols.back()->Initialize("URF", EProtocol::urf, URF_PORT, URF_IPV4, URF_IPV6)) + if (! m_Protocols.back()->Initialize("URF", EProtocol::urf, uint16_t(g_Conf.GetUnsigned(g_Conf.j.urf.port)), URF_IPV4, URF_IPV6)) return false; -#ifndef NO_G3 m_Protocols.emplace_back(std::unique_ptr(new CG3Protocol)); if (! m_Protocols.back()->Initialize("XLX", EProtocol::g3, G3_DV_PORT, DMR_IPV4, DMR_IPV6)) return false; -#endif } m_Mutex.unlock(); diff --git a/reflector/Semaphore.h b/reflector/Semaphore.h index f3e324f..e8f8dcf 100644 --- a/reflector/Semaphore.h +++ b/reflector/Semaphore.h @@ -18,7 +18,8 @@ #pragma once - +#include +#include class CSemaphore { @@ -39,6 +40,6 @@ protected: // data std::mutex m_Mutex; std::condition_variable m_Condition; - size_t m_Count; + std::size_t m_Count; }; diff --git a/reflector/URFClient.h b/reflector/URFClient.h index d0a2a9b..5f43145 100644 --- a/reflector/URFClient.h +++ b/reflector/URFClient.h @@ -18,6 +18,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "Defines.h" #include "Client.h" class CURFClient : public CClient diff --git a/reflector/URFProtocol.cpp b/reflector/URFProtocol.cpp index f3fda2e..ce7cbaf 100644 --- a/reflector/URFProtocol.cpp +++ b/reflector/URFProtocol.cpp @@ -22,7 +22,7 @@ #include "URFProtocol.h" #include "Reflector.h" #include "GateKeeper.h" - +#include "Global.h" //////////////////////////////////////////////////////////////////////////////////////// // operation @@ -73,14 +73,14 @@ void CURFProtocol::Task(void) else if ( IsValidKeepAlivePacket(Buffer, &Callsign) ) { // find peer - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); std::shared_ptrpeer = peers->FindPeer(Ip, EProtocol::urf); if ( peer != nullptr ) { // keep it alive peer->Alive(); } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } else if ( IsValidDvHeaderPacket(Buffer, Header) ) { @@ -126,7 +126,7 @@ void CURFProtocol::Task(void) if ( g_Gate.MayLink(Callsign, Ip, EProtocol::urf, Modules) ) { // already connected ? - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); if ( peers->FindPeer(Callsign, Ip, EProtocol::urf) == nullptr ) { // create the new peer @@ -137,7 +137,7 @@ void CURFProtocol::Task(void) // this also add all new clients to reflector client list peers->AddPeer(peer); } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } } else if ( IsValidDisconnectPacket(Buffer, &Callsign) ) @@ -145,7 +145,7 @@ void CURFProtocol::Task(void) std::cout << "URF disconnect packet from " << Callsign << " at " << Ip << std::endl; // find peer - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); std::shared_ptrpeer = peers->FindPeer(Ip, EProtocol::urf); if ( peer != nullptr ) { @@ -154,7 +154,7 @@ void CURFProtocol::Task(void) // and delete them peers->RemovePeer(peer); } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } else if ( IsValidNackPacket(Buffer, &Callsign) ) { @@ -216,7 +216,7 @@ void CURFProtocol::HandleQueue(void) if ( EncodeDvPacket(*packet, buffer) ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::urf, it)) != nullptr ) @@ -232,7 +232,7 @@ void CURFProtocol::HandleQueue(void) } } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } } @@ -251,7 +251,7 @@ void CURFProtocol::HandleKeepalives(void) EncodeKeepAlivePacket(&keepalive); // iterate on peers - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); auto pit = peers->begin(); std::shared_ptrpeer = nullptr; while ( (peer = peers->FindNextPeer(EProtocol::urf, pit)) != nullptr ) @@ -278,7 +278,7 @@ void CURFProtocol::HandleKeepalives(void) peers->RemovePeer(peer); } } - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -290,7 +290,7 @@ void CURFProtocol::HandlePeerLinks(void) // get the list of peers CPeerCallsignList *list = g_Gate.GetPeerList(); - CPeers *peers = g_Refl..GetPeers(); + CPeers *peers = g_Refl.GetPeers(); // check if all our connected peers are still listed by gatekeeper // if not, disconnect @@ -324,13 +324,13 @@ void CURFProtocol::HandlePeerLinks(void) it->ResolveIp(); // send connect packet to re-initiate peer link EncodeConnectPacket(&buffer, it->GetModules()); - Send(buffer, it->GetIp(), URF_PORT); + Send(buffer, it->GetIp(), m_Port); std::cout << "Sending connect packet to URF peer " << cs << " @ " << it->GetIp() << " for modules " << it->GetModules() << std::endl; } } // done - g_Refl..ReleasePeers(); + g_Refl.ReleasePeers(); g_Gate.ReleasePeerList(); } @@ -363,11 +363,11 @@ void CURFProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // no stream open yet, open a new one // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::urf, Header->GetRpt2Module()); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::urf, Header->GetRpt2Module()); if ( client ) { // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; @@ -376,10 +376,10 @@ void CURFProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, peer = client->GetCallsign(); } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2, peer); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2, peer); + g_Refl.ReleaseUsers(); } } @@ -420,7 +420,7 @@ bool CURFProtocol::IsValidConnectPacket(const CBuffer &Buffer, CCallsign *callsi memcpy(modules, Buffer.data()+10, 27); for ( unsigned i = 0; i < strlen(modules); i++ ) { - valid &= (nullptr != strchr(ACTIVE_MODULES, modules[i])); + valid = valid && (g_Refl.IsValidModule (modules[i])); } } return valid; @@ -450,7 +450,7 @@ bool CURFProtocol::IsValidAckPacket(const CBuffer &Buffer, CCallsign *callsign, memcpy(modules, Buffer.data()+10, 27); for ( unsigned i = 0; i < strlen(modules); i++ ) { - valid &= (nullptr != strchr(ACTIVE_MODULES, modules[i])); + valid = valid && (g_Refl.IsValidModule(modules[i])); } } return valid; @@ -521,7 +521,7 @@ void CURFProtocol::EncodeKeepAlivePacket(CBuffer *Buffer) { Buffer->Set("PING"); Buffer->resize(10); - g_Refl..GetCallsign().CodeOut(Buffer->data()+4); + g_Refl.GetCallsign().CodeOut(Buffer->data()+4); } void CURFProtocol::EncodeConnectPacket(CBuffer *Buffer, const char *Modules) @@ -530,12 +530,12 @@ void CURFProtocol::EncodeConnectPacket(CBuffer *Buffer, const char *Modules) Buffer->Set("CONN"); // our callsign Buffer->resize(37); - g_Refl..GetCallsign().CodeOut(Buffer->data()+4); + g_Refl.GetCallsign().CodeOut(Buffer->data()+4); // our version Buffer->ReplaceAt(10, (uint8_t *)Modules, strlen(Modules)); - Buffer->Append((uint8_t)VERSION_MAJOR); - Buffer->Append((uint8_t)VERSION_MINOR); - Buffer->Append((uint8_t)VERSION_REVISION); + Buffer->Append((uint8_t)g_Vers.GetMajor()); + Buffer->Append((uint8_t)g_Vers.GetMinor()); + Buffer->Append((uint8_t)g_Vers.GetRevision()); } void CURFProtocol::EncodeDisconnectPacket(CBuffer *Buffer) @@ -543,7 +543,7 @@ void CURFProtocol::EncodeDisconnectPacket(CBuffer *Buffer) Buffer->Set("DISC"); // our callsign Buffer->resize(10); - g_Refl..GetCallsign().CodeOut(Buffer->data()+4); + g_Refl.GetCallsign().CodeOut(Buffer->data()+4); } void CURFProtocol::EncodeConnectAckPacket(CBuffer *Buffer, const char *Modules) @@ -551,18 +551,18 @@ void CURFProtocol::EncodeConnectAckPacket(CBuffer *Buffer, const char *Modules) Buffer->Set("ACKN"); // our callsign Buffer->resize(37); - g_Refl..GetCallsign().CodeOut(Buffer->data()+4); + g_Refl.GetCallsign().CodeOut(Buffer->data()+4); // the shared modules Buffer->ReplaceAt(10, (uint8_t *)Modules, strlen(Modules)); // our version - Buffer->Append((uint8_t)VERSION_MAJOR); - Buffer->Append((uint8_t)VERSION_MINOR); - Buffer->Append((uint8_t)VERSION_REVISION); + Buffer->Append((uint8_t)g_Vers.GetMajor()); + Buffer->Append((uint8_t)g_Vers.GetMinor()); + Buffer->Append((uint8_t)g_Vers.GetRevision()); } void CURFProtocol::EncodeConnectNackPacket(CBuffer *Buffer) { Buffer->Set("NACK"); Buffer->resize(10); - g_Refl..GetCallsign().CodeOut(Buffer->data()+4); + g_Refl.GetCallsign().CodeOut(Buffer->data()+4); } diff --git a/reflector/URFProtocol.h b/reflector/URFProtocol.h index 5418a0e..482d8e6 100644 --- a/reflector/URFProtocol.h +++ b/reflector/URFProtocol.h @@ -18,6 +18,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "Defines.h" #include "Version.h" #include "Timer.h" #include "SEProtocol.h" diff --git a/reflector/USRPClient.h b/reflector/USRPClient.h index 2157d2b..bb5e307 100644 --- a/reflector/USRPClient.h +++ b/reflector/USRPClient.h @@ -19,7 +19,9 @@ #pragma once +#include "Defines.h" #include "Client.h" + class CUSRPClient : public CClient { public: diff --git a/reflector/USRPProtocol.cpp b/reflector/USRPProtocol.cpp index 076d7ff..9a559fb 100644 --- a/reflector/USRPProtocol.cpp +++ b/reflector/USRPProtocol.cpp @@ -22,8 +22,7 @@ #include "USRPClient.h" #include "USRPProtocol.h" -#include "Reflector.h" -#include "GateKeeper.h" +#include "Global.h" const uint8_t USRP_TYPE_VOICE = 0; const uint8_t USRP_TYPE_TEXT = 2; @@ -38,10 +37,13 @@ const uint8_t TLV_TAG_SET_INFO = 8; bool CUSRPProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { + // config data + m_DefaultCallsign.assign(g_Conf.GetString(g_Conf.j.usrp.defaultcallsign)); + m_AutolinkModule = g_Conf.GetAutolinkModule(g_Conf.j.usrp.autolinkmod); CBuffer buffer; m_uiStreamId = 0; - CCallsign cs(USRP_DEFAULT_CALLSIGN); - CClients *clients = g_Refl..GetClients(); + CCallsign cs(m_DefaultCallsign.c_str()); + CClients *clients = g_Refl.GetClients(); std::ifstream file; std::streampos size; @@ -49,7 +51,7 @@ bool CUSRPProtocol::Initialize(const char *type, const EProtocol ptype, const ui if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) return false; - file.open(USRPCLIENTS_PATH, std::ios::in | std::ios::binary | std::ios::ate); + file.open(g_Conf.GetString(g_Conf.j.usrp.clientfilepath), std::ios::in | std::ios::binary | std::ios::ate); if ( file.is_open() ) { // read file @@ -83,9 +85,9 @@ bool CUSRPProtocol::Initialize(const char *type, const EProtocol ptype, const ui uint32_t ui = atoi(port); CIp Ip(AF_INET, ui, ip); auto newclient = std::make_shared(cs, Ip); -#if USRP_AUTOLINK_ENABLE - newclient->SetReflectorModule(USRP_AUTOLINK_MODULE); -#endif + if (m_AutolinkModule) + newclient->SetReflectorModule(m_AutolinkModule); + clients->AddClient(newclient); } } @@ -93,7 +95,7 @@ bool CUSRPProtocol::Initialize(const char *type, const EProtocol ptype, const ui } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update time m_LastKeepaliveTime.start(); @@ -192,7 +194,7 @@ void CUSRPProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::usrp); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::usrp); if ( client ) { // get client callsign @@ -201,18 +203,18 @@ void CUSRPProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, Header->SetRpt2Module(m); rpt2.SetCSModule(m); // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } @@ -249,7 +251,7 @@ void CUSRPProtocol::HandleQueue(void) if ( buffer.size() > 0 ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::usrp, it)) != nullptr ) @@ -261,7 +263,7 @@ void CUSRPProtocol::HandleQueue(void) Send(buffer, client->GetIp()); } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } m_Queue.Unlock(); @@ -279,8 +281,8 @@ bool CUSRPProtocol::IsValidDvPacket(const CIp &Ip, const CBuffer &Buffer, std::u if ( !stream ) { m_uiStreamId = static_cast(::rand()); - CCallsign csMY = CCallsign(USRP_DEFAULT_CALLSIGN); - CCallsign rpt1 = CCallsign(USRP_DEFAULT_CALLSIGN); + CCallsign csMY = CCallsign(m_DefaultCallsign.c_str()); + CCallsign rpt1 = CCallsign(m_DefaultCallsign.c_str()); CCallsign rpt2 = m_ReflectorCallsign; rpt1.SetCSModule(USRP_MODULE_ID); rpt2.SetCSModule(' '); @@ -375,7 +377,7 @@ void CUSRPProtocol::EncodeUSRPPacket(const CDvHeaderPacket &Header, const CDvFra void CUSRPProtocol::HandleKeepalives(void) { // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::usrp, it)) != nullptr ) @@ -395,5 +397,5 @@ void CUSRPProtocol::HandleKeepalives(void) //} } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } diff --git a/reflector/USRPProtocol.h b/reflector/USRPProtocol.h index b4b2877..6362a77 100644 --- a/reflector/USRPProtocol.h +++ b/reflector/USRPProtocol.h @@ -19,6 +19,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "Protocol.h" #include "DVHeaderPacket.h" @@ -53,7 +54,7 @@ protected: // queue helper void HandleQueue(void); void HandleKeepalives(void); - + // stream helpers void OnDvHeaderPacketIn(std::unique_ptr &, const CIp &); @@ -72,4 +73,8 @@ protected: // for queue header caches std::unordered_map m_StreamsCache; uint32_t m_uiStreamId; + + // config data + std::string m_DefaultCallsign; + char m_AutolinkModule; }; diff --git a/reflector/User.cpp b/reflector/User.cpp index c42729e..cfac5ae 100644 --- a/reflector/User.cpp +++ b/reflector/User.cpp @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - +#include #include #include "User.h" diff --git a/reflector/Users.cpp b/reflector/Users.cpp index beb2106..8027503 100644 --- a/reflector/Users.cpp +++ b/reflector/Users.cpp @@ -18,7 +18,7 @@ #include "Users.h" -#include "Reflector.h" +#include "Global.h" //////////////////////////////////////////////////////////////////////////////////////// // constructor @@ -28,6 +28,7 @@ CUsers::CUsers() {} //////////////////////////////////////////////////////////////////////////////////////// // users management +#define LASTHEARD_USERS_MAX_SIZE 20 void CUsers::AddUser(const CUser &user) { // add @@ -40,7 +41,7 @@ void CUsers::AddUser(const CUser &user) } // notify - g_Refl..OnUsersChanged(); + g_Refl.OnUsersChanged(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -48,7 +49,7 @@ void CUsers::AddUser(const CUser &user) void CUsers::Hearing(const CCallsign &my, const CCallsign &rpt1, const CCallsign &rpt2) { - Hearing(my, rpt1, rpt2, g_Refl..GetCallsign()); + Hearing(my, rpt1, rpt2, g_Refl.GetCallsign()); } void CUsers::Hearing(const CCallsign &my, const CCallsign &rpt1, const CCallsign &rpt2, const CCallsign &xlx) diff --git a/reflector/WiresXCmdHandler.cpp b/reflector/WiresXCmdHandler.cpp index e90b0a3..e2c8d63 100644 --- a/reflector/WiresXCmdHandler.cpp +++ b/reflector/WiresXCmdHandler.cpp @@ -22,11 +22,9 @@ #include "YSFFich.h" #include "YSFPayload.h" #include "YSFClient.h" -#include "YSFNodeDirFile.h" -#include "YSFNodeDirHttp.h" #include "YSFUtils.h" -#include "Reflector.h" #include "WiresXCmdHandler.h" +#include "Global.h" //////////////////////////////////////////////////////////////////////////////////////// // constructor @@ -61,8 +59,8 @@ CWiresxCmdHandler::~CWiresxCmdHandler() bool CWiresxCmdHandler::Init(void) { // fill our wiresx info - m_ReflectorWiresxInfo.SetCallsign(g_Refl..GetCallsign()); - m_ReflectorWiresxInfo.SetNode(g_Refl..GetCallsign()); + m_ReflectorWiresxInfo.SetCallsign(g_Refl.GetCallsign()); + m_ReflectorWiresxInfo.SetNode(g_Refl.GetCallsign()); m_ReflectorWiresxInfo.SetName("Reflector"); // reset stop flag @@ -141,7 +139,6 @@ void CWiresxCmdHandler::Task(void) // handle it if ( bCmd ) { - const char *modules = ACTIVE_MODULES; // fill our info object Info = m_ReflectorWiresxInfo; g_LYtr.FindFrequencies(Cmd.GetCallsign(), &uiNodeTxFreq, &uiNodeRxFreq); @@ -149,13 +146,13 @@ void CWiresxCmdHandler::Task(void) // find our client and the module it's currentlink linked to cModule = ' '; - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), EProtocol::ysf); if ( client ) { cModule = client->GetReflectorModule(); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // and crack the cmd switch ( Cmd.GetCmd() ) @@ -173,19 +170,19 @@ void CWiresxCmdHandler::Task(void) break; case WIRESX_CMD_CONN_REQ: cModule = 'A' + (char)(Cmd.GetArg() - 1); - if (::strchr(modules, cModule)) + if (g_Refl.IsValidModule(cModule)) { std::cout << "Wires-X CONN_REQ command to link on module " << cModule << " from " << Cmd.GetCallsign() << " at " << Cmd.GetIp() << std::endl; // acknowledge ReplyToWiresxConnReqPacket(Cmd.GetIp(), Info, cModule); // change client's module - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), EProtocol::ysf); if ( client ) { client->SetReflectorModule(cModule); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else { @@ -198,13 +195,13 @@ void CWiresxCmdHandler::Task(void) ReplyToWiresxDiscReqPacket(Cmd.GetIp(), Info); // change client's module { - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), EProtocol::ysf); if ( client != nullptr ) { client->SetReflectorModule(' '); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } break; case WIRESX_CMD_UNKNOWN: @@ -337,8 +334,8 @@ bool CWiresxCmdHandler::ReplyToWiresxAllReqPacket(const CIp &Ip, const CWiresxIn memcpy(data + 12U, WiresxInfo.GetNode(), 10U); // number of entries - const char *modules = ACTIVE_MODULES; - uint NB_OF_MODULES = ::strlen(modules); + const std::string modules(g_Conf.GetString(g_Conf.j.modules.modules)); + uint NB_OF_MODULES = modules.size(); uint total = NB_OF_MODULES; uint n = NB_OF_MODULES - Start; if (n > 20U) @@ -741,8 +738,8 @@ bool CWiresxCmdHandler::DebugTestDecodePacket(const CBuffer &Buffer) std::cout << "Trailer" << std::endl; std::cout << "length of payload : " << len << std::endl; dump.Set(command, len); - dump.DebugDump(g_Refl..m_DebugFile); - dump.DebugDumpAscii(g_Refl..m_DebugFile); + dump.DebugDump(g_Refl.m_DebugFile); + dump.DebugDumpAscii(g_Refl.m_DebugFile); break; case YSF_FI_COMMUNICATIONS: if ( Fich.getDT() == YSF_DT_DATA_FR_MODE ) diff --git a/reflector/WiresXInfo.cpp b/reflector/WiresXInfo.cpp index 6fd11c9..3069a32 100644 --- a/reflector/WiresXInfo.cpp +++ b/reflector/WiresXInfo.cpp @@ -18,10 +18,10 @@ #include +#include "Defines.h" #include "Callsign.h" #include "WiresXInfo.h" - //////////////////////////////////////////////////////////////////////////////////////// // constructor diff --git a/reflector/YSFClient.h b/reflector/YSFClient.h index 08ff034..9b662b4 100644 --- a/reflector/YSFClient.h +++ b/reflector/YSFClient.h @@ -18,7 +18,9 @@ #pragma once +#include "Defines.h" #include "Client.h" + class CYsfClient : public CClient { public: diff --git a/reflector/YSFNode.h b/reflector/YSFNode.h index ba4889d..202c940 100644 --- a/reflector/YSFNode.h +++ b/reflector/YSFNode.h @@ -18,7 +18,7 @@ #pragma once - +#include class CYsfNode { diff --git a/reflector/YSFProtocol.cpp b/reflector/YSFProtocol.cpp index 15e9149..30fbf46 100644 --- a/reflector/YSFProtocol.cpp +++ b/reflector/YSFProtocol.cpp @@ -21,12 +21,9 @@ #include "CRC.h" #include "YSFPayload.h" #include "YSFClient.h" -#include "YSFNodeDirFile.h" -#include "YSFNodeDirHttp.h" #include "YSFUtils.h" #include "YSFProtocol.h" -#include "Reflector.h" -#include "GateKeeper.h" +#include "Global.h" //////////////////////////////////////////////////////////////////////////////////////// // constructor @@ -40,6 +37,9 @@ CYsfProtocol::CYsfProtocol() bool CYsfProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { + // config data + m_AutolinkModule = g_Conf.GetAutolinkModule(g_Conf.j.ysf.autolinkmod); + // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) return false; @@ -145,7 +145,7 @@ void CYsfProtocol::Task(void) Send(Buffer, Ip); // add client if needed - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Callsign, Ip, EProtocol::ysf); // client already connected ? if ( client == nullptr ) @@ -156,9 +156,8 @@ void CYsfProtocol::Task(void) auto newclient = std::make_shared(Callsign, Ip); // aautolink, if enabled -#if YSF_AUTOLINK_ENABLE - newclient->SetReflectorModule(YSF_AUTOLINK_MODULE); -#endif + if (m_AutolinkModule) + newclient->SetReflectorModule(m_AutolinkModule); // and append clients->AddClient(newclient); @@ -168,7 +167,7 @@ void CYsfProtocol::Task(void) client->Alive(); } // and done - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } else if ( IsValidDisconnectPacket(Buffer) ) @@ -176,7 +175,7 @@ void CYsfProtocol::Task(void) std::cout << "YSF disconnect packet from " << Ip << std::endl; // find client - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); std::shared_ptrclient = clients->FindClient(Ip, EProtocol::ysf); if ( client != nullptr ) { @@ -186,7 +185,7 @@ void CYsfProtocol::Task(void) //EncodeDisconnectPacket(&Buffer); //Send(Buffer, Ip); } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } else if ( IsValidwirexPacket(Buffer, &Fich, &Callsign, &iWiresxCmd, &iWiresxArg) ) { @@ -263,7 +262,7 @@ void CYsfProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Refl..GetClients()->FindClient(Ip, EProtocol::ysf); + std::shared_ptrclient = g_Refl.GetClients()->FindClient(Ip, EProtocol::ysf); if ( client ) { // get client callsign @@ -274,20 +273,20 @@ void CYsfProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, rpt2.SetCSModule(m); // and try to open the stream - if ( (stream = g_Refl..OpenStream(Header, client)) != nullptr ) + if ( (stream = g_Refl.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams[stream->GetStreamId()] = stream; } } // release - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); // update last heard - if ( g_Refl..IsValidModule(rpt2.GetCSModule()) ) + if ( g_Refl.IsValidModule(rpt2.GetCSModule()) ) { - g_Refl..GetUsers()->Hearing(my, rpt1, rpt2); - g_Refl..ReleaseUsers(); + g_Refl.GetUsers()->Hearing(my, rpt1, rpt2); + g_Refl.ReleaseUsers(); } } } @@ -346,7 +345,7 @@ void CYsfProtocol::HandleQueue(void) if ( buffer.size() > 0 ) { // and push it to all our clients linked to the module and who are not streaming in - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::ysf, it)) != nullptr ) @@ -359,7 +358,7 @@ void CYsfProtocol::HandleQueue(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } } m_Queue.Unlock(); @@ -375,7 +374,7 @@ void CYsfProtocol::HandleKeepalives(void) // and disconnect them if not // iterate on clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; while ( (client = clients->FindNextClient(EProtocol::ysf, it)) != nullptr ) @@ -395,7 +394,7 @@ void CYsfProtocol::HandleKeepalives(void) } } - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); } //////////////////////////////////////////////////////////////////////////////////////// @@ -998,7 +997,7 @@ bool CYsfProtocol::EncodeServerStatusPacket(CBuffer *Buffer) const const std::string cs = YSF_REFLECTOR_NAME; memcpy(callsign, cs.c_str(), cs.size() > 16 ? 16 : cs.size()); #else - g_Refl..GetCallsign().GetCallsign(callsign); + g_Refl.GetCallsign().GetCallsign(callsign); #endif char sz[16]; ::sprintf(sz, "%05u", CalcHash(callsign, 16) % 100000U); @@ -1010,9 +1009,9 @@ bool CYsfProtocol::EncodeServerStatusPacket(CBuffer *Buffer) const memcpy(description, desc.c_str(), desc.size() > 14 ? 14 : desc.size()); Buffer->Append(description, 14); // connected clients - CClients *clients = g_Refl..GetClients(); + CClients *clients = g_Refl.GetClients(); int count = MIN(999, clients->GetSize()); - g_Refl..ReleaseClients(); + g_Refl.ReleaseClients(); ::sprintf(sz, "%03u", count); Buffer->Append((uint8_t *)sz, 3); @@ -1090,8 +1089,8 @@ bool CYsfProtocol::DebugTestDecodePacket(const CBuffer &Buffer) std::cout << "Trailer" << std::endl; std::cout << "length of payload : " << len << std::endl; dump.Set(command, len); - dump.DebugDump(g_Refl..m_DebugFile); - dump.DebugDumpAscii(g_Refl..m_DebugFile); + dump.DebugDump(g_Refl.m_DebugFile); + dump.DebugDumpAscii(g_Refl.m_DebugFile); break; case YSF_FI_COMMUNICATIONS: if ( Fich.getDT() == YSF_DT_DATA_FR_MODE ) diff --git a/reflector/YSFProtocol.h b/reflector/YSFProtocol.h index 6e0534d..da1eee4 100644 --- a/reflector/YSFProtocol.h +++ b/reflector/YSFProtocol.h @@ -18,6 +18,7 @@ #pragma once +#include "Defines.h" #include "Timer.h" #include "Protocol.h" #include "DVHeaderPacket.h" @@ -129,4 +130,7 @@ protected: CWiresxCmdHandler m_WiresxCmdHandler; unsigned char m_seqNo; uint32_t m_uiStreamId; + + // config data + char m_AutolinkModule; }; diff --git a/reflector/YSFUtils.cpp b/reflector/YSFUtils.cpp index 32349a9..b47cf8d 100644 --- a/reflector/YSFUtils.cpp +++ b/reflector/YSFUtils.cpp @@ -19,20 +19,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . - #include #include "YSFDefines.h" #include "YSFUtils.h" #include "Golay24128.h" -//////////////////////////////////////////////////////////////////////////////////////// -// constants & defines - - - -//////////////////////////////////////////////////////////////////////////////////////// -// - void CYsfUtils::DecodeVD2Vchs(uint8_t *data, uint8_t **ambe) { int frame = 0; diff --git a/reflector/YSFUtils.h b/reflector/YSFUtils.h index 6805c66..6191a7f 100644 --- a/reflector/YSFUtils.h +++ b/reflector/YSFUtils.h @@ -21,6 +21,8 @@ #pragma once +#include + //////////////////////////////////////////////////////////////////////////////////////// // class diff --git a/reflector/example.ini b/reflector/example.ini index 87913d1..98e24be 100644 --- a/reflector/example.ini +++ b/reflector/example.ini @@ -58,7 +58,7 @@ Port = 17000 [MMDVM] Port = 62030 -DefaultId = 0 +DefaultId = 0 # if the DMR id is zero, this will be used (also used for P25) [NXDN] Port = 41400