|
|
|
|
@ -40,21 +40,15 @@ void MetadataNetwork::PacketHandler::announce(TrafficNetwork* network, MetadataN
|
|
|
|
|
|
|
|
|
|
// validate peer (simple validation really)
|
|
|
|
|
if (connection->connected() && connection->address() == ip && aff != nullptr) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, 0U); // Source Address
|
|
|
|
|
uint32_t dstId = GET_UINT24(req->buffer, 3U); // Destination Address
|
|
|
|
|
aff->groupUnaff(srcId);
|
|
|
|
|
aff->groupAff(srcId, dstId);
|
|
|
|
|
|
|
|
|
|
// attempt to repeat traffic to replica masters
|
|
|
|
|
if (network->m_host->m_peerNetworks.size() > 0) {
|
|
|
|
|
for (auto& peer : network->m_host->m_peerNetworks) {
|
|
|
|
|
if (peer.second != nullptr) {
|
|
|
|
|
if (peer.second->isEnabled() && peer.second->isReplica()) {
|
|
|
|
|
peer.second->writeMaster({ NET_FUNC::ANNOUNCE, NET_SUBFUNC::ANNC_SUBFUNC_GRP_AFFIL },
|
|
|
|
|
req->buffer, req->length, req->rtpHeader.getSequence(), streamId, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req->length >= static_cast<int>(MSG_ANNC_GRP_AFFIL)) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, 0U); // Source Address
|
|
|
|
|
uint32_t dstId = GET_UINT24(req->buffer, 3U); // Destination Address
|
|
|
|
|
network->updatePeerAffiliation(peerId, srcId, dstId);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LogWarning(LOG_MASTER, "PEER %u (%s) announced malformed group affiliation, length = %u",
|
|
|
|
|
peerId, connection->identWithQualifier().c_str(), req->length);
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
@ -77,20 +71,14 @@ void MetadataNetwork::PacketHandler::announce(TrafficNetwork* network, MetadataN
|
|
|
|
|
|
|
|
|
|
// validate peer (simple validation really)
|
|
|
|
|
if (connection->connected() && connection->address() == ip && aff != nullptr) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, 0U); // Source Address
|
|
|
|
|
aff->unitReg(srcId, ssrc);
|
|
|
|
|
network->m_globalAff->unitReg(srcId, ssrc);
|
|
|
|
|
|
|
|
|
|
// attempt to repeat traffic to replica masters
|
|
|
|
|
if (network->m_host->m_peerNetworks.size() > 0) {
|
|
|
|
|
for (auto& peer : network->m_host->m_peerNetworks) {
|
|
|
|
|
if (peer.second != nullptr) {
|
|
|
|
|
if (peer.second->isEnabled() && peer.second->isReplica()) {
|
|
|
|
|
peer.second->writeMaster({ NET_FUNC::ANNOUNCE, NET_SUBFUNC::ANNC_SUBFUNC_UNIT_REG },
|
|
|
|
|
req->buffer, req->length, req->rtpHeader.getSequence(), streamId, true, 0U, ssrc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req->length >= static_cast<int>(MSG_ANNC_UNIT_REG)) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, 0U); // Source Address
|
|
|
|
|
network->updatePeerUnitRegistration(peerId, srcId, ssrc);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LogWarning(LOG_MASTER, "PEER %u (%s) announced malformed unit registration, length = %u",
|
|
|
|
|
peerId, connection->identWithQualifier().c_str(), req->length);
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
@ -112,20 +100,14 @@ void MetadataNetwork::PacketHandler::announce(TrafficNetwork* network, MetadataN
|
|
|
|
|
|
|
|
|
|
// validate peer (simple validation really)
|
|
|
|
|
if (connection->connected() && connection->address() == ip && aff != nullptr) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, 0U); // Source Address
|
|
|
|
|
aff->unitDereg(srcId);
|
|
|
|
|
network->m_globalAff->unitDereg(srcId);
|
|
|
|
|
|
|
|
|
|
// attempt to repeat traffic to replica masters
|
|
|
|
|
if (network->m_host->m_peerNetworks.size() > 0) {
|
|
|
|
|
for (auto& peer : network->m_host->m_peerNetworks) {
|
|
|
|
|
if (peer.second != nullptr) {
|
|
|
|
|
if (peer.second->isEnabled() && peer.second->isReplica()) {
|
|
|
|
|
peer.second->writeMaster({ NET_FUNC::ANNOUNCE, NET_SUBFUNC::ANNC_SUBFUNC_UNIT_DEREG },
|
|
|
|
|
req->buffer, req->length, req->rtpHeader.getSequence(), streamId, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req->length >= static_cast<int>(MSG_ANNC_UNIT_REG)) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, 0U); // Source Address
|
|
|
|
|
network->removePeerUnitRegistration(peerId, srcId);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LogWarning(LOG_MASTER, "PEER %u (%s) announced malformed unit deregistration, length = %u",
|
|
|
|
|
peerId, connection->identWithQualifier().c_str(), req->length);
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
@ -148,20 +130,14 @@ void MetadataNetwork::PacketHandler::announce(TrafficNetwork* network, MetadataN
|
|
|
|
|
|
|
|
|
|
// validate peer (simple validation really)
|
|
|
|
|
if (connection->connected() && connection->address() == ip && aff != nullptr) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, 0U); // Source Address
|
|
|
|
|
aff->groupUnaff(srcId);
|
|
|
|
|
network->m_globalAff->groupUnaff(srcId);
|
|
|
|
|
|
|
|
|
|
// attempt to repeat traffic to replica masters
|
|
|
|
|
if (network->m_host->m_peerNetworks.size() > 0) {
|
|
|
|
|
for (auto& peer : network->m_host->m_peerNetworks) {
|
|
|
|
|
if (peer.second != nullptr) {
|
|
|
|
|
if (peer.second->isEnabled() && peer.second->isReplica()) {
|
|
|
|
|
peer.second->writeMaster({ NET_FUNC::ANNOUNCE, NET_SUBFUNC::ANNC_SUBFUNC_GRP_UNAFFIL },
|
|
|
|
|
req->buffer, req->length, req->rtpHeader.getSequence(), streamId, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (req->length >= static_cast<int>(MSG_ANNC_GRP_UNAFFIL)) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, 0U); // Source Address
|
|
|
|
|
network->removePeerAffiliation(peerId, srcId);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
LogWarning(LOG_MASTER, "PEER %u (%s) announced malformed group unaffiliation, length = %u",
|
|
|
|
|
peerId, connection->identWithQualifier().c_str(), req->length);
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
@ -185,33 +161,33 @@ void MetadataNetwork::PacketHandler::announce(TrafficNetwork* network, MetadataN
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aff != nullptr) {
|
|
|
|
|
aff->clearGroupAff(0U, true);
|
|
|
|
|
if (aff != nullptr && req->length >= 4) {
|
|
|
|
|
const uint32_t len = GET_UINT32(req->buffer, 0U);
|
|
|
|
|
const uint32_t availableEntries = (static_cast<uint32_t>(req->length) - 4U) / 8U;
|
|
|
|
|
if (len != availableEntries || static_cast<uint32_t>(req->length) != 4U + (len * 8U)) {
|
|
|
|
|
LogWarning(LOG_MASTER, "PEER %u (%s) announced malformed affiliations, count = %u, length = %u",
|
|
|
|
|
peerId, connection->identWithQualifier().c_str(), len, req->length);
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update TGID lists
|
|
|
|
|
uint32_t len = GET_UINT32(req->buffer, 0U);
|
|
|
|
|
std::unordered_map<uint32_t, uint32_t> affiliations;
|
|
|
|
|
affiliations.reserve(len);
|
|
|
|
|
uint32_t offs = 4U;
|
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, offs);
|
|
|
|
|
uint32_t dstId = GET_UINT24(req->buffer, offs + 4U);
|
|
|
|
|
|
|
|
|
|
aff->groupAff(srcId, dstId);
|
|
|
|
|
network->m_globalAff->groupAff(srcId, dstId);
|
|
|
|
|
for (uint32_t i = 0U; i < len; i++) {
|
|
|
|
|
const uint32_t srcId = GET_UINT24(req->buffer, offs);
|
|
|
|
|
const uint32_t dstId = GET_UINT24(req->buffer, offs + 4U);
|
|
|
|
|
affiliations[srcId] = dstId;
|
|
|
|
|
offs += 8U;
|
|
|
|
|
}
|
|
|
|
|
LogInfoEx(LOG_MASTER, "PEER %u (%s) announced %u affiliations", peerId, connection->identWithQualifier().c_str(), len);
|
|
|
|
|
|
|
|
|
|
// attempt to repeat traffic to replica masters
|
|
|
|
|
if (network->m_host->m_peerNetworks.size() > 0) {
|
|
|
|
|
for (auto& peer : network->m_host->m_peerNetworks) {
|
|
|
|
|
if (peer.second != nullptr) {
|
|
|
|
|
if (peer.second->isEnabled() && peer.second->isReplica()) {
|
|
|
|
|
peer.second->writeMaster({ NET_FUNC::ANNOUNCE, NET_SUBFUNC::ANNC_SUBFUNC_AFFILS },
|
|
|
|
|
req->buffer, req->length, req->rtpHeader.getSequence(), streamId, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
network->replacePeerAffiliations(peerId, affiliations);
|
|
|
|
|
LogInfoEx(LOG_MASTER, "PEER %u (%s) announced %u affiliations", peerId, connection->identWithQualifier().c_str(), len);
|
|
|
|
|
}
|
|
|
|
|
else if (aff != nullptr) {
|
|
|
|
|
LogWarning(LOG_MASTER, "PEER %u (%s) announced malformed affiliations, length = %u",
|
|
|
|
|
peerId, connection->identWithQualifier().c_str(), req->length);
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
@ -235,32 +211,32 @@ void MetadataNetwork::PacketHandler::announce(TrafficNetwork* network, MetadataN
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aff != nullptr) {
|
|
|
|
|
aff->clearUnitReg();
|
|
|
|
|
if (aff != nullptr && req->length >= 4) {
|
|
|
|
|
const uint32_t len = GET_UINT32(req->buffer, 0U);
|
|
|
|
|
const uint32_t availableEntries = (static_cast<uint32_t>(req->length) - 4U) / 3U;
|
|
|
|
|
if (len != availableEntries || static_cast<uint32_t>(req->length) != 4U + (len * 3U)) {
|
|
|
|
|
LogWarning(LOG_MASTER, "PEER %u (%s) announced malformed unit registrations, count = %u, length = %u",
|
|
|
|
|
peerId, connection->identWithQualifier().c_str(), len, req->length);
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// update unit registration lists
|
|
|
|
|
uint32_t len = GET_UINT32(req->buffer, 0U);
|
|
|
|
|
std::vector<uint32_t> registrations;
|
|
|
|
|
registrations.reserve(len);
|
|
|
|
|
uint32_t offs = 4U;
|
|
|
|
|
for (uint32_t i = 0; i < len; i++) {
|
|
|
|
|
uint32_t srcId = GET_UINT24(req->buffer, offs);
|
|
|
|
|
|
|
|
|
|
aff->unitReg(srcId, ssrc);
|
|
|
|
|
network->m_globalAff->unitReg(srcId, ssrc);
|
|
|
|
|
for (uint32_t i = 0U; i < len; i++) {
|
|
|
|
|
const uint32_t srcId = GET_UINT24(req->buffer, offs);
|
|
|
|
|
registrations.push_back(srcId);
|
|
|
|
|
offs += 3U;
|
|
|
|
|
}
|
|
|
|
|
LogInfoEx(LOG_MASTER, "PEER %u (%s) announced %u unit registrations", peerId, connection->identWithQualifier().c_str(), len);
|
|
|
|
|
|
|
|
|
|
// attempt to repeat traffic to replica masters
|
|
|
|
|
if (network->m_host->m_peerNetworks.size() > 0) {
|
|
|
|
|
for (auto& peer : network->m_host->m_peerNetworks) {
|
|
|
|
|
if (peer.second != nullptr) {
|
|
|
|
|
if (peer.second->isEnabled() && peer.second->isReplica()) {
|
|
|
|
|
peer.second->writeMaster({ NET_FUNC::ANNOUNCE, NET_SUBFUNC::ANNC_SUBFUNC_UNIT_REGS },
|
|
|
|
|
req->buffer, req->length, req->rtpHeader.getSequence(), streamId, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
network->replacePeerUnitRegistrations(peerId, registrations, ssrc);
|
|
|
|
|
LogInfoEx(LOG_MASTER, "PEER %u (%s) announced %u unit registrations", peerId, connection->identWithQualifier().c_str(), len);
|
|
|
|
|
}
|
|
|
|
|
else if (aff != nullptr) {
|
|
|
|
|
LogWarning(LOG_MASTER, "PEER %u (%s) announced malformed unit registrations, length = %u",
|
|
|
|
|
peerId, connection->identWithQualifier().c_str(), req->length);
|
|
|
|
|
network->writePeerNAK(peerId, streamId, TAG_ANNOUNCE, NET_CONN_NAK_INVALID);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|