rearrange processing for C*Protocol::OnDvHeaderPacketIn

pull/1/head
Tom Early 5 years ago
parent 2ff9fd1eaf
commit 78b3489904

@ -74,12 +74,9 @@ void CDcsProtocol::Task(void)
// crack the packet // crack the packet
if ( IsValidDvPacket(Buffer, Header, Frame) ) if ( IsValidDvPacket(Buffer, Header, Frame) )
{ {
//std::cout << "DCS DV packet" << std::endl;
// callsign muted? // callsign muted?
if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DCS, Header->GetRpt2Module()) ) if ( g_GateKeeper.MayTransmit(Header->GetMyCallsign(), Ip, PROTOCOL_DCS, Header->GetRpt2Module()) )
{ {
// handle it
OnDvHeaderPacketIn(Header, Ip); OnDvHeaderPacketIn(Header, Ip);
if ( !Frame->IsLastPacket() ) if ( !Frame->IsLastPacket() )
@ -196,17 +193,25 @@ void CDcsProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header,
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); 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 // 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 // find this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DCS);
if ( client != nullptr ) if ( client )
{ {
// get client callsign // get client callsign
via = client->GetCallsign(); rpt1 = client->GetCallsign();
// and try to open the stream // and try to open the stream
if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr )
{ {
@ -218,15 +223,9 @@ void CDcsProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header,
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
// update last heard // update last heard
g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2);
g_Reflector.ReleaseUsers(); g_Reflector.ReleaseUsers();
} }
else
{
// stream already open
// skip packet, but tickle the stream
stream->Tickle();
}
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

@ -399,17 +399,25 @@ void CDextraProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Heade
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); 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 // 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 // find this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DEXTRA); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DEXTRA);
if ( client != nullptr ) if ( client )
{ {
// get client callsign // get client callsign
via = client->GetCallsign(); rpt1 = client->GetCallsign();
// apply protocol revision details // apply protocol revision details
if ( client->GetProtocolRevision() == 2 ) if ( client->GetProtocolRevision() == 2 )
{ {
@ -428,15 +436,9 @@ void CDextraProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Heade
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
// update last heard // update last heard
g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2);
g_Reflector.ReleaseUsers(); g_Reflector.ReleaseUsers();
} }
else
{
// stream already open
// skip packet, but tickle the stream
stream->Tickle();
}
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

@ -261,22 +261,27 @@ void CDmrmmdvmProtocol::Task(void)
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
// streams helpers // streams helpers
bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, const CIp &Ip, uint8 cmd, uint8 CallType) void CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, const CIp &Ip, uint8 cmd, uint8 CallType)
{ {
bool newstream = false;
bool lastheard = false; bool lastheard = false;
//
CCallsign via(Header->GetRpt1Callsign());
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); 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 // no stream open yet, open a new one
// firstfind this client // firstfind this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRMMDVM); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRMMDVM);
if ( client != nullptr ) if ( client )
{ {
// process cmd if any // process cmd if any
if ( !client->HasReflectorModule() ) if ( !client->HasReflectorModule() )
@ -284,15 +289,15 @@ bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Hea
// not linked yet // not linked yet
if ( cmd == CMD_LINK ) 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 // link
client->SetReflectorModule(Header->GetRpt2Module()); client->SetReflectorModule(rpt2.GetModule());
} }
else 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<CDvHeaderPacket> &Hea
else else
{ {
// replace rpt2 module with currently linked module // 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 // 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 // yes, try to open the stream
if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr )
{ {
// keep the handle // keep the handle
m_Streams.push_back(stream); m_Streams.push_back(stream);
newstream = true;
lastheard = true; lastheard = true;
} }
} }
@ -336,19 +342,10 @@ bool CDmrmmdvmProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Hea
// update last heard // update last heard
if ( lastheard ) if ( lastheard )
{ {
g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2);
g_Reflector.ReleaseUsers(); g_Reflector.ReleaseUsers();
} }
} }
else
{
// stream already open
// skip packet, but tickle the stream
stream->Tickle();
}
// done
return newstream;
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

@ -81,7 +81,7 @@ protected:
void HandleKeepalives(void); void HandleKeepalives(void);
// stream helpers // stream helpers
bool OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &, const CIp &, uint8, uint8); void OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &, const CIp &, uint8, uint8);
// packet decoding helpers // packet decoding helpers
bool IsValidConnectPacket(const CBuffer &, CCallsign *, const CIp &); bool IsValidConnectPacket(const CBuffer &, CCallsign *, const CIp &);

