mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-07 16:33:08 +00:00
Implemented store methods wrappers
This commit is contained in:
parent
15dbe6284e
commit
fa56c3540b
@ -7,7 +7,7 @@ use std::time::Duration;
|
|||||||
use crate::general::Result;
|
use crate::general::Result;
|
||||||
use crate::general::{FilterSubscription, JsonResponse, MessageId, PeerId};
|
use crate::general::{FilterSubscription, JsonResponse, MessageId, PeerId};
|
||||||
|
|
||||||
/// Creates a subscription in a lightnode for messages that matches a content filter and optionally a [`PubSubTopic`]
|
/// 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)
|
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_filter_subscribechar-filterjson-char-peerid-int-timeoutms)
|
||||||
pub fn waku_filter_subscribe(
|
pub fn waku_filter_subscribe(
|
||||||
filter_subscription: &FilterSubscription,
|
filter_subscription: &FilterSubscription,
|
||||||
@ -40,7 +40,7 @@ pub fn waku_filter_subscribe(
|
|||||||
Result::from(response).map(|_| ())
|
Result::from(response).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Removes subscriptions in a light node matching a content filter and, optionally, a [`PubSubTopic`]
|
/// Removes subscriptions in a light node matching a content filter and, optionally, a [`WakuPubSubTopic`](`crate::general::WakuPubSubTopic`)
|
||||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_filter_unsubscribechar-filterjson-int-timeoutms)
|
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_filter_unsubscribechar-filterjson-int-timeoutms)
|
||||||
pub fn waku_filter_unsubscribe(
|
pub fn waku_filter_unsubscribe(
|
||||||
filter_subscription: &FilterSubscription,
|
filter_subscription: &FilterSubscription,
|
||||||
|
|||||||
@ -4,6 +4,7 @@ mod lightpush;
|
|||||||
mod management;
|
mod management;
|
||||||
mod peers;
|
mod peers;
|
||||||
mod relay;
|
mod relay;
|
||||||
|
mod store;
|
||||||
|
|
||||||
// std
|
// std
|
||||||
use aes_gcm::{Aes256Gcm, Key};
|
use aes_gcm::{Aes256Gcm, Key};
|
||||||
|
|||||||
40
waku/src/node/store.rs
Normal file
40
waku/src/node/store.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// std
|
||||||
|
use std::ffi::{CStr, CString};
|
||||||
|
use std::time::Duration;
|
||||||
|
// crates
|
||||||
|
// internal
|
||||||
|
use crate::general::{JsonResponse, PeerId, Result, StoreQuery, StoreResponse};
|
||||||
|
|
||||||
|
/// 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`),
|
||||||
|
/// 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_store_query(
|
||||||
|
query: &StoreQuery,
|
||||||
|
peer_id: PeerId,
|
||||||
|
timeout: Duration,
|
||||||
|
) -> Result<StoreResponse> {
|
||||||
|
let result = unsafe {
|
||||||
|
CStr::from_ptr(waku_sys::waku_store_query(
|
||||||
|
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(),
|
||||||
|
CString::new(peer_id)
|
||||||
|
.expect("CString should build properly from peer id")
|
||||||
|
.into_raw(),
|
||||||
|
timeout
|
||||||
|
.as_millis()
|
||||||
|
.try_into()
|
||||||
|
.expect("Duration as milliseconds should fit in a i32"),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
.to_str()
|
||||||
|
.expect("Response should always succeed to load to a &str");
|
||||||
|
|
||||||
|
let response: JsonResponse<StoreResponse> =
|
||||||
|
serde_json::from_str(result).expect("JsonResponse should always succeed to deserialize");
|
||||||
|
response.into()
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user