aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Finrod Felagund <finrod.felagund.97@gmail.com>2024-04-15 22:26:34 +0200
committerLibravatar Finrod Felagund <finrod.felagund.97@gmail.com>2024-04-16 16:57:00 +0200
commit4b66a41aff99ef5f7c72f46171dbdf6605c240b4 (patch)
tree35aabe02bae14d819d7a33fd02ef99a48ac8c52c
parent357b6813b908c3f9b272243c9e99a5bc1b442c89 (diff)
use uuid_v4 to generate faster UUIDs than Boost
-rw-r--r--CMakeLists.txt18
-rw-r--r--src/nostr_service.cpp19
2 files changed, 21 insertions, 16 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4e46b70..0610f3f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,14 +5,22 @@ project(NostrSDK VERSION 0.0.1)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
+set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/bin/)
+set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/lib/)
+set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/out/${CMAKE_BUILD_TYPE}/lib/)
+
+if(DEFINED ENV{WORKSPACE})
+ list(APPEND CMAKE_PREFIX_PATH $ENV{WORKSPACE}/env/uuid_v4)
+else()
+ list(APPEND CMAKE_PREFIX_PATH ../env/uuid_v4)
+endif()
# Build the project.
set(INCLUDE_DIR ./include)
set(CLIENT_INCLUDE_DIR ./include/client)
include_directories(${INCLUDE_DIR})
include_directories(${CLIENT_INCLUDE_DIR})
+
set(HEADERS
${INCLUDE_DIR}/nostr.hpp
${CLIENT_INCLUDE_DIR}/web_socket_client.hpp
@@ -27,21 +35,20 @@ set(SOURCES
${CLIENT_SOURCE_DIR}/websocketpp_client.cpp
)
-find_package(Boost REQUIRED COMPONENTS random system)
find_package(nlohmann_json CONFIG REQUIRED)
+find_package(uuid_v4 REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(plog CONFIG REQUIRED)
find_package(websocketpp CONFIG REQUIRED)
add_library(NostrSDK ${SOURCES} ${HEADERS})
target_link_libraries(NostrSDK PRIVATE
- Boost::random
- Boost::system
nlohmann_json::nlohmann_json
OpenSSL::SSL
OpenSSL::Crypto
plog::plog
websocketpp::websocketpp
+ uuid_v4::uuid_v4
)
set_target_properties(NostrSDK PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
@@ -73,6 +80,7 @@ target_link_libraries(NostrSDKTest PRIVATE
NostrSDK
plog::plog
websocketpp::websocketpp
+ uuid_v4::uuid_v4
)
set_target_properties(NostrSDKTest PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
diff --git a/src/nostr_service.cpp b/src/nostr_service.cpp
index 3dbff62..3a59fa6 100644
--- a/src/nostr_service.cpp
+++ b/src/nostr_service.cpp
@@ -1,19 +1,15 @@
#include <algorithm>
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
-#include <boost/uuid/uuid_io.hpp>
+
#include <nlohmann/json.hpp>
#include <plog/Init.h>
#include <plog/Log.h>
#include <websocketpp/client.hpp>
#include <websocketpp/config/asio_client.hpp>
+#include <uuid_v4/uuid_v4.h>
#include "nostr.hpp"
#include "client/web_socket_client.hpp"
-using boost::uuids::random_generator;
-using boost::uuids::to_string;
-using boost::uuids::uuid;
using nlohmann::json;
using std::async;
using std::exception;
@@ -49,7 +45,7 @@ NostrService::NostrService(
shared_ptr<ISigner> signer,
RelayList relays)
: _defaultRelays(relays), _client(client), _signer(signer)
-{
+{
plog::init(plog::debug, appender.get());
client->start();
};
@@ -178,7 +174,7 @@ tuple<RelayList, RelayList> NostrService::publishEvent(shared_ptr<Event> event)
}
});
});
-
+
if (!success)
{
PLOG_WARNING << "Failed to send event to relay: " << relay;
@@ -288,7 +284,7 @@ string NostrService::queryRelays(
for (const string relay : this->_activeRelays)
{
this->_subscriptions[relay].push_back(subscriptionId);
-
+
promise<tuple<string, bool>> requestPromise;
requestFutures.push_back(move(requestPromise.get_future()));
future<tuple<string, bool>> requestFuture = async(
@@ -517,8 +513,9 @@ void NostrService::disconnect(string relay)
string NostrService::generateSubscriptionId()
{
- uuid uuid = random_generator()();
- return to_string(uuid);
+ UUIDv4::UUIDGenerator<std::mt19937_64> uuidGenerator;
+ UUIDv4::UUID uuid = uuidGenerator.getUUID();
+ return uuid.bytes();
};
string NostrService::generateCloseRequest(string subscriptionId)