@ -156,10 +156,6 @@ void CDmrplusProtocol::Task(void)
} }
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
} }
else
{
//std::cout << "DMRPlus packet (" << Buffer.size() << ")" << " at " << Ip << std::endl;
}
} }
// handle end of streaming timeout // handle end of streaming timeout
@ -187,12 +183,22 @@ void CDmrplusProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Head
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); 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 // no stream open yet, open a new one
// find this client // find this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRPLUS); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DMRPLUS);
if ( client != nullptr ) if ( client )
{ {
// and try to open the stream // and try to open the stream
if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr )
@ -203,17 +209,10 @@ void CDmrplusProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Head
} }
// release // release
g_Reflector.ReleaseClients(); 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();
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

@ -181,17 +181,25 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); 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 // 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 // first, check module is valid
if ( g_Reflector.IsValidModule(Header->GetRpt1Module()) ) if ( g_Reflector.IsValidModule(rpt1.GetModule()) )
{ {
// find this client // find this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_DPLUS); std::shared_ptr<CClient>client = 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 // now we know if it's a dextra dongle or a genuine dplus node
if ( Header->GetRpt2Callsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) ) if ( Header->GetRpt2Callsign().HasSameCallsignWithWildcard(CCallsign("XRF*")) )
@ -201,10 +209,10 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header
// now we know its module, let's update it // now we know its module, let's update it
if ( !client->HasModule() ) if ( !client->HasModule() )
{ {
client->SetModule(Header->GetRpt1Module()); client->SetModule(rpt1.GetModule());
} }
// get client callsign // get client callsign
via = client->GetCallsign(); rpt1 = client->GetCallsign();
// and try to open the stream // and try to open the stream
if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr )
{ {
@ -216,20 +224,14 @@ void CDplusProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
// update last heard // update last heard
g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2);
g_Reflector.ReleaseUsers(); g_Reflector.ReleaseUsers();
} }
else 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();
}
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

@ -526,10 +526,18 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, c
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId(), &Ip); 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 // 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 // find this client
CClients *clients = g_Reflector.GetClients(); CClients *clients = g_Reflector.GetClients();
@ -544,15 +552,15 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, c
} }
} }
if ( client != nullptr ) if ( client )
{ {
// move it to the proper module // 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)) if (strchr(m_Modules.c_str(), '*') || strchr(m_Modules.c_str(), new_module))
{ {
client->SetReflectorModule(new_module); client->SetReflectorModule(new_module);
@ -565,7 +573,7 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, c
} }
// get client callsign // get client callsign
via = client->GetCallsign(); rpt1 = client->GetCallsign();
// and try to open the stream // and try to open the stream
if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr )
@ -575,19 +583,13 @@ void CG3Protocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header, c
} }
// update last heard // update last heard
g_Reflector.GetUsers()->Hearing(Header->GetMyCallsign(), via, Header->GetRpt2Callsign()); g_Reflector.GetUsers()->Hearing(my, rpt1, rpt2);
g_Reflector.ReleaseUsers(); g_Reflector.ReleaseUsers();
} }
} }
// release // release
g_Reflector.ReleaseClients(); g_Reflector.ReleaseClients();
} }
else
{
// stream already open
// skip packet, but tickle the stream
stream->Tickle();
}
} }

@ -396,12 +396,21 @@ void CXlxProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header,
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); 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 // no stream open yet, open a new one
// find this client // find this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX, Header->GetRpt2Module()); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_XLX, Header->GetRpt2Module());
if ( client != nullptr ) if ( client )
{ {
// and try to open the stream // and try to open the stream
if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr ) if ( (stream = g_Reflector.OpenStream(Header, client)) != nullptr )
@ -414,17 +423,10 @@ void CXlxProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header,
} }
// release // release
g_Reflector.ReleaseClients(); 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<CDvFramePacket> &DvFrame, const CIp *Ip) void CXlxProtocol::OnDvFramePacketIn(std::unique_ptr<CDvFramePacket> &DvFrame, const CIp *Ip)

@ -227,17 +227,25 @@ void CYsfProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header,
{ {
// find the stream // find the stream
CPacketStream *stream = GetStream(Header->GetStreamId()); 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 // 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 // find this client
std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_YSF); std::shared_ptr<CClient>client = g_Reflector.GetClients()->FindClient(Ip, PROTOCOL_YSF);
if ( client != nullptr ) if ( client )
{ {
// get client callsign // get client callsign
via = client->GetCallsign(); rpt2 = client->GetCallsign();
// get module it's linked to // get module it's linked to
Header->SetRpt2Module(client->GetReflectorModule()); Header->SetRpt2Module(client->GetReflectorModule());
@ -254,16 +262,10 @@ void CYsfProtocol::OnDvHeaderPacketIn(std::unique_ptr<CDvHeaderPacket> &Header,
// update last heard // update last heard
if ( g_Reflector.IsValidModule(Header->GetRpt2Module()) ) 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(); g_Reflector.ReleaseUsers();
} }
} }
else
{
// stream already open
// skip packet, but tickle the stream
stream->Tickle();
}
} }
//////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////

Loading…
Cancel
Save

Powered by TurnKey Linux.