Page MenuHomePhabricator

D3239.id9758.diff
No OneTemporary

D3239.id9758.diff

diff --git a/services/tunnelbroker/docker-server/contents/server/src/Database/DatabaseManager.h b/services/tunnelbroker/docker-server/contents/server/src/Database/DatabaseManager.h
--- a/services/tunnelbroker/docker-server/contents/server/src/Database/DatabaseManager.h
+++ b/services/tunnelbroker/docker-server/contents/server/src/Database/DatabaseManager.h
@@ -13,6 +13,7 @@
#include <aws/dynamodb/model/DescribeTableResult.h>
#include <aws/dynamodb/model/GetItemRequest.h>
#include <aws/dynamodb/model/PutItemRequest.h>
+#include <aws/dynamodb/model/QueryRequest.h>
#include <memory>
#include <string>
@@ -50,6 +51,8 @@
void putMessageItem(const MessageItem &item);
std::shared_ptr<MessageItem> findMessageItem(const std::string &messageID);
+ std::vector<std::shared_ptr<MessageItem>>
+ findMessageItemsByReceiever(const std::string &toDeviceID);
void removeMessageItem(const std::string &messageID);
};
diff --git a/services/tunnelbroker/docker-server/contents/server/src/Database/DatabaseManager.cpp b/services/tunnelbroker/docker-server/contents/server/src/Database/DatabaseManager.cpp
--- a/services/tunnelbroker/docker-server/contents/server/src/Database/DatabaseManager.cpp
+++ b/services/tunnelbroker/docker-server/contents/server/src/Database/DatabaseManager.cpp
@@ -193,6 +193,34 @@
return std::move(this->innerFindItem<MessageItem>(request));
}
+std::vector<std::shared_ptr<MessageItem>>
+DatabaseManager::findMessageItemsByReceiever(const std::string &toDeviceID) {
+ std::vector<std::shared_ptr<MessageItem>> result;
+
+ Aws::DynamoDB::Model::QueryRequest req;
+ req.SetTableName(MessageItem().getTableName());
+ req.SetKeyConditionExpression(
+ MessageItem::FIELD_TO_DEVICE_ID + " = :valueToMatch");
+
+ AttributeValues attributeValues;
+ attributeValues.emplace(":valueToMatch", toDeviceID);
+
+ req.SetExpressionAttributeValues(attributeValues);
+ req.SetIndexName("toDeviceID-index");
+
+ const Aws::DynamoDB::Model::QueryOutcome &outcome =
+ getDynamoDBClient()->Query(req);
+ if (!outcome.IsSuccess()) {
+ throw std::runtime_error(outcome.GetError().GetMessage());
+ }
+ const Aws::Vector<AttributeValues> &items = outcome.GetResult().GetItems();
+ for (auto &item : items) {
+ result.push_back(std::make_shared<MessageItem>(item));
+ }
+
+ return result;
+}
+
void DatabaseManager::removeMessageItem(const std::string &messageID) {
this->innerRemoveItem(*(createItemByType<MessageItem>()), messageID);
}

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 3:12 PM (3 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2612142
Default Alt Text
D3239.id9758.diff (2 KB)

Event Timeline