Page MenuHomePhabricator

D3808.diff
No OneTemporary

D3808.diff

diff --git a/services/tunnelbroker/src/Constants.h b/services/tunnelbroker/src/Constants.h
--- a/services/tunnelbroker/src/Constants.h
+++ b/services/tunnelbroker/src/Constants.h
@@ -27,7 +27,7 @@
// AMQP (RabbitMQ)
const std::string AMQP_FANOUT_EXCHANGE_NAME = "allBrokers";
-// message TTL
+// Message broker queue message TTL
const size_t AMQP_MESSAGE_TTL = 300 * 1000; // 5 min
// queue TTL in case of no consumers (tunnelbroker is down)
const size_t AMQP_QUEUE_TTL = 24 * 3600 * 1000; // 24 hours
@@ -50,6 +50,8 @@
// DeliveryBroker
const size_t DELIVERY_BROKER_MAX_QUEUE_SIZE = 100;
+// Database messages TTL
+const size_t MESSAGE_RECORD_TTL = 300 * 24 * 60 * 60; // 300 days
} // namespace network
} // namespace comm
diff --git a/services/tunnelbroker/src/Database/DatabaseManager.cpp b/services/tunnelbroker/src/Database/DatabaseManager.cpp
--- a/services/tunnelbroker/src/Database/DatabaseManager.cpp
+++ b/services/tunnelbroker/src/Database/DatabaseManager.cpp
@@ -184,7 +184,8 @@
Aws::DynamoDB::Model::AttributeValue(item.getBlobHashes()));
request.AddItem(
MessageItem::FIELD_EXPIRE,
- Aws::DynamoDB::Model::AttributeValue(std::to_string(item.getExpire())));
+ Aws::DynamoDB::Model::AttributeValue(std::to_string(
+ static_cast<size_t>(std::time(0) + MESSAGE_RECORD_TTL))));
request.AddItem(
MessageItem::FIELD_CREATED_AT,
Aws::DynamoDB::Model::AttributeValue(
diff --git a/services/tunnelbroker/src/Database/MessageItem.h b/services/tunnelbroker/src/Database/MessageItem.h
--- a/services/tunnelbroker/src/Database/MessageItem.h
+++ b/services/tunnelbroker/src/Database/MessageItem.h
@@ -46,8 +46,7 @@
const std::string fromDeviceID,
const std::string toDeviceID,
const std::string payload,
- const std::string blobHashes,
- const uint64_t expire);
+ const std::string blobHashes);
MessageItem(const AttributeValues &itemFromDB);
void assignItemFromDatabase(const AttributeValues &itemFromDB) override;
};
diff --git a/services/tunnelbroker/src/Database/MessageItem.cpp b/services/tunnelbroker/src/Database/MessageItem.cpp
--- a/services/tunnelbroker/src/Database/MessageItem.cpp
+++ b/services/tunnelbroker/src/Database/MessageItem.cpp
@@ -22,14 +22,12 @@
const std::string fromDeviceID,
const std::string toDeviceID,
const std::string payload,
- const std::string blobHashes,
- const uint64_t expire)
+ const std::string blobHashes)
: messageID(messageID),
fromDeviceID(fromDeviceID),
toDeviceID(toDeviceID),
payload(payload),
- blobHashes(blobHashes),
- expire(expire) {
+ blobHashes(blobHashes) {
this->validate();
}
@@ -45,7 +43,6 @@
throw std::runtime_error("Error: ToDeviceID format is wrong.");
}
tools::checkIfNotEmpty("messageID", this->messageID);
- tools::checkIfNotZero("expire", this->expire);
}
void MessageItem::assignItemFromDatabase(const AttributeValues &itemFromDB) {
diff --git a/services/tunnelbroker/test/DatabaseManagerTest.cpp b/services/tunnelbroker/test/DatabaseManagerTest.cpp
--- a/services/tunnelbroker/test/DatabaseManagerTest.cpp
+++ b/services/tunnelbroker/test/DatabaseManagerTest.cpp
@@ -36,8 +36,7 @@
"iGhpnX7Hp4xpBL3h2IkvGviDRQ98UvW0ugwUuPxm1NOQpjLG5dPoqQ0jrMst0Bl5rgPw"
"ajjNGsUWmp9r0ST0wRQXrQcY30PoSoqKSlCEgFMLzHWLrPQ86QFyCICismGSe7iBIqdD"
"6d37StvXBzfJoZVU79UeOF2bFvb3DNoArEOe",
- "7s6ZUSDoFfZe3eJWQ15ngYhgMw1TsfbECnMVQTYvY6OyqWPBQi5wiftFcluoxor8",
- static_cast<uint64_t>(std::time(0)) + 600);
+ "7s6ZUSDoFfZe3eJWQ15ngYhgMw1TsfbECnMVQTYvY6OyqWPBQi5wiftFcluoxor8");
const size_t currentTimestamp = tools::getCurrentTimestamp();
EXPECT_EQ(
database::DatabaseManager::getInstance().isTableAvailable(
@@ -52,7 +51,11 @@
EXPECT_EQ(item.getToDeviceID(), foundItem->getToDeviceID());
EXPECT_EQ(item.getPayload(), foundItem->getPayload());
EXPECT_EQ(item.getBlobHashes(), foundItem->getBlobHashes());
- EXPECT_EQ(item.getExpire(), foundItem->getExpire());
+ EXPECT_EQ(
+ (foundItem->getExpire() >= static_cast<size_t>(std::time(0))) &&
+ (foundItem->getExpire() <=
+ static_cast<size_t>(std::time(0) + MESSAGE_RECORD_TTL)),
+ true);
EXPECT_EQ(
foundItem->getCreatedAt() >= currentTimestamp &&
foundItem->getCreatedAt() <= tools::getCurrentTimestamp(),
@@ -67,8 +70,7 @@
"mobile:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH),
"web:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH),
tools::generateRandomString(256),
- tools::generateRandomString(256),
- static_cast<uint64_t>(std::time(0)) + 600);
+ tools::generateRandomString(256));
EXPECT_EQ(
database::DatabaseManager::getInstance().isTableAvailable(
item.getTableName()),
@@ -94,10 +96,6 @@
<< "Generated BlobHashes \"" << item.getBlobHashes()
<< "\" differs from what is found in the database "
<< foundItem->getBlobHashes();
- EXPECT_EQ(item.getExpire(), foundItem->getExpire())
- << "Generated Expire time \"" << item.getExpire()
- << "\" differs from what is found in the database "
- << foundItem->getExpire();
database::DatabaseManager::getInstance().removeMessageItem(
item.getMessageID());
}
@@ -277,8 +275,7 @@
"iGhpnX7Hp4xpBL3h2IkvGviDRQ98UvW0ugwUuPxm1NOQpjLG5dPoqQ0jrMst0Bl5rgPw"
"ajjNGsUWmp9r0ST0wRQXrQcY30PoSoqKSlCEgFMLzHWLrPQ86QFyCICismGSe7iBIqdD"
"6d37StvXBzfJoZVU79UeOF2bFvb3DNoArEOe",
- "7s6ZUSDoFfZe3eJWQ15ngYhgMw1TsfbECnMVQTYvY6OyqWPBQi5wiftFcluoxor8",
- static_cast<uint64_t>(std::time(0)) + 600);
+ "7s6ZUSDoFfZe3eJWQ15ngYhgMw1TsfbECnMVQTYvY6OyqWPBQi5wiftFcluoxor8");
EXPECT_EQ(
database::DatabaseManager::getInstance().isTableAvailable(
item.getTableName()),
@@ -292,7 +289,11 @@
EXPECT_EQ(item.getToDeviceID(), foundItems[0]->getToDeviceID());
EXPECT_EQ(item.getPayload(), foundItems[0]->getPayload());
EXPECT_EQ(item.getBlobHashes(), foundItems[0]->getBlobHashes());
- EXPECT_EQ(item.getExpire(), foundItems[0]->getExpire());
+ EXPECT_EQ(
+ (foundItems[0]->getExpire() >= static_cast<size_t>(std::time(0))) &&
+ (foundItems[0]->getExpire() <=
+ static_cast<size_t>(std::time(0) + MESSAGE_RECORD_TTL)),
+ true);
database::DatabaseManager::getInstance().removeMessageItem(
item.getMessageID());
}

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 7:04 AM (21 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2604147
Default Alt Text
D3808.diff (6 KB)

Event Timeline