Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3531082
D4027.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D4027.diff
View Options
diff --git a/services/lib/src/GlobalTools.h b/services/lib/src/GlobalTools.h
--- a/services/lib/src/GlobalTools.h
+++ b/services/lib/src/GlobalTools.h
@@ -14,5 +14,7 @@
bool isDevMode();
+std::string generateUUID();
+
} // namespace network
} // namespace comm
diff --git a/services/lib/src/GlobalTools.cpp b/services/lib/src/GlobalTools.cpp
--- a/services/lib/src/GlobalTools.cpp
+++ b/services/lib/src/GlobalTools.cpp
@@ -1,6 +1,9 @@
#include "GlobalTools.h"
#include <openssl/sha.h>
+#include <boost/uuid/uuid.hpp>
+#include <boost/uuid/uuid_generators.hpp>
+#include <boost/uuid/uuid_io.hpp>
#include <chrono>
#include <iomanip>
@@ -34,5 +37,10 @@
return hasEnvFlag("COMM_SERVICES_DEV_MODE");
}
+std::string generateUUID() {
+ thread_local boost::uuids::random_generator random_generator;
+ return boost::uuids::to_string(random_generator());
+}
+
} // namespace network
} // namespace comm
diff --git a/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.cpp b/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.cpp
--- a/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.cpp
+++ b/services/tunnelbroker/src/Service/TunnelbrokerServiceImpl.cpp
@@ -5,6 +5,7 @@
#include "CryptoTools.h"
#include "DatabaseManager.h"
#include "DeliveryBroker.h"
+#include "GlobalTools.h"
#include "Tools.h"
#include <glog/logging.h>
@@ -76,7 +77,7 @@
}
const std::string signature = request->signature();
const std::string publicKey = request->publickey();
- const std::string newSessionID = tools::generateUUID();
+ const std::string newSessionID = generateUUID();
try {
sessionSignItem =
database::DatabaseManager::getInstance().findSessionSignItem(deviceID);
@@ -152,7 +153,7 @@
"No such session found. SessionID: " + sessionID);
}
const std::string clientDeviceID = sessionItem->getDeviceID();
- const std::string messageID = tools::generateUUID();
+ const std::string messageID = generateUUID();
if (!AmqpManager::getInstance().send(
messageID,
clientDeviceID,
diff --git a/services/tunnelbroker/src/Tools/Tools.h b/services/tunnelbroker/src/Tools/Tools.h
--- a/services/tunnelbroker/src/Tools/Tools.h
+++ b/services/tunnelbroker/src/Tools/Tools.h
@@ -10,7 +10,6 @@
std::string generateRandomString(std::size_t length);
int64_t getCurrentTimestamp();
bool validateDeviceID(std::string deviceID);
-std::string generateUUID();
bool validateSessionID(std::string sessionID);
void checkIfNotEmpty(std::string fieldName, std::string stringToCheck);
void checkIfNotZero(std::string fieldName, uint64_t numberToCheck);
diff --git a/services/tunnelbroker/src/Tools/Tools.cpp b/services/tunnelbroker/src/Tools/Tools.cpp
--- a/services/tunnelbroker/src/Tools/Tools.cpp
+++ b/services/tunnelbroker/src/Tools/Tools.cpp
@@ -4,9 +4,6 @@
#include <glog/logging.h>
#include <boost/lexical_cast.hpp>
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
-#include <boost/uuid/uuid_io.hpp>
#include <chrono>
#include <iostream>
@@ -52,11 +49,6 @@
}
}
-std::string generateUUID() {
- thread_local boost::uuids::random_generator random_generator;
- return boost::uuids::to_string(random_generator());
-}
-
bool validateSessionID(std::string sessionID) {
try {
return std::regex_match(sessionID, SESSION_ID_FORMAT_REGEX);
diff --git a/services/tunnelbroker/test/AmqpManagerTest.cpp b/services/tunnelbroker/test/AmqpManagerTest.cpp
--- a/services/tunnelbroker/test/AmqpManagerTest.cpp
+++ b/services/tunnelbroker/test/AmqpManagerTest.cpp
@@ -2,6 +2,7 @@
#include "ConfigManager.h"
#include "Constants.h"
#include "DeliveryBroker.h"
+#include "GlobalTools.h"
#include "Tools.h"
#include <gtest/gtest.h>
@@ -47,7 +48,7 @@
}
TEST_F(AmqpManagerTest, SentAndPopedMessagesAreSameOnGeneratedData) {
- const std::string messageID = tools::generateUUID();
+ const std::string messageID = generateUUID();
const std::string toDeviceID =
"mobile:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH);
const std::string fromDeviceID =
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
@@ -1,6 +1,7 @@
#include "DatabaseManager.h"
#include "ConfigManager.h"
#include "Constants.h"
+#include "GlobalTools.h"
#include "Tools.h"
#include <gtest/gtest.h>
@@ -66,7 +67,7 @@
TEST_F(DatabaseManagerTest, PutAndFoundMessageItemsGeneratedDataIsSame) {
const database::MessageItem item(
- tools::generateUUID(),
+ generateUUID(),
"mobile:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH),
"web:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH),
tools::generateRandomString(256),
diff --git a/services/tunnelbroker/test/DeliveryBrokerTest.cpp b/services/tunnelbroker/test/DeliveryBrokerTest.cpp
--- a/services/tunnelbroker/test/DeliveryBrokerTest.cpp
+++ b/services/tunnelbroker/test/DeliveryBrokerTest.cpp
@@ -1,4 +1,5 @@
#include "DeliveryBroker.h"
+#include "GlobalTools.h"
#include "Tools.h"
#include <gtest/gtest.h>
@@ -46,7 +47,7 @@
const std::string toDeviceID =
"mobile:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH);
const DeliveryBrokerMessage message{
- .messageID = tools::generateUUID(),
+ .messageID = generateUUID(),
.deliveryTag = static_cast<uint64_t>(std::time(0)),
.fromDeviceID =
"mobile:" + tools::generateRandomString(DEVICEID_CHAR_LENGTH),
diff --git a/services/tunnelbroker/test/ToolsTest.cpp b/services/tunnelbroker/test/ToolsTest.cpp
--- a/services/tunnelbroker/test/ToolsTest.cpp
+++ b/services/tunnelbroker/test/ToolsTest.cpp
@@ -1,5 +1,6 @@
#include "Tools.h"
#include "Constants.h"
+#include "GlobalTools.h"
#include <gtest/gtest.h>
@@ -58,7 +59,7 @@
}
TEST(ToolsTest, ValidateSessionIDReturnsTrueOnValidGeneratedSessionID) {
- const std::string validSessionID = tools::generateUUID();
+ const std::string validSessionID = generateUUID();
EXPECT_EQ(tools::validateSessionID(validSessionID), true)
<< "Valid generated sessionID \"" << validSessionID
<< "\" is invalid by the function";
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 26, 5:50 AM (42 m, 36 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2704007
Default Alt Text
D4027.diff (6 KB)
Attached To
Mode
D4027: [services] Move generateUUID to global tools
Attached
Detach File
Event Timeline
Log In to Comment