mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-02 14:03:12 +00:00
few adaptations to use latest nwaku master
This commit is contained in:
parent
863d3aee9c
commit
4cdbacda19
@ -40,7 +40,12 @@ async fn main() -> Result<(), Error> {
|
||||
println!("Message Received in NODE 2: {}", msg);
|
||||
println!("::::::::::::::::::::::::::::::::::::::::::::::::::::");
|
||||
}
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {} // do nothing
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {
|
||||
// dbg!("Relay topic change evt", evt);
|
||||
}
|
||||
WakuEvent::ConnectionChange(_evt) => {
|
||||
// dbg!("Conn change evt", evt);
|
||||
}
|
||||
WakuEvent::Unrecognized(err) => panic!("Unrecognized waku event: {:?}", err),
|
||||
_ => panic!("event case not expected"),
|
||||
};
|
||||
@ -64,6 +69,12 @@ async fn main() -> Result<(), Error> {
|
||||
println!("Message Received in NODE 1: {}", msg);
|
||||
println!("::::::::::::::::::::::::::::::::::::::::::::::::::::");
|
||||
}
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {
|
||||
// dbg!("Relay topic change evt", evt);
|
||||
}
|
||||
WakuEvent::ConnectionChange(_evt) => {
|
||||
// dbg!("Conn change evt", evt);
|
||||
}
|
||||
WakuEvent::Unrecognized(err) => panic!("Unrecognized waku event: {:?}", err),
|
||||
_ => panic!("event case not expected"),
|
||||
};
|
||||
|
||||
@ -75,7 +75,12 @@ impl TicTacToeApp<Initialized> {
|
||||
}
|
||||
}
|
||||
},
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {}, // do nothing
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {
|
||||
// dbg!("Relay topic change evt", evt);
|
||||
},
|
||||
WakuEvent::ConnectionChange(_evt) => {
|
||||
// dbg!("Conn change evt", evt);
|
||||
},
|
||||
WakuEvent::Unrecognized(err) => panic!("Unrecognized waku event: {:?}", err),
|
||||
_ => panic!("event case not expected"),
|
||||
};
|
||||
@ -89,14 +94,14 @@ impl TicTacToeApp<Initialized> {
|
||||
let waku = self.waku.start().await.expect("waku should start");
|
||||
|
||||
// Subscribe to desired topic using the relay protocol
|
||||
// waku.relay_subscribe(&self.game_topic).await.expect("waku should subscribe");
|
||||
waku.relay_subscribe(&self.game_topic).await.expect("waku should subscribe");
|
||||
|
||||
// Example filter subscription. This is needed in edge nodes (resource-restricted devices)
|
||||
// Nodes usually use either relay or lightpush/filter protocols
|
||||
|
||||
let ctopic = WakuContentTopic::new("waku", "2", "tictactoegame", Encoding::Proto);
|
||||
let content_topics = vec![ctopic];
|
||||
waku.filter_subscribe(&self.game_topic, content_topics).await.expect("waku should subscribe");
|
||||
// let ctopic = WakuContentTopic::new("waku", "2", "tictactoegame", Encoding::Proto);
|
||||
// let content_topics = vec![ctopic];
|
||||
// waku.filter_subscribe(&self.game_topic, content_topics).await.expect("waku should subscribe");
|
||||
|
||||
// End filter example ----------------------------------------
|
||||
|
||||
@ -137,18 +142,18 @@ impl TicTacToeApp<Running> {
|
||||
false,
|
||||
);
|
||||
|
||||
// if let Ok(msg_hash) = self.waku.relay_publish_message(&message, &self.game_topic, None).await {
|
||||
// dbg!(format!("message hash published: {}", msg_hash));
|
||||
// }
|
||||
if let Ok(msg_hash) = self.waku.relay_publish_message(&message, &self.game_topic, None).await {
|
||||
dbg!(format!("message hash published: {}", msg_hash));
|
||||
}
|
||||
|
||||
// Example lightpush publish message. This is needed in edge nodes (resource-restricted devices)
|
||||
// Nodes usually use either relay or lightpush/filter protocols
|
||||
//
|
||||
let msg_hash_ret = self.waku.lightpush_publish_message(&message, &self.game_topic).await;
|
||||
match msg_hash_ret {
|
||||
Ok(msg_hash) => println!("Published message hash {:?}", msg_hash.to_string()),
|
||||
Err(error) => println!("Failed to publish with lightpush: {}", error)
|
||||
}
|
||||
// let msg_hash_ret = self.waku.lightpush_publish_message(&message, &self.game_topic).await;
|
||||
// match msg_hash_ret {
|
||||
// Ok(msg_hash) => println!("Published message hash {:?}", msg_hash.to_string()),
|
||||
// Err(error) => println!("Failed to publish with lightpush: {}", error)
|
||||
// }
|
||||
// End example lightpush publish message
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +111,12 @@ impl App<Initialized> {
|
||||
}
|
||||
}
|
||||
},
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {} // do nothing
|
||||
WakuEvent::RelayTopicHealthChange(_evt) => {
|
||||
// dbg!("Relay topic change evt", evt);
|
||||
},
|
||||
WakuEvent::ConnectionChange(_evt) => {
|
||||
// dbg!("Conn change evt", evt);
|
||||
},
|
||||
WakuEvent::Unrecognized(err) => eprintln!("Unrecognized waku event: {:?}", err),
|
||||
_ => eprintln!("event case not expected"),
|
||||
};
|
||||
@ -120,9 +125,6 @@ impl App<Initialized> {
|
||||
|
||||
let waku = self.waku.start().await?;
|
||||
|
||||
let pubsub_topic = PubsubTopic::new(DEFAULT_PUBSUB_TOPIC);
|
||||
waku.relay_subscribe(&pubsub_topic).await?;
|
||||
|
||||
Ok(App {
|
||||
input: self.input,
|
||||
nick: self.nick,
|
||||
|
||||
@ -24,6 +24,9 @@ pub enum WakuEvent {
|
||||
#[serde(rename = "relay_topic_health_change")]
|
||||
RelayTopicHealthChange(TopicHealthEvent),
|
||||
|
||||
#[serde(rename = "connection_change")]
|
||||
ConnectionChange(ConnectionChangeEvent),
|
||||
|
||||
Unrecognized(serde_json::Value),
|
||||
}
|
||||
|
||||
@ -39,7 +42,7 @@ pub struct WakuMessageEvent {
|
||||
pub waku_message: WakuMessage,
|
||||
}
|
||||
|
||||
/// Type of `event` field for a `message` event
|
||||
/// Type of `event` field for a `topic health` event
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TopicHealthEvent {
|
||||
@ -49,10 +52,20 @@ pub struct TopicHealthEvent {
|
||||
pub topic_health: String,
|
||||
}
|
||||
|
||||
/// Type of `event` field for a `connection change` event
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ConnectionChangeEvent {
|
||||
/// The pubsub topic on which the message was received
|
||||
pub peer_id: String,
|
||||
/// The message hash
|
||||
pub peer_event: String,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::WakuEvent;
|
||||
use crate::WakuEvent::RelayTopicHealthChange;
|
||||
use crate::WakuEvent::{ConnectionChange, RelayTopicHealthChange};
|
||||
|
||||
#[test]
|
||||
fn deserialize_message_event() {
|
||||
@ -73,4 +86,20 @@ mod tests {
|
||||
_ => panic!("Expected RelayTopicHealthChange event, but got {:?}", evt),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn deserialize_connection_change_event() {
|
||||
let s = "{\"eventType\":\"connection_change\", \"peerId\":\"16Uiu2HAmAR24Mbb6VuzoyUiGx42UenDkshENVDj4qnmmbabLvo31\",\"peerEvent\":\"Joined\"}";
|
||||
let evt: WakuEvent = serde_json::from_str(s).unwrap();
|
||||
match evt {
|
||||
ConnectionChange(conn_change_event) => {
|
||||
assert_eq!(
|
||||
conn_change_event.peer_id,
|
||||
"16Uiu2HAmAR24Mbb6VuzoyUiGx42UenDkshENVDj4qnmmbabLvo31"
|
||||
);
|
||||
assert_eq!(conn_change_event.peer_event, "Joined");
|
||||
}
|
||||
_ => panic!("Expected RelayTopicHealthChange event, but got {:?}", evt),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 1d206a5f5e89f7bac855bfd2e25066bcf1187ade
|
||||
Subproject commit 625c8ee51bc3e065da0e2e8d3a53d3634589f548
|
||||
Loading…
x
Reference in New Issue
Block a user