From a487f79179c870e6065f7f3bd8b0263b70aa59cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?rich=CE=9Brd?= Date: Thu, 13 Jul 2023 18:33:24 -0400 Subject: [PATCH] feat: websockets support (#63) --- Cargo.lock | 4 ++-- waku-bindings/Cargo.toml | 4 ++-- waku-bindings/src/lib.rs | 6 +++--- waku-bindings/src/node/config.rs | 26 ++++++++++++++++++++++++++ waku-bindings/src/node/discovery.rs | 4 +--- waku-bindings/src/node/filter.rs | 4 ++-- waku-bindings/src/node/mod.rs | 10 +++------- waku-sys/Cargo.toml | 2 +- waku-sys/vendor | 2 +- 9 files changed, 41 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b07c759..5c348da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1674,7 +1674,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waku-bindings" -version = "0.1.1" +version = "0.2.0" dependencies = [ "aes-gcm", "base64 0.21.0", @@ -1697,7 +1697,7 @@ dependencies = [ [[package]] name = "waku-sys" -version = "0.1.0" +version = "0.2.0" dependencies = [ "bindgen", ] diff --git a/waku-bindings/Cargo.toml b/waku-bindings/Cargo.toml index 92d2160..235405d 100644 --- a/waku-bindings/Cargo.toml +++ b/waku-bindings/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "waku-bindings" -version = "0.1.1" +version = "0.2.0" edition = "2021" authors = [ "Daniel Sanchez Quiros " @@ -26,7 +26,7 @@ serde_json = "1.0" sscanf = "0.4" smart-default = "0.6" url = "2.3" -waku-sys = { version = "0.1.0", path = "../waku-sys" } +waku-sys = { version = "0.2.0", path = "../waku-sys" } [dev-dependencies] futures = "0.3.25" diff --git a/waku-bindings/src/lib.rs b/waku-bindings/src/lib.rs index c62a4da..46064b2 100644 --- a/waku-bindings/src/lib.rs +++ b/waku-bindings/src/lib.rs @@ -9,9 +9,9 @@ mod utils; pub use node::{ waku_create_content_topic, waku_create_pubsub_topic, waku_dafault_pubsub_topic, - waku_dns_discovery, waku_discv5_update_bootnodes, waku_new, Aes256Gcm, DnsInfo, GossipSubParams, Initialized, Key, Multiaddr, - Protocol, PublicKey, Running, SecretKey, WakuLogLevel, WakuNodeConfig, WakuNodeHandle, - WakuPeerData, WakuPeers, + waku_discv5_update_bootnodes, waku_dns_discovery, waku_new, Aes256Gcm, DnsInfo, + GossipSubParams, Initialized, Key, Multiaddr, Protocol, PublicKey, Running, SecretKey, + WakuLogLevel, WakuNodeConfig, WakuNodeHandle, WakuPeerData, WakuPeers, WebsocketParams, }; pub use general::{ diff --git a/waku-bindings/src/node/config.rs b/waku-bindings/src/node/config.rs index a9f32ac..296fa7d 100644 --- a/waku-bindings/src/node/config.rs +++ b/waku-bindings/src/node/config.rs @@ -69,6 +69,12 @@ pub struct WakuNodeConfig { pub discv5_udp_port: Option, /// Gossipsub custom configuration. pub gossipsub_params: Option, + /// The domain name resolving to the node's public IPv4 address. + #[serde(rename = "dns4DomainName")] + pub dns4_domain_name: Option, + /// Custom websocket support parameters + #[serde(rename = "websockets")] + pub websocket_params: Option, } #[derive(Clone, SmartDefault, Serialize, Deserialize, Debug)] @@ -195,6 +201,26 @@ pub struct GossipSubParams { pub seen_messages_ttl_seconds: Option, } +#[derive(Clone, SmartDefault, Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct WebsocketParams { + /// Indicates if websockets support will be enabled + #[default(Some(false))] + pub enabled: Option, + /// Listening address for websocket connections. Default `0.0.0.0` + #[default(Some(std::net::IpAddr::V4(std::net::Ipv4Addr::new(0, 0, 0, 0))))] + pub host: Option, + /// TCP listening port for websocket connection. Use `0` for **random**. Default `60001`, if secure websockets support is enabled, the default is `6443“` + pub port: Option, + /// Enable secure websockets support + #[default(Some(false))] + pub secure: Option, + /// Secure websocket certificate path. Mandatory if secure websockets support is enabled. + pub cert_path: Option, + /// Secure websocket key path. Mandatory if secure websockets support is enabled. + pub key_path: Option, +} + #[derive(Clone, Default, Serialize, Deserialize, Debug)] pub enum WakuLogLevel { #[default] diff --git a/waku-bindings/src/node/discovery.rs b/waku-bindings/src/node/discovery.rs index 141cec3..0445371 100644 --- a/waku-bindings/src/node/discovery.rs +++ b/waku-bindings/src/node/discovery.rs @@ -60,9 +60,7 @@ pub fn waku_dns_discovery( } /// Update the bootnodes used by DiscoveryV5 by passing a list of ENRs -pub fn waku_discv5_update_bootnodes( - bootnodes: Vec -) -> Result<()> { +pub fn waku_discv5_update_bootnodes(bootnodes: Vec) -> Result<()> { let bootnodes_ptr = CString::new( serde_json::to_string(&bootnodes) .expect("Serialization from properly built bootnode array should never fail"), diff --git a/waku-bindings/src/node/filter.rs b/waku-bindings/src/node/filter.rs index bd63e33..77a9c2b 100644 --- a/waku-bindings/src/node/filter.rs +++ b/waku-bindings/src/node/filter.rs @@ -28,7 +28,7 @@ pub fn waku_filter_subscribe( .into_raw(); let result_ptr = unsafe { - let result_ptr = waku_sys::waku_filter_subscribe( + let result_ptr = waku_sys::waku_legacy_filter_subscribe( filter_subscription_ptr, peer_id_ptr, timeout @@ -56,7 +56,7 @@ pub fn waku_filter_unsubscribe( .expect("CString should build properly from the serialized filter subscription") .into_raw(); let result_ptr = unsafe { - let res = waku_sys::waku_filter_unsubscribe( + let res = waku_sys::waku_legacy_filter_unsubscribe( filter_subscription_ptr, timeout .as_millis() diff --git a/waku-bindings/src/node/mod.rs b/waku-bindings/src/node/mod.rs index 8a91a79..cb675a6 100644 --- a/waku-bindings/src/node/mod.rs +++ b/waku-bindings/src/node/mod.rs @@ -24,8 +24,8 @@ use crate::general::{ WakuMessage, WakuPubSubTopic, }; -pub use config::{GossipSubParams, WakuLogLevel, WakuNodeConfig}; -pub use discovery::{waku_dns_discovery, waku_discv5_update_bootnodes, DnsInfo}; +pub use config::{GossipSubParams, WakuLogLevel, WakuNodeConfig, WebsocketParams}; +pub use discovery::{waku_discv5_update_bootnodes, waku_dns_discovery, DnsInfo}; pub use peers::{Protocol, WakuPeerData, WakuPeers}; pub use relay::{waku_create_content_topic, waku_create_pubsub_topic, waku_dafault_pubsub_topic}; pub use store::{waku_local_store_query, waku_store_query}; @@ -313,14 +313,10 @@ impl WakuNodeHandle { filter::waku_filter_unsubscribe(filter_subscription, timeout) } - /// Update the bootnodes used by DiscoveryV5 by passing a list of ENRs - pub fn discv5_update_bootnodes( - bootnodes: Vec - ) -> Result<()> { + pub fn discv5_update_bootnodes(bootnodes: Vec) -> Result<()> { discovery::waku_discv5_update_bootnodes(bootnodes) } - } /// Spawn a new Waku node with the given configuration (default configuration if `None` provided) diff --git a/waku-sys/Cargo.toml b/waku-sys/Cargo.toml index 1284636..6f691ef 100644 --- a/waku-sys/Cargo.toml +++ b/waku-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "waku-sys" -version = "0.1.0" +version = "0.2.0" edition = "2021" authors = [ "Daniel Sanchez Quiros " diff --git a/waku-sys/vendor b/waku-sys/vendor index f6fe353..bc6a305 160000 --- a/waku-sys/vendor +++ b/waku-sys/vendor @@ -1 +1 @@ -Subproject commit f6fe353e2ee31bd5514811327cb1ca2478e2e4a9 +Subproject commit bc6a305759f2f09ffd1426697730562ffdd4a3dd