mirror of
https://github.com/waku-org/waku-rust-bindings.git
synced 2025-02-18 01:27:09 +00:00
add discv5 stuff in test
This commit is contained in:
parent
b7e4de39ec
commit
2171f6c69e
@ -119,6 +119,11 @@ impl WakuNodeHandle<Running> {
|
|||||||
stop_node()
|
stop_node()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Stops the DiscoveryV5 service
|
||||||
|
pub fn discv5_stop(&self) -> Result<bool> {
|
||||||
|
discv5::waku_discv5_stop()
|
||||||
|
}
|
||||||
|
|
||||||
/// Dial peer using a multiaddress
|
/// Dial peer using a multiaddress
|
||||||
/// If `timeout` as milliseconds doesn't fit into a `i32` it is clamped to [`i32::MAX`]
|
/// If `timeout` as milliseconds doesn't fit into a `i32` it is clamped to [`i32::MAX`]
|
||||||
/// If the function execution takes longer than `timeout` value, the execution will be canceled and an error returned.
|
/// If the function execution takes longer than `timeout` value, the execution will be canceled and an error returned.
|
||||||
|
@ -34,6 +34,9 @@ pub fn main() -> Result<(), String> {
|
|||||||
discv5_bootstrap_nodes: Vec::new(),
|
discv5_bootstrap_nodes: Vec::new(),
|
||||||
};
|
};
|
||||||
let node = waku_new(Some(config))?;
|
let node = waku_new(Some(config))?;
|
||||||
|
let result = node.discv5_start()?;
|
||||||
|
println!("Discv5 started: {}", result);
|
||||||
|
|
||||||
let node = node.start()?;
|
let node = node.start()?;
|
||||||
println!("Node peer id: {}", node.peer_id()?);
|
println!("Node peer id: {}", node.peer_id()?);
|
||||||
|
|
||||||
@ -52,7 +55,7 @@ pub fn main() -> Result<(), String> {
|
|||||||
let ssk = Aes256Gcm::generate_key(&mut thread_rng());
|
let ssk = Aes256Gcm::generate_key(&mut thread_rng());
|
||||||
|
|
||||||
let content = "Hi from 🦀!";
|
let content = "Hi from 🦀!";
|
||||||
let content_callback = content.clone();
|
let content_callback = content;
|
||||||
|
|
||||||
waku_set_event_callback(move |signal| match signal.event() {
|
waku_set_event_callback(move |signal| match signal.event() {
|
||||||
Event::WakuMessage(message) => {
|
Event::WakuMessage(message) => {
|
||||||
@ -111,8 +114,7 @@ pub fn main() -> Result<(), String> {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|peer| peer.peer_id())
|
.map(|peer| peer.peer_id())
|
||||||
.filter(|id| id.as_str() != node.peer_id().unwrap().as_str())
|
.find(|id| id.as_str() != node.peer_id().unwrap().as_str())
|
||||||
.next()
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
@ -127,14 +129,7 @@ pub fn main() -> Result<(), String> {
|
|||||||
None,
|
None,
|
||||||
)?;
|
)?;
|
||||||
node.lightpush_publish_encrypt_symmetric(&message, None, peer_id.clone(), &ssk, None, None)?;
|
node.lightpush_publish_encrypt_symmetric(&message, None, peer_id.clone(), &ssk, None, None)?;
|
||||||
node.lightpush_publish_encrypt_symmetric(
|
node.lightpush_publish_encrypt_symmetric(&message, None, peer_id, &ssk, Some(&sk), None)?;
|
||||||
&message,
|
|
||||||
None,
|
|
||||||
peer_id.clone(),
|
|
||||||
&ssk,
|
|
||||||
Some(&sk),
|
|
||||||
None,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
for node_data in node.peers()? {
|
for node_data in node.peers()? {
|
||||||
if node_data.peer_id() != &node.peer_id()? {
|
if node_data.peer_id() != &node.peer_id()? {
|
||||||
@ -143,6 +138,8 @@ pub fn main() -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::thread::sleep(Duration::from_secs(2));
|
std::thread::sleep(Duration::from_secs(2));
|
||||||
|
let result = node.discv5_stop()?;
|
||||||
|
assert!(result, "Discv5 should be stopped");
|
||||||
node.stop()?;
|
node.stop()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user