Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jt/82 webrtcinrustping #84

Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
766c909
starting
John-LittleBearLabs Nov 28, 2022
ad93609
Merge remote-tracking branch 'up/master' into jt/82_webrtcinrustping
John-LittleBearLabs Nov 28, 2022
65117e1
squash! Merge remote-tracking branch 'up/master' into jt/82_webrtcinr…
John-LittleBearLabs Nov 28, 2022
54466dd
compiles...
John-LittleBearLabs Nov 29, 2022
2653436
unknown protocol string: webrtc
John-LittleBearLabs Nov 29, 2022
a9a4f18
Update Cargo.toml to pull in new release
John-LittleBearLabs Nov 30, 2022
79b4441
hold
John-LittleBearLabs Nov 30, 2022
b114212
Restricting to webrtc-enabled versions to verify that.
John-LittleBearLabs Dec 2, 2022
2cc28e0
switch to test_param. Currently taking its value only from default, a…
John-LittleBearLabs Dec 2, 2022
2d0bc4a
removing some temporary stuff
John-LittleBearLabs Dec 2, 2022
31666f5
oops
John-LittleBearLabs Dec 2, 2022
31e8197
Change to optional return value
John-LittleBearLabs Dec 2, 2022
76b9283
Merge remote-tracking branch 'up/master' into jt/82_webrtcinrustping
John-LittleBearLabs Dec 2, 2022
8991625
Post-merge duplicate group IDs, also reverting inappropriate type cha…
John-LittleBearLabs Dec 2, 2022
89ce9f1
express it in code
John-LittleBearLabs Dec 2, 2022
35869fe
Porting updates to testplan_0510
John-LittleBearLabs Dec 2, 2022
e9c0ba4
Some PR comments
John-LittleBearLabs Dec 5, 2022
5cae933
expect
John-LittleBearLabs Dec 6, 2022
afe3a77
logging verbosity
John-LittleBearLabs Dec 9, 2022
24c1f23
listen_on now returns an address across all versions.
John-LittleBearLabs Dec 9, 2022
a8fefc2
updates
John-LittleBearLabs Dec 12, 2022
c3207d2
Positive consequences of previous shifts.
John-LittleBearLabs Dec 13, 2022
8696244
cargo fmt
ddimaria Dec 14, 2022
c916d4b
fix clippy lints
ddimaria Dec 14, 2022
3dab17b
prefer Anyhow's context
ddimaria Dec 14, 2022
26f311a
Improve logging, fix typo
ddimaria Dec 15, 2022
753cd1b
Merge branch 'libp2p:master' into jt/82_webrtcinrustping
ddimaria Dec 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,116 changes: 1,012 additions & 104 deletions ping/rust/Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ping/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ libp2pv0461 = { package = "libp2p", version = "0.46.1", default_features = false
libp2pv0470 = { package = "libp2p", version = "0.47.0", default_features = false, features = ["websocket", "mplex", "yamux", "tcp-async-io", "ping", "noise", "dns-async-std"] }
libp2pv0480 = { package = "libp2p", version = "0.48.0", default_features = false, features = ["websocket", "mplex", "yamux", "tcp-async-io", "ping", "noise", "dns-async-std", "rsa"] }
libp2pv0490 = { package = "libp2p", version = "0.49.0", features = ["websocket", "mplex", "yamux", "tcp", "async-std", "ping", "noise", "dns", "rsa"] }
libp2pv0500 = { package = "libp2p", version = "0.50.0", features = ["websocket", "mplex", "yamux", "tcp", "async-std", "ping", "noise", "dns", "rsa", "macros"] }
libp2pv0500 = { package = "libp2p", version = "0.50.0", features = ["websocket", "mplex", "yamux", "tcp", "tokio", "ping", "noise", "dns", "rsa", "macros", "webrtc"] }

# Next release
[dependencies."libp2pv0510"]
package = "libp2p"
git = "https://github.com/libp2p/rust-libp2p"
rev = "be0b62a78fe9d72811b9eda742137cc8ddc4da35" # This should usually point to a commit on master.
features = ["websocket", "mplex", "yamux", "tcp", "ping", "noise", "dns", "async-std", "rsa", "macros"]
features = ["websocket", "mplex", "yamux", "tcp", "ping", "noise", "dns", "tokio", "rsa", "macros", "webrtc"]
3 changes: 2 additions & 1 deletion ping/rust/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ instances = { min = 2, max = 10000, default = 5 }

[testcases.params]
max_latency_ms = { type = "int", desc = "maximum value for random local link latency", unit = "ms", default = 1000 }
iterations = { type = "int", desc = "number of ping iterations we'll run against each peer", unit = "count", default = 5 }
iterations = { type = "int", desc = "number of ping iterations we'll run against each peer", unit = "count", default = 5 }
transport = { type = "enum", desc = "transport used", values = ["tcp", "webrtc"], default = "tcp" }
8 changes: 4 additions & 4 deletions ping/rust/src/bin/testplan_0440.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async fn main() -> Result<()> {
),
local_peer_id,
));

