diff --git a/reflector/BMClient.h b/reflector/BMClient.h index 7d0c5ee..980adf7 100644 --- a/reflector/BMClient.h +++ b/reflector/BMClient.h @@ -33,9 +33,9 @@ public: virtual ~CBmClient() {}; // identity - int GetProtocol(void) const { return PROTOCOL_XLX; } + EProtocol GetProtocol(void) const { return EProtocol::ulx; } int GetProtocolRevision(void) const { return XLX_PROTOCOL_REVISION_2; } - const char *GetProtocolName(void) const { return "XLX"; } + const char *GetProtocolName(void) const { return "ULX"; } int GetCodec(void) const { return CODEC_AMBE2PLUS; } bool IsPeer(void) const { return true; } diff --git a/reflector/BMPeer.h b/reflector/BMPeer.h index 5520312..765ac3a 100644 --- a/reflector/BMPeer.h +++ b/reflector/BMPeer.h @@ -40,7 +40,7 @@ public: bool IsAlive(void) const; // identity - int GetProtocol(void) const { return PROTOCOL_XLX; } + EProtocol GetProtocol(void) const { return EProtocol::ulx; } const char *GetProtocolName(void) const { return "XLX"; } // revision helper diff --git a/reflector/Client.h b/reflector/Client.h index f9d0d43..13e203c 100644 --- a/reflector/Client.h +++ b/reflector/Client.h @@ -56,7 +56,7 @@ public: void SetReflectorModule(char c) { m_ReflectorModule = c; } // identity - virtual int GetProtocol(void) const { return PROTOCOL_NONE; } + virtual EProtocol GetProtocol(void) const { return EProtocol::none; } virtual int GetProtocolRevision(void) const { return 0; } virtual int GetCodec(void) const { return CODEC_NONE; } virtual const char *GetProtocolName(void) const { return "none"; } diff --git a/reflector/Clients.cpp b/reflector/Clients.cpp index 70ba461..a034e20 100644 --- a/reflector/Clients.cpp +++ b/reflector/Clients.cpp @@ -125,7 +125,7 @@ std::shared_ptr CClients::FindClient(const CIp &Ip) return nullptr; } -std::shared_ptr CClients::FindClient(const CIp &Ip, int Protocol) +std::shared_ptr CClients::FindClient(const CIp &Ip, const EProtocol Protocol) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -140,7 +140,7 @@ std::shared_ptr CClients::FindClient(const CIp &Ip, int Protocol) return nullptr; } -std::shared_ptr CClients::FindClient(const CIp &Ip, int Protocol, char ReflectorModule) +std::shared_ptr CClients::FindClient(const CIp &Ip, const EProtocol Protocol, const char ReflectorModule) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -155,7 +155,7 @@ std::shared_ptr CClients::FindClient(const CIp &Ip, int Protocol, char return nullptr; } -std::shared_ptr CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, int Protocol) +std::shared_ptr CClients::FindClient(const CCallsign &Callsign, const CIp &Ip, const EProtocol Protocol) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -169,7 +169,7 @@ std::shared_ptr CClients::FindClient(const CCallsign &Callsign, const C return nullptr; } -std::shared_ptr CClients::FindClient(const CCallsign &Callsign, char module, const CIp &Ip, int Protocol) +std::shared_ptr CClients::FindClient(const CCallsign &Callsign, char module, const CIp &Ip, const EProtocol Protocol) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -183,7 +183,7 @@ std::shared_ptr CClients::FindClient(const CCallsign &Callsign, char mo return nullptr; } -std::shared_ptr CClients::FindClient(const CCallsign &Callsign, int Protocol) +std::shared_ptr CClients::FindClient(const CCallsign &Callsign, const EProtocol Protocol) { // find client for ( auto it=begin(); it!=end(); it++ ) @@ -200,7 +200,7 @@ std::shared_ptr CClients::FindClient(const CCallsign &Callsign, int Pro //////////////////////////////////////////////////////////////////////////////////////// // iterate on clients -std::shared_ptr CClients::FindNextClient(int Protocol, std::list>::iterator &it) +std::shared_ptr CClients::FindNextClient(const EProtocol Protocol, std::list>::iterator &it) { while ( it != end() ) { @@ -213,7 +213,7 @@ std::shared_ptr CClients::FindNextClient(int Protocol, std::list CClients::FindNextClient(const CIp &Ip, int Protocol, std::list>::iterator &it) +std::shared_ptr CClients::FindNextClient(const CIp &Ip, const EProtocol Protocol, std::list>::iterator &it) { while ( it != end() ) { @@ -226,7 +226,7 @@ std::shared_ptr CClients::FindNextClient(const CIp &Ip, int Protocol, s return nullptr; } -std::shared_ptr CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, int Protocol, std::list>::iterator &it) +std::shared_ptr CClients::FindNextClient(const CCallsign &Callsign, const CIp &Ip, const EProtocol Protocol, std::list>::iterator &it) { while ( it != end() ) { diff --git a/reflector/Clients.h b/reflector/Clients.h index cb89ce4..74183c3 100644 --- a/reflector/Clients.h +++ b/reflector/Clients.h @@ -55,16 +55,16 @@ public: // find clients std::shared_ptr FindClient(const CIp &); - std::shared_ptr FindClient(const CIp &, int); - std::shared_ptr FindClient(const CIp &, int, char); - std::shared_ptr FindClient(const CCallsign &, const CIp &, int); - std::shared_ptr FindClient(const CCallsign &, char, const CIp &, int); - std::shared_ptr FindClient(const CCallsign &, int); + std::shared_ptr FindClient(const CIp &, const EProtocol); + std::shared_ptr FindClient(const CIp &, const EProtocol, const char); + std::shared_ptr FindClient(const CCallsign &, const CIp &, const EProtocol); + std::shared_ptr FindClient(const CCallsign &, char, const CIp &, const EProtocol); + std::shared_ptr FindClient(const CCallsign &, const EProtocol); // iterate on clients - std::shared_ptr FindNextClient(int, std::list>::iterator &); - std::shared_ptr FindNextClient(const CIp &, int, std::list>::iterator &); - std::shared_ptr FindNextClient(const CCallsign &, const CIp &, int, std::list>::iterator &); + std::shared_ptr FindNextClient(const EProtocol, std::list>::iterator &); + std::shared_ptr FindNextClient(const CIp &, const EProtocol, std::list>::iterator &); + std::shared_ptr FindNextClient(const CCallsign &, const CIp &, const EProtocol, std::list>::iterator &); protected: // data diff --git a/reflector/CodecStream.cpp b/reflector/CodecStream.cpp index ee0e73f..e4f9c29 100644 --- a/reflector/CodecStream.cpp +++ b/reflector/CodecStream.cpp @@ -83,14 +83,14 @@ bool CCodecStream::Init(uint16_t uiPort) // create socket address, family based on transcoder listen address #ifdef LISTEN_IPV4 #ifdef LISTEN_IPV6 - const auto paddr = (AF_INET == m_Ip.GetFamily()) ? g_Reflector.m_Address.GetV4Address(PROTOCOL_ANY) : g_Reflector.m_Address.GetV6Address(PROTOCOL_ANY); + auto paddr = (AF_INET == m_Ip.GetFamily()) ? LISTEN_IPV4 : LISTEN_IPV6; #else - const auto paddr = g_Reflector.m_Address.GetV4Address(PROTOCOL_ANY); + auto paddr = LISTEN_IPV4; #endif #else - const auto paddr = g_Reflector.m_Address.GetV6Address(PROTOCOL_ANY); + auto paddr = LISTEN_IPV6; #endif - CIp ip(m_Ip.GetFamily(), m_uiPort, paddr.c_str()); + CIp ip(m_Ip.GetFamily(), m_uiPort, paddr); // create our socket if (ip.IsSet()) diff --git a/reflector/DCSClient.h b/reflector/DCSClient.h index ce7eb68..47fb496 100644 --- a/reflector/DCSClient.h +++ b/reflector/DCSClient.h @@ -32,7 +32,7 @@ public: virtual ~CDcsClient() {}; // identity - int GetProtocol(void) const { return PROTOCOL_DCS; } + EProtocol GetProtocol(void) const { return EProtocol::dcs; } const char *GetProtocolName(void) const { return "DCS"; } int GetCodec(void) const { return CODEC_AMBEPLUS; } bool IsNode(void) const { return true; } diff --git a/reflector/DCSProtocol.cpp b/reflector/DCSProtocol.cpp index bbd4394..bac3fc1 100644 --- a/reflector/DCSProtocol.cpp +++ b/reflector/DCSProtocol.cpp @@ -26,7 +26,7 @@ //////////////////////////////////////////////////////////////////////////////////////// // operation -bool CDcsProtocol::Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) +bool CDcsProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) @@ -68,7 +68,7 @@ void CDcsProtocol::Task(void) if ( IsValidDvPacket(Buffer, Header, Frame) ) { // callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DCS, Header->GetRpt2Module()) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, EProtocol::dcs, Header->GetRpt2Module()) ) { OnDvHeaderPacketIn(Header, Ip); @@ -89,7 +89,7 @@ void CDcsProtocol::Task(void) std::cout << "DCS connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_DCS) && g_Reflector.IsValidModule(ToLinkModule) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::dcs) && g_Reflector.IsValidModule(ToLinkModule) ) { // valid module ? if ( g_Reflector.IsValidModule(ToLinkModule) ) @@ -125,7 +125,7 @@ void CDcsProtocol::Task(void) // find client CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DCS); + std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dcs); if ( client != nullptr ) { // remove it @@ -144,7 +144,7 @@ void CDcsProtocol::Task(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DCS, it)) != nullptr ) + while ( (client = clients->FindNextClient(Callsign, Ip, EProtocol::dcs, it)) != nullptr ) { client->Alive(); } @@ -202,7 +202,7 @@ void CDcsProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS); + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, EProtocol::dcs); if ( client ) { // get client callsign @@ -273,7 +273,7 @@ void CDcsProtocol::HandleQueue(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dcs, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -305,7 +305,7 @@ void CDcsProtocol::HandleKeepalives(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DCS, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dcs, it)) != nullptr ) { // encode client's specific keepalive packet CBuffer keepalive2; diff --git a/reflector/DCSProtocol.h b/reflector/DCSProtocol.h index b6240af..6460629 100644 --- a/reflector/DCSProtocol.h +++ b/reflector/DCSProtocol.h @@ -44,7 +44,7 @@ class CDcsProtocol : public CProtocol { public: // initialization - bool Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); // task void Task(void); diff --git a/reflector/DExtraClient.h b/reflector/DExtraClient.h index 0c5eafb..ce77489 100644 --- a/reflector/DExtraClient.h +++ b/reflector/DExtraClient.h @@ -39,7 +39,7 @@ public: virtual ~CDextraClient() {}; // identity - int GetProtocol(void) const { return PROTOCOL_DEXTRA; } + EProtocol GetProtocol(void) const { return EProtocol::dextra; } int GetProtocolRevision(void) const { return m_ProtRev; } const char *GetProtocolName(void) const { return "DExtra"; } int GetCodec(void) const { return CODEC_AMBEPLUS; } diff --git a/reflector/DExtraPeer.h b/reflector/DExtraPeer.h index 02364d3..ddf2e62 100644 --- a/reflector/DExtraPeer.h +++ b/reflector/DExtraPeer.h @@ -34,8 +34,8 @@ public: bool IsAlive(void) const; // identity - int GetProtocol(void) const { return PROTOCOL_DEXTRA; } - const char *GetProtocolName(void) const { return "DExtra"; } + 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 2df1414..5d3d89f 100644 --- a/reflector/DExtraProtocol.cpp +++ b/reflector/DExtraProtocol.cpp @@ -28,7 +28,7 @@ //////////////////////////////////////////////////////////////////////////////////////// // operation -bool CDextraProtocol::Initialize(const char *type, int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) +bool CDextraProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) @@ -75,7 +75,7 @@ void CDextraProtocol::Task(void) else if ( IsValidDvHeaderPacket(Buffer, Header) ) { // callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DEXTRA, Header->GetRpt2Module()) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, EProtocol::dextra, Header->GetRpt2Module()) ) { OnDvHeaderPacketIn(Header, Ip); } @@ -89,7 +89,7 @@ void CDextraProtocol::Task(void) std::cout << "DExtra connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << " rev " << ProtRev << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_DEXTRA) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::dextra) ) { // valid module ? if ( g_Reflector.IsValidModule(ToLinkModule) ) @@ -103,7 +103,7 @@ void CDextraProtocol::Task(void) // already connected ? CPeers *peers = g_Reflector.GetPeers(); - if ( peers->FindPeer(Callsign, Ip, PROTOCOL_DEXTRA) == nullptr ) + if ( peers->FindPeer(Callsign, Ip, EProtocol::dextra) == nullptr ) { // create the new peer // this also create one client per module @@ -147,7 +147,7 @@ void CDextraProtocol::Task(void) // find client & remove it CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DEXTRA); + std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dextra); if ( client != nullptr ) { // ack disconnect packet @@ -173,7 +173,7 @@ void CDextraProtocol::Task(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DEXTRA, it)) != nullptr ) + while ( (client = clients->FindNextClient(Callsign, Ip, EProtocol::dextra, it)) != nullptr ) { client->Alive(); } @@ -234,7 +234,7 @@ void CDextraProtocol::HandleQueue(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dextra, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -268,7 +268,7 @@ void CDextraProtocol::HandleKeepalives(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DEXTRA, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dextra, it)) != nullptr ) { // send keepalive Send(keepalive, client->GetIp()); @@ -283,7 +283,7 @@ void CDextraProtocol::HandleKeepalives(void) else if ( !client->IsAlive() ) { CPeers *peers = g_Reflector.GetPeers(); - std::shared_ptrpeer = peers->FindPeer(client->GetCallsign(), client->GetIp(), PROTOCOL_DEXTRA); + std::shared_ptrpeer = peers->FindPeer(client->GetCallsign(), client->GetIp(), EProtocol::dextra); if ( peer != nullptr && peer->GetReflectorModules()[0] == client->GetReflectorModule() ) { // no, but this is a peer client, so it will be handled below @@ -309,7 +309,7 @@ void CDextraProtocol::HandleKeepalives(void) CPeers *peers = g_Reflector.GetPeers(); auto pit = peers->begin(); std::shared_ptrpeer = nullptr; - while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != nullptr ) + while ( (peer = peers->FindNextPeer(EProtocol::dextra, pit)) != nullptr ) { // keepalives are sent between clients @@ -349,7 +349,7 @@ void CDextraProtocol::HandlePeerLinks(void) // if not, disconnect auto pit = peers->begin(); std::shared_ptrpeer = nullptr; - while ( (peer = peers->FindNextPeer(PROTOCOL_DEXTRA, pit)) != nullptr ) + while ( (peer = peers->FindNextPeer(EProtocol::dextra, pit)) != nullptr ) { if ( list->FindListItem(peer->GetCallsign()) == nullptr ) { @@ -370,7 +370,7 @@ void CDextraProtocol::HandlePeerLinks(void) continue; if ( strlen((*it).GetModules()) != 2 ) continue; - if ( peers->FindPeer((*it).GetCallsign(), PROTOCOL_DEXTRA) == nullptr ) + if ( peers->FindPeer((*it).GetCallsign(), EProtocol::dextra) == nullptr ) { // resolve again peer's IP in case it's a dynamic IP (*it).ResolveIp(); @@ -407,7 +407,7 @@ void CDextraProtocol::OnDvHeaderPacketIn(std::unique_ptr &Heade CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DEXTRA); + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, EProtocol::dextra); if ( client ) { // get client callsign diff --git a/reflector/DExtraProtocol.h b/reflector/DExtraProtocol.h index 41b1b8e..ef886f8 100644 --- a/reflector/DExtraProtocol.h +++ b/reflector/DExtraProtocol.h @@ -52,7 +52,7 @@ class CDextraProtocol : public CProtocol { public: // initialization - bool Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); // task void Task(void); diff --git a/reflector/DMRMMDVMClient.h b/reflector/DMRMMDVMClient.h index 041c0df..00924a3 100644 --- a/reflector/DMRMMDVMClient.h +++ b/reflector/DMRMMDVMClient.h @@ -32,7 +32,7 @@ public: virtual ~CDmrmmdvmClient() {}; // identity - int GetProtocol(void) const { return PROTOCOL_DMRMMDVM; } + EProtocol GetProtocol(void) const { return EProtocol::dmrmmdvm; } const char *GetProtocolName(void) const { return "DMRMmdvm"; } int GetCodec(void) const { return CODEC_AMBE2PLUS; } bool IsNode(void) const { return true; } diff --git a/reflector/DMRMMDVMProtocol.cpp b/reflector/DMRMMDVMProtocol.cpp index df71382..eefce2c 100644 --- a/reflector/DMRMMDVMProtocol.cpp +++ b/reflector/DMRMMDVMProtocol.cpp @@ -47,7 +47,7 @@ static uint8_t g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; //////////////////////////////////////////////////////////////////////////////////////// // operation -bool CDmrmmdvmProtocol::Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) +bool CDmrmmdvmProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) @@ -105,7 +105,7 @@ void CDmrmmdvmProtocol::Task(void) else if ( IsValidDvHeaderPacket(Buffer, Header, &Cmd, &CallType) ) { // callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DMRMMDVM) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, EProtocol::dmrmmdvm) ) { // handle it OnDvHeaderPacketIn(Header, Ip, Cmd, CallType); @@ -120,7 +120,7 @@ void CDmrmmdvmProtocol::Task(void) std::cout << "DMRmmdvm connect packet from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_DMRMMDVM) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::dmrmmdvm) ) { // acknowledge the request EncodeConnectAckPacket(&Buffer, Callsign, m_uiAuthSeed); @@ -139,7 +139,7 @@ void CDmrmmdvmProtocol::Task(void) std::cout << "DMRmmdvm authentication packet from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_DMRMMDVM) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::dmrmmdvm) ) { // acknowledge the request EncodeAckPacket(&Buffer, Callsign); @@ -147,7 +147,7 @@ void CDmrmmdvmProtocol::Task(void) // add client if needed CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Callsign, Ip, PROTOCOL_DMRMMDVM); + std::shared_ptrclient = clients->FindClient(Callsign, Ip, EProtocol::dmrmmdvm); // client already connected ? if ( client == nullptr ) { @@ -177,7 +177,7 @@ void CDmrmmdvmProtocol::Task(void) // find client & remove it CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DMRMMDVM); + std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dmrmmdvm); if ( client != nullptr ) { clients->RemoveClient(client); @@ -200,7 +200,7 @@ void CDmrmmdvmProtocol::Task(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(Callsign, Ip, PROTOCOL_DMRMMDVM, it)) != nullptr ) + while ( (client = clients->FindNextClient(Callsign, Ip, EProtocol::dmrmmdvm, it)) != nullptr ) { // acknowledge EncodeKeepAlivePacket(&Buffer, client); @@ -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_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRMMDVM); + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, EProtocol::dmrmmdvm); if ( client ) { // process cmd if any @@ -413,7 +413,7 @@ void CDmrmmdvmProtocol::HandleQueue(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dmrmmdvm, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -442,7 +442,7 @@ void CDmrmmdvmProtocol::HandleKeepalives(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DMRMMDVM, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dmrmmdvm, it)) != nullptr ) { // is this client busy ? if ( client->IsAMaster() ) diff --git a/reflector/DMRMMDVMProtocol.h b/reflector/DMRMMDVMProtocol.h index 4aee151..af62297 100644 --- a/reflector/DMRMMDVMProtocol.h +++ b/reflector/DMRMMDVMProtocol.h @@ -60,7 +60,7 @@ class CDmrmmdvmProtocol : public CProtocol { public: // initialization - bool Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); // task void Task(void); diff --git a/reflector/DMRPlusClient.h b/reflector/DMRPlusClient.h index f7992ed..1a8d3ba 100644 --- a/reflector/DMRPlusClient.h +++ b/reflector/DMRPlusClient.h @@ -32,7 +32,7 @@ public: virtual ~CDmrplusClient() {}; // identity - int GetProtocol(void) const { return PROTOCOL_DMRPLUS; } + EProtocol GetProtocol(void) const { return EProtocol::dmrplus; } const char *GetProtocolName(void) const { return "DMRplus"; } int GetCodec(void) const { return CODEC_AMBE2PLUS; } bool IsNode(void) const { return true; } diff --git a/reflector/DMRPlusProtocol.cpp b/reflector/DMRPlusProtocol.cpp index abdfbb0..d04c899 100644 --- a/reflector/DMRPlusProtocol.cpp +++ b/reflector/DMRPlusProtocol.cpp @@ -40,7 +40,7 @@ static uint8_t g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; //////////////////////////////////////////////////////////////////////////////////////// // operation -bool CDmrplusProtocol::Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) +bool CDmrplusProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) @@ -93,7 +93,7 @@ void CDmrplusProtocol::Task(void) else if ( IsValidDvHeaderPacket(Ip, Buffer, Header) ) { // callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DMRPLUS) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, EProtocol::dmrplus) ) { // handle it OnDvHeaderPacketIn(Header, Ip); @@ -104,7 +104,7 @@ void CDmrplusProtocol::Task(void) //std::cout << "DMRplus keepalive/connect packet for module " << ToLinkModule << " from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_DMRPLUS) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::dmrplus) ) { // acknowledge the request EncodeConnectAckPacket(&Buffer); @@ -112,7 +112,7 @@ void CDmrplusProtocol::Task(void) // add client if needed CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Callsign, Ip, PROTOCOL_DMRPLUS); + std::shared_ptrclient = clients->FindClient(Callsign, Ip, EProtocol::dmrplus); // client already connected ? if ( client == nullptr ) { @@ -142,7 +142,7 @@ void CDmrplusProtocol::Task(void) // find client & remove it CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DMRPLUS); + std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dmrplus); if ( client != nullptr ) { clients->RemoveClient(client); @@ -196,7 +196,7 @@ void CDmrplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Head // no stream open yet, open a new one // find this client - std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRPLUS); + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, EProtocol::dmrplus); if ( client ) { // and try to open the stream @@ -278,7 +278,7 @@ void CDmrplusProtocol::HandleQueue(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dmrplus, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -304,7 +304,7 @@ void CDmrplusProtocol::SendBufferToClients(const CBuffer &buffer, uint8_t module CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dmrplus, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == module) ) @@ -334,7 +334,7 @@ void CDmrplusProtocol::HandleKeepalives(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DMRPLUS, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dmrplus, it)) != nullptr ) { // is this client busy ? if ( client->IsAMaster() ) diff --git a/reflector/DMRPlusProtocol.h b/reflector/DMRPlusProtocol.h index 039aec2..c358682 100644 --- a/reflector/DMRPlusProtocol.h +++ b/reflector/DMRPlusProtocol.h @@ -50,7 +50,7 @@ class CDmrplusProtocol : public CProtocol { public: // initialization - bool Initialize(const char *type, const int pytpe, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + bool Initialize(const char *type, const EProtocol pytpe, const uint16_t port, const bool has_ipv4, const bool has_ipv6); // task void Task(void); diff --git a/reflector/DPlusClient.h b/reflector/DPlusClient.h index 961e69a..514a463 100644 --- a/reflector/DPlusClient.h +++ b/reflector/DPlusClient.h @@ -32,7 +32,7 @@ public: virtual ~CDplusClient() {}; // identity - int GetProtocol(void) const { return PROTOCOL_DPLUS; } + EProtocol GetProtocol(void) const { return EProtocol::dplus; } const char *GetProtocolName(void) const { return "DPlus"; } int GetCodec(void) const { return CODEC_AMBEPLUS; } bool IsNode(void) const { return true; } diff --git a/reflector/DPlusProtocol.cpp b/reflector/DPlusProtocol.cpp index 7b138cc..c03a793 100644 --- a/reflector/DPlusProtocol.cpp +++ b/reflector/DPlusProtocol.cpp @@ -27,7 +27,7 @@ //////////////////////////////////////////////////////////////////////////////////////// // operation -bool CDplusProtocol::Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) +bool CDplusProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) @@ -73,7 +73,7 @@ void CDplusProtocol::Task(void) else if ( IsValidDvHeaderPacket(Buffer, Header) ) { // is muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DPLUS, Header->GetRpt2Module()) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, EProtocol::dplus, Header->GetRpt2Module()) ) { // handle it OnDvHeaderPacketIn(Header, Ip); @@ -95,7 +95,7 @@ void CDplusProtocol::Task(void) std::cout << "DPlus login packet from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_DPLUS) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::dplus) ) { // acknowledge the request EncodeLoginAckPacket(&Buffer); @@ -119,7 +119,7 @@ void CDplusProtocol::Task(void) // find client CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Ip, PROTOCOL_DPLUS); + std::shared_ptrclient = clients->FindClient(Ip, EProtocol::dplus); if ( client != nullptr ) { // remove it @@ -138,7 +138,7 @@ void CDplusProtocol::Task(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(Ip, PROTOCOL_DPLUS, it)) != nullptr ) + while ( (client = clients->FindNextClient(Ip, EProtocol::dplus, it)) != nullptr ) { client->Alive(); } @@ -193,7 +193,7 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header if ( g_Reflector.IsValidModule(rpt2.GetModule()) ) { // find this client - std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DPLUS); + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, EProtocol::dplus); if ( client ) { // now we know if it's a dextra dongle or a genuine dplus node @@ -262,7 +262,7 @@ void CDplusProtocol::HandleQueue(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dplus, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() ) @@ -352,7 +352,7 @@ void CDplusProtocol::HandleKeepalives(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_DPLUS, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::dplus, it)) != nullptr ) { // send keepalive //std::cout << "Sending DPlus packet @ " << client->GetIp() << std::endl; diff --git a/reflector/DPlusProtocol.h b/reflector/DPlusProtocol.h index ee14576..7991127 100644 --- a/reflector/DPlusProtocol.h +++ b/reflector/DPlusProtocol.h @@ -39,7 +39,7 @@ class CDplusProtocol : public CProtocol { public: // initialization - bool Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); // task void Task(void); diff --git a/reflector/G3Client.h b/reflector/G3Client.h index c3b91d2..3fac01a 100644 --- a/reflector/G3Client.h +++ b/reflector/G3Client.h @@ -32,7 +32,7 @@ public: virtual ~CG3Client() {}; // identity - int GetProtocol(void) const { return PROTOCOL_G3; } + EProtocol GetProtocol(void) const { return EProtocol::g3; } const char *GetProtocolName(void) const { return "Terminal/AP"; } int GetCodec(void) const { return CODEC_AMBEPLUS; } bool IsNode(void) const { return true; } diff --git a/reflector/G3Protocol.cpp b/reflector/G3Protocol.cpp index 793d530..d93aa7d 100644 --- a/reflector/G3Protocol.cpp +++ b/reflector/G3Protocol.cpp @@ -31,7 +31,7 @@ //////////////////////////////////////////////////////////////////////////////////////// // operation -bool CG3Protocol::Initialize(const char */*type*/, const int /*type*/, const uint16_t /*port*/, const bool /*has_ipv4*/, const bool /*has_ipv6*/) +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 { ReadOptions(); @@ -46,8 +46,7 @@ bool CG3Protocol::Initialize(const char */*type*/, const int /*type*/, const uin //m_ReflectorCallsign.PatchCallsign(0, (const uint8_t *)"XLX", 3); // create our sockets - auto s = g_Reflector.m_Address.GetV4Address(PROTOCOL_G3); - CIp ip(AF_INET, G3_DV_PORT, s.c_str()); + CIp ip(AF_INET, G3_DV_PORT, LISTEN_IPV4); if ( ip.IsSet() ) { if (! m_Socket4.Open(ip)) @@ -181,7 +180,7 @@ void CG3Protocol::PresenceTask(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrextant = nullptr; - while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) + while ( (extant = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) { CIp ClIp = extant->GetIp(); if (ClIp.GetAddr() == Ip.GetAddr()) @@ -195,7 +194,7 @@ void CG3Protocol::PresenceTask(void) it = clients->begin(); // do we already have a client with the same call (IP changed)? - while ( (extant = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) + while ( (extant = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) { if (extant->GetCallsign().HasSameCallsign(Terminal)) { @@ -347,7 +346,7 @@ void CG3Protocol::IcmpTask(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) { CIp ClientIp = client->GetIp(); if (ClientIp.GetAddr() == Ip.GetAddr()) @@ -383,7 +382,7 @@ void CG3Protocol::Task(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) { ClIp = client->GetIp(); if (ClIp.GetAddr() == Ip.GetAddr()) @@ -408,7 +407,7 @@ void CG3Protocol::Task(void) else if ( IsValidDvHeaderPacket(Buffer, Header) ) { // callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_G3, Header->GetRpt2Module()) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, EProtocol::g3, Header->GetRpt2Module()) ) { // handle it OnDvHeaderPacketIn(Header, *BaseIp); @@ -464,7 +463,7 @@ void CG3Protocol::HandleQueue(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -497,7 +496,7 @@ void CG3Protocol::HandleKeepalives(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) { if (!client->IsAlive()) { @@ -537,7 +536,7 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) { CIp ClIp = client->GetIp(); if (ClIp.GetAddr() == Ip.GetAddr()) @@ -705,7 +704,7 @@ void CG3Protocol::NeedReload(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_G3, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::g3, it)) != nullptr ) { char module = client->GetReflectorModule(); if (!strchr(m_Modules.c_str(), module) && !strchr(m_Modules.c_str(), '*')) diff --git a/reflector/G3Protocol.h b/reflector/G3Protocol.h index cb3e5bf..5da0c32 100644 --- a/reflector/G3Protocol.h +++ b/reflector/G3Protocol.h @@ -60,7 +60,7 @@ public: CG3Protocol() : m_GwAddress(0u), m_Modules("*"), m_LastModTime(0) {} // initialization - bool Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); // close void Close(void); diff --git a/reflector/GateKeeper.cpp b/reflector/GateKeeper.cpp index 66d3c07..9367b8d 100644 --- a/reflector/GateKeeper.cpp +++ b/reflector/GateKeeper.cpp @@ -75,21 +75,21 @@ void CGateKeeper::Close(void) //////////////////////////////////////////////////////////////////////////////////////// // authorisations -bool CGateKeeper::MayLink(const CCallsign &callsign, const CIp &ip, int protocol, char *modules) const +bool CGateKeeper::MayLink(const CCallsign &callsign, const CIp &ip, EProtocol protocol, char *modules) const { bool ok = true; switch (protocol) { // repeaters - case PROTOCOL_DEXTRA: - case PROTOCOL_DPLUS: - case PROTOCOL_DCS: - case PROTOCOL_DMRPLUS: - case PROTOCOL_DMRMMDVM: - case PROTOCOL_YSF: + case EProtocol::dextra: + case EProtocol::dplus: + case EProtocol::dcs: + case EProtocol::dmrplus: + case EProtocol::dmrmmdvm: + case EProtocol::ysf: #ifndef NO_G3 - case PROTOCOL_G3: + case EProtocol::g3: #endif // first check is IP & callsigned listed OK ok &= IsNodeListedOk(callsign, ip); @@ -97,12 +97,12 @@ bool CGateKeeper::MayLink(const CCallsign &callsign, const CIp &ip, int protocol break; // XLX interlinks - case PROTOCOL_XLX: + case EProtocol::ulx: ok &= IsPeerListedOk(callsign, ip, modules); break; // unsupported - case PROTOCOL_NONE: + case EProtocol::none: default: ok = false; break; @@ -111,29 +111,29 @@ bool CGateKeeper::MayLink(const CCallsign &callsign, const CIp &ip, int protocol // report if ( !ok ) { - std::cout << "Gatekeeper blocking linking of " << callsign << " @ " << ip << " using protocol " << protocol << std::endl; + std::cout << "Gatekeeper blocking linking of " << callsign << " @ " << ip << " using protocol " << ProtocolName(protocol) << std::endl; } // done return ok; } -bool CGateKeeper::MayTransmit(const CCallsign &callsign, const CIp &ip, int protocol, char module) const +bool CGateKeeper::MayTransmit(const CCallsign &callsign, const CIp &ip, const EProtocol protocol, char module) const { bool ok = true; switch (protocol) { // repeaters, protocol specific - case PROTOCOL_ANY: - case PROTOCOL_DEXTRA: - case PROTOCOL_DPLUS: - case PROTOCOL_DCS: - case PROTOCOL_DMRPLUS: - case PROTOCOL_DMRMMDVM: - case PROTOCOL_YSF: + case EProtocol::any: + case EProtocol::dextra: + case EProtocol::dplus: + case EProtocol::dcs: + case EProtocol::dmrplus: + case EProtocol::dmrmmdvm: + case EProtocol::ysf: #ifndef NO_G3 - case PROTOCOL_G3: + case EProtocol::g3: #endif // first check is IP & callsigned listed OK ok = ok && IsNodeListedOk(callsign, ip, module); @@ -141,12 +141,12 @@ bool CGateKeeper::MayTransmit(const CCallsign &callsign, const CIp &ip, int prot break; // XLX interlinks - case PROTOCOL_XLX: + case EProtocol::ulx: ok = ok && IsPeerListedOk(callsign, ip, module); break; // unsupported - case PROTOCOL_NONE: + case EProtocol::none: default: ok = false; break; @@ -155,7 +155,7 @@ bool CGateKeeper::MayTransmit(const CCallsign &callsign, const CIp &ip, int prot // report if ( !ok ) { - std::cout << "Gatekeeper blocking transmitting of " << callsign << " @ " << ip << " using protocol " << protocol << std::endl; + std::cout << "Gatekeeper blocking transmitting of " << callsign << " @ " << ip << " using protocol " << ProtocolName(protocol) << std::endl; } // done @@ -264,3 +264,29 @@ bool CGateKeeper::IsPeerListedOk(const CCallsign &callsign, const CIp &ip, char // done return ok; } + +const std::string CGateKeeper::ProtocolName(const EProtocol p) const +{ + switch (p) { + case EProtocol::any: + return "ANY"; + case EProtocol::dcs: + return "DCS"; + case EProtocol::dextra: + return "DExtra"; + case EProtocol::dmrmmdvm: + return "MMDVM DMR"; + case EProtocol::dmrplus: + return "DMR+"; + case EProtocol::ulx: + return "ULX"; + case EProtocol::ysf: + return "YSF"; +#ifndef NO_G3 + case EProtocol::g3: + return "Icom G3"; +#endif + default: + return "NONE"; + } +} diff --git a/reflector/GateKeeper.h b/reflector/GateKeeper.h index 1358a9d..490c7f1 100644 --- a/reflector/GateKeeper.h +++ b/reflector/GateKeeper.h @@ -42,8 +42,8 @@ public: void Close(void); // authorizations - bool MayLink(const CCallsign &, const CIp &, int, char * = nullptr) const; - bool MayTransmit(const CCallsign &, const CIp &, int = PROTOCOL_ANY, char = ' ') const; + bool MayLink(const CCallsign &, const CIp &, const EProtocol, char * = nullptr) const; + bool MayTransmit(const CCallsign &, const CIp &, EProtocol = EProtocol::any, char = ' ') const; // peer list handeling CPeerCallsignList *GetPeerList(void) { m_PeerList.Lock(); return &m_PeerList; } @@ -57,6 +57,7 @@ protected: bool IsNodeListedOk(const CCallsign &, const CIp &, char = ' ') const; bool IsPeerListedOk(const CCallsign &, const CIp &, char) const; bool IsPeerListedOk(const CCallsign &, const CIp &, char *) const; + const std::string ProtocolName(EProtocol) const; protected: // data diff --git a/reflector/Main.h b/reflector/Main.h index 6396dc4..16972e5 100644 --- a/reflector/Main.h +++ b/reflector/Main.h @@ -71,17 +71,10 @@ // protocols --------------------------------------------------- -#define PROTOCOL_ANY -1 -#define PROTOCOL_NONE 0 -#define PROTOCOL_DEXTRA 1 -#define PROTOCOL_DPLUS 2 -#define PROTOCOL_DCS 3 -#define PROTOCOL_XLX 4 -#define PROTOCOL_DMRPLUS 5 -#define PROTOCOL_DMRMMDVM 6 -#define PROTOCOL_YSF 7 #ifndef NO_G3 -#define PROTOCOL_G3 8 +enum class EProtocol { any, none, dextra, dplus, dcs, ulx, dmrplus, dmrmmdvm, ysf, g3 }; +#else +enum class EProtocol { any, none, dextra, dplus, dcs, xlx, dmrplus, dmrmmdvm, ysf }; #endif // DExtra diff --git a/reflector/Makefile b/reflector/Makefile index 9c7ff3e..504f8a1 100644 --- a/reflector/Makefile +++ b/reflector/Makefile @@ -36,18 +36,16 @@ endif LDFLAGS=-pthread -XRFSRCS = 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 DVLastFramePacket.cpp GateKeeper.cpp IP.cpp Notification.cpp Packet.cpp PacketStream.cpp PeerCallsignList.cpp Peer.cpp Peers.cpp ProtoAddress.cpp Protocol.cpp Protocols.cpp Reflector.cpp UDPSocket.cpp User.cpp Users.cpp Version.cpp Main.cpp +XRFSRCS = 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 DVLastFramePacket.cpp GateKeeper.cpp IP.cpp Notification.cpp Packet.cpp PacketStream.cpp PeerCallsignList.cpp Peer.cpp Peers.cpp Protocol.cpp Protocols.cpp Reflector.cpp UDPSocket.cpp User.cpp Users.cpp Version.cpp Main.cpp XLXSRCS = BMClient.cpp BMPeer.cpp BPTC19696.cpp CRC.cpp DMRIdDir.cpp DMRIdDirFile.cpp DMRIdDirHttp.cpp DMRMMDVMClient.cpp DMRMMDVMProtocol.cpp DMRPlusClient.cpp DMRPlusProtocol.cpp Golay2087.cpp Golay24128.cpp Hamming.cpp QR1676.cpp RS129.cpp Semaphore.cpp Utils.cpp WiresXCmd.cpp WiresXCmdHandler.cpp WiresXInfo.cpp ULXClient.cpp ULXProtocol.cpp ULXPeer.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 = $(XRFSRCS) -ifeq ($(is_xlx), true) SRCS += $(XLXSRCS) ifeq ($(ysf_db), true) LDFLAGS += `mysql_config --libs` endif -endif ifdef tc_ip SRCS += Transcoder.cpp CodecStream.cpp @@ -60,11 +58,7 @@ endif OBJS = $(SRCS:.cpp=.o) DEPS = $(SRCS:.cpp=.d) -ifeq ($(is_xlx), true) EXE=ulxd -else -EXE=xrfd -endif all : $(EXE) diff --git a/reflector/Peer.h b/reflector/Peer.h index a2ac046..6d280cb 100644 --- a/reflector/Peer.h +++ b/reflector/Peer.h @@ -46,9 +46,9 @@ public: // set // identity - virtual int GetProtocol(void) const { return PROTOCOL_NONE; } + virtual EProtocol GetProtocol(void) const { return EProtocol::none; } virtual int GetProtocolRevision(void) const { return 0; } - virtual const char *GetProtocolName(void) const { return "none"; } + virtual const char *GetProtocolName(void) const { return "NONE"; } // status virtual bool IsAMaster(void) const; diff --git a/reflector/Peers.cpp b/reflector/Peers.cpp index ce53ed3..20f0ca8 100644 --- a/reflector/Peers.cpp +++ b/reflector/Peers.cpp @@ -107,7 +107,7 @@ void CPeers::RemovePeer(std::shared_ptr peer) //////////////////////////////////////////////////////////////////////////////////////// // find peers -std::shared_ptr CPeers::FindPeer(const CIp &Ip, int Protocol) +std::shared_ptr CPeers::FindPeer(const CIp &Ip, const EProtocol Protocol) { for ( auto it=begin(); it!=end(); it++ ) { @@ -120,7 +120,7 @@ std::shared_ptr CPeers::FindPeer(const CIp &Ip, int Protocol) return nullptr; } -std::shared_ptr CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol) +std::shared_ptr CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, const EProtocol Protocol) { for ( auto it=begin(); it!=end(); it++ ) { @@ -133,7 +133,7 @@ std::shared_ptr CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip return nullptr; } -std::shared_ptr CPeers::FindPeer(const CCallsign &Callsign, int Protocol) +std::shared_ptr CPeers::FindPeer(const CCallsign &Callsign, const EProtocol Protocol) { for ( auto it=begin(); it!=end(); it++ ) { @@ -150,7 +150,7 @@ std::shared_ptr CPeers::FindPeer(const CCallsign &Callsign, int Protocol) //////////////////////////////////////////////////////////////////////////////////////// // iterate on peers -std::shared_ptr CPeers::FindNextPeer(int Protocol, std::list>::iterator &it) +std::shared_ptr CPeers::FindNextPeer(const EProtocol Protocol, std::list>::iterator &it) { while ( it!=end() ) { diff --git a/reflector/Peers.h b/reflector/Peers.h index 944903c..9fb2831 100644 --- a/reflector/Peers.h +++ b/reflector/Peers.h @@ -45,12 +45,12 @@ public: std::list>::const_iterator cend() const { return m_Peers.cend(); } // find peers - std::shared_ptr FindPeer(const CIp &, int); - std::shared_ptr FindPeer(const CCallsign &, const CIp &, int); - std::shared_ptr FindPeer(const CCallsign &, int); + std::shared_ptr FindPeer(const CIp &, const EProtocol); + std::shared_ptr FindPeer(const CCallsign &, const CIp &, const EProtocol); + std::shared_ptr FindPeer(const CCallsign &, const EProtocol); // iterate on peers - std::shared_ptr FindNextPeer(int, std::list>::iterator &); + std::shared_ptr FindNextPeer(const EProtocol, std::list>::iterator &); protected: // data diff --git a/reflector/ProtoAddress.cpp b/reflector/ProtoAddress.cpp deleted file mode 100644 index 55235d4..0000000 --- a/reflector/ProtoAddress.cpp +++ /dev/null @@ -1,96 +0,0 @@ -// ulxd -- 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 "ProtoAddress.h" - -CProtoAddress::CProtoAddress() -{ -#ifdef LISTEN_IPV4 - v4address[PROTOCOL_ANY] = LISTEN_IPV4; -#endif -#ifdef LISTEN_V4_DPLUS - v4address[PROTOCOL_DPLUS] = LISTEN_V4_DPLUS; -#endif -#ifdef LISTEN_V4_DCS - v4address[PROTOCOL_DCS] = LISTEN_V4_DCS; -#endif -#ifdef LISTEN_V4_DEXTRA - v4address[PROTOCOL_DEXTRA] = LISTEN_V4_DEXTRA; -#endif -#ifdef LISTEN_V4_DMRMMDVM - v4address[PROTOCOL_DMRMMDVM] = LISTEN_V4_DMRMMDVM; -#endif -#ifdef LISTEN_V4_DMRPLUS - v4address[PROTOCOL_DMRPLUS] = LISTEN_V4_DMRPLUS; -#endif -#ifdef LISTEN_V4_YSF - v4address[PROTOCOL_YSF] = LISTEN_V4_YSF; -#endif -#ifdef LISTEN_V4_XLX - v4address[PROTOCOL_XLX] = LISTEN_V4_XLX; -#endif -#ifdef LISTEN_V4_G3 - v4address[PROTOCOL_G3] = LISTEN_V4_G3; -#endif - -#ifdef LISTEN_IPV6 - v6address[PROTOCOL_ANY] = LISTEN_IPV6; -#endif -#ifdef LISTEN_V6_DPLUS - v6address[PROTOCOL_DPLUS] = LISTEN_V6_DPLUS; -#endif -#ifdef LISTEN_V6_DCS - v6address[PROTOCOL_DCS] = LISTEN_V6_DCS; -#endif -#ifdef LISTEN_V6_DEXTRA - v6address[PROTOCOL_DEXTRA] = LISTEN_V6_DEXTRA; -#endif -#ifdef LISTEN_V6_DMRMMDVM - v6address[PROTOCOL_DMRMMDVM] = LISTEN_V6_DMRMMDVM; -#endif -#ifdef LISTEN_V6_DMRPLUS - v6address[PROTOCOL_DMRPLUS] = LISTEN_V6_DMRPLUS; -#endif -#ifdef LISTEN_V6_YSF - v6address[PROTOCOL_YSF] = LISTEN_V6_YSF; -#endif -#ifdef LISTEN_V6_XLX - v6address[PROTOCOL_XLX] = LISTEN_V6_XLX; -#endif -#ifdef LISTEN_V6_G3 - v6address[PROTOCOL_G3] = LISTEN_V6_G3; -#endif -} - -#ifdef LISTEN_IPV4 -std::string CProtoAddress::GetV4Address(int protocol) -{ - if (v4address.end() == v4address.find(protocol)) - return v4address[PROTOCOL_ANY]; - else - return v4address[protocol]; -} -#endif - -#ifdef LISTEN_IPV6 -std::string CProtoAddress::GetV6Address(int protocol) -{ - if (v6address.end() == v6address.find(protocol)) - return v6address[PROTOCOL_ANY]; - else - return v6address[protocol]; -} -#endif diff --git a/reflector/ProtoAddress.h b/reflector/ProtoAddress.h deleted file mode 100644 index 7a6d437..0000000 --- a/reflector/ProtoAddress.h +++ /dev/null @@ -1,42 +0,0 @@ -// ulxd -- 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 -#include - -#include "Main.h" - -class CProtoAddress -{ -public: - CProtoAddress(); -#ifdef LISTEN_IPV4 - std::string GetV4Address(int protocol); -#endif -#ifdef LISTEN_IPV6 - std::string GetV6Address(int protocol); -#endif - -private: -#ifdef LISTEN_IPV4 - std::unordered_map v4address; -#endif -#ifdef LISTEN_IPV6 - std::unordered_map v6address; -#endif -}; diff --git a/reflector/Protocol.cpp b/reflector/Protocol.cpp index b0a3f29..65f7d39 100644 --- a/reflector/Protocol.cpp +++ b/reflector/Protocol.cpp @@ -49,7 +49,7 @@ CProtocol::~CProtocol() //////////////////////////////////////////////////////////////////////////////////////// // initialization -bool CProtocol::Initialize(const char *type, int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) +bool CProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // init reflector apparent callsign m_ReflectorCallsign = g_Reflector.GetCallsign(); @@ -65,8 +65,7 @@ bool CProtocol::Initialize(const char *type, int ptype, const uint16_t port, con #ifdef LISTEN_IPV4 if (has_ipv4) { - const auto s = g_Reflector.m_Address.GetV4Address(ptype); - CIp ip4(AF_INET, port, s.c_str()); + CIp ip4(AF_INET, port, LISTEN_IPV4); if ( ip4.IsSet() ) { if (! m_Socket4.Open(ip4)) @@ -79,7 +78,7 @@ bool CProtocol::Initialize(const char *type, int ptype, const uint16_t port, con #ifdef LISTEN_IPV6 if (has_ipv6) { - CIp ip6(AF_INET6, port, g_Reflector.m_Address.GetV6Address(ptype).c_str()); + CIp ip6(AF_INET6, port, LISTEN_IPV6); if ( ip6.IsSet() ) { if (! m_Socket6.Open(ip6)) diff --git a/reflector/Protocol.h b/reflector/Protocol.h index ef394ca..a5a6d6a 100644 --- a/reflector/Protocol.h +++ b/reflector/Protocol.h @@ -69,7 +69,7 @@ public: virtual ~CProtocol(); // initialization - virtual bool Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + virtual bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); virtual void Close(void); // queue diff --git a/reflector/Protocols.cpp b/reflector/Protocols.cpp index 1278321..4502679 100644 --- a/reflector/Protocols.cpp +++ b/reflector/Protocols.cpp @@ -45,36 +45,36 @@ bool CProtocols::Init(void) m_Mutex.lock(); { m_Protocols.emplace_back(std::unique_ptr(new CDextraProtocol)); - if (! m_Protocols.back()->Initialize("XRF", PROTOCOL_DEXTRA, DEXTRA_PORT, DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("XRF", EProtocol::dextra, DEXTRA_PORT, DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDplusProtocol)); - if (! m_Protocols.back()->Initialize("REF", PROTOCOL_DPLUS, DPLUS_PORT, DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("REF", EProtocol::dplus, DPLUS_PORT, DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDcsProtocol)); - if (! m_Protocols.back()->Initialize("DCS", PROTOCOL_DCS, DCS_PORT, DSTAR_IPV4, DSTAR_IPV6)) + if (! m_Protocols.back()->Initialize("DCS", EProtocol::dcs, DCS_PORT, DSTAR_IPV4, DSTAR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDmrmmdvmProtocol)); - if (! m_Protocols.back()->Initialize(nullptr, PROTOCOL_DMRMMDVM, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrmmdvm, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CDmrplusProtocol)); - if (! m_Protocols.back()->Initialize(nullptr, PROTOCOL_DMRPLUS, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize(nullptr, EProtocol::dmrplus, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CYsfProtocol)); - if (! m_Protocols.back()->Initialize("YSF", PROTOCOL_YSF, YSF_PORT, YSF_IPV4, YSF_IPV6)) + if (! m_Protocols.back()->Initialize("YSF", EProtocol::ysf, YSF_PORT, YSF_IPV4, YSF_IPV6)) return false; m_Protocols.emplace_back(std::unique_ptr(new CUlxProtocol)); - if (! m_Protocols.back()->Initialize("XLX", PROTOCOL_XLX, XLX_PORT, DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize("XLX", EProtocol::ulx, XLX_PORT, DMR_IPV4, DMR_IPV6)) return false; #ifndef NO_G3 m_Protocols.emplace_back(std::unique_ptr(new CG3Protocol)); - if (! m_Protocols.back()->Initialize("XLX", PROTOCOL_G3, G3_DV_PORT, DMR_IPV4, DMR_IPV6)) + if (! m_Protocols.back()->Initialize("XLX", EProtocol::g3, G3_DV_PORT, DMR_IPV4, DMR_IPV6)) return false; #endif diff --git a/reflector/Reflector.h b/reflector/Reflector.h index 3ca23e7..0f77279 100644 --- a/reflector/Reflector.h +++ b/reflector/Reflector.h @@ -18,7 +18,6 @@ #pragma once -#include "ProtoAddress.h" #include "Users.h" #include "Clients.h" #include "Peers.h" @@ -78,9 +77,6 @@ public: CUsers *GetUsers(void) { m_Users.Lock(); return &m_Users; } void ReleaseUsers(void) { m_Users.Unlock(); } - // IP Addresses - CProtoAddress m_Address; - // get bool IsValidModule(char c) const { return (GetModuleIndex(c) >= 0); } int GetModuleIndex(char) const; diff --git a/reflector/Transcoder.cpp b/reflector/Transcoder.cpp index 1f3d1b3..d1fb875 100644 --- a/reflector/Transcoder.cpp +++ b/reflector/Transcoder.cpp @@ -76,14 +76,14 @@ bool CTranscoder::Init(void) // now open the transcoder port #ifdef LISTEN_IPV4 #ifdef LISTEN_IPV6 - const auto paddr = (AF_INET == m_Ip.GetFamily()) ? g_Reflector.m_Address.GetV4Address(PROTOCOL_ANY) : g_Reflector.m_Address.GetV6Address(PROTOCOL_ANY); + auto paddr = (AF_INET == m_Ip.GetFamily()) ? LISTEN_IPV4 : LISTEN_IPV6; #else - const auto paddr = g_Reflector.m_Address.GetV4Address(PROTOCOL_ANY); + auto paddr = LISTEN_IPV4; #endif #else - const auto paddr = g_Reflector.m_address.GetV6Address(PROTOCOL_ANY); + auto paddr = LISTEN_IPV6; #endif - CIp tc(m_Ip.GetFamily(), TRANSCODER_PORT, paddr.c_str()); + CIp tc(m_Ip.GetFamily(), TRANSCODER_PORT, paddr); // create our socket if (tc.IsSet()) diff --git a/reflector/ULXClient.h b/reflector/ULXClient.h index fdc0b39..350bd42 100644 --- a/reflector/ULXClient.h +++ b/reflector/ULXClient.h @@ -36,7 +36,7 @@ public: virtual ~CUlxClient() {}; // identity - int GetProtocol(void) const { return PROTOCOL_XLX; } + EProtocol GetProtocol(void) const { return EProtocol::ulx; } int GetProtocolRevision(void) const { return m_ProtRev; } const char *GetProtocolName(void) const { return "XLX"; } int GetCodec(void) const; diff --git a/reflector/ULXPeer.h b/reflector/ULXPeer.h index 773c7be..1573e11 100644 --- a/reflector/ULXPeer.h +++ b/reflector/ULXPeer.h @@ -33,8 +33,8 @@ public: bool IsAlive(void) const; // identity - int GetProtocol(void) const { return PROTOCOL_XLX; } - const char *GetProtocolName(void) const { return "XLX"; } + EProtocol GetProtocol(void) const { return EProtocol::ulx; } + const char *GetProtocolName(void) const { return "ULX"; } // revision helper static int GetProtocolRevision(const CVersion &); diff --git a/reflector/ULXProtocol.cpp b/reflector/ULXProtocol.cpp index 655f092..fb15288 100644 --- a/reflector/ULXProtocol.cpp +++ b/reflector/ULXProtocol.cpp @@ -28,7 +28,7 @@ //////////////////////////////////////////////////////////////////////////////////////// // operation -bool CUlxProtocol::Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) +bool CUlxProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) return false; @@ -88,7 +88,7 @@ void CUlxProtocol::Task(void) std::cout << "XLX (" << Version.GetMajor() << "." << Version.GetMinor() << "." << Version.GetRevision() << ") connect packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_XLX, Modules) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::ulx, Modules) ) { // acknowledge connecting request // following is version dependent @@ -98,7 +98,7 @@ void CUlxProtocol::Task(void) { // already connected ? CPeers *peers = g_Reflector.GetPeers(); - if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == nullptr ) + if ( peers->FindPeer(Callsign, Ip, EProtocol::ulx) == nullptr ) { // acknowledge the request EncodeConnectAckPacket(&Buffer, Modules); @@ -129,11 +129,11 @@ void CUlxProtocol::Task(void) std::cout << "XLX ack packet for modules " << Modules << " from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_XLX, Modules) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::ulx, Modules) ) { // already connected ? CPeers *peers = g_Reflector.GetPeers(); - if ( peers->FindPeer(Callsign, Ip, PROTOCOL_XLX) == nullptr ) + if ( peers->FindPeer(Callsign, Ip, EProtocol::ulx) == nullptr ) { // create the new peer // this also create one client per module @@ -152,7 +152,7 @@ void CUlxProtocol::Task(void) // find peer CPeers *peers = g_Reflector.GetPeers(); - std::shared_ptrpeer = peers->FindPeer(Ip, PROTOCOL_XLX); + std::shared_ptrpeer = peers->FindPeer(Ip, EProtocol::ulx); if ( peer != nullptr ) { // remove it from reflector peer list @@ -172,7 +172,7 @@ void CUlxProtocol::Task(void) // find peer CPeers *peers = g_Reflector.GetPeers(); - std::shared_ptrpeer = peers->FindPeer(Ip, PROTOCOL_XLX); + std::shared_ptrpeer = peers->FindPeer(Ip, EProtocol::ulx); if ( peer != nullptr ) { // keep it alive @@ -247,7 +247,7 @@ void CUlxProtocol::HandleQueue(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_XLX, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::ulx, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -298,7 +298,7 @@ void CUlxProtocol::HandleKeepalives(void) CPeers *peers = g_Reflector.GetPeers(); auto pit = peers->begin(); std::shared_ptrpeer = nullptr; - while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != nullptr ) + while ( (peer = peers->FindNextPeer(EProtocol::ulx, pit)) != nullptr ) { // send keepalive Send(keepalive, peer->GetIp()); @@ -340,7 +340,7 @@ void CUlxProtocol::HandlePeerLinks(void) // if not, disconnect auto pit = peers->begin(); std::shared_ptrpeer = nullptr; - while ( (peer = peers->FindNextPeer(PROTOCOL_XLX, pit)) != nullptr ) + while ( (peer = peers->FindNextPeer(EProtocol::ulx, pit)) != nullptr ) { if ( list->FindListItem(peer->GetCallsign()) == nullptr ) { @@ -359,7 +359,7 @@ void CUlxProtocol::HandlePeerLinks(void) { if ( (*it).GetCallsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) continue; - if ( peers->FindPeer((*it).GetCallsign(), PROTOCOL_XLX) == nullptr ) + if ( peers->FindPeer((*it).GetCallsign(), EProtocol::ulx) == nullptr ) { // resolve again peer's IP in case it's a dynamic IP (*it).ResolveIp(); @@ -404,7 +404,7 @@ void CUlxProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // no stream open yet, open a new one // find this client - std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX, Header->GetRpt2Module()); + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, EProtocol::ulx, Header->GetRpt2Module()); if ( client ) { // and try to open the stream diff --git a/reflector/ULXProtocol.h b/reflector/ULXProtocol.h index 0210c64..39d797b 100644 --- a/reflector/ULXProtocol.h +++ b/reflector/ULXProtocol.h @@ -34,7 +34,7 @@ class CUlxProtocol : public CDextraProtocol { public: // initialization - bool Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); // task void Task(void); diff --git a/reflector/WiresXCmdHandler.cpp b/reflector/WiresXCmdHandler.cpp index a7d9e9a..7331079 100644 --- a/reflector/WiresXCmdHandler.cpp +++ b/reflector/WiresXCmdHandler.cpp @@ -149,7 +149,7 @@ void CWiresxCmdHandler::Task(void) // find our client and the module it's currentlink linked to cModule = ' '; CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); + std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), EProtocol::ysf); if ( client ) { cModule = client->GetReflectorModule(); @@ -179,7 +179,7 @@ void CWiresxCmdHandler::Task(void) ReplyToWiresxConnReqPacket(Cmd.GetIp(), Info, cModule); // change client's module CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); + std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), EProtocol::ysf); if ( client ) { client->SetReflectorModule(cModule); @@ -198,7 +198,7 @@ void CWiresxCmdHandler::Task(void) // change client's module { CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), PROTOCOL_YSF); + std::shared_ptrclient = clients->FindClient(Cmd.GetCallsign(), Cmd.GetIp(), EProtocol::ysf); if ( client != nullptr ) { client->SetReflectorModule(' '); diff --git a/reflector/YSFClient.h b/reflector/YSFClient.h index adb64f2..ef38b9d 100644 --- a/reflector/YSFClient.h +++ b/reflector/YSFClient.h @@ -31,7 +31,7 @@ public: virtual ~CYsfClient() {}; // identity - int GetProtocol(void) const { return PROTOCOL_YSF; } + EProtocol GetProtocol(void) const { return EProtocol::ysf; } const char *GetProtocolName(void) const { return "YSF"; } int GetCodec(void) const { return CODEC_AMBE2PLUS; } bool IsNode(void) const { return true; } diff --git a/reflector/YSFProtocol.cpp b/reflector/YSFProtocol.cpp index 2b31bdc..1ead876 100644 --- a/reflector/YSFProtocol.cpp +++ b/reflector/YSFProtocol.cpp @@ -38,7 +38,7 @@ CYsfProtocol::CYsfProtocol() //////////////////////////////////////////////////////////////////////////////////////// // operation -bool CYsfProtocol::Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) +bool CYsfProtocol::Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6) { // base class if (! CProtocol::Initialize(type, ptype, port, has_ipv4, has_ipv6)) @@ -119,7 +119,7 @@ void CYsfProtocol::Task(void) else if ( IsValidDvHeaderPacket(Ip, Fich, Buffer, Header, Frames) ) { // node linked and callsign muted? - if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_YSF, Header->GetRpt2Module()) ) + if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, EProtocol::ysf, Header->GetRpt2Module()) ) { // handle it OnDvHeaderPacketIn(Header, Ip); @@ -138,7 +138,7 @@ void CYsfProtocol::Task(void) //std::cout << "YSF keepalive/connect packet from " << Callsign << " at " << Ip << std::endl; // callsign authorized? - if ( g_GateKeeper.MayLink(Callsign, Ip, PROTOCOL_YSF) ) + if ( g_GateKeeper.MayLink(Callsign, Ip, EProtocol::ysf) ) { // acknowledge the request EncodeConnectAckPacket(&Buffer); @@ -146,7 +146,7 @@ void CYsfProtocol::Task(void) // add client if needed CClients *clients = g_Reflector.GetClients(); - std::shared_ptrclient = clients->FindClient(Callsign, Ip, PROTOCOL_YSF); + std::shared_ptrclient = clients->FindClient(Callsign, Ip, EProtocol::ysf); // client already connected ? if ( client == nullptr ) { @@ -240,7 +240,7 @@ void CYsfProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, CCallsign rpt2(Header->GetRpt2Callsign()); // find this client - std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_YSF); + std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, EProtocol::ysf); if ( client ) { // get client callsign @@ -328,7 +328,7 @@ void CYsfProtocol::HandleQueue(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::ysf, it)) != nullptr ) { // is this client busy ? if ( !client->IsAMaster() && (client->GetReflectorModule() == packet->GetModuleId()) ) @@ -357,7 +357,7 @@ void CYsfProtocol::HandleKeepalives(void) CClients *clients = g_Reflector.GetClients(); auto it = clients->begin(); std::shared_ptrclient = nullptr; - while ( (client = clients->FindNextClient(PROTOCOL_YSF, it)) != nullptr ) + while ( (client = clients->FindNextClient(EProtocol::ysf, it)) != nullptr ) { // is this client busy ? if ( client->IsAMaster() ) diff --git a/reflector/YSFProtocol.h b/reflector/YSFProtocol.h index da1f353..47ad309 100644 --- a/reflector/YSFProtocol.h +++ b/reflector/YSFProtocol.h @@ -65,7 +65,7 @@ public: CYsfProtocol(); // initialization - bool Initialize(const char *type, const int ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); + bool Initialize(const char *type, const EProtocol ptype, const uint16_t port, const bool has_ipv4, const bool has_ipv6); void Close(void); // task