mirror of
https://github.com/logos-messaging/logos-messaging-rust-bindings.git
synced 2026-01-03 06:23:11 +00:00
Fix peer id connect
This commit is contained in:
parent
592338b35b
commit
29c9cd9f6c
@ -73,7 +73,7 @@ impl<State: WakuNodeState> WakuNodeHandle<State> {
|
||||
/// Add a node multiaddress and protocol to the waku node’s peerstore
|
||||
///
|
||||
/// wrapper around [`peers::waku_add_peers`]
|
||||
pub fn add_peer(&self, address: Multiaddr, protocol_id: ProtocolId) -> Result<PeerId> {
|
||||
pub fn add_peer(&self, address: &Multiaddr, protocol_id: ProtocolId) -> Result<PeerId> {
|
||||
peers::waku_add_peers(address, protocol_id)
|
||||
}
|
||||
}
|
||||
@ -118,7 +118,7 @@ impl WakuNodeHandle<Running> {
|
||||
/// wrapper around [`peers::waku_connect_peer_with_address`]
|
||||
pub fn connect_peer_with_address(
|
||||
&self,
|
||||
address: Multiaddr,
|
||||
address: &Multiaddr,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<()> {
|
||||
peers::waku_connect_peer_with_address(address, timeout)
|
||||
|
||||
@ -11,7 +11,7 @@ use crate::general::{JsonResponse, PeerId, ProtocolId, Result};
|
||||
|
||||
/// Add a node multiaddress and protocol to the waku node’s peerstore.
|
||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_add_peerchar-address-char-protocolid)
|
||||
pub fn waku_add_peers(address: Multiaddr, protocol_id: ProtocolId) -> Result<PeerId> {
|
||||
pub fn waku_add_peers(address: &Multiaddr, protocol_id: ProtocolId) -> Result<PeerId> {
|
||||
let response = unsafe {
|
||||
CStr::from_ptr(waku_sys::waku_add_peer(
|
||||
CString::new(address.to_string())
|
||||
@ -36,7 +36,10 @@ pub fn waku_add_peers(address: Multiaddr, protocol_id: ProtocolId) -> Result<Pee
|
||||
/// If the function execution takes longer than `timeout` value, the execution will be canceled and an error returned.
|
||||
/// Use 0 for no timeout
|
||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_connect_peerchar-address-int-timeoutms)
|
||||
pub fn waku_connect_peer_with_address(address: Multiaddr, timeout: Option<Duration>) -> Result<()> {
|
||||
pub fn waku_connect_peer_with_address(
|
||||
address: &Multiaddr,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<()> {
|
||||
let response = unsafe {
|
||||
CStr::from_ptr(waku_sys::waku_connect(
|
||||
CString::new(address.to_string())
|
||||
@ -63,7 +66,7 @@ pub fn waku_connect_peer_with_address(address: Multiaddr, timeout: Option<Durati
|
||||
/// As per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_connect_peeridchar-peerid-int-timeoutms)
|
||||
pub fn waku_connect_peer_with_id(peer_id: PeerId, timeout: Option<Duration>) -> Result<()> {
|
||||
let response = unsafe {
|
||||
CStr::from_ptr(waku_sys::waku_connect(
|
||||
CStr::from_ptr(waku_sys::waku_connect_peerid(
|
||||
CString::new(peer_id)
|
||||
.expect("CString should build properly from peer id")
|
||||
.into_raw(),
|
||||
|
||||
36
waku/tests/node.rs
Normal file
36
waku/tests/node.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use multiaddr::Multiaddr;
|
||||
use std::net::IpAddr;
|
||||
use std::str::FromStr;
|
||||
use waku::{waku_new, ProtocolId, WakuNodeConfig};
|
||||
|
||||
const NODES: &[&str] = &[
|
||||
"/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/30303/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm",
|
||||
"/dns4/node-01.do-ams3.wakuv2.test.statusim.net/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ",
|
||||
"/dns4/node-01.gc-us-central1-a.wakuv2.test.statusim.net/tcp/30303/p2p/16Uiu2HAmJb2e28qLXxT5kZxVUUoJt72EMzNGXB47Rxx5hw3q4YjS"
|
||||
];
|
||||
|
||||
#[test]
|
||||
pub fn main() -> Result<(), String> {
|
||||
let config = WakuNodeConfig {
|
||||
host: IpAddr::from_str("0.0.0.0").ok(),
|
||||
port: None,
|
||||
advertise_addr: None,
|
||||
node_key: None,
|
||||
keep_alive_interval: None,
|
||||
relay: None,
|
||||
min_peers_to_publish: None,
|
||||
filter: None,
|
||||
};
|
||||
let node = waku_new(Some(config))?;
|
||||
let node = node.start()?;
|
||||
println!("Node peer id: {}", node.peer_id()?);
|
||||
|
||||
for node_address in NODES {
|
||||
let address: Multiaddr = node_address.parse().unwrap();
|
||||
let peer_id = node.add_peer(&address, ProtocolId::Relay)?;
|
||||
node.connect_peer_with_id(peer_id, None)?;
|
||||
}
|
||||
|
||||
node.stop()?;
|
||||
Ok(())
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user