diff --git a/waku-bindings/src/node/discovery.rs b/waku-bindings/src/node/discovery.rs index 19acacd..d9164ab 100644 --- a/waku-bindings/src/node/discovery.rs +++ b/waku-bindings/src/node/discovery.rs @@ -5,7 +5,7 @@ use std::time::Duration; use multiaddr::Multiaddr; use url::{Host, Url}; // internal -use crate::utils::decode_response; +use crate::utils::decode_and_free_response; use crate::Result; /// RetrieveNodes returns a list of multiaddress given a url to a DNS discoverable ENR tree. @@ -44,5 +44,5 @@ pub fn waku_dns_discovery( res }; - decode_response(result_ptr) + decode_and_free_response(result_ptr) } diff --git a/waku-bindings/src/node/filter.rs b/waku-bindings/src/node/filter.rs index 5708bcb..bd63e33 100644 --- a/waku-bindings/src/node/filter.rs +++ b/waku-bindings/src/node/filter.rs @@ -8,7 +8,7 @@ use std::time::Duration; // internal use crate::general::Result; use crate::general::{FilterSubscription, PeerId}; -use crate::utils::decode_response; +use crate::utils::decode_and_free_response; /// Creates a subscription in a lightnode for messages that matches a content filter and optionally a [`WakuPubSubTopic`](`crate::general::WakuPubSubTopic`) /// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_filter_subscribechar-filterjson-char-peerid-int-timeoutms) @@ -40,7 +40,7 @@ pub fn waku_filter_subscribe( drop(CString::from_raw(peer_id_ptr)); result_ptr }; - decode_response::(result_ptr).map(|_| ()) + decode_and_free_response::(result_ptr).map(|_| ()) } /// Removes subscriptions in a light node matching a content filter and, optionally, a [`WakuPubSubTopic`](`crate::general::WakuPubSubTopic`) @@ -67,5 +67,5 @@ pub fn waku_filter_unsubscribe( res }; - decode_response::(result_ptr).map(|_| ()) + decode_and_free_response::(result_ptr).map(|_| ()) } diff --git a/waku-bindings/src/node/lightpush.rs b/waku-bindings/src/node/lightpush.rs index 8e15659..7dc2cfd 100644 --- a/waku-bindings/src/node/lightpush.rs +++ b/waku-bindings/src/node/lightpush.rs @@ -9,7 +9,7 @@ use secp256k1::{PublicKey, SecretKey}; // internal use crate::general::{MessageId, PeerId, Result, WakuMessage, WakuPubSubTopic}; use crate::node::waku_dafault_pubsub_topic; -use crate::utils::decode_response; +use crate::utils::decode_and_free_response; /// Publish a message using Waku Lightpush /// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_lightpush_publishchar-messagejson-char-topic-char-peerid-int-timeoutms) @@ -54,7 +54,7 @@ pub fn waku_lightpush_publish( res }; - decode_response(result_ptr) + decode_and_free_response(result_ptr) } /// Optionally sign, encrypt using asymmetric encryption and publish a message using Waku Lightpush @@ -117,7 +117,7 @@ pub fn waku_lightpush_publish_encrypt_asymmetric( res }; - decode_response(result_ptr) + decode_and_free_response(result_ptr) } /// Optionally sign, encrypt using symmetric encryption and publish a message using Waku Lightpush @@ -179,5 +179,5 @@ pub fn waku_lightpush_publish_encrypt_symmetric( res }; - decode_response(result_ptr) + decode_and_free_response(result_ptr) } diff --git a/waku-bindings/src/node/management.rs b/waku-bindings/src/node/management.rs index 063ac40..7459d5a 100644 --- a/waku-bindings/src/node/management.rs +++ b/waku-bindings/src/node/management.rs @@ -7,7 +7,7 @@ use std::ffi::{CStr, CString}; // internal use super::config::WakuNodeConfig; use crate::general::{JsonResponse, PeerId, Result}; -use crate::utils::decode_response; +use crate::utils::decode_and_free_response; /// Instantiates a Waku node /// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_newchar-jsonconfig) @@ -99,7 +99,7 @@ pub fn waku_peer_id() -> Result { /// as per [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_listen_addresses) pub fn waku_listen_addresses() -> Result> { let response_ptr = unsafe { waku_sys::waku_listen_addresses() }; - decode_response(response_ptr) + decode_and_free_response(response_ptr) } #[cfg(test)] diff --git a/waku-bindings/src/node/peers.rs b/waku-bindings/src/node/peers.rs index 75cd9d3..29c3823 100644 --- a/waku-bindings/src/node/peers.rs +++ b/waku-bindings/src/node/peers.rs @@ -8,7 +8,7 @@ use multiaddr::Multiaddr; use serde::Deserialize; // internal use crate::general::{JsonResponse, PeerId, ProtocolId, Result}; -use crate::utils::decode_response; +use crate::utils::decode_and_free_response; /// Add a node multiaddress and protocol to the waku node’s peerstore. /// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_add_peerchar-address-char-protocolid) @@ -206,7 +206,7 @@ pub type WakuPeers = Vec; /// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_peers) pub fn waku_peers() -> Result { let response_ptr = unsafe { waku_sys::waku_peers() }; - decode_response(response_ptr) + decode_and_free_response(response_ptr) } #[cfg(test)] diff --git a/waku-bindings/src/node/relay.rs b/waku-bindings/src/node/relay.rs index 974c0e6..f025850 100644 --- a/waku-bindings/src/node/relay.rs +++ b/waku-bindings/src/node/relay.rs @@ -10,7 +10,7 @@ use secp256k1::{PublicKey, SecretKey}; use crate::general::{ Encoding, JsonResponse, MessageId, Result, WakuContentTopic, WakuMessage, WakuPubSubTopic, }; -use crate::utils::decode_response; +use crate::utils::decode_and_free_response; /// Create a content topic according to [RFC 23](https://rfc.vac.dev/spec/23/) /// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_content_topicchar-applicationname-unsigned-int-applicationversion-char-contenttopicname-char-encoding) @@ -138,7 +138,7 @@ pub fn waku_relay_publish_message( res }; - decode_response(result_ptr) + decode_and_free_response(result_ptr) } /// Optionally sign, encrypt using asymmetric encryption and publish a message using Waku Relay @@ -196,7 +196,7 @@ pub fn waku_relay_publish_encrypt_asymmetric( res }; - decode_response(result_ptr) + decode_and_free_response(result_ptr) } /// Optionally sign, encrypt using symmetric encryption and publish a message using Waku Relay @@ -254,7 +254,7 @@ pub fn waku_relay_publish_encrypt_symmetric( res }; - decode_response(result_ptr) + decode_and_free_response(result_ptr) } pub fn waku_enough_peers(pubsub_topic: Option) -> Result { @@ -299,7 +299,7 @@ pub fn waku_relay_subscribe(pubsub_topic: Option) -> Result<()> res }; - decode_response::(result_ptr).map(|_| ()) + decode_and_free_response::(result_ptr).map(|_| ()) } pub fn waku_relay_unsubscribe(pubsub_topic: Option) -> Result<()> { @@ -317,5 +317,5 @@ pub fn waku_relay_unsubscribe(pubsub_topic: Option) -> Result<( res }; - decode_response::(result_ptr).map(|_| ()) + decode_and_free_response::(result_ptr).map(|_| ()) } diff --git a/waku-bindings/src/node/store.rs b/waku-bindings/src/node/store.rs index e5fcf04..824ff04 100644 --- a/waku-bindings/src/node/store.rs +++ b/waku-bindings/src/node/store.rs @@ -6,7 +6,7 @@ use std::time::Duration; // crates // internal use crate::general::{PeerId, Result, StoreQuery, StoreResponse}; -use crate::utils::decode_response; +use crate::utils::decode_and_free_response; /// Retrieves historical messages on specific content topics. This method may be called with [`PagingOptions`](`crate::general::PagingOptions`), /// to retrieve historical messages on a per-page basis. If the request included [`PagingOptions`](`crate::general::PagingOptions`), @@ -44,5 +44,5 @@ pub fn waku_store_query( res }; - decode_response(result_ptr) + decode_and_free_response(result_ptr) } diff --git a/waku-bindings/src/utils.rs b/waku-bindings/src/utils.rs index 663e6bb..4744c46 100644 --- a/waku-bindings/src/utils.rs +++ b/waku-bindings/src/utils.rs @@ -4,7 +4,7 @@ use std::ffi::{c_char, CStr}; /// Safety: The caller is responsible for ensuring that the pointer is valid for the duration of the call. /// This takes a pointer to a C string coming from the waku lib, that data is consumed and then freed using [`waku_sys::waku_utils_free`]. -pub fn decode_response(response_ptr: *mut c_char) -> Result { +pub fn decode_and_free_response(response_ptr: *mut c_char) -> Result { let response = unsafe { CStr::from_ptr(response_ptr) } .to_str() .expect("Response should always succeed to load to a &str");