run_ping(swarm).await?;
let client = testground::client::Client::new_and_init().await?;
run_ping(swarm, client).await?;

Ok(())
}
Expand All @@ -31,7 +31,7 @@ struct OrphanRuleWorkaround(Swarm<ping::Behaviour>);

#[async_trait]
impl PingSwarm for OrphanRuleWorkaround {
async fn listen_on(&mut self, address: &str) -> Result<()> {
async fn listen_on(&mut self, address: &str) -> Result<Option<String>> {
let id = self.0.listen_on(address.parse()?)?;

loop {
Expand All @@ -42,7 +42,7 @@ impl PingSwarm for OrphanRuleWorkaround {
}
}

Ok(())
Ok(None)
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions ping/rust/src/bin/testplan_0451.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async fn main() -> Result<()> {
),
local_peer_id,
));

run_ping(swarm).await?;
let client = testground::client::Client::new_and_init().await?;
run_ping(swarm, client).await?;

Ok(())
}
Expand All @@ -31,7 +31,7 @@ struct OrphanRuleWorkaround(Swarm<ping::Behaviour>);

#[async_trait]
impl PingSwarm for OrphanRuleWorkaround {
async fn listen_on(&mut self, address: &str) -> Result<()> {
async fn listen_on(&mut self, address: &str) -> Result<Option<String>> {
let id = self.0.listen_on(address.parse()?)?;

loop {
Expand All @@ -42,7 +42,7 @@ impl PingSwarm for OrphanRuleWorkaround {
}
}

Ok(())
Ok(None)
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions ping/rust/src/bin/testplan_0461.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async fn main() -> Result<()> {
),
local_peer_id,
));

run_ping(swarm).await?;
let client = testground::client::Client::new_and_init().await?;
run_ping(swarm, client).await?;

Ok(())
}
Expand All @@ -31,7 +31,7 @@ struct OrphanRuleWorkaround(Swarm<ping::Behaviour>);

#[async_trait]
impl PingSwarm for OrphanRuleWorkaround {
async fn listen_on(&mut self, address: &str) -> Result<()> {
async fn listen_on(&mut self, address: &str) -> Result<Option<String>> {
let id = self.0.listen_on(address.parse()?)?;

loop {
Expand All @@ -42,7 +42,7 @@ impl PingSwarm for OrphanRuleWorkaround {
}
}

Ok(())
Ok(None)
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions ping/rust/src/bin/testplan_0470.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async fn main() -> Result<()> {
),
local_peer_id,
));

run_ping(swarm).await?;
let client = testground::client::Client::new_and_init().await?;
run_ping(swarm, client).await?;

Ok(())
}
Expand All @@ -31,7 +31,7 @@ struct OrphanRuleWorkaround(Swarm<ping::Behaviour>);

#[async_trait]
impl PingSwarm for OrphanRuleWorkaround {
async fn listen_on(&mut self, address: &str) -> Result<()> {
async fn listen_on(&mut self, address: &str) -> Result<Option<String>> {
let id = self.0.listen_on(address.parse()?)?;

loop {
Expand All @@ -42,7 +42,7 @@ impl PingSwarm for OrphanRuleWorkaround {
}
}

Ok(())
Ok(None)
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions ping/rust/src/bin/testplan_0480.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ async fn main() -> Result<()> {
),
local_peer_id,
));

run_ping(swarm).await?;
let client = testground::client::Client::new_and_init().await?;
run_ping(swarm, client).await?;

Ok(())
}
Expand All @@ -31,7 +31,7 @@ struct OrphanRuleWorkaround(Swarm<ping::Behaviour>);

