feat: expose list of topics

This commit is contained in:
Richard Ramos 2023-05-09 14:51:34 -04:00
parent 3356edc31a
commit 64dc964244
No known key found for this signature in database
GPG Key ID: 1CE87DB518195760
6 changed files with 27 additions and 7 deletions

View File

@ -201,7 +201,7 @@ fn run_app<B: Backend>(
1,
Utc::now().timestamp_nanos() as usize,
meta,
false
false,
);
if let Err(e) =
app.node_handle

View File

@ -104,7 +104,7 @@ impl WakuMessage {
version: WakuMessageVersion,
timestamp: usize,
meta: META,
ephemeral: bool
ephemeral: bool,
) -> Self {
let payload = payload.as_ref().to_vec();
let meta = meta.as_ref().to_vec();

View File

@ -212,6 +212,11 @@ impl WakuNodeHandle<Running> {
relay::waku_relay_unsubscribe(pubsub_topic)
}
/// Returns the list of pubsub topics the node is subscribed to in Waku Relay
pub fn relay_topics(&self) -> Result<Vec<String>> {
relay::waku_relay_topics()
}
/// 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.

View File

@ -97,6 +97,13 @@ pub fn waku_dafault_pubsub_topic() -> WakuPubSubTopic {
result
}
/// Get the list of subscribed pubsub topics in Waku Relay.
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_relay_topics)
pub fn waku_relay_topics() -> Result<Vec<String>> {
let result_ptr = unsafe { waku_sys::waku_relay_topics() };
decode_and_free_response(result_ptr)
}
/// Publish a message using Waku Relay
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_relay_publishchar-messagejson-char-pubsubtopic-int-timeoutms)
pub fn waku_relay_publish_message(

View File

@ -10,9 +10,9 @@ use std::{collections::HashSet, str::from_utf8};
use tokio::sync::mpsc::{self, Sender};
use tokio::time;
use waku_bindings::{
waku_new, waku_set_event_callback, Encoding, Event, GossipSubParams, Key, MessageId,
ProtocolId, Running, WakuContentTopic, WakuLogLevel, WakuMessage, WakuNodeConfig,
WakuNodeHandle,
waku_dafault_pubsub_topic, waku_new, waku_set_event_callback, Encoding, Event, GossipSubParams,
Key, MessageId, ProtocolId, Running, WakuContentTopic, WakuLogLevel, WakuMessage,
WakuNodeConfig, WakuNodeHandle, WakuPubSubTopic,
};
const ECHO_TIMEOUT: u64 = 10;
@ -120,7 +120,7 @@ async fn test_echo_messages(
.try_into()
.unwrap(),
Vec::new(),
false
false,
);
let (tx, mut rx) = mpsc::channel(1);
@ -179,6 +179,13 @@ async fn discv5_echo() -> Result<(), String> {
node.relay_subscribe(None)?;
let content_topic = WakuContentTopic::new("toychat", 2, "huilong", Encoding::Proto);
let topics = node.relay_topics()?;
let default_topic = waku_dafault_pubsub_topic();
assert!(topics.len() == 1);
let topic: WakuPubSubTopic = topics[0].parse().unwrap();
assert!(topic == default_topic);
let sleep = time::sleep(Duration::from_secs(ECHO_TIMEOUT));
tokio::pin!(sleep);
@ -283,6 +290,7 @@ fn gossipsub_config() -> Result<(), String> {
max_ihave_length: Some(32),
max_ihave_messages: Some(8),
iwant_followup_time_seconds: Some(120),
seen_messages_ttl_seconds: Some(120),
};
let config = WakuNodeConfig {

@ -1 +1 @@
Subproject commit 3c4a863cb7c898a6c551a51288a6badf809fd6f5
Subproject commit d9a12bf079a8bbb59ab1df591062b9bb91d3804d