Skip to content

Commit

Permalink
feat: websockets support (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos authored Jul 13, 2023
1 parent 263c6ef commit a487f79
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions waku-bindings/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "waku-bindings"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
authors = [
"Daniel Sanchez Quiros <danielsq@status.im>"
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions waku-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
26 changes: 26 additions & 0 deletions waku-bindings/src/node/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ pub struct WakuNodeConfig {
pub discv5_udp_port: Option<u16>,
/// Gossipsub custom configuration.
pub gossipsub_params: Option<GossipSubParams>,
/// The domain name resolving to the node's public IPv4 address.
#[serde(rename = "dns4DomainName")]
pub dns4_domain_name: Option<String>,
/// Custom websocket support parameters
#[serde(rename = "websockets")]
pub websocket_params: Option<WebsocketParams>,
}

#[derive(Clone, SmartDefault, Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -195,6 +201,26 @@ pub struct GossipSubParams {
pub seen_messages_ttl_seconds: Option<i32>,
}

#[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<bool>,
/// 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<std::net::IpAddr>,
/// 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<usize>,
/// Enable secure websockets support
#[default(Some(false))]
pub secure: Option<bool>,
/// Secure websocket certificate path. Mandatory if secure websockets support is enabled.
pub cert_path: Option<String>,
/// Secure websocket key path. Mandatory if secure websockets support is enabled.
pub key_path: Option<String>,
}

#[derive(Clone, Default, Serialize, Deserialize, Debug)]
pub enum WakuLogLevel {
#[default]
Expand Down
4 changes: 1 addition & 3 deletions waku-bindings/src/node/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>
) -> Result<()> {
pub fn waku_discv5_update_bootnodes(bootnodes: Vec<String>) -> Result<()> {
let bootnodes_ptr = CString::new(
serde_json::to_string(&bootnodes)
.expect("Serialization from properly built bootnode array should never fail"),
Expand Down
4 changes: 2 additions & 2 deletions waku-bindings/src/node/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 3 additions & 7 deletions waku-bindings/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -313,14 +313,10 @@ impl WakuNodeHandle<Running> {
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<String>
) -> Result<()> {
pub fn discv5_update_bootnodes(bootnodes: Vec<String>) -> Result<()> {
discovery::waku_discv5_update_bootnodes(bootnodes)
}

}

/// Spawn a new Waku node with the given configuration (default configuration if `None` provided)
Expand Down
2 changes: 1 addition & 1 deletion waku-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "waku-sys"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
authors = [
"Daniel Sanchez Quiros <danielsq@status.im>"
Expand Down
2 changes: 1 addition & 1 deletion waku-sys/vendor

0 comments on commit a487f79

Please sign in to comment.