#[async_trait]
impl PingSwarm for OrphanRuleWorkaround {
async fn listen_on(&mut self, address: &str) -> Result<()> {
async fn listen_on(&mut self, address: &str) -> Result<Option<String>> {
let id = self.0.listen_on(address.parse()?)?;

loop {
Expand All @@ -42,7 +42,7 @@ impl PingSwarm for OrphanRuleWorkaround {
}
}

Ok(())
Ok(None)
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions ping/rust/src/bin/testplan_0490.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ async fn main() -> Result<()> {
),
local_peer_id,
));

run_ping(swarm).await?;
let client = testground::client::Client::new_and_init().await?;
run_ping(swarm, client).await?;

Ok(())
}
Expand All @@ -33,7 +33,7 @@ struct OrphanRuleWorkaround(Swarm<ping::Behaviour>);

#[async_trait]
impl PingSwarm for OrphanRuleWorkaround {
async fn listen_on(&mut self, address: &str) -> Result<()> {
async fn listen_on(&mut self, address: &str) -> Result<Option<String>> {
let id = self.0.listen_on(address.parse()?)?;

loop {
Expand All @@ -44,7 +44,7 @@ impl PingSwarm for OrphanRuleWorkaround {
}
}

Ok(())
Ok(None)
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand Down
56 changes: 41 additions & 15 deletions ping/rust/src/bin/testplan_0500.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
use anyhow::Result;
use async_trait::async_trait;
use futures::StreamExt;
use libp2pv0500::core::multiaddr::*;
use libp2pv0500::core::muxing::*;
use libp2pv0500::swarm::{keep_alive, NetworkBehaviour, SwarmEvent};
use libp2pv0500::*;
use std::collections::HashSet;
use std::time::Duration;
use testplan::{run_ping, PingSwarm};
use libp2pv0500::{tokio_development_transport, webrtc};
use log::info;
use rand::thread_rng;
use std::{collections::HashSet, time::Duration};
use testplan::*;

#[async_std::main]
async fn main() -> Result<()> {
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());

let swarm = OrphanRuleWorkaround(Swarm::with_async_std_executor(
development_transport(local_key).await?,
let client = testground::client::Client::new_and_init().await?;
let transport = match transport_param(&client).as_str() {
"tcp" => tokio_development_transport(local_key)?,
"webrtc" => webrtc::tokio::Transport::new(
local_key,
webrtc::tokio::Certificate::generate(&mut thread_rng())?,
)
.map(|(peer_id, conn), _| (peer_id, StreamMuxerBox::new(conn)))
.boxed(),
unhandled => unimplemented!("Transport unhandled in test: '{}'", unhandled),
};
John-LittleBearLabs marked this conversation as resolved.
Show resolved Hide resolved
let swarm = OrphanRuleWorkaround(Swarm::with_tokio_executor(
transport,
Behaviour {
keep_alive: keep_alive::Behaviour,
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
},
local_peer_id,
));

run_ping(swarm).await?;
run_ping(swarm, client).await?;

Ok(())
}
Expand All @@ -37,18 +51,23 @@ struct OrphanRuleWorkaround(Swarm<Behaviour>);

#[async_trait]
impl PingSwarm for OrphanRuleWorkaround {
async fn listen_on(&mut self, address: &str) -> Result<()> {
async fn listen_on(&mut self, address: &str) -> Result<Option<String>> {
John-LittleBearLabs marked this conversation as resolved.
Show resolved Hide resolved
let id = self.0.listen_on(address.parse()?)?;

loop {
if let Some(SwarmEvent::NewListenAddr { listener_id, .. }) = self.0.next().await {
if let Some(SwarmEvent::NewListenAddr {
listener_id,
address,
}) = self.0.next().await
{
if listener_id == id {
break;
info!(
"NewListenAddr event: listener_id={:?}, address={:?}",
&listener_id, &address
);
return Ok(Some(address.to_string()));
}
}
}

Ok(())
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand All @@ -61,8 +80,15 @@ impl PingSwarm for OrphanRuleWorkaround {
let mut connected = HashSet::with_capacity(number);

while connected.len() < number {
if let Some(SwarmEvent::ConnectionEstablished { peer_id, .. }) = self.0.next().await {
connected.insert(peer_id);
match self.0.next().await {
Some(SwarmEvent::ConnectionEstablished {
peer_id, endpoint, ..
}) => {
info!("Connection established! {:?}={:?}", &peer_id, &endpoint);
connected.insert(peer_id);
}
Some(event) => info!("Received event {:?}", &event),
John-LittleBearLabs marked this conversation as resolved.
Show resolved Hide resolved
None => (),
}
}
}
Expand Down
53 changes: 39 additions & 14 deletions ping/rust/src/bin/testplan_0510.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
use anyhow::Result;
use async_trait::async_trait;
use futures::StreamExt;
use libp2pv0510::swarm::{keep_alive, NetworkBehaviour, SwarmEvent};
use libp2pv0510::*;
use libp2pv0510::{
core::muxing::StreamMuxerBox,
identity, ping,
swarm::{keep_alive, NetworkBehaviour, SwarmEvent},
tokio_development_transport, webrtc, Multiaddr, PeerId, Swarm, Transport,
};
use log::info;
use rand::thread_rng;
use std::collections::HashSet;
use std::time::Duration;
use testplan::{run_ping, PingSwarm};
use testplan::{run_ping, transport_param, PingSwarm};

#[async_std::main]
async fn main() -> Result<()> {
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());

let swarm = OrphanRuleWorkaround(Swarm::with_async_std_executor(
development_transport(local_key).await?,
let client = testground::client::Client::new_and_init().await?;
let transport = match transport_param(&client).as_str() {
"tcp" => tokio_development_transport(local_key)?,
"webrtc" => webrtc::tokio::Transport::new(
local_key,
webrtc::tokio::Certificate::generate(&mut thread_rng())?,
)
.map(|(peer_id, conn), _| (peer_id, StreamMuxerBox::new(conn)))
.boxed(),
unhandled => unimplemented!("Transport unhandled in test: '{}'", unhandled),
};
let swarm = OrphanRuleWorkaround(Swarm::with_tokio_executor(
transport,
Behaviour {
keep_alive: keep_alive::Behaviour,
ping: ping::Behaviour::new(ping::Config::new().with_interval(Duration::from_secs(1))),
},
local_peer_id,
));

run_ping(swarm).await?;
run_ping(swarm, client).await?;

Ok(())
}
Expand All @@ -37,18 +53,20 @@ struct OrphanRuleWorkaround(Swarm<Behaviour>);

#[async_trait]
impl PingSwarm for OrphanRuleWorkaround {
async fn listen_on(&mut self, address: &str) -> Result<()> {
async fn listen_on(&mut self, address: &str) -> Result<Option<String>> {
let id = self.0.listen_on(address.parse()?)?;

loop {
if let Some(SwarmEvent::NewListenAddr { listener_id, .. }) = self.0.next().await {
if let Some(SwarmEvent::NewListenAddr {
listener_id,
address,
}) = self.0.next().await
{
if listener_id == id {
break;
return Ok(Some(address.to_string()));
}
}
}

Ok(())
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand All @@ -61,8 +79,15 @@ impl PingSwarm for OrphanRuleWorkaround {
let mut connected = HashSet::with_capacity(number);

while connected.len() < number {
if let Some(SwarmEvent::ConnectionEstablished { peer_id, .. }) = self.0.next().await {
connected.insert(peer_id);
match self.0.next().await {
Some(SwarmEvent::ConnectionEstablished {
peer_id, endpoint, ..
}) => {
info!("Connection established! {:?}={:?}", &peer_id, &endpoint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PeerId supports Display so we don't need to use Debug here. Would also be a nicer log message if we get a multi-address out of endpoint and Display log that one.

Suggested change
info!("Connection established! {:?}={:?}", &peer_id, &endpoint);
info!("Connection established! {}={:?}", &peer_id, &endpoint);

connected.insert(peer_id);
}
Some(event) => info!("Received event {:?}", &event), //This is useful, because it sometimes logs error messages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, info is likely way too noisy.

None => (),
}
}
}
Expand Down
Loading