From 0f4494bf6b292ad7883219cd6628689e7ddb9438 Mon Sep 17 00:00:00 2001 From: Finrod Felagund Date: Wed, 15 May 2024 16:41:51 +0200 Subject: better management of include_dir and headers --- CMakeLists.txt | 29 +++++++++++++---------------- README.md | 4 +++- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce940bb..744eccf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.19) -cmake_policy(SET CMP0135 NEW) + +if(CMAKE_VERSION VERSION_GREATER "3.24.0") + # FIXME this policy isn't compatible with versions prior to 3.24 + cmake_policy(SET CMP0135 NEW) +endif() project(aedile VERSION 0.0.2) include(ExternalProject) @@ -39,27 +43,18 @@ find_package(plog CONFIG REQUIRED) find_package(websocketpp CONFIG REQUIRED) #======== Configure uuid_v4 ========# + FetchContent_Declare( uuid_v4 GIT_REPOSITORY git@github.com:crashoz/uuid_v4.git GIT_TAG v1.0.0 ) -FetchContent_Populate(uuid_v4) -set(uuid_v4_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/_deps/uuid_v4-src/) - -find_path(uuid_v4_INCLUDE_DIR uuid_v4.h) -include_directories(${uuid_v4_INCLUDE_DIR}) +FetchContent_MakeAvailable(uuid_v4) #======== 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 -) +list(APPEND INCLUDE_DIR ./include) +list(APPEND INCLUDE_DIR ./include/client) +list(APPEND INCLUDE_DIR ${CMAKE_SOURCE_DIR}/build/linux/_deps/uuid_v4-src/) set(SOURCE_DIR ./src) set(CLIENT_SOURCE_DIR ./src/client) @@ -70,7 +65,7 @@ set(SOURCES ${CLIENT_SOURCE_DIR}/websocketpp_client.cpp ) -add_library(aedile ${SOURCES} ${HEADERS}) +add_library(aedile ${SOURCES}) target_link_libraries(aedile PRIVATE nlohmann_json::nlohmann_json OpenSSL::SSL @@ -78,6 +73,7 @@ target_link_libraries(aedile PRIVATE plog::plog websocketpp::websocketpp ) +target_include_directories(aedile PUBLIC ${INCLUDE_DIR}) set_target_properties(aedile PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES) #======== Build the tests ========# @@ -108,6 +104,7 @@ target_link_libraries(aedile_test PRIVATE plog::plog websocketpp::websocketpp ) +target_include_directories(aedile_test PUBLIC ${INCLUDE_DIR}) set_target_properties(aedile_test PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES) gtest_add_tests(TARGET aedile_test) diff --git a/README.md b/README.md index e9189dc..b2cd674 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,9 @@ The SDK aims to support Linux, Windows, and macOS build targets. It currently s To build the SDK on Linux, run the following commands from the project root: ```bash -cmake --build --preset linux +export VCPKG_ROOT=/path/to/vcpkg/installation +cmake --preset=linux # configuration step +cmake --build build/linux # compilation or build step ``` To run unit tests, use the following command: -- cgit From 43b61ff06e18a79a3e16e38445e92b0ad678bd9f Mon Sep 17 00:00:00 2001 From: Finrod Felagund Date: Mon, 3 Jun 2024 17:43:06 +0200 Subject: remove trailing whitespace and unimplemented closeSubscriptions() function --- include/nostr.hpp | 14 ++++---------- src/client/websocketpp_client.cpp | 8 ++++---- src/filters.cpp | 2 +- src/nostr_service.cpp | 4 ++-- test/nostr_service_test.cpp | 28 ++++++++++++++-------------- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/include/nostr.hpp b/include/nostr.hpp index e5b29c7..b2cdfc5 100644 --- a/include/nostr.hpp +++ b/include/nostr.hpp @@ -164,7 +164,7 @@ public: * @brief Closes any open connections to the specified Nostr relays. */ void closeRelayConnections(std::vector relays); - + /** * @brief Publishes a Nostr event to all open relay connections. * @returns A tuple of `std::vector` objects, of the form ``, indicating @@ -206,7 +206,7 @@ public: std::function)> eventHandler, std::function eoseHandler, std::function closeHandler); - + /** * @brief Closes the subscription with the given ID on all open relay connections. * @returns A tuple of `std::vector` objects, of the form ``, indicating @@ -229,12 +229,6 @@ public: */ std::vector closeSubscriptions(); - /** - * @brief Closes all open subscriptions on the given relays. - * @returns A list of any subscription IDs that failed to close. - */ - std::vector closeSubscriptions(std::vector relays); - private: ///< The maximum number of events the service will store for each subscription. const int MAX_EVENTS_PER_SUBSCRIPTION = 128; @@ -249,7 +243,7 @@ private: ///< The default set of Nostr relays to which the service will attempt to connect. std::vector _defaultRelays; ///< The set of Nostr relays to which the service is currently connected. - std::vector _activeRelays; + std::vector _activeRelays; ///< A map from subscription IDs to the relays on which each subscription is open. std::unordered_map> _subscriptions; @@ -327,7 +321,7 @@ private: std::function)> eventHandler, std::function eoseHandler, std::function closeHandler); - + /** * @brief Parses OK messages received from the relay and invokes the given acceptance handler. * @remark The OK message type is sent to indicate whether the relay has accepted an event sent diff --git a/src/client/websocketpp_client.cpp b/src/client/websocketpp_client.cpp index baae054..c7504e1 100644 --- a/src/client/websocketpp_client.cpp +++ b/src/client/websocketpp_client.cpp @@ -18,7 +18,7 @@ class WebsocketppClient : public IWebSocketClient { public: void start() override - { + { this->_client.init_asio(); this->_client.start_perpetual(); }; @@ -34,7 +34,7 @@ public: error_code error; websocketpp_client::connection_ptr connection = this->_client.get_connection(uri, error); - if (error.value() == -1) + if (error.value() == -1) { // PLOG_ERROR << "Error connecting to relay " << relay << ": " << error.message(); } @@ -72,7 +72,7 @@ public: websocketpp::frame::opcode::text, error); - if (error.value() == -1) + if (error.value() == -1) { return make_tuple(uri, false); } @@ -110,7 +110,7 @@ public: handle, websocketpp::close::status::going_away, "_client requested close."); - + this->_connectionHandles.erase(uri); }; diff --git a/src/filters.cpp b/src/filters.cpp index 40596eb..6f62e0b 100644 --- a/src/filters.cpp +++ b/src/filters.cpp @@ -10,7 +10,7 @@ string Filters::serialize(string& subscriptionId) try { this->validate(); - } + } catch (const invalid_argument& e) { throw e; diff --git a/src/nostr_service.cpp b/src/nostr_service.cpp index 664243f..5adca3b 100644 --- a/src/nostr_service.cpp +++ b/src/nostr_service.cpp @@ -350,13 +350,13 @@ tuple, vector> NostrService::closeSubscription(string sub PLOG_WARNING << "Subscription " << subscriptionId << " not found."; return make_tuple(successfulRelays, failedRelays); } - + for (const string relay : subscriptionRelays) { future> closeFuture = async([this, subscriptionId, relay]() { bool success = this->closeSubscription(subscriptionId, relay); - + return make_tuple(relay, success); }); closeFutures.push_back(move(closeFuture)); diff --git a/test/nostr_service_test.cpp b/test/nostr_service_test.cpp index b3b9b28..5867e8e 100644 --- a/test/nostr_service_test.cpp +++ b/test/nostr_service_test.cpp @@ -29,7 +29,7 @@ public: MOCK_METHOD(void, closeConnection, (string uri), (override)); }; -class FakeSigner : public nostr::ISigner +class FakeSigner : public nostr::ISigner { public: void sign(shared_ptr event) override @@ -71,7 +71,7 @@ public: nostr::Event event1; event1.pubkey = "13tn5ccv2guflxgffq4aj0hw5x39pz70zcdrfd6vym887gry38zys28dask"; event1.kind = 1; - event1.tags = + event1.tags = { { "e", "5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36", "wss://nostr.example.com" }, { "p", "f7234bd4c1394dda46d09f35bd384dd30cc552ad5541990f98844fb06676e9ca" }, @@ -91,7 +91,7 @@ public: }; event2.content = "Welcome to Nostr!"; event2.createdAt = currentTime; - + nostr::Event event3; event3.pubkey = "187ujhtmnv82ftg03h4heetwk3dd9mlfkf8th3fvmrk20nxk9mansuzuyla"; event3.kind = 1; @@ -124,7 +124,7 @@ public: } static const string getTestEventMessage(shared_ptr event, string subscriptionId) - { + { auto signer = make_unique(); signer->sign(event); @@ -140,7 +140,7 @@ public: { nostr::Filters filters; filters.authors = { - "13tn5ccv2guflxgffq4aj0hw5x39pz70zcdrfd6vym887gry38zys28dask", + "13tn5ccv2guflxgffq4aj0hw5x39pz70zcdrfd6vym887gry38zys28dask", "1l9d9jh67rkwayalrxcy686aujyz5pper5kzjv8jvg8pu9v9ns4ls0xvq42", "187ujhtmnv82ftg03h4heetwk3dd9mlfkf8th3fvmrk20nxk9mansuzuyla" }; @@ -154,7 +154,7 @@ public: { nostr::Filters filters; filters.authors = { - "13tn5ccv2guflxgffq4aj0hw5x39pz70zcdrfd6vym887gry38zys28dask", + "13tn5ccv2guflxgffq4aj0hw5x39pz70zcdrfd6vym887gry38zys28dask", "1l9d9jh67rkwayalrxcy686aujyz5pper5kzjv8jvg8pu9v9ns4ls0xvq42", "187ujhtmnv82ftg03h4heetwk3dd9mlfkf8th3fvmrk20nxk9mansuzuyla" }; @@ -240,7 +240,7 @@ TEST_F(NostrServiceTest, OpenRelayConnections_OpensConnections_ToDefaultRelays) } return status; })); - + auto nostrService = make_unique( testAppender, mockClient, @@ -468,7 +468,7 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_AllSuccesses) return make_tuple(uri, true); })); - + auto testEvent = make_shared(getTextNoteTestEvent()); auto [successes, failures] = nostrService->publishEvent(testEvent); @@ -514,7 +514,7 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_AllFailures) { return make_tuple(uri, false); })); - + auto testEvent = make_shared(getTextNoteTestEvent()); auto [successes, failures] = nostrService->publishEvent(testEvent); @@ -573,7 +573,7 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_MixedSuccessesAndFailur return make_tuple(uri, true); })); - + auto testEvent = make_shared(getTextNoteTestEvent()); auto [successes, failures] = nostrService->publishEvent(testEvent); @@ -623,7 +623,7 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_RejectedEvent) return make_tuple(uri, true); })); - + auto testEvent = make_shared(getTextNoteTestEvent()); auto [successes, failures] = nostrService->publishEvent(testEvent); @@ -686,7 +686,7 @@ TEST_F(NostrServiceTest, PublishEvent_CorrectlyIndicates_EventRejectedBySomeRela return make_tuple(uri, true); })); - + auto testEvent = make_shared(getTextNoteTestEvent()); auto [successes, failures] = nostrService->publishEvent(testEvent); @@ -890,7 +890,7 @@ TEST_F(NostrServiceTest, QueryRelays_CallsHandler_WithReturnedEvents) } }, [](const string&, const string&) {}); - + eoseReceivedFuture.wait(); // Check that the service is keeping track of its active subscriptions. @@ -1055,7 +1055,7 @@ TEST_F(NostrServiceTest, Service_MaintainsMultipleSubscriptions_ThenClosesAll) longFormPromise.set_value(); }, [](const string&, const string&) {}); - + shortFormFuture.wait(); longFormFuture.wait(); -- cgit