From 63ecf6b0b504b4af8c1d1ede66f15206d09098fa Mon Sep 17 00:00:00 2001 From: Finrod Felagund Date: Mon, 15 Apr 2024 22:24:49 +0200 Subject: [PATCH 1/5] configure vcpkg build --- CMakePresets.json | 13 +++++++++++++ vcpkg-configuration.json | 14 ++++++++++++++ vcpkg.json | 8 ++++++++ 3 files changed, 35 insertions(+) create mode 100644 CMakePresets.json create mode 100644 vcpkg-configuration.json create mode 100644 vcpkg.json diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..8c57178 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,13 @@ +{ + "version": 2, + "configurePresets": [ + { + "name": "default", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + } + } + ] + } \ No newline at end of file diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json new file mode 100644 index 0000000..850abfe --- /dev/null +++ b/vcpkg-configuration.json @@ -0,0 +1,14 @@ +{ + "default-registry": { + "kind": "git", + "baseline": "582a4de14bef91df217f4f49624cf5b2b04bd7ca", + "repository": "https://github.com/microsoft/vcpkg" + }, + "registries": [ + { + "kind": "artifact", + "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip", + "name": "microsoft" + } + ] +} diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..579ca88 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,8 @@ +{ + "dependencies": [ + "nlohmann-json", + "openssl", + "plog", + "websocketpp" + ] +} From 03377747e9f37f19365aa2d620f1e7cea0654656 Mon Sep 17 00:00:00 2001 From: Finrod Felagund Date: Mon, 15 Apr 2024 22:26:02 +0200 Subject: [PATCH 2/5] fix include sha.h --- src/event.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/event.cpp b/src/event.cpp index 347065c..2df1c3a 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "nostr.hpp" @@ -20,7 +20,7 @@ using std::string; using std::stringstream; using std::time; -namespace nostr +namespace nostr { string Event::serialize() { From be178e83437ec6930b922959170ac91fb9b6ea1b Mon Sep 17 00:00:00 2001 From: Finrod Felagund Date: Mon, 15 Apr 2024 22:26:34 +0200 Subject: [PATCH 3/5] use uuid_v4 to generate faster UUIDs than Boost --- CMakeLists.txt | 18 +++++++++++++----- src/nostr_service.cpp | 19 ++++++++----------- 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 -#include -#include -#include + #include #include #include #include #include +#include #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 signer, RelayList relays) : _defaultRelays(relays), _client(client), _signer(signer) -{ +{ plog::init(plog::debug, appender.get()); client->start(); }; @@ -178,7 +174,7 @@ tuple NostrService::publishEvent(shared_ptr 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> requestPromise; requestFutures.push_back(move(requestPromise.get_future())); future> requestFuture = async( @@ -517,8 +513,9 @@ void NostrService::disconnect(string relay) string NostrService::generateSubscriptionId() { - uuid uuid = random_generator()(); - return to_string(uuid); + UUIDv4::UUIDGenerator uuidGenerator; + UUIDv4::UUID uuid = uuidGenerator.getUUID(); + return uuid.bytes(); }; string NostrService::generateCloseRequest(string subscriptionId) From ae20acb1e40d44fe4b40383d88e08b2f7605d010 Mon Sep 17 00:00:00 2001 From: Finrod Felagund Date: Mon, 15 Apr 2024 22:54:16 +0200 Subject: [PATCH 4/5] put binary outputs at the level of GitRepublic --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0610f3f..ca378b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,9 @@ project(NostrSDK VERSION 0.0.1) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -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/) +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) From 2c9956cc35644a83f8035cb14302fbfd27070d9b Mon Sep 17 00:00:00 2001 From: Finrod Felagund Date: Tue, 16 Apr 2024 16:51:19 +0200 Subject: [PATCH 5/5] use namespaces instead of using specific variables --- src/event.cpp | 16 ++-------------- src/filters.cpp | 10 ++-------- src/nostr_service.cpp | 27 +++++---------------------- 3 files changed, 9 insertions(+), 44 deletions(-) diff --git a/src/event.cpp b/src/event.cpp index 2df1c3a..cf6b117 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -1,24 +1,12 @@ #include #include -#include -#include -#include #include #include #include "nostr.hpp" -using nlohmann::json; -using std::hex; -using std::invalid_argument; -using std::make_shared; -using std::ostringstream; -using std::setw; -using std::setfill; -using std::shared_ptr; -using std::string; -using std::stringstream; -using std::time; +using namespace nlohmann; +using namespace std; namespace nostr { diff --git a/src/filters.cpp b/src/filters.cpp index 83756f9..af9960c 100644 --- a/src/filters.cpp +++ b/src/filters.cpp @@ -1,15 +1,9 @@ -#include -#include -#include #include #include "nostr.hpp" +using namespace nlohmann; +using namespace std; -using nlohmann::json; -using std::invalid_argument; -using std::stringstream; -using std::string; -using std::time; namespace nostr { diff --git a/src/nostr_service.cpp b/src/nostr_service.cpp index 3a59fa6..de40180 100644 --- a/src/nostr_service.cpp +++ b/src/nostr_service.cpp @@ -10,26 +10,9 @@ #include "nostr.hpp" #include "client/web_socket_client.hpp" -using nlohmann::json; -using std::async; -using std::exception; -using std::find_if; -using std::function; -using std::future; -using std::invalid_argument; -using std::lock_guard; -using std::make_shared; -using std::make_tuple; -using std::move; -using std::mutex; -using std::out_of_range; -using std::promise; -using std::shared_ptr; -using std::string; -using std::thread; -using std::tuple; -using std::unique_ptr; -using std::vector; +using namespace nlohmann; +using namespace std; +using namespace UUIDv4; namespace nostr { @@ -513,8 +496,8 @@ void NostrService::disconnect(string relay) string NostrService::generateSubscriptionId() { - UUIDv4::UUIDGenerator uuidGenerator; - UUIDv4::UUID uuid = uuidGenerator.getUUID(); + UUIDGenerator uuidGenerator; + UUID uuid = uuidGenerator.getUUID(); return uuid.bytes(); };