diff --git a/src/cdcsprotocol.cpp b/src/cdcsprotocol.cpp index f9ee5ee..6e85b56 100644 --- a/src/cdcsprotocol.cpp +++ b/src/cdcsprotocol.cpp @@ -74,12 +74,9 @@ void CDcsProtocol::Task(void) // crack the packet if ( IsValidDvPacket(Buffer, Header, Frame) ) { - //std::cout << "DCS DV packet" << std::endl; - // callsign muted? if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DCS, Header->GetRpt2Module()) ) { - // handle it OnDvHeaderPacketIn(Header, Ip); if ( !Frame->IsLastPacket() ) @@ -196,17 +193,25 @@ void CDcsProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, { // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == nullptr ) + if ( stream ) + { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + } + else { // no stream open yet, open a new one - CCallsign via(Header->GetRpt1Callsign()); + CCallsign my(Header->GetMyCallsign()); + CCallsign rpt1(Header->GetRpt1Callsign()); + CCallsign rpt2(Header->GetRpt2Callsign()); // find this client std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS); - if ( client != nullptr ) + if ( client ) { // get client callsign - via = client->GetCallsign(); + rpt1 = client->GetCallsign(); // and try to open the stream if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { @@ -218,15 +223,9 @@ void CDcsProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, g_Reflector.ReleaseClients(); // update last heard - g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); + g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2); g_Reflector.ReleaseUsers(); } - else - { - // stream already open - // skip packet, but tickle the stream - stream->Tickle(); - } } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/cdextraprotocol.cpp b/src/cdextraprotocol.cpp index 33b876c..b5fedea 100644 --- a/src/cdextraprotocol.cpp +++ b/src/cdextraprotocol.cpp @@ -399,17 +399,25 @@ void CDextraProtocol::OnDvHeaderPacketIn(std::unique_ptr &Heade { // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == nullptr ) + if ( stream ) + { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + } + else { // no stream open yet, open a new one - CCallsign via(Header->GetRpt1Callsign()); + CCallsign my(Header->GetMyCallsign()); + CCallsign rpt1(Header->GetRpt1Callsign()); + CCallsign rpt2(Header->GetRpt2Callsign()); // find this client std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DEXTRA); - if ( client != nullptr ) + if ( client ) { // get client callsign - via = client->GetCallsign(); + rpt1 = client->GetCallsign(); // apply protocol revision details if ( client->GetProtocolRevision() == 2 ) { @@ -428,15 +436,9 @@ void CDextraProtocol::OnDvHeaderPacketIn(std::unique_ptr &Heade g_Reflector.ReleaseClients(); // update last heard - g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); + g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2); g_Reflector.ReleaseUsers(); } - else - { - // stream already open - // skip packet, but tickle the stream - stream->Tickle(); - } } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/cdmrmmdvmprotocol.cpp b/src/cdmrmmdvmprotocol.cpp index 0c3ccf7..cc2ad56 100644 --- a/src/cdmrmmdvmprotocol.cpp +++ b/src/cdmrmmdvmprotocol.cpp @@ -261,22 +261,27 @@ void CDmrmmdvmProtocol::Task(void) //////////////////////////////////////////////////////////////////////////////////////// // streams helpers -bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, const CIp &Ip, uint8 cmd, uint8 CallType) +void CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, const CIp &Ip, uint8 cmd, uint8 CallType) { - bool newstream = false; bool lastheard = false; - // - CCallsign via(Header->GetRpt1Callsign()); - // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == nullptr ) + if ( stream ) + { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + } + else { + CCallsign my(Header->GetMyCallsign()); + CCallsign rpt1(Header->GetRpt1Callsign()); + 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); - if ( client != nullptr ) + if ( client ) { // process cmd if any if ( !client->HasReflectorModule() ) @@ -284,15 +289,15 @@ bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Hea // not linked yet if ( cmd == CMD_LINK ) { - if ( g_Reflector.IsValidModule(Header->GetRpt2Module()) ) + if ( g_Reflector.IsValidModule(rpt2.GetModule()) ) { - std::cout << "DMRmmdvm client " << client->GetCallsign() << " linking on module " << Header->GetRpt2Module() << std::endl; + std::cout << "DMRmmdvm client " << client->GetCallsign() << " linking on module " << rpt2.GetModule() << std::endl; // link - client->SetReflectorModule(Header->GetRpt2Module()); + client->SetReflectorModule(rpt2.GetModule()); } else { - std::cout << "DMRMMDVM node " << via << " link attempt on non-existing module" << std::endl; + std::cout << "DMRMMDVM node " << rpt1 << " link attempt on non-existing module" << std::endl; } } } @@ -308,19 +313,20 @@ bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Hea else { // replace rpt2 module with currently linked module - Header->SetRpt2Module(client->GetReflectorModule()); + auto m = client->GetReflectorModule(); + Header->SetRpt2Module(m); + rpt2.SetModule(m); } } // and now, re-check module is valid && that it's not a private call - if ( g_Reflector.IsValidModule(Header->GetRpt2Module()) && (CallType == DMR_GROUP_CALL) ) + if ( g_Reflector.IsValidModule(rpt2.GetModule()) && (CallType == DMR_GROUP_CALL) ) { // yes, try to open the stream if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { // keep the handle m_Streams.push_back(stream); - newstream = true; lastheard = true; } } @@ -336,19 +342,10 @@ bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr &Hea // update last heard if ( lastheard ) { - g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); + g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2); g_Reflector.ReleaseUsers(); } } - else - { - // stream already open - // skip packet, but tickle the stream - stream->Tickle(); - } - - // done - return newstream; } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/cdmrmmdvmprotocol.h b/src/cdmrmmdvmprotocol.h index dcbf996..99bd83e 100644 --- a/src/cdmrmmdvmprotocol.h +++ b/src/cdmrmmdvmprotocol.h @@ -81,7 +81,7 @@ protected: void HandleKeepalives(void); // stream helpers - bool OnDvHeaderPacketIn(std::unique_ptr &, const CIp &, uint8, uint8); + void OnDvHeaderPacketIn(std::unique_ptr &, const CIp &, uint8, uint8); // packet decoding helpers bool IsValidConnectPacket(const CBuffer &, CCallsign *, const CIp &); diff --git a/src/cdmrplusprotocol.cpp b/src/cdmrplusprotocol.cpp index 90c65e5..e8fad41 100644 --- a/src/cdmrplusprotocol.cpp +++ b/src/cdmrplusprotocol.cpp @@ -156,10 +156,6 @@ void CDmrplusProtocol::Task(void) } g_Reflector.ReleaseClients(); } - else - { - //std::cout << "DMRPlus packet (" << Buffer.size() << ")" << " at " << Ip << std::endl; - } } // handle end of streaming timeout @@ -187,12 +183,22 @@ void CDmrplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Head { // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == nullptr ) + if ( stream ) + { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + } + else { + CCallsign my(Header->GetMyCallsign()); + CCallsign rpt1(Header->GetRpt1Callsign()); + CCallsign rpt2(Header->GetRpt2Callsign()); + // no stream open yet, open a new one // find this client std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRPLUS); - if ( client != nullptr ) + if ( client ) { // and try to open the stream if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) @@ -203,17 +209,10 @@ void CDmrplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Head } // release g_Reflector.ReleaseClients(); + // update last heard + g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2); + g_Reflector.ReleaseUsers(); } - else - { - // stream already open - // skip packet, but tickle the stream - stream->Tickle(); - } - - // update last heard - g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), Header->GetRpt1Callsign(), Header->GetRpt2Callsign()); - g_Reflector.ReleaseUsers(); } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/cdplusprotocol.cpp b/src/cdplusprotocol.cpp index 19efcbf..7a260c6 100644 --- a/src/cdplusprotocol.cpp +++ b/src/cdplusprotocol.cpp @@ -181,17 +181,25 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header { // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == nullptr ) + if ( stream ) + { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + } + else { // no stream open yet, open a new one - CCallsign via(Header->GetRpt1Callsign()); + CCallsign my(Header->GetMyCallsign()); + CCallsign rpt1(Header->GetRpt1Callsign()); + CCallsign rpt2(Header->GetRpt2Callsign()); // first, check module is valid - if ( g_Reflector.IsValidModule(Header->GetRpt1Module()) ) + if ( g_Reflector.IsValidModule(rpt1.GetModule()) ) { // find this client std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DPLUS); - if ( client != nullptr ) + if ( client ) { // now we know if it's a dextra dongle or a genuine dplus node if ( Header->GetRpt2Callsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) @@ -201,10 +209,10 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header // now we know its module, let's update it if ( !client->HasModule() ) { - client->SetModule(Header->GetRpt1Module()); + client->SetModule(rpt1.GetModule()); } // get client callsign - via = client->GetCallsign(); + rpt1 = client->GetCallsign(); // and try to open the stream if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) { @@ -216,20 +224,14 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header g_Reflector.ReleaseClients(); // update last heard - g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); + g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2); g_Reflector.ReleaseUsers(); } else { - std::cout << "DPlus node " << via << " link attempt on non-existing module" << std::endl; + std::cout << "DPlus node " << rpt1 << " link attempt on non-existing module" << std::endl; } } - else - { - // stream already open - // skip packet, but tickle the stream - stream->Tickle(); - } } //////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/cg3protocol.cpp b/src/cg3protocol.cpp index fb98765..b1a8691 100644 --- a/src/cg3protocol.cpp +++ b/src/cg3protocol.cpp @@ -526,10 +526,18 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c // find the stream CPacketStream *stream = GetStream(Header->GetStreamId(), &Ip); - if ( stream == nullptr ) + if ( stream ) + { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + } + else { // no stream open yet, open a new one - CCallsign via(Header->GetRpt1Callsign()); + CCallsign my(Header->GetMyCallsign()); + CCallsign rpt1(Header->GetRpt1Callsign()); + CCallsign rpt2(Header->GetRpt2Callsign()); // find this client CClients *clients = g_Reflector.GetClients(); @@ -544,15 +552,15 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c } } - if ( client != nullptr ) + if ( client ) { // move it to the proper module - if (m_ReflectorCallsign.HasSameCallsign(Header->GetRpt2Callsign())) + if (m_ReflectorCallsign.HasSameCallsign(rpt2)) { - if (client->GetReflectorModule() != Header->GetRpt2Callsign().GetModule()) + if (client->GetReflectorModule() != rpt2.GetModule()) { - char new_module = Header->GetRpt2Callsign().GetModule(); + auto new_module = rpt2.GetModule(); if (strchr(m_Modules.c_str(), '*') || strchr(m_Modules.c_str(), new_module)) { client->SetReflectorModule(new_module); @@ -565,7 +573,7 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c } // get client callsign - via = client->GetCallsign(); + rpt1 = client->GetCallsign(); // and try to open the stream if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) @@ -575,19 +583,13 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr &Header, c } // update last heard - g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); + g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2); g_Reflector.ReleaseUsers(); } } // release g_Reflector.ReleaseClients(); } - else - { - // stream already open - // skip packet, but tickle the stream - stream->Tickle(); - } } diff --git a/src/cxlxprotocol.cpp b/src/cxlxprotocol.cpp index dbf9f91..5890162 100644 --- a/src/cxlxprotocol.cpp +++ b/src/cxlxprotocol.cpp @@ -396,12 +396,21 @@ void CXlxProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == nullptr ) + if ( stream ) { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + } + else + { + CCallsign my(Header->GetMyCallsign()); + CCallsign rpt1(Header->GetRpt1Callsign()); + 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()); - if ( client != nullptr ) + if ( client ) { // and try to open the stream if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) @@ -414,17 +423,10 @@ void CXlxProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, } // release g_Reflector.ReleaseClients(); + // update last heard + g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2, peer); + g_Reflector.ReleaseUsers(); } - else - { - // stream already open - // skip packet, but tickle the stream - stream->Tickle(); - } - - // update last heard - g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), Header->GetRpt1Callsign(), Header->GetRpt2Callsign(), peer); - g_Reflector.ReleaseUsers(); } void CXlxProtocol::OnDvFramePacketIn(std::unique_ptr &DvFrame, const CIp *Ip) diff --git a/src/cysfprotocol.cpp b/src/cysfprotocol.cpp index 2892dc7..77e6ff8 100644 --- a/src/cysfprotocol.cpp +++ b/src/cysfprotocol.cpp @@ -227,17 +227,25 @@ void CYsfProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, { // find the stream CPacketStream *stream = GetStream(Header->GetStreamId()); - if ( stream == nullptr ) + if ( stream ) + { + // stream already open + // skip packet, but tickle the stream + stream->Tickle(); + } + else { // no stream open yet, open a new one - CCallsign via(Header->GetRpt1Callsign()); + CCallsign my(Header->GetMyCallsign()); + CCallsign rpt1(Header->GetRpt1Callsign()); + CCallsign rpt2(Header->GetRpt2Callsign()); // find this client std::shared_ptrclient = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_YSF); - if ( client != nullptr ) + if ( client ) { // get client callsign - via = client->GetCallsign(); + rpt2 = client->GetCallsign(); // get module it's linked to Header->SetRpt2Module(client->GetReflectorModule()); @@ -254,16 +262,10 @@ void CYsfProtocol::OnDvHeaderPacketIn(std::unique_ptr &Header, // update last heard if ( g_Reflector.IsValidModule(Header->GetRpt2Module()) ) { - g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); + g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2); g_Reflector.ReleaseUsers(); } } - else - { - // stream already open - // skip packet, but tickle the stream - stream->Tickle(); - } } ////////////////////////////////////////////////////////////////////////////////////////