treat every one-shot subscriber operation as a unique event regardless of retained history, update the operation store contract, and add regression coverage for repeated occurrences;

r05a06_dev
Bryan Biedenkapp 8 hours ago
parent 7a5fac134b
commit b387e70bbd

@ -38,7 +38,7 @@ SubscriberOperationStore::SubscriberOperationStore() :
/* Starts a uniquely correlatable operation. */
uint64_t SubscriberOperationStore::start(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId, uint16_t requestValue)
uint64_t SubscriberOperationStore::start(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId, uint32_t requestValue)
{
const auto now = std::chrono::steady_clock::now();
std::lock_guard<std::mutex> lock(m_mutex);
@ -68,7 +68,7 @@ uint64_t SubscriberOperationStore::start(Protocol protocol, Kind kind, uint32_t
/* Completes the matching active operation. */
bool SubscriberOperationStore::complete(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId,
uint16_t resultValue, bool success)
uint32_t resultValue, bool success)
{
const auto now = std::chrono::steady_clock::now();
std::lock_guard<std::mutex> lock(m_mutex);
@ -96,20 +96,13 @@ bool SubscriberOperationStore::complete(Protocol protocol, Kind kind, uint32_t t
/* Adds a uniquely correlatable one-shot operation. */
uint64_t SubscriberOperationStore::oneShot(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId, uint16_t requestValue)
uint64_t SubscriberOperationStore::oneShot(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId, uint32_t requestValue,
uint32_t resultValue)
{
const auto now = std::chrono::steady_clock::now();
std::lock_guard<std::mutex> lock(m_mutex);
expireLocked(now);
// suppress an equivalent one-shot while its result remains available
for (const auto& entry : m_operations) {
const Operation& operation = entry.second.value;
if (operation.protocol == protocol && operation.kind == kind && operation.targetId == targetId) {
return 0U;
}
}
// create a new operation with a unique ID and store it with expiration times
uint64_t id = m_nextId++;
if (id == 0U) {
@ -117,7 +110,7 @@ uint64_t SubscriberOperationStore::oneShot(Protocol protocol, Kind kind, uint32_
}
const uint64_t createdAt = unixMilliseconds();
Operation operation { id, protocol, kind, State::SUCCEEDED, targetId, peerId, requestValue, 0U, createdAt, createdAt };
Operation operation { id, protocol, kind, State::SUCCEEDED, targetId, peerId, requestValue, resultValue, createdAt, createdAt };
m_operations.emplace(id, StoredOperation { operation, now + OPERATION_TIMEOUT, now + RESULT_RETENTION });
return id;
}

@ -95,8 +95,8 @@ namespace network
State state; //!< Current lifecycle state.
uint32_t targetId; //!< Target subscriber ID.
uint32_t peerId; //!< Requested or responding peer ID.
uint16_t requestValue; //!< Optional requested status/message value.
uint16_t resultValue; //!< Optional returned status value.
uint32_t requestValue; //!< Optional requested status/message value.
uint32_t resultValue; //!< Optional returned status value.
uint64_t createdAt; //!< Creation time in Unix milliseconds.
uint64_t completedAt; //!< Completion time in Unix milliseconds, or zero.
};
@ -127,7 +127,7 @@ namespace network
* @param[in] requestValue Optional requested value.
* @returns Operation identifier, or zero when an equivalent request is already pending.
*/
uint64_t start(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId, uint16_t requestValue = 0U);
uint64_t start(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId, uint32_t requestValue = 0U);
/**
* @brief Completes the matching active operation.
@ -140,7 +140,7 @@ namespace network
* @returns bool True when an active operation was completed.
*/
bool complete(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId,
uint16_t resultValue = 0U, bool success = true);
uint32_t resultValue = 0U, bool success = true);
/**
* @brief Adds a uniquely correlatable one-shot operation.
@ -149,9 +149,11 @@ namespace network
* @param[in] targetId Target subscriber ID.
* @param[in] peerId Requested peer ID, or zero for routed fanout.
* @param[in] requestValue Optional requested value.
* @returns Operation identifier, or zero when an equivalent request is already pending.
* @param[in] resultValue Optional returned value.
* @returns Unique operation identifier.
*/
uint64_t oneShot(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId, uint16_t requestValue = 0U);
uint64_t oneShot(Protocol protocol, Kind kind, uint32_t targetId, uint32_t peerId, uint32_t requestValue = 0U,
uint32_t resultValue = 0U);
/**
* @brief Adds a status report and completes a matching P25 status query.

@ -42,7 +42,7 @@ void MetadataNetwork::PacketHandler::announce(TrafficNetwork* network, MetadataN
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->subscriberOperations().oneShot(SubscriberOperationStore::Protocol::SYSTEM, SubscriberOperationStore::Kind::GRP_AFFIL, srcId, peerId, (uint16_t)dstId); // this is bugged and will truncate 24-bit TGIDs
network->subscriberOperations().oneShot(SubscriberOperationStore::Protocol::SYSTEM, SubscriberOperationStore::Kind::GRP_AFFIL, srcId, peerId, 0U, dstId);
// update group affiliation only for non-replica peers
if (!connection->isReplica())

@ -84,7 +84,7 @@ TEST_CASE("FNE subscriber operations return recent history newest first", "[fne]
CHECK(store.getLast(0U).empty());
}
TEST_CASE("FNE subscriber one-shot operations suppress retained duplicates", "[fne][subscriber-operations]")
TEST_CASE("FNE subscriber one-shot operations retain every occurrence", "[fne][subscriber-operations]")
{
SubscriberOperationStore store;
const uint32_t targetId = 0x2345U;
@ -92,10 +92,14 @@ TEST_CASE("FNE subscriber one-shot operations suppress retained duplicates", "[f
SubscriberOperationStore::Kind::EMERG_CALL, targetId, 42U);
REQUIRE(operationId != 0U);
CHECK(store.oneShot(SubscriberOperationStore::Protocol::NXDN,
SubscriberOperationStore::Kind::EMERG_CALL, targetId, 42U) == 0U);
CHECK(store.oneShot(SubscriberOperationStore::Protocol::NXDN,
SubscriberOperationStore::Kind::EMERG_CALL, targetId, 43U) == 0U);
const uint64_t duplicateId = store.oneShot(SubscriberOperationStore::Protocol::NXDN,
SubscriberOperationStore::Kind::EMERG_CALL, targetId, 42U);
const uint64_t otherPeerId = store.oneShot(SubscriberOperationStore::Protocol::NXDN,
SubscriberOperationStore::Kind::EMERG_CALL, targetId, 43U);
CHECK(duplicateId != 0U);
CHECK(duplicateId != operationId);
CHECK(otherPeerId != 0U);
CHECK(otherPeerId != duplicateId);
CHECK(store.oneShot(SubscriberOperationStore::Protocol::DMR,
SubscriberOperationStore::Kind::EMERG_CALL, targetId, 42U) != 0U);

Loading…
Cancel
Save

Powered by TurnKey Linux.