better handle checking if a peer affiliation table has become invalid (null); better handle cleanup and creation of peer affiliation tables;

pull/51/head
Bryan Biedenkapp 2 years ago
parent 690bac453d
commit 94da264f55

@ -542,11 +542,7 @@ void* FNENetwork::threadedNetworkRx(void* arg)
connection->lastPing(now);
connection->currStreamId(streamId);
lookups::AffiliationLookup* affLookup = network->m_peerAffiliations[peerId];
if (affLookup != nullptr)
delete affLookup;
network->m_peerAffiliations.erase(peerId);
network->erasePeerAffiliations(peerId);
network->setupRepeaterLogin(peerId, connection);
} else {
network->writePeerNAK(peerId, TAG_REPEATER_LOGIN, NET_CONN_NAK_BAD_CONN_STATE, req->address, req->addrLen);
@ -696,7 +692,7 @@ void* FNENetwork::threadedNetworkRx(void* arg)
// setup the affiliations list for this peer
std::stringstream peerName;
peerName << "PEER " << peerId;
network->m_peerAffiliations[peerId] = new lookups::AffiliationLookup(peerName.str(), network->m_verbose);
network->createPeerAffiliations(peerId, peerName.str());
// spin up a thread and send ACL list over to peer
network->peerACLUpdate(peerId);
@ -927,9 +923,12 @@ void* FNENetwork::threadedNetworkRx(void* arg)
if (connection != nullptr) {
std::string ip = udp::Socket::address(req->address);
lookups::AffiliationLookup* aff = network->m_peerAffiliations[peerId];
if (aff == nullptr) {
LogError(LOG_NET, "PEER %u has an invalid affiliations lookup? This shouldn't happen BUGBUG.", peerId);
}
// validate peer (simple validation really)
if (connection->connected() && connection->address() == ip) {
if (connection->connected() && connection->address() == ip && aff != nullptr) {
uint32_t srcId = __GET_UINT16(req->buffer, 0U); // Source Address
uint32_t dstId = __GET_UINT16(req->buffer, 3U); // Destination Address
aff->groupUnaff(srcId);
@ -947,9 +946,12 @@ void* FNENetwork::threadedNetworkRx(void* arg)
if (connection != nullptr) {
std::string ip = udp::Socket::address(req->address);
lookups::AffiliationLookup* aff = network->m_peerAffiliations[peerId];
if (aff == nullptr) {
LogError(LOG_NET, "PEER %u has an invalid affiliations lookup? This shouldn't happen BUGBUG.", peerId);
}
// validate peer (simple validation really)
if (connection->connected() && connection->address() == ip) {
if (connection->connected() && connection->address() == ip && aff != nullptr) {
uint32_t srcId = __GET_UINT16(req->buffer, 0U); // Source Address
aff->unitReg(srcId);
}
@ -965,9 +967,12 @@ void* FNENetwork::threadedNetworkRx(void* arg)
if (connection != nullptr) {
std::string ip = udp::Socket::address(req->address);
lookups::AffiliationLookup* aff = network->m_peerAffiliations[peerId];
if (aff == nullptr) {
LogError(LOG_NET, "PEER %u has an invalid affiliations lookup? This shouldn't happen BUGBUG.", peerId);
}
// validate peer (simple validation really)
if (connection->connected() && connection->address() == ip) {
if (connection->connected() && connection->address() == ip && aff != nullptr) {
uint32_t srcId = __GET_UINT16(req->buffer, 0U); // Source Address
aff->unitDereg(srcId);
}
@ -986,19 +991,25 @@ void* FNENetwork::threadedNetworkRx(void* arg)
// validate peer (simple validation really)
if (connection->connected() && connection->address() == ip) {
lookups::AffiliationLookup* aff = network->m_peerAffiliations[peerId];
aff->clearGroupAff(0U, true);
if (aff == nullptr) {
LogError(LOG_NET, "PEER %u has an invalid affiliations lookup? This shouldn't happen BUGBUG.", peerId);
}
if (aff != nullptr) {
aff->clearGroupAff(0U, true);
// update TGID lists
uint32_t len = __GET_UINT32(req->buffer, 0U);
uint32_t offs = 4U;
for (uint32_t i = 0; i < len; i++) {
uint32_t srcId = __GET_UINT16(req->buffer, offs);
uint32_t dstId = __GET_UINT16(req->buffer, offs + 4U);
// update TGID lists
uint32_t len = __GET_UINT32(req->buffer, 0U);
uint32_t offs = 4U;
for (uint32_t i = 0; i < len; i++) {
uint32_t srcId = __GET_UINT16(req->buffer, offs);
uint32_t dstId = __GET_UINT16(req->buffer, offs + 4U);
aff->groupAff(srcId, dstId);
offs += 8U;
aff->groupAff(srcId, dstId);
offs += 8U;
}
LogMessage(LOG_NET, "PEER %u announced %u affiliations", peerId, len);
}
LogMessage(LOG_NET, "PEER %u announced %u affiliations", peerId, len);
}
else {
network->writePeerNAK(peerId, TAG_ANNOUNCE, NET_CONN_NAK_FNE_UNAUTHORIZED);
@ -1027,6 +1038,20 @@ void* FNENetwork::threadedNetworkRx(void* arg)
return nullptr;
}
/// <summary>
/// Helper to create a peer on the peers affiliations list.
/// </summary>
/// <param name="peerId"></param>
/// <param name="peerName"></param>
/// <returns></returns>
void FNENetwork::createPeerAffiliations(uint32_t peerId, std::string peerName)
{
erasePeerAffiliations(peerId);
std::lock_guard<std::mutex> lock(m_peerMutex);
m_peerAffiliations[peerId] = new lookups::AffiliationLookup(peerName, m_verbose);
}
/// <summary>
/// Helper to erase the peer from the peers affiliations list.
/// </summary>
@ -1038,8 +1063,9 @@ bool FNENetwork::erasePeerAffiliations(uint32_t peerId)
auto it = std::find_if(m_peerAffiliations.begin(), m_peerAffiliations.end(), [&](PeerAffiliationMapPair x) { return x.first == peerId; });
if (it != m_peerAffiliations.end()) {
lookups::AffiliationLookup* aff = m_peerAffiliations[peerId];
if (aff != nullptr)
delete aff;
m_peerAffiliations.erase(peerId);
delete aff;
return true;
}

@ -309,6 +309,8 @@ namespace network
/// <summary>Entry point to process a given network packet.</summary>
static void* threadedNetworkRx(void* arg);
/// <summary>Helper to create a peer on the peers affiliations list.</summary>
void createPeerAffiliations(uint32_t peerId, std::string peerName);
/// <summary>Helper to erase the peer from the peers affiliations list.</summary>
bool erasePeerAffiliations(uint32_t peerId);
/// <summary>Helper to erase the peer from the peers list.</summary>

@ -593,8 +593,14 @@ bool TagDMRData::isPeerPermitted(uint32_t peerId, data::Data& data, uint32_t str
if (tg.config().affiliated()) {
// check the affiliations for this peer to see if we can repeat traffic
lookups::AffiliationLookup* aff = m_network->m_peerAffiliations[peerId];
if (!aff->hasGroupAff(data.getDstId())) {
return false;
if (aff == nullptr) {
LogError(LOG_NET, "PEER %u has an invalid affiliations lookup? This shouldn't happen BUGBUG.", peerId);
return false; // this will cause no traffic to pass for this peer now...I'm not sure this is good behavior
}
else {
if (!aff->hasGroupAff(data.getDstId())) {
return false;
}
}
}
}

@ -426,8 +426,14 @@ bool TagNXDNData::isPeerPermitted(uint32_t peerId, lc::RTCH& lc, uint8_t message
if (tg.config().affiliated()) {
// check the affiliations for this peer to see if we can repeat traffic
lookups::AffiliationLookup* aff = m_network->m_peerAffiliations[peerId];
if (!aff->hasGroupAff(lc.getDstId())) {
return false;
if (aff == nullptr) {
LogError(LOG_NET, "PEER %u has an invalid affiliations lookup? This shouldn't happen BUGBUG.", peerId);
return false; // this will cause no traffic to pass for this peer now...I'm not sure this is good behavior
}
else {
if (!aff->hasGroupAff(lc.getDstId())) {
return false;
}
}
}
}

@ -776,8 +776,14 @@ bool TagP25Data::isPeerPermitted(uint32_t peerId, lc::LC& control, uint8_t duid,
if (tg.config().affiliated()) {
// check the affiliations for this peer to see if we can repeat traffic
lookups::AffiliationLookup* aff = m_network->m_peerAffiliations[peerId];
if (!aff->hasGroupAff(control.getDstId())) {
return false;
if (aff == nullptr) {
LogError(LOG_NET, "PEER %u has an invalid affiliations lookup? This shouldn't happen BUGBUG.", peerId);
return false; // this will cause no traffic to pass for this peer now...I'm not sure this is good behavior
}
else {
if (!aff->hasGroupAff(control.getDstId())) {
return false;
}
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.