diff --git a/.gitignore b/.gitignore index 668ff8a..75ac156 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ vendor/* result result/ cmake-build-* +lib/ diff --git a/flake.lock b/flake.lock index b9757af..d54e3e0 100644 --- a/flake.lock +++ b/flake.lock @@ -1,9 +1,52 @@ { "nodes": { + "logos-capability-module": { + "inputs": { + "logos-cpp-sdk": "logos-cpp-sdk_2", + "logos-liblogos": "logos-liblogos_2", + "nixpkgs": [ + "logos-liblogos", + "logos-capability-module", + "logos-liblogos", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1767809111, + "narHash": "sha256-jehjsB+BpDJlVu3I7x+vFVOdXmy9MDmFTJtRqzFUONo=", + "owner": "logos-co", + "repo": "logos-capability-module", + "rev": "7b35383e0aa4e28a4633ed18a87efb57636939b1", + "type": "github" + }, + "original": { + "owner": "logos-co", + "repo": "logos-capability-module", + "type": "github" + } + }, "logos-cpp-sdk": { "inputs": { "nixpkgs": "nixpkgs" }, + "locked": { + "lastModified": 1770132997, + "narHash": "sha256-Iv0QMXMD6kf+y2Qx37jXR7Ik6h1dqOzuxBzCdc5S6KA=", + "owner": "logos-co", + "repo": "logos-cpp-sdk", + "rev": "30ef7986f4b65b7dcf43af84bb073233b1b77821", + "type": "github" + }, + "original": { + "owner": "logos-co", + "repo": "logos-cpp-sdk", + "type": "github" + } + }, + "logos-cpp-sdk_2": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, "locked": { "lastModified": 1761230734, "narHash": "sha256-CMRUwXH7pJZ1OI6bd/TDDDXKqQ1tQZHQEOOwK8TgYHI=", @@ -18,9 +61,9 @@ "type": "github" } }, - "logos-cpp-sdk_2": { + "logos-cpp-sdk_3": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1761230734, @@ -36,15 +79,78 @@ "type": "github" } }, + "logos-cpp-sdk_4": { + "inputs": { + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1767724329, + "narHash": "sha256-UPkqxqxbKwU5Dmu00TnjiJVXUmfVylF3p1qziEuYwIE=", + "owner": "logos-co", + "repo": "logos-cpp-sdk", + "rev": "32f1d7080d784ff044d91d076ef2f0c7305d4784", + "type": "github" + }, + "original": { + "owner": "logos-co", + "repo": "logos-cpp-sdk", + "type": "github" + } + }, + "logos-cpp-sdk_5": { + "inputs": { + "nixpkgs": "nixpkgs_5" + }, + "locked": { + "lastModified": 1767724329, + "narHash": "sha256-UPkqxqxbKwU5Dmu00TnjiJVXUmfVylF3p1qziEuYwIE=", + "owner": "logos-co", + "repo": "logos-cpp-sdk", + "rev": "32f1d7080d784ff044d91d076ef2f0c7305d4784", + "type": "github" + }, + "original": { + "owner": "logos-co", + "repo": "logos-cpp-sdk", + "type": "github" + } + }, "logos-liblogos": { "inputs": { - "logos-cpp-sdk": "logos-cpp-sdk_2", + "logos-capability-module": "logos-capability-module", + "logos-cpp-sdk": "logos-cpp-sdk_4", + "logos-module": "logos-module", "nixpkgs": [ "logos-liblogos", "logos-cpp-sdk", "nixpkgs" ] }, + "locked": { + "lastModified": 1770837874, + "narHash": "sha256-wr75lv1q4U1FS5+l/6ypwzJFJe06l2RyUvx1npoRS88=", + "owner": "logos-co", + "repo": "logos-liblogos", + "rev": "e3741c01fd3abf6b7bd9ff2fa8edf89c41fc0cea", + "type": "github" + }, + "original": { + "owner": "logos-co", + "repo": "logos-liblogos", + "type": "github" + } + }, + "logos-liblogos_2": { + "inputs": { + "logos-cpp-sdk": "logos-cpp-sdk_3", + "nixpkgs": [ + "logos-liblogos", + "logos-capability-module", + "logos-liblogos", + "logos-cpp-sdk", + "nixpkgs" + ] + }, "locked": { "lastModified": 1761845775, "narHash": "sha256-ulK8xq05ejK6qIgZ7WtWb/MJt2rk5BKfDA2z7mM3wq8=", @@ -59,6 +165,52 @@ "type": "github" } }, + "logos-messaging-nim": { + "inputs": { + "nixpkgs": "nixpkgs_6", + "zerokit": "zerokit" + }, + "locked": { + "lastModified": 1772086348, + "narHash": "sha256-GCmgc6/9KVvJR3YyO5I5hLf/H8B2K+M41segihFfEkI=", + "ref": "poc/logos-testnet-mix", + "rev": "7ed4fed7d0f54ee4b06ca55c407edca031fb4cfc", + "revCount": 2227, + "submodules": true, + "type": "git", + "url": "https://github.com/logos-messaging/logos-delivery" + }, + "original": { + "ref": "poc/logos-testnet-mix", + "submodules": true, + "type": "git", + "url": "https://github.com/logos-messaging/logos-delivery" + } + }, + "logos-module": { + "inputs": { + "logos-cpp-sdk": "logos-cpp-sdk_5", + "nixpkgs": [ + "logos-liblogos", + "logos-module", + "logos-cpp-sdk", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1770062426, + "narHash": "sha256-zc7ZxDTlqOCYGyEHhrTA/7GS1EWh7+4amdPUKh+gGds=", + "owner": "logos-co", + "repo": "logos-module", + "rev": "f7ee69d9ad9f27c84f04f59896e9194125e951dc", + "type": "github" + }, + "original": { + "owner": "logos-co", + "repo": "logos-module", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1759036355, @@ -91,15 +243,125 @@ "type": "github" } }, + "nixpkgs_3": { + "locked": { + "lastModified": 1759036355, + "narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e9f00bd893984bc8ce46c895c3bf7cac95331127", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { + "locked": { + "lastModified": 1759036355, + "narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e9f00bd893984bc8ce46c895c3bf7cac95331127", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_5": { + "locked": { + "lastModified": 1759036355, + "narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e9f00bd893984bc8ce46c895c3bf7cac95331127", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_6": { + "locked": { + "lastModified": 1757590060, + "narHash": "sha256-EWwwdKLMZALkgHFyKW7rmyhxECO74+N+ZO5xTDnY/5c=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0ef228213045d2cdb5a169a95d63ded38670b293", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0ef228213045d2cdb5a169a95d63ded38670b293", + "type": "github" + } + }, "root": { "inputs": { "logos-cpp-sdk": "logos-cpp-sdk", "logos-liblogos": "logos-liblogos", + "logos-messaging-nim": "logos-messaging-nim", "nixpkgs": [ "logos-liblogos", "nixpkgs" ] } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "logos-messaging-nim", + "zerokit", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1748399823, + "narHash": "sha256-kahD8D5hOXOsGbNdoLLnqCL887cjHkx98Izc37nDjlA=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "d68a69dc71bc19beb3479800392112c2f6218159", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "zerokit": { + "inputs": { + "nixpkgs": [ + "logos-messaging-nim", + "nixpkgs" + ], + "rust-overlay": "rust-overlay" + }, + "locked": { + "lastModified": 1762211504, + "narHash": "sha256-SbDoBElFYJ4cYebltxlO2lYnz6qOaDAVY6aNJ5bqHDE=", + "ref": "refs/heads/master", + "rev": "3160d9504d07791f2fc9b610948a6cf9a58ed488", + "revCount": 342, + "type": "git", + "url": "https://github.com/vacp2p/zerokit" + }, + "original": { + "rev": "3160d9504d07791f2fc9b610948a6cf9a58ed488", + "type": "git", + "url": "https://github.com/vacp2p/zerokit" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index bc31e14..c5e2b7c 100644 --- a/flake.nix +++ b/flake.nix @@ -6,26 +6,35 @@ nixpkgs.follows = "logos-liblogos/nixpkgs"; logos-cpp-sdk.url = "github:logos-co/logos-cpp-sdk"; logos-liblogos.url = "github:logos-co/logos-liblogos"; + # logos-messaging-nim: branch poc/logos-testnet-mix + # Uses git+https (not github:) because the build needs submodules, + # and github: type fetches tarballs which don't include submodule content. + logos-messaging-nim = { + url = "git+https://github.com/logos-messaging/logos-delivery?ref=poc/logos-testnet-mix&submodules=1"; + }; }; - outputs = { self, nixpkgs, logos-cpp-sdk, logos-liblogos }: + outputs = { self, nixpkgs, logos-cpp-sdk, logos-liblogos, logos-messaging-nim }: let systems = [ "aarch64-darwin" "x86_64-darwin" "aarch64-linux" "x86_64-linux" ]; forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f { pkgs = import nixpkgs { inherit system; }; logosSdk = logos-cpp-sdk.packages.${system}.default; logosLiblogos = logos-liblogos.packages.${system}.default; + logosMessagingNim = (logos-messaging-nim.packages.${system}.libwaku).overrideAttrs (old: { + NIMFLAGS = (old.NIMFLAGS or "") + " -d:chronicles_colors:none"; + }); }); in { - packages = forAllSystems ({ pkgs, logosSdk, logosLiblogos }: + packages = forAllSystems ({ pkgs, logosSdk, logosLiblogos, logosMessagingNim }: let # Common configuration common = import ./nix/default.nix { inherit pkgs logosSdk logosLiblogos; }; src = ./.; - + # Library package (plugin + libwaku) - lib = import ./nix/lib.nix { inherit pkgs common src; }; + lib = import ./nix/lib.nix { inherit pkgs common src logosMessagingNim; }; # Include package (generated headers from plugin) include = import ./nix/include.nix { inherit pkgs common src lib logosSdk; }; @@ -47,7 +56,7 @@ } ); - devShells = forAllSystems ({ pkgs, logosSdk, logosLiblogos }: { + devShells = forAllSystems ({ pkgs, logosSdk, logosLiblogos, logosMessagingNim }: { default = pkgs.mkShell { nativeBuildInputs = [ pkgs.cmake diff --git a/lib/README.md b/lib/README.md deleted file mode 100644 index 47d5e13..0000000 --- a/lib/README.md +++ /dev/null @@ -1 +0,0 @@ -yes this should not be here; temporarily until nwaku nix flake is working diff --git a/lib/libwaku.dylib b/lib/libwaku.dylib deleted file mode 100755 index 01e9c8e..0000000 Binary files a/lib/libwaku.dylib and /dev/null differ diff --git a/lib/libwaku.h b/lib/libwaku.h deleted file mode 100644 index b5d6c9b..0000000 --- a/lib/libwaku.h +++ /dev/null @@ -1,253 +0,0 @@ - -// Generated manually and inspired by the one generated by the Nim Compiler. -// In order to see the header file generated by Nim just run `make libwaku` -// from the root repo folder and the header should be created in -// nimcache/release/libwaku/libwaku.h -#ifndef __libwaku__ -#define __libwaku__ - -#include -#include - -// The possible returned values for the functions that return int -#define RET_OK 0 -#define RET_ERR 1 -#define RET_MISSING_CALLBACK 2 - -#ifdef __cplusplus -extern "C" { -#endif - -typedef void (*WakuCallBack) (int callerRet, const char* msg, size_t len, void* userData); - -// Creates a new instance of the waku node. -// Sets up the waku node from the given configuration. -// Returns a pointer to the Context needed by the rest of the API functions. -void* waku_new( - const char* configJson, - WakuCallBack callback, - void* userData); - -int waku_start(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_stop(void* ctx, - WakuCallBack callback, - void* userData); - -// Destroys an instance of a waku node created with waku_new -int waku_destroy(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_version(void* ctx, - WakuCallBack callback, - void* userData); - -// Sets a callback that will be invoked whenever an event occurs. -// It is crucial that the passed callback is fast, non-blocking and potentially thread-safe. -void waku_set_event_callback(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_content_topic(void* ctx, - const char* appName, - unsigned int appVersion, - const char* contentTopicName, - const char* encoding, - WakuCallBack callback, - void* userData); - -int waku_pubsub_topic(void* ctx, - const char* topicName, - WakuCallBack callback, - void* userData); - -int waku_default_pubsub_topic(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_relay_publish(void* ctx, - const char* pubSubTopic, - const char* jsonWakuMessage, - unsigned int timeoutMs, - WakuCallBack callback, - void* userData); - -int waku_lightpush_publish(void* ctx, - const char* pubSubTopic, - const char* jsonWakuMessage, - WakuCallBack callback, - void* userData); - -int waku_relay_subscribe(void* ctx, - const char* pubSubTopic, - WakuCallBack callback, - void* userData); - -int waku_relay_add_protected_shard(void* ctx, - int clusterId, - int shardId, - char* publicKey, - WakuCallBack callback, - void* userData); - -int waku_relay_unsubscribe(void* ctx, - const char* pubSubTopic, - WakuCallBack callback, - void* userData); - -int waku_filter_subscribe(void* ctx, - const char* pubSubTopic, - const char* contentTopics, - WakuCallBack callback, - void* userData); - -int waku_filter_unsubscribe(void* ctx, - const char* pubSubTopic, - const char* contentTopics, - WakuCallBack callback, - void* userData); - -int waku_filter_unsubscribe_all(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_relay_get_num_connected_peers(void* ctx, - const char* pubSubTopic, - WakuCallBack callback, - void* userData); - -int waku_relay_get_connected_peers(void* ctx, - const char* pubSubTopic, - WakuCallBack callback, - void* userData); - -int waku_relay_get_num_peers_in_mesh(void* ctx, - const char* pubSubTopic, - WakuCallBack callback, - void* userData); - -int waku_relay_get_peers_in_mesh(void* ctx, - const char* pubSubTopic, - WakuCallBack callback, - void* userData); - -int waku_store_query(void* ctx, - const char* jsonQuery, - const char* peerAddr, - int timeoutMs, - WakuCallBack callback, - void* userData); - -int waku_connect(void* ctx, - const char* peerMultiAddr, - unsigned int timeoutMs, - WakuCallBack callback, - void* userData); - -int waku_disconnect_peer_by_id(void* ctx, - const char* peerId, - WakuCallBack callback, - void* userData); - -int waku_disconnect_all_peers(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_dial_peer(void* ctx, - const char* peerMultiAddr, - const char* protocol, - int timeoutMs, - WakuCallBack callback, - void* userData); - -int waku_dial_peer_by_id(void* ctx, - const char* peerId, - const char* protocol, - int timeoutMs, - WakuCallBack callback, - void* userData); - -int waku_get_peerids_from_peerstore(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_get_connected_peers_info(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_get_peerids_by_protocol(void* ctx, - const char* protocol, - WakuCallBack callback, - void* userData); - -int waku_listen_addresses(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_get_connected_peers(void* ctx, - WakuCallBack callback, - void* userData); - -// Returns a list of multiaddress given a url to a DNS discoverable ENR tree -// Parameters -// char* entTreeUrl: URL containing a discoverable ENR tree -// char* nameDnsServer: The nameserver to resolve the ENR tree url. -// int timeoutMs: Timeout value in milliseconds to execute the call. -int waku_dns_discovery(void* ctx, - const char* entTreeUrl, - const char* nameDnsServer, - int timeoutMs, - WakuCallBack callback, - void* userData); - -// Updates the bootnode list used for discovering new peers via DiscoveryV5 -// bootnodes - JSON array containing the bootnode ENRs i.e. `["enr:...", "enr:..."]` -int waku_discv5_update_bootnodes(void* ctx, - char* bootnodes, - WakuCallBack callback, - void* userData); - -int waku_start_discv5(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_stop_discv5(void* ctx, - WakuCallBack callback, - void* userData); - -// Retrieves the ENR information -int waku_get_my_enr(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_get_my_peerid(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_get_metrics(void* ctx, - WakuCallBack callback, - void* userData); - -int waku_peer_exchange_request(void* ctx, - int numPeers, - WakuCallBack callback, - void* userData); - -int waku_ping_peer(void* ctx, - const char* peerAddr, - int timeoutMs, - WakuCallBack callback, - void* userData); - -int waku_is_online(void* ctx, - WakuCallBack callback, - void* userData); - -#ifdef __cplusplus -} -#endif - -#endif /* __libwaku__ */ diff --git a/lib/libwaku.so b/lib/libwaku.so deleted file mode 100755 index 3a85cd7..0000000 Binary files a/lib/libwaku.so and /dev/null differ diff --git a/metadata.json b/metadata.json index 89b3245..e29c4e4 100644 --- a/metadata.json +++ b/metadata.json @@ -1,13 +1,16 @@ { - "name": "waku_module", - "version": "1.0.0", - "description": "Waku module", - "author": "Logos Core Team", + "name": "waku_module_mix", + "version": "1.0.1", + "description": "Waku module with mix and capability discovery", + "author": "Logos AnonComms Team", "type": "core", "category": "protocol", "main": "waku_module_plugin", "dependencies": [], - "include": ["libwaku.so", "libwaku.dylib", "libwaku.dll"], - "capabilities": [ - ] -} \ No newline at end of file + "include": [ + "libwaku.so", + "libwaku.dylib", + "libwaku.dll" + ], + "capabilities": [] +} diff --git a/nix/lib.nix b/nix/lib.nix index ab82749..e11c420 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -1,36 +1,62 @@ # Builds the logos-waku-module library -{ pkgs, common, src }: +# logosMessagingNim: the libwaku package from logos-messaging-nim flake (poc/logos-testnet-mix branch) +{ pkgs, common, src, logosMessagingNim }: pkgs.stdenv.mkDerivation { pname = "${common.pname}-lib"; version = common.version; - + inherit src; inherit (common) nativeBuildInputs buildInputs cmakeFlags meta env; - + # Determine platform-specific library extension libwakuLib = if pkgs.stdenv.hostPlatform.isDarwin then "libwaku.dylib" else "libwaku.so"; - - postInstall = '' - mkdir -p $out/lib - - # Copy libwaku library from source - srcLib="$src/lib/''${libwakuLib}" + + # Copy libwaku from logos-messaging-nim into lib/ before CMake configure + preConfigure = '' + runHook prePreConfigure + + mkdir -p lib + + # logos-messaging-nim installs the built library into $out/bin/ + srcLib="${logosMessagingNim}/bin/''${libwakuLib}" if [ ! -f "$srcLib" ]; then - echo "Expected ''${libwakuLib} in $src/lib/" >&2 + echo "Expected ''${libwakuLib} in ${logosMessagingNim}/bin/" >&2 + echo "Contents of ${logosMessagingNim}/bin/:" + ls -la "${logosMessagingNim}/bin/" 2>/dev/null || echo "bin/ directory does not exist" exit 1 fi - cp "$srcLib" "$out/lib/" - + cp "$srcLib" lib/ + chmod u+w lib/''${libwakuLib} + + # Copy the header file if available + if [ -f "${logosMessagingNim}/include/libwaku.h" ]; then + cp "${logosMessagingNim}/include/libwaku.h" lib/ + chmod u+w lib/libwaku.h + fi + + echo "Copied libwaku from logos-messaging-nim into lib/:" + ls -la lib/ + + runHook postPreConfigure + ''; + + postInstall = '' + mkdir -p $out/lib + + # Copy libwaku library directly from logos-messaging-nim output + cp "${logosMessagingNim}/bin/''${libwakuLib}" "$out/lib/" + chmod u+w "$out/lib/''${libwakuLib}" + # Fix the install name of libwaku on macOS ${pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin '' ${pkgs.darwin.cctools}/bin/install_name_tool -id "@rpath/''${libwakuLib}" "$out/lib/''${libwakuLib}" ''} - + # Copy the waku module plugin from the installed location if [ -f "$out/lib/logos/modules/waku_module_plugin.dylib" ]; then cp "$out/lib/logos/modules/waku_module_plugin.dylib" "$out/lib/" - + # Fix the plugin's reference to libwaku on macOS ${pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin '' # Find what libwaku path the plugin is referencing and change it to @rpath @@ -44,7 +70,7 @@ pkgs.stdenv.mkDerivation { echo "Error: No waku_module_plugin library file found" exit 1 fi - + # Remove the nested structure we don't want rm -rf "$out/lib/logos" 2>/dev/null || true rm -rf "$out/share" 2>/dev/null || true diff --git a/waku_module_interface.h b/waku_module_interface.h index 8daaa63..7a3b32a 100644 --- a/waku_module_interface.h +++ b/waku_module_interface.h @@ -12,17 +12,20 @@ class WakuModuleInterface : public PluginInterface Q_INVOKABLE virtual bool startWaku() = 0; Q_INVOKABLE virtual bool stopWaku() = 0; Q_INVOKABLE virtual bool setEventCallback() = 0; - Q_INVOKABLE virtual bool relaySubscribe(const QString &pubSubTopic) = 0; + Q_INVOKABLE virtual bool relaySubscribe(const QString &contentTopic, const QString &pubSubTopic = QString()) = 0; Q_INVOKABLE virtual bool relayPublish(const QString &pubSubTopic, const QString &jsonWakuMessage) = 0; Q_INVOKABLE virtual bool filterSubscribe(const QString &pubSubTopic, const QString &contentTopics) = 0; Q_INVOKABLE virtual bool storeQuery(const QString &jsonQuery, const QString &peerAddr) = 0; Q_INVOKABLE virtual bool getConnectedPeers() = 0; Q_INVOKABLE virtual bool getMetrics() = 0; + Q_INVOKABLE virtual bool lightPublish(const QString &pubSubTopic, const QString &jsonWakuMessage) = 0; + Q_INVOKABLE virtual bool getMixnodePoolSize() = 0; + Q_INVOKABLE virtual bool getLightpushPeersCount() = 0; signals: // for now this is required for events, later it might not be necessary if using a proxy - void eventResponse(const QString& eventName, const QVariantList& data); + void eventResponse(const QString &eventName, const QVariantList &data); }; #define WakuModuleInterface_iid "org.logos.WakuModuleInterface" -Q_DECLARE_INTERFACE(WakuModuleInterface, WakuModuleInterface_iid) \ No newline at end of file +Q_DECLARE_INTERFACE(WakuModuleInterface, WakuModuleInterface_iid) \ No newline at end of file diff --git a/waku_module_plugin.cpp b/waku_module_plugin.cpp index 072676d..5d467e0 100644 --- a/waku_module_plugin.cpp +++ b/waku_module_plugin.cpp @@ -10,29 +10,34 @@ WakuModulePlugin::WakuModulePlugin() : wakuCtx(nullptr) qDebug() << "WakuModulePlugin: Initialized successfully"; } -WakuModulePlugin::~WakuModulePlugin() +WakuModulePlugin::~WakuModulePlugin() { // Clean up resources - if (logosAPI) { + if (logosAPI) + { delete logosAPI; logosAPI = nullptr; } - + // Clean up Waku context if it exists - if (wakuCtx) { + if (wakuCtx) + { // TODO: Call waku_destroy when needed wakuCtx = nullptr; } } -void WakuModulePlugin::emitEvent(const QString& eventName, const QVariantList& data) { - if (!logosAPI) { +void WakuModulePlugin::emitEvent(const QString &eventName, const QVariantList &data) +{ + if (!logosAPI) + { qWarning() << "WakuModulePlugin: LogosAPI not available, cannot emit" << eventName; return; } - LogosAPIClient* client = logosAPI->getClient("waku_module"); - if (!client) { + LogosAPIClient *client = logosAPI->getClient("waku_module"); + if (!client) + { qWarning() << "WakuModulePlugin: Failed to get waku_module client for event" << eventName; return; } @@ -46,7 +51,7 @@ bool WakuModulePlugin::foo(const QString &bar) // Create event data with the bar parameter QVariantList eventData; - eventData << bar; // Add the bar parameter to the event data + eventData << bar; // Add the bar parameter to the event data eventData << QDateTime::currentDateTime().toString(Qt::ISODate); // Add timestamp // Trigger the event using emitEvent helper @@ -57,35 +62,53 @@ bool WakuModulePlugin::foo(const QString &bar) return true; } -void WakuModulePlugin::init_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::init_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::init_callback called with ret:" << callerRet; - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); qDebug() << "WakuModulePlugin::init_callback message:" << message; } + + WakuModulePlugin *plugin = static_cast(userData); + if (plugin) + { + plugin->m_initSuccess.store(callerRet == RET_OK); + plugin->m_initSemaphore.release(); + } } -void WakuModulePlugin::start_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::start_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::start_callback called with ret:" << callerRet; - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); qDebug() << "WakuModulePlugin::start_callback message:" << message; } + + WakuModulePlugin *plugin = static_cast(userData); + if (plugin) + { + plugin->m_startSuccess.store(callerRet == RET_OK); + plugin->m_startSemaphore.release(); + } } -void WakuModulePlugin::event_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::event_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::event_callback called with ret:" << callerRet; - WakuModulePlugin* plugin = static_cast(userData); - if (!plugin) { + WakuModulePlugin *plugin = static_cast(userData); + if (!plugin) + { qWarning() << "WakuModulePlugin::event_callback: Invalid userData"; return; } - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); // qDebug() << "WakuModulePlugin::event_callback message:" << message; @@ -100,45 +123,67 @@ void WakuModulePlugin::event_callback(int callerRet, const char* msg, size_t len } } -void WakuModulePlugin::relay_subscribe_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::relay_subscribe_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::relay_subscribe_callback called with ret:" << callerRet; - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); qDebug() << "WakuModulePlugin::relay_subscribe_callback message:" << message; } } -void WakuModulePlugin::relay_publish_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::relay_publish_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::relay_publish_callback called with ret:" << callerRet; - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); qDebug() << "WakuModulePlugin::relay_publish_callback message:" << message; } } -void WakuModulePlugin::filter_subscribe_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::light_publish_callback(int callerRet, const char *msg, size_t len, void *userData) +{ + qDebug() << "WakuModulePlugin::light_publish_callback called with ret:" << callerRet; + if (msg && len > 0) + { + QString message = QString::fromUtf8(msg, len); + if (callerRet == RET_OK) + { + qDebug() << "WakuModulePlugin::light_publish_callback msgHash:" << message; + } + else + { + qWarning() << "WakuModulePlugin::light_publish_callback error:" << message; + } + } +} + +void WakuModulePlugin::filter_subscribe_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::filter_subscribe_callback called with ret:" << callerRet; - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); qDebug() << "WakuModulePlugin::filter_subscribe_callback message:" << message; } } -void WakuModulePlugin::store_query_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::store_query_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::store_query_callback called with ret:" << callerRet; - WakuModulePlugin* plugin = static_cast(userData); - if (!plugin) { + WakuModulePlugin *plugin = static_cast(userData); + if (!plugin) + { qWarning() << "WakuModulePlugin::store_query_callback: Invalid userData"; exit(1); return; } - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); // qDebug() << "WakuModulePlugin::store_query_callback message:" << message; @@ -153,26 +198,29 @@ void WakuModulePlugin::store_query_callback(int callerRet, const char* msg, size } } -void WakuModulePlugin::stop_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::stop_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::stop_callback called with ret:" << callerRet; - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); qDebug() << "WakuModulePlugin::stop_callback message:" << message; } } -void WakuModulePlugin::get_connected_peers_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::get_connected_peers_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::get_connected_peers_callback called with ret:" << callerRet; - WakuModulePlugin* plugin = static_cast(userData); - if (!plugin) { + WakuModulePlugin *plugin = static_cast(userData); + if (!plugin) + { qWarning() << "WakuModulePlugin::get_connected_peers_callback: Invalid userData"; return; } - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); qDebug() << "WakuModulePlugin::get_connected_peers_callback message:" << message; qDebug() << "WakuModulePlugin::get_connected_peers_callback message length:" << len; @@ -188,17 +236,19 @@ void WakuModulePlugin::get_connected_peers_callback(int callerRet, const char* m } } -void WakuModulePlugin::get_metrics_callback(int callerRet, const char* msg, size_t len, void* userData) +void WakuModulePlugin::get_metrics_callback(int callerRet, const char *msg, size_t len, void *userData) { qDebug() << "WakuModulePlugin::get_metrics_callback called with ret:" << callerRet; - WakuModulePlugin* plugin = static_cast(userData); - if (!plugin) { + WakuModulePlugin *plugin = static_cast(userData); + if (!plugin) + { qWarning() << "WakuModulePlugin::get_metrics_callback: Invalid userData"; return; } - if (msg && len > 0) { + if (msg && len > 0) + { QString message = QString::fromUtf8(msg, len); qDebug() << "WakuModulePlugin::get_metrics_callback message:" << message; qDebug() << "WakuModulePlugin::get_metrics_callback message length:" << len; @@ -214,8 +264,10 @@ void WakuModulePlugin::get_metrics_callback(int callerRet, const char* msg, size } } -void WakuModulePlugin::initLogos(LogosAPI* logosAPIInstance) { - if (logosAPI) { +void WakuModulePlugin::initLogos(LogosAPI *logosAPIInstance) +{ + if (logosAPI) + { delete logosAPI; } logosAPI = logosAPIInstance; @@ -223,18 +275,21 @@ void WakuModulePlugin::initLogos(LogosAPI* logosAPIInstance) { bool WakuModulePlugin::initWaku(const QString &cfg) { - qDebug() << "WakuModulePlugin::initWaku called with cfg:" << cfg; - + qDebug() << "WakuModulePlugin-Updated::initWaku called with cfg:" << cfg; + // Convert QString to UTF-8 byte array QByteArray cfgUtf8 = cfg.toUtf8(); - + // Call waku_new with the configuration wakuCtx = waku_new(cfgUtf8.constData(), init_callback, this); - - if (wakuCtx) { + + if (wakuCtx) + { qDebug() << "WakuModulePlugin: Waku context created successfully"; return true; - } else { + } + else + { qWarning() << "WakuModulePlugin: Failed to create Waku context"; return false; } @@ -243,19 +298,39 @@ bool WakuModulePlugin::initWaku(const QString &cfg) bool WakuModulePlugin::startWaku() { qDebug() << "WakuModulePlugin::startWaku called"; - - if (!wakuCtx) { + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot start Waku - context not initialized. Call initWaku first."; return false; } - + + // Wait for init_callback to signal that waku_new has fully completed + qDebug() << "WakuModulePlugin: Waiting for node initialization to complete..."; + if (!m_initSemaphore.tryAcquire(1, 30000)) + { + qWarning() << "WakuModulePlugin: Timed out waiting for Waku node initialization (30s)"; + return false; + } + + if (!m_initSuccess.load()) + { + qWarning() << "WakuModulePlugin: Waku node initialization failed, cannot start"; + return false; + } + + qDebug() << "WakuModulePlugin: Node initialization confirmed, starting Waku..."; + // Call waku_start with the saved context int result = waku_start(wakuCtx, start_callback, this); - - if (result == RET_OK) { + + if (result == RET_OK) + { qDebug() << "==================WakuModulePlugin: Waku start initiated successfully======================="; return true; - } else { + } + else + { qWarning() << "WakuModulePlugin: Failed to start Waku, error code:" << result; return false; } @@ -264,39 +339,48 @@ bool WakuModulePlugin::startWaku() bool WakuModulePlugin::setEventCallback() { qDebug() << "WakuModulePlugin::setEventCallback called"; - - if (!wakuCtx) { + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot set event callback - context not initialized. Call initWaku first."; return false; } - + // Set the event callback using waku_set_event_callback - waku_set_event_callback(wakuCtx, event_callback, this); - + set_event_callback(wakuCtx, event_callback, this); + qDebug() << "WakuModulePlugin: Event callback set successfully"; return true; } -bool WakuModulePlugin::relaySubscribe(const QString &pubSubTopic) +bool WakuModulePlugin::relaySubscribe(const QString &contentTopic, const QString &pubSubTopic) { - qDebug() << "WakuModulePlugin::relaySubscribe called with pubSubTopic:" << pubSubTopic; - - if (!wakuCtx) { + qDebug() << "WakuModulePlugin::relaySubscribe called with contentTopic:" << contentTopic << ", pubSubTopic:" << pubSubTopic; + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot subscribe to relay - context not initialized. Call initWaku first."; return false; } - - // Convert QString to UTF-8 byte array - QByteArray topicUtf8 = pubSubTopic.toUtf8(); - - // Call waku_relay_subscribe with the pubsub topic - int result = waku_relay_subscribe(wakuCtx, topicUtf8.constData(), relay_subscribe_callback, this); - - if (result == RET_OK) { - qDebug() << "WakuModulePlugin: Relay subscribe initiated successfully for topic:" << pubSubTopic; + + // Convert QStrings to UTF-8 byte arrays + QByteArray contentTopicUtf8 = contentTopic.toUtf8(); + QByteArray pubSubTopicUtf8 = pubSubTopic.toUtf8(); + + // Call waku_relay_subscribe with both pubSubTopic and contentTopic + // Pass empty string "" if not provided instead of nullptr + int result = waku_relay_subscribe(wakuCtx, relay_subscribe_callback, this, + pubSubTopicUtf8.isEmpty() ? "" : pubSubTopicUtf8.constData(), + contentTopicUtf8.isEmpty() ? "" : contentTopicUtf8.constData()); + + if (result == RET_OK) + { + qDebug() << "WakuModulePlugin: Relay subscribe initiated successfully"; return true; - } else { - qWarning() << "WakuModulePlugin: Failed to subscribe to relay topic:" << pubSubTopic << ", error code:" << result; + } + else + { + qWarning() << "WakuModulePlugin: Failed to subscribe to relay, error code:" << result; return false; } } @@ -305,49 +389,87 @@ bool WakuModulePlugin::relayPublish(const QString &pubSubTopic, const QString &j { qDebug() << "WakuModulePlugin::relayPublish called with pubSubTopic:" << pubSubTopic; qDebug() << "WakuModulePlugin::relayPublish message:" << jsonWakuMessage; - - if (!wakuCtx) { + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot publish to relay - context not initialized. Call initWaku first."; return false; } - + // Convert QStrings to UTF-8 byte arrays QByteArray topicUtf8 = pubSubTopic.toUtf8(); QByteArray messageUtf8 = jsonWakuMessage.toUtf8(); - + // Call waku_relay_publish with hardcoded timeout of 10000ms - int result = waku_relay_publish(wakuCtx, topicUtf8.constData(), messageUtf8.constData(), 10000, relay_publish_callback, this); - - if (result == RET_OK) { + int result = waku_relay_publish(wakuCtx, relay_publish_callback, this, topicUtf8.constData(), messageUtf8.constData(), 10000); + + if (result == RET_OK) + { qDebug() << "WakuModulePlugin: Relay publish initiated successfully for topic:" << pubSubTopic; return true; - } else { + } + else + { qWarning() << "WakuModulePlugin: Failed to publish to relay topic:" << pubSubTopic << ", error code:" << result; return false; } } +bool WakuModulePlugin::lightPublish(const QString &pubSubTopic, const QString &jsonWakuMessage) +{ + qDebug() << "WakuModulePlugin::lightPublish called with pubSubTopic:" << pubSubTopic; + qDebug() << "WakuModulePlugin::lightPublish message:" << jsonWakuMessage; + + if (!wakuCtx) + { + qWarning() << "WakuModulePlugin: Cannot publish using lightpush - context not initialized. Call initWaku first."; + return false; + } + + // Convert QStrings to UTF-8 byte arrays + QByteArray topicUtf8 = pubSubTopic.toUtf8(); + QByteArray messageUtf8 = jsonWakuMessage.toUtf8(); + + // why there is no timeout for lightpush publish??? + int result = waku_lightpush_publish(wakuCtx, light_publish_callback, this, topicUtf8.constData(), messageUtf8.constData()); + + if (result == RET_OK) + { + qDebug() << "WakuModulePlugin: Lightpush publish initiated successfully for topic:" << pubSubTopic; + return true; + } + else + { + qWarning() << "WakuModulePlugin: Failed to publish to lightpush topic:" << pubSubTopic << ", error code:" << result; + return false; + } +} + bool WakuModulePlugin::filterSubscribe(const QString &pubSubTopic, const QString &contentTopics) { qDebug() << "WakuModulePlugin::filterSubscribe called with pubSubTopic:" << pubSubTopic; qDebug() << "WakuModulePlugin::filterSubscribe contentTopics:" << contentTopics; - - if (!wakuCtx) { + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot subscribe to filter - context not initialized. Call initWaku first."; return false; } - + // Convert QStrings to UTF-8 byte arrays QByteArray topicUtf8 = pubSubTopic.toUtf8(); QByteArray contentTopicsUtf8 = contentTopics.toUtf8(); - + // Call waku_filter_subscribe - int result = waku_filter_subscribe(wakuCtx, topicUtf8.constData(), contentTopicsUtf8.constData(), filter_subscribe_callback, this); - - if (result == RET_OK) { + int result = waku_filter_subscribe(wakuCtx, filter_subscribe_callback, this, topicUtf8.constData(), contentTopicsUtf8.constData()); + + if (result == RET_OK) + { qDebug() << "WakuModulePlugin: Filter subscribe initiated successfully for topic:" << pubSubTopic; return true; - } else { + } + else + { qWarning() << "WakuModulePlugin: Failed to subscribe to filter topic:" << pubSubTopic << ", error code:" << result; return false; } @@ -357,23 +479,27 @@ bool WakuModulePlugin::storeQuery(const QString &jsonQuery, const QString &peerA { qDebug() << "WakuModulePlugin::storeQuery called with jsonQuery:" << jsonQuery; qDebug() << "WakuModulePlugin::storeQuery peerAddr:" << peerAddr; - - if (!wakuCtx) { + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot execute store query - context not initialized. Call initWaku first."; return false; } - + // Convert QStrings to UTF-8 byte arrays QByteArray queryUtf8 = jsonQuery.toUtf8(); QByteArray peerAddrUtf8 = peerAddr.toUtf8(); - + // Call waku_store_query with hardcoded timeout of 30000ms - int result = waku_store_query(wakuCtx, queryUtf8.constData(), peerAddrUtf8.constData(), 30000, store_query_callback, this); - - if (result == RET_OK) { + int result = waku_store_query(wakuCtx, store_query_callback, this, queryUtf8.constData(), peerAddrUtf8.constData(), 30000); + + if (result == RET_OK) + { qDebug() << "WakuModulePlugin: Store query initiated successfully for peer:" << peerAddr; return true; - } else { + } + else + { qWarning() << "WakuModulePlugin: Failed to execute store query for peer:" << peerAddr << ", error code:" << result; return false; } @@ -382,19 +508,23 @@ bool WakuModulePlugin::storeQuery(const QString &jsonQuery, const QString &peerA bool WakuModulePlugin::stopWaku() { qDebug() << "WakuModulePlugin::stopWaku called"; - - if (!wakuCtx) { + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot stop Waku - context not initialized. Call initWaku first."; return false; } - + // Call waku_stop with the saved context int result = waku_stop(wakuCtx, stop_callback, this); - - if (result == RET_OK) { + + if (result == RET_OK) + { qDebug() << "==================WakuModulePlugin: Waku stop initiated successfully======================="; return true; - } else { + } + else + { qWarning() << "WakuModulePlugin: Failed to stop Waku, error code:" << result; return false; } @@ -403,19 +533,23 @@ bool WakuModulePlugin::stopWaku() bool WakuModulePlugin::getConnectedPeers() { qDebug() << "WakuModulePlugin::getConnectedPeers called"; - - if (!wakuCtx) { + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot get connected peers - context not initialized. Call initWaku first."; return false; } - + // Call waku_get_connected_peers int result = waku_get_connected_peers(wakuCtx, get_connected_peers_callback, this); - - if (result == RET_OK) { + + if (result == RET_OK) + { qDebug() << "WakuModulePlugin: Get connected peers initiated successfully"; return true; - } else { + } + else + { qWarning() << "WakuModulePlugin: Failed to get connected peers, error code:" << result; return false; } @@ -424,20 +558,126 @@ bool WakuModulePlugin::getConnectedPeers() bool WakuModulePlugin::getMetrics() { qDebug() << "WakuModulePlugin::getMetrics called"; - - if (!wakuCtx) { + + if (!wakuCtx) + { qWarning() << "WakuModulePlugin: Cannot get metrics - context not initialized. Call initWaku first."; return false; } - + // Call waku_get_metrics int result = waku_get_metrics(wakuCtx, get_metrics_callback, this); - - if (result == RET_OK) { + + if (result == RET_OK) + { qDebug() << "WakuModulePlugin: Get metrics initiated successfully"; return true; - } else { + } + else + { qWarning() << "WakuModulePlugin: Failed to get metrics, error code:" << result; return false; } } + +void WakuModulePlugin::get_mixnode_pool_size_callback(int callerRet, const char *msg, size_t len, void *userData) +{ + qDebug() << "WakuModulePlugin::get_mixnode_pool_size_callback called with ret:" << callerRet; + + WakuModulePlugin *plugin = static_cast(userData); + if (!plugin) + { + qWarning() << "WakuModulePlugin::get_mixnode_pool_size_callback: Invalid userData"; + return; + } + + if (msg && len > 0) + { + QString message = QString::fromUtf8(msg, len); + qDebug() << "WakuModulePlugin::get_mixnode_pool_size_callback message:" << message; + + // Create event data with the mixnode pool size result + QVariantList eventData; + eventData << message; + eventData << QDateTime::currentDateTime().toString(Qt::ISODate); + + // Trigger event using emitEvent helper + plugin->emitEvent("mixnodePoolSizeResponse", eventData); + } +} + +void WakuModulePlugin::get_lightpush_peers_count_callback(int callerRet, const char *msg, size_t len, void *userData) +{ + qDebug() << "WakuModulePlugin::get_lightpush_peers_count_callback called with ret:" << callerRet; + + WakuModulePlugin *plugin = static_cast(userData); + if (!plugin) + { + qWarning() << "WakuModulePlugin::get_lightpush_peers_count_callback: Invalid userData"; + return; + } + + if (msg && len > 0) + { + QString message = QString::fromUtf8(msg, len); + qDebug() << "WakuModulePlugin::get_lightpush_peers_count_callback message:" << message; + + // Create event data with the lightpush peers count result + QVariantList eventData; + eventData << message; + eventData << QDateTime::currentDateTime().toString(Qt::ISODate); + + // Trigger event using emitEvent helper + plugin->emitEvent("lightpushPeersCountResponse", eventData); + } +} + +bool WakuModulePlugin::getMixnodePoolSize() +{ + qDebug() << "WakuModulePlugin::getMixnodePoolSize called"; + + if (!wakuCtx) + { + qWarning() << "WakuModulePlugin: Cannot get mixnode pool size - context not initialized. Call initWaku first."; + return false; + } + + // Call waku_get_mixnode_pool_size + int result = waku_get_mixnode_pool_size(wakuCtx, get_mixnode_pool_size_callback, this); + + if (result == RET_OK) + { + qDebug() << "WakuModulePlugin: Get mixnode pool size initiated successfully"; + return true; + } + else + { + qWarning() << "WakuModulePlugin: Failed to get mixnode pool size, error code:" << result; + return false; + } +} + +bool WakuModulePlugin::getLightpushPeersCount() +{ + qDebug() << "WakuModulePlugin::getLightpushPeersCount called"; + + if (!wakuCtx) + { + qWarning() << "WakuModulePlugin: Cannot get lightpush peers count - context not initialized. Call initWaku first."; + return false; + } + + // Call waku_get_lightpush_peers_count + int result = waku_get_lightpush_peers_count(wakuCtx, get_lightpush_peers_count_callback, this); + + if (result == RET_OK) + { + qDebug() << "WakuModulePlugin: Get lightpush peers count initiated successfully"; + return true; + } + else + { + qWarning() << "WakuModulePlugin: Failed to get lightpush peers count, error code:" << result; + return false; + } +} diff --git a/waku_module_plugin.h b/waku_module_plugin.h index 8699a52..3478109 100644 --- a/waku_module_plugin.h +++ b/waku_module_plugin.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include #include "waku_module_interface.h" #include "logos_api.h" #include "logos_api_client.h" @@ -21,37 +23,48 @@ class WakuModulePlugin : public QObject, public WakuModuleInterface Q_INVOKABLE bool startWaku() override; Q_INVOKABLE bool stopWaku() override; Q_INVOKABLE bool setEventCallback() override; - Q_INVOKABLE bool relaySubscribe(const QString &pubSubTopic) override; + Q_INVOKABLE bool relaySubscribe(const QString &contentTopic, const QString &pubSubTopic = QString()) override; Q_INVOKABLE bool relayPublish(const QString &pubSubTopic, const QString &jsonWakuMessage) override; Q_INVOKABLE bool filterSubscribe(const QString &pubSubTopic, const QString &contentTopics) override; Q_INVOKABLE bool storeQuery(const QString &jsonQuery, const QString &peerAddr) override; Q_INVOKABLE bool getConnectedPeers() override; Q_INVOKABLE bool getMetrics() override; + Q_INVOKABLE bool lightPublish(const QString &pubSubTopic, const QString &jsonWakuMessage) override; + Q_INVOKABLE bool getMixnodePoolSize() override; + Q_INVOKABLE bool getLightpushPeersCount() override; + QString name() const override { return "waku_module"; } QString version() const override { return "1.0.0"; } // LogosAPI initialization - Q_INVOKABLE void initLogos(LogosAPI* logosAPIInstance); + Q_INVOKABLE void initLogos(LogosAPI *logosAPIInstance); signals: // for now this is required for events, later it might not be necessary if using a proxy - void eventResponse(const QString& eventName, const QVariantList& data); + void eventResponse(const QString &eventName, const QVariantList &data); private: - void* wakuCtx; - + void *wakuCtx; + QSemaphore m_initSemaphore; + std::atomic m_initSuccess{false}; + QSemaphore m_startSemaphore; + std::atomic m_startSuccess{false}; + // Helper method for emitting events - void emitEvent(const QString& eventName, const QVariantList& data); - + void emitEvent(const QString &eventName, const QVariantList &data); + // Static callback functions for waku - static void init_callback(int callerRet, const char* msg, size_t len, void* userData); - static void start_callback(int callerRet, const char* msg, size_t len, void* userData); - static void stop_callback(int callerRet, const char* msg, size_t len, void* userData); - static void event_callback(int callerRet, const char* msg, size_t len, void* userData); - static void relay_subscribe_callback(int callerRet, const char* msg, size_t len, void* userData); - static void relay_publish_callback(int callerRet, const char* msg, size_t len, void* userData); - static void filter_subscribe_callback(int callerRet, const char* msg, size_t len, void* userData); - static void store_query_callback(int callerRet, const char* msg, size_t len, void* userData); - static void get_connected_peers_callback(int callerRet, const char* msg, size_t len, void* userData); - static void get_metrics_callback(int callerRet, const char* msg, size_t len, void* userData); -}; \ No newline at end of file + static void init_callback(int callerRet, const char *msg, size_t len, void *userData); + static void start_callback(int callerRet, const char *msg, size_t len, void *userData); + static void stop_callback(int callerRet, const char *msg, size_t len, void *userData); + static void event_callback(int callerRet, const char *msg, size_t len, void *userData); + static void relay_subscribe_callback(int callerRet, const char *msg, size_t len, void *userData); + static void relay_publish_callback(int callerRet, const char *msg, size_t len, void *userData); + static void filter_subscribe_callback(int callerRet, const char *msg, size_t len, void *userData); + static void store_query_callback(int callerRet, const char *msg, size_t len, void *userData); + static void get_connected_peers_callback(int callerRet, const char *msg, size_t len, void *userData); + static void get_metrics_callback(int callerRet, const char *msg, size_t len, void *userData); + static void light_publish_callback(int callerRet, const char *msg, size_t len, void *userData); + static void get_mixnode_pool_size_callback(int callerRet, const char *msg, size_t len, void *userData); + static void get_lightpush_peers_count_callback(int callerRet, const char *msg, size_t len, void *userData); +};