From 3593ff18e6c79f382f4dc896a60c90a7af5a06b0 Mon Sep 17 00:00:00 2001 From: Daniel Sanchez Date: Wed, 15 Feb 2023 10:57:39 +0100 Subject: [PATCH] Expose local archive query method (#44) * Update vendor * Expose local archive query Update to beta4 * Update bindings package to beta4 * Update bindings package to beta4 * Make store response fields public * Added store configuration * Use decode response function --- Cargo.lock | 12 ++++++------ examples/Cargo.lock | 4 ++-- examples/toy-chat/src/main.rs | 1 + waku-bindings/Cargo.toml | 4 ++-- waku-bindings/src/general/mod.rs | 4 ++-- waku-bindings/src/node/config.rs | 13 ++++++++++++- waku-bindings/src/node/mod.rs | 8 ++++++++ waku-bindings/src/node/store.rs | 18 ++++++++++++++++++ waku-sys/Cargo.toml | 4 ++-- waku-sys/vendor | 2 +- 10 files changed, 54 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f7f9564..11a210e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -87,9 +87,9 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bindgen" -version = "0.63.0" +version = "0.64.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885" +checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4" dependencies = [ "bitflags", "cexpr", @@ -1246,9 +1246,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.24.2" +version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a12a59981d9e3c38d216785b0c37399f6e415e8d0712047620f189371b0bb" +checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", "pin-project-lite", @@ -1381,7 +1381,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waku-bindings" -version = "0.1.0-beta3" +version = "0.1.0-beta4" dependencies = [ "aes-gcm", "base64", @@ -1403,7 +1403,7 @@ dependencies = [ [[package]] name = "waku-sys" -version = "0.1.0-beta3" +version = "0.1.0-beta4" dependencies = [ "bindgen", ] diff --git a/examples/Cargo.lock b/examples/Cargo.lock index e326045..dfa9764 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -1203,7 +1203,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waku-bindings" -version = "0.1.0-beta1" +version = "0.1.0-beta3" dependencies = [ "aes-gcm", "base64", @@ -1222,7 +1222,7 @@ dependencies = [ [[package]] name = "waku-sys" -version = "0.1.0-beta1" +version = "0.1.0-beta4" dependencies = [ "bindgen", ] diff --git a/examples/toy-chat/src/main.rs b/examples/toy-chat/src/main.rs index 716fc79..cf0c9bc 100644 --- a/examples/toy-chat/src/main.rs +++ b/examples/toy-chat/src/main.rs @@ -102,6 +102,7 @@ fn retrieve_history( }) .collect()) } + fn setup_node_handle() -> std::result::Result, Box> { let node_handle = waku_new(None)?; let node_handle = node_handle.start()?; diff --git a/waku-bindings/Cargo.toml b/waku-bindings/Cargo.toml index c650a59..f8f28df 100644 --- a/waku-bindings/Cargo.toml +++ b/waku-bindings/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "waku-bindings" -version = "0.1.0-beta3" +version = "0.1.0-beta4" edition = "2021" authors = [ "Daniel Sanchez Quiros " @@ -25,7 +25,7 @@ serde_json = "1.0" sscanf = "0.3" smart-default = "0.6" url = "2.3" -waku-sys = { version = "0.1.0-beta3", path = "../waku-sys" } +waku-sys = { version = "0.1.0-beta4", path = "../waku-sys" } [dev-dependencies] futures = "0.3.25" diff --git a/waku-bindings/src/general/mod.rs b/waku-bindings/src/general/mod.rs index 9d0f16b..6148e2a 100644 --- a/waku-bindings/src/general/mod.rs +++ b/waku-bindings/src/general/mod.rs @@ -249,9 +249,9 @@ pub struct StoreQuery { pub struct StoreResponse { /// Array of retrieved historical messages in [`WakuMessage`] format #[serde(default)] - messages: Vec, + pub messages: Vec, /// Paging information in [`PagingOptions`] format from which to resume further historical queries - paging_options: Option, + pub paging_options: Option, } impl StoreResponse { diff --git a/waku-bindings/src/node/config.rs b/waku-bindings/src/node/config.rs index 71d68ee..bd9026b 100644 --- a/waku-bindings/src/node/config.rs +++ b/waku-bindings/src/node/config.rs @@ -34,7 +34,18 @@ pub struct WakuNodeConfig { /// Enable relay protocol. Default `true` #[default(Some(true))] pub relay: Option, - #[serde(default)] + /// Enable store protocol to persist message history + #[default(Some(false))] + pub store: Option, + /// Url connection string. Accepts SQLite and PostgreSQL connection strings + #[default(Some("sqlite3://store.db".to_string()))] + pub database_url: Option, + /// Max number of messages to store in the databas + #[default(Some(1000))] + pub store_retention_max_messages: Option, + /// Max number of seconds that a message will be persisted in the database, default 1 day + #[default(Some(86400))] + pub store_retention_max_seconds: Option, pub relay_topics: Vec, /// The minimum number of peers required on a topic to allow broadcasting a message. Default `0` #[default(Some(0))] diff --git a/waku-bindings/src/node/mod.rs b/waku-bindings/src/node/mod.rs index e39c3b1..d601e53 100644 --- a/waku-bindings/src/node/mod.rs +++ b/waku-bindings/src/node/mod.rs @@ -225,6 +225,14 @@ impl WakuNodeHandle { store::waku_store_query(query, peer_id, timeout) } + /// Retrieves locally stored 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`), + /// the node must return messages on a per-page basis and include [`PagingOptions`](`crate::general::PagingOptions`) in the response. + /// These [`PagingOptions`](`crate::general::PagingOptions`) must contain a cursor pointing to the Index from which a new page can be requested + pub fn local_store_query(&self, query: &StoreQuery) -> Result { + store::waku_local_store_query(query) + } + /// 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) pub fn lightpush_publish( diff --git a/waku-bindings/src/node/store.rs b/waku-bindings/src/node/store.rs index 824ff04..c5dca16 100644 --- a/waku-bindings/src/node/store.rs +++ b/waku-bindings/src/node/store.rs @@ -46,3 +46,21 @@ pub fn waku_store_query( decode_and_free_response(result_ptr) } + +/// Retrieves locally stored historical messages on specific content topics from the local archive system. 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`), +/// the node must return messages on a per-page basis and include [`PagingOptions`](`crate::general::PagingOptions`) in the response. +/// These [`PagingOptions`](`crate::general::PagingOptions`) must contain a cursor pointing to the Index from which a new page can be requested +pub fn waku_local_store_query(query: &StoreQuery) -> Result { + let query_ptr = CString::new( + serde_json::to_string(query).expect("StoreQuery should always be able to be serialized"), + ) + .expect("CString should build properly from the serialized filter subscription") + .into_raw(); + let result_ptr = unsafe { + let res = waku_sys::waku_store_local_query(query_ptr); + drop(CString::from_raw(query_ptr)); + res + }; + decode_and_free_response(result_ptr) +} diff --git a/waku-sys/Cargo.toml b/waku-sys/Cargo.toml index 45838a4..37dcc1a 100644 --- a/waku-sys/Cargo.toml +++ b/waku-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "waku-sys" -version = "0.1.0-beta3" +version = "0.1.0-beta4" edition = "2021" authors = [ "Daniel Sanchez Quiros " @@ -19,4 +19,4 @@ crate-type = ["rlib"] [dependencies] [build-dependencies] -bindgen = "0.63" \ No newline at end of file +bindgen = "0.64" \ No newline at end of file diff --git a/waku-sys/vendor b/waku-sys/vendor index 6c989fb..11161b8 160000 --- a/waku-sys/vendor +++ b/waku-sys/vendor @@ -1 +1 @@ -Subproject commit 6c989fb1780159aacd8ec210ac4d7a33f40005df +Subproject commit 11161b8919d2d2ad28b9f51dc38ca28ce2c94b72