Revert "Fix #32: add discoveryV5 functions"

This commit is contained in:
Al Liu 2023-01-06 21:59:20 +13:00 committed by GitHub
parent 6e93c4f2b6
commit 110c455438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 41 additions and 1586 deletions

View File

@ -77,6 +77,7 @@ jobs:
with:
command: test
lints:
name: Rust lints
runs-on: ubuntu-latest
@ -108,4 +109,4 @@ jobs:
continue-on-error: false
with:
command: clippy
args: -- --deny warnings
args: -- --deny warnings

2
.gitignore vendored
View File

@ -1,4 +1,4 @@
**target
/target
/Cargo.lock
/.idea
/.fleet

155
Cargo.lock generated
View File

@ -337,19 +337,6 @@ dependencies = [
"syn",
]
[[package]]
name = "dashmap"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "907076dfda823b0b36d2a1bb5f90c96660a5bbcd7729e10727f07858f22c4edc"
dependencies = [
"cfg-if",
"hashbrown",
"lock_api",
"once_cell",
"parking_lot_core",
]
[[package]]
name = "data-encoding"
version = "2.3.2"
@ -391,83 +378,6 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "futures"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac"
[[package]]
name = "futures-executor"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb"
[[package]]
name = "futures-sink"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9"
[[package]]
name = "futures-task"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea"
[[package]]
name = "futures-util"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
name = "generic-array"
version = "0.14.6"
@ -505,12 +415,6 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "hex"
version = "0.4.3"
@ -794,18 +698,6 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
[[package]]
name = "pin-project-lite"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "polyval"
version = "0.6.0"
@ -1031,31 +923,6 @@ dependencies = [
"serde",
]
[[package]]
name = "serial_test"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c789ec87f4687d022a2405cf46e0cd6284889f1839de292cadeb6c6019506f2"
dependencies = [
"dashmap",
"futures",
"lazy_static",
"log",
"parking_lot",
"serial_test_derive",
]
[[package]]
name = "serial_test_derive"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b64f9e531ce97c88b4778aad0ceee079216071cffec6ac9b904277f8f92e7fe3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "shlex"
version = "1.1.0"
@ -1092,32 +959,12 @@ dependencies = [
"libc",
]
[[package]]
name = "slab"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
dependencies = [
"autocfg",
]
[[package]]
name = "smallvec"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0"
[[package]]
name = "smart-default"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sscanf"
version = "0.3.1"
@ -1357,8 +1204,6 @@ dependencies = [
"secp256k1",
"serde",
"serde_json",
"serial_test",
"smart-default",
"sscanf",
"url",
"waku-sys",

1393
examples/Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -23,9 +23,5 @@ secp256k1 = { version = "0.24", features = ["rand", "recovery", "serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sscanf = "0.3"
smart-default = "0.6"
url = "2.3"
waku-sys = { version = "0.1.0-beta1", path = "../waku-sys" }
[dev-dependencies]
serial_test = "0.10.0"

View File

@ -19,3 +19,27 @@ pub use general::{
};
pub use events::{waku_set_event_callback, Event, Signal, WakuMessageEvent};
#[cfg(test)]
mod tests {
use std::ffi::CStr;
use std::os::raw::c_char;
use waku_sys::waku_content_topic;
#[test]
fn content_topic() {
let topic = unsafe {
waku_content_topic(
"foo_bar".as_ptr() as *mut c_char,
1,
"foo_topic".as_ptr() as *mut c_char,
"rfc26".as_ptr() as *mut c_char,
)
};
let topic_str = unsafe { CStr::from_ptr(topic) }
.to_str()
.expect("Decoded return");
println!("{}", topic_str);
}
}

View File

@ -7,18 +7,15 @@ use std::str::FromStr;
use multiaddr::Multiaddr;
use secp256k1::SecretKey;
use serde::{Deserialize, Serialize};
use smart_default::SmartDefault;
// internal
/// Waku node configuration
#[derive(Clone, SmartDefault, Serialize, Deserialize, Debug)]
#[derive(Clone, Default, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct WakuNodeConfig {
/// Listening IP address. 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>,
/// Libp2p TCP listening port. Default `60000`. Use `0` for **random**
#[default(Some(60000))]
pub port: Option<usize>,
/// External address to advertise to other nodes. Can be ip4, ip6 or dns4, dns6.
/// If null, the multiaddress(es) generated from the ip and port specified in the config (or default ones) will be used.
@ -28,31 +25,15 @@ pub struct WakuNodeConfig {
#[serde(with = "secret_key_serde")]
pub node_key: Option<SecretKey>,
/// Interval in seconds for pinging peers to keep the connection alive. Default `20`
#[default(Some(20))]
pub keep_alive_interval: Option<usize>,
/// Enable relay protocol. Default `true`
#[default(Some(true))]
pub relay: Option<bool>,
/// The minimum number of peers required on a topic to allow broadcasting a message. Default `0`
#[default(Some(0))]
pub min_peers_to_publish: Option<usize>,
/// Enable filter protocol. Default `false`
#[default(Some(false))]
pub filter: Option<bool>,
/// Set the log level. Default `INFO`. Allowed values "DEBUG", "INFO", "WARN", "ERROR", "DPANIC", "PANIC", "FATAL"
#[default(Some(WakuLogLevel::Info))]
pub log_level: Option<WakuLogLevel>,
/// Enable DiscoveryV5. Default `false`
#[default(Some(false))]
#[serde(rename = "discV5")]
pub discv5: Option<bool>,
/// Array of bootstrap nodes ENR.
#[serde(rename = "discV5BootstrapNodes")]
pub discv5_bootstrap_nodes: Vec<String>,
/// UDP port for DiscoveryV5. Default `9000`.
#[default(Some(9000))]
#[serde(rename = "discV5UDPPort")]
pub discv5_udp_port: Option<u16>,
}
#[derive(Clone, Default, Serialize, Deserialize, Debug)]

View File

@ -43,7 +43,7 @@ pub fn waku_start() -> Result<bool> {
/// Stops a Waku node
/// as per the [specification](https://rfc.vac.dev/spec/36/#extern-char-waku_stop)
pub fn waku_stop() -> Result<bool> {
let response = unsafe { CStr::from_ptr(waku_sys::waku_stop()) }
let response = unsafe { CStr::from_ptr(waku_sys::waku_start()) }
.to_str()
.expect("Response should always succeed to load to a &str");
@ -82,10 +82,8 @@ pub fn waku_listen_addresses() -> Result<Vec<Multiaddr>> {
mod test {
use super::waku_new;
use crate::node::management::{waku_listen_addresses, waku_peer_id, waku_start, waku_stop};
use serial_test::serial;
#[test]
#[serial]
fn waku_flow() {
waku_new(None).unwrap();
waku_start().unwrap();

View File

@ -326,10 +326,8 @@ pub fn waku_new(config: Option<WakuNodeConfig>) -> Result<WakuNodeHandle<Initial
#[cfg(test)]
mod tests {
use super::waku_new;
use serial_test::serial;
#[test]
#[serial]
fn exclusive_running() {
let handle1 = waku_new(None).unwrap();
let handle2 = waku_new(None);

View File

@ -29,9 +29,6 @@ pub fn main() -> Result<(), String> {
min_peers_to_publish: None,
filter: None,
log_level: Some(WakuLogLevel::Error),
discv5: Some(true),
discv5_udp_port: Some(9000),
discv5_bootstrap_nodes: Vec::new(),
};
let node = waku_new(Some(config))?;
let node = node.start()?;
@ -52,7 +49,7 @@ pub fn main() -> Result<(), String> {
let ssk = Aes256Gcm::generate_key(&mut thread_rng());
let content = "Hi from 🦀!";
let content_callback = content;
let content_callback = content.clone();
waku_set_event_callback(move |signal| match signal.event() {
Event::WakuMessage(message) => {
@ -111,7 +108,8 @@ pub fn main() -> Result<(), String> {
.unwrap()
.iter()
.map(|peer| peer.peer_id())
.find(|id| id.as_str() != node.peer_id().unwrap().as_str())
.filter(|id| id.as_str() != node.peer_id().unwrap().as_str())
.next()
.unwrap()
.clone();
@ -126,7 +124,14 @@ pub fn main() -> Result<(), String> {
None,
)?;
node.lightpush_publish_encrypt_symmetric(&message, None, peer_id.clone(), &ssk, None, None)?;
node.lightpush_publish_encrypt_symmetric(&message, None, peer_id, &ssk, Some(&sk), None)?;
node.lightpush_publish_encrypt_symmetric(
&message,
None,
peer_id.clone(),
&ssk,
Some(&sk),
None,
)?;
for node_data in node.peers()? {
if node_data.peer_id() != &node.peer_id()? {

@ -1 +1 @@
Subproject commit 2c9c763c306dfa10dc371134d830702d4e0fbf0f
Subproject commit 77e23638de8e2c307f9fd22786d665ae25487880