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 all 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" }
7 changes: 2 additions & 5 deletions ping/rust/src/bin/testplan_0440.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async fn main() -> Result<()> {
),
local_peer_id,
));

run_ping(swarm).await?;

Ok(())
Expand All @@ -31,18 +30,16 @@ 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<String> {
let id = self.0.listen_on(address.parse()?)?;

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

Ok(())
}

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

run_ping(swarm).await?;

Ok(())
}

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<String> {
let id = self.0.listen_on(address.parse()?)?;

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

Ok(())
}

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

run_ping(swarm).await?;

Ok(())
Expand All @@ -31,18 +30,16 @@ 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<String> {
let id = self.0.listen_on(address.parse()?)?;

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

Ok(())
}

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

run_ping(swarm).await?;

Ok(())
Expand All @@ -31,18 +30,16 @@ 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<String> {
let id = self.0.listen_on(address.parse()?)?;

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

Ok(())
}

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

run_ping(swarm).await?;

Ok(())
Expand All @@ -31,18 +30,16 @@ 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<String> {
let id = self.0.listen_on(address.parse()?)?;

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

Ok(())
}

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

run_ping(swarm).await?;

Ok(())
Expand All @@ -33,18 +32,16 @@ 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<String> {
let id = self.0.listen_on(address.parse()?)?;

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

Ok(())
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand Down
73 changes: 55 additions & 18 deletions ping/rust/src/bin/testplan_0500.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
use anyhow::Result;
use async_trait::async_trait;
use futures::StreamExt;
use libp2pv0500::swarm::{keep_alive, NetworkBehaviour, SwarmEvent};
use libp2pv0500::*;
use std::collections::HashSet;
use std::time::Duration;
use testplan::{run_ping, PingSwarm};

#[async_std::main]
use libp2pv0500::{
core::{
either::EitherOutput,
muxing::StreamMuxerBox,
upgrade::{SelectUpgrade, Version},
},
identity, mplex, noise, ping,
swarm::{keep_alive, NetworkBehaviour, SwarmEvent},
tcp, webrtc, yamux, Multiaddr, PeerId, Swarm, Transport,
};
use log::{debug, info};
use rand::thread_rng;
use std::{collections::HashSet, time::Duration};
use testplan::*;

#[tokio::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 transport = tcp::tokio::Transport::default()
.upgrade(Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap())
.multiplex(SelectUpgrade::new(
yamux::YamuxConfig::default(),
mplex::MplexConfig::default(),
))
.timeout(Duration::from_secs(20))
.or_transport(webrtc::tokio::Transport::new(
local_key,
webrtc::tokio::Certificate::generate(&mut thread_rng())?,
))
.map(|either, _| match either {
EitherOutput::First((p, conn)) => (p, StreamMuxerBox::new(conn)),
EitherOutput::Second((p, conn)) => (p, StreamMuxerBox::new(conn)),
})
.boxed();
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))),
Expand All @@ -37,18 +62,19 @@ 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<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(address.to_string());
}
}
}

Ok(())
}

fn dial(&mut self, address: &str) -> Result<()> {
Expand All @@ -61,8 +87,19 @@ 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.get_remote_address()
);
connected.insert(peer_id);
}
Some(event) => debug!("Received event {:?}", &event), //This is useful, because it sometimes logs error messages
None => (),
}
}
}
Expand Down
Loading