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 @@ -185,6 +185,10 @@ request.AddItem( MessageItem::FIELD_EXPIRE, Aws::DynamoDB::Model::AttributeValue(std::to_string(item.getExpire()))); + request.AddItem( + MessageItem::FIELD_CREATED_AT, + Aws::DynamoDB::Model::AttributeValue( + std::to_string(static_cast(std::time(0))))); this->innerPutItem(std::make_shared(item), request); } 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 @@ -15,6 +15,7 @@ std::string payload; std::string blobHashes; uint64_t expire; + uint64_t createdAt; void validate() const override; @@ -25,6 +26,7 @@ static const std::string FIELD_PAYLOAD; static const std::string FIELD_BLOB_HASHES; static const std::string FIELD_EXPIRE; + static const std::string FIELD_CREATED_AT; std::string getPrimaryKey() const override; std::string getTableName() const override; @@ -34,6 +36,7 @@ std::string getPayload() const; std::string getBlobHashes() const; uint64_t getExpire() const; + uint64_t getCreatedAt() const; MessageItem() { } 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 @@ -14,6 +14,7 @@ const std::string MessageItem::FIELD_PAYLOAD = "Payload"; const std::string MessageItem::FIELD_BLOB_HASHES = "BlobHashes"; const std::string MessageItem::FIELD_EXPIRE = "Expire"; +const std::string MessageItem::FIELD_CREATED_AT = "CreatedAt"; MessageItem::MessageItem( const std::string messageID, @@ -55,6 +56,8 @@ this->payload = itemFromDB.at(MessageItem::FIELD_PAYLOAD).GetS(); this->blobHashes = itemFromDB.at(MessageItem::FIELD_BLOB_HASHES).GetS(); this->expire = std::stoull(itemFromDB.at(MessageItem::FIELD_EXPIRE).GetS()); + this->createdAt = + std::stoull(itemFromDB.at(MessageItem::FIELD_CREATED_AT).GetS()); } catch (const std::exception &e) { throw std::runtime_error( "Got an exception at MessageItem: " + std::string(e.what())); @@ -95,6 +98,10 @@ return this->expire; } +uint64_t MessageItem::getCreatedAt() const { + return this->createdAt; +} + } // namespace database } // namespace network } // namespace comm