Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

rust/: Add support for QUIC #51

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
22 changes: 11 additions & 11 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,48 @@ set -u
# Make sure to kill all background tasks when exiting.
trap "kill 0" EXIT

TransportSecurityProtocols=( noise plaintext )
TcpTransportSecurityProtocols=( noise plaintext )

echo "# Start Rust and Golang servers."
./rust/target/release/server --private-key-pkcs8 rust/test.pk8 --listen-address /ip4/0.0.0.0/tcp/9992 > /dev/null 2>&1 &
./golang/go-libp2p-perf --fake-crypto-seed --listen-address /ip4/0.0.0.0/tcp/9993 --transport-security noise > /dev/null 2>&1 &
./golang/go-libp2p-perf --fake-crypto-seed --listen-address /ip4/0.0.0.0/tcp/9994 --transport-security plaintext > /dev/null 2>&1 &
./golang/go-libp2p-perf --fake-crypto-seed --listen-address /ip4/0.0.0.0/tcp/9993 --tcp-transport-security noise > /dev/null 2>&1 &
Copy link

Choose a reason for hiding this comment

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

I am not quite sure whether it worked for QUIC at all but the addresses should be in the form of /ipX/Y/udp/Z/quic.

Copy link

@kpp kpp Nov 15, 2021

Choose a reason for hiding this comment

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

No, it doesn’t work. I will push a patch

./golang/go-libp2p-perf --fake-crypto-seed --listen-address /ip4/0.0.0.0/tcp/9994 --tcp-transport-security plaintext > /dev/null 2>&1 &

sleep 1

echo
echo "# Rust -> Rust"
for Protocol in ${TransportSecurityProtocols[*]}
for Protocol in ${TcpTransportSecurityProtocols[*]}
do
echo
echo "## Transport security $Protocol"
./rust/target/release/client --server-address /ip4/127.0.0.1/tcp/9992 --transport-security $Protocol
./rust/target/release/client --server-address /ip4/127.0.0.1/tcp/9992 --tcp-transport-security $Protocol
done

echo
echo "# Rust -> Golang"
echo
echo "## Transport security noise"
./rust/target/release/client --server-address /ip4/127.0.0.1/tcp/9993 --transport-security noise
./rust/target/release/client --server-address /ip4/127.0.0.1/tcp/9993 --tcp-transport-security noise
echo
echo "## Transport security plaintext"
./rust/target/release/client --server-address /ip4/127.0.0.1/tcp/9994 --transport-security plaintext
./rust/target/release/client --server-address /ip4/127.0.0.1/tcp/9994 --tcp-transport-security plaintext

echo
echo "# Golang -> Rust"
for Protocol in ${TransportSecurityProtocols[*]}
for Protocol in ${TcpTransportSecurityProtocols[*]}
do
echo
echo "## Transport security $Protocol"
./golang/go-libp2p-perf --server-address /ip4/127.0.0.1/tcp/9992/p2p/Qmcqq9TFaYbb94uwdER1BXyGfCFY4Bb1gKozxNyVvLvTSw --transport-security $Protocol
./golang/go-libp2p-perf --server-address /ip4/127.0.0.1/tcp/9992/p2p/Qmcqq9TFaYbb94uwdER1BXyGfCFY4Bb1gKozxNyVvLvTSw --tcp-transport-security $Protocol
done

echo
echo "# Golang -> Golang"
echo
echo "## Transport security noise"
./golang/go-libp2p-perf --server-address /ip4/127.0.0.1/tcp/9993/p2p/12D3KooWL3XJ9EMCyZvmmGXL2LMiVBtrVa2BuESsJiXkSj7333Jw --transport-security noise
./golang/go-libp2p-perf --server-address /ip4/127.0.0.1/tcp/9993/p2p/12D3KooWL3XJ9EMCyZvmmGXL2LMiVBtrVa2BuESsJiXkSj7333Jw --tcp-transport-security noise
echo
echo "## Transport security plaintext"
./golang/go-libp2p-perf --server-address /ip4/127.0.0.1/tcp/9994/p2p/12D3KooWL3XJ9EMCyZvmmGXL2LMiVBtrVa2BuESsJiXkSj7333Jw --transport-security plaintext
./golang/go-libp2p-perf --server-address /ip4/127.0.0.1/tcp/9994/p2p/12D3KooWL3XJ9EMCyZvmmGXL2LMiVBtrVa2BuESsJiXkSj7333Jw --tcp-transport-security plaintext

3 changes: 2 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libp2p = { version = "0.40.0-rc.1", default-features = false, features = ["dns-async-std", "noise", "plaintext", "tcp-async-io", "yamux"] }
libp2p = { git = "https://github.com/kpp/rust-libp2p", branch = "libp2p-quic", version = "0.40.0", default-features = false, features = ["dns-async-std", "noise", "plaintext", "tcp-async-io", "yamux", "quic"] }
libp2p-quic = { git = "https://github.com/kpp/rust-libp2p", branch = "libp2p-quic", version = "0.6.0", default-features = false, features = ["tls"] }
futures_codec = "0.4"
futures = "0.3.1"
async-std = { version = "1.6.2", features = ["attributes"] }
Expand Down
11 changes: 2 additions & 9 deletions rust/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use libp2p::{
},
Multiaddr, PeerId,
};
use std::error;
use std::fmt;
use std::task::{Context, Poll};
use std::time::Duration;
Expand Down Expand Up @@ -63,7 +62,6 @@ impl NetworkBehaviour for Perf {
peer_id: &PeerId,
_: &ConnectionId,
connected_point: &ConnectedPoint,
_failed_addresses: Option<&Vec<Multiaddr>>,
) {
let direction = match connected_point {
ConnectedPoint::Dialer { .. } => Direction::Outgoing,
Expand Down Expand Up @@ -95,13 +93,8 @@ impl NetworkBehaviour for Perf {
}
}

fn inject_dial_failure(
&mut self,
_peer_id: Option<PeerId>,
_handler: PerfHandler,
_error: &DialError,
) {
panic!("inject dial failure");
fn inject_dial_failure(&mut self, _peer_id: &PeerId, _handler: PerfHandler, error: DialError) {
panic!("inject dial failure: {:?}", error);
}

fn inject_new_listen_addr(&mut self, _: ListenerId, _addr: &Multiaddr) {}
Expand Down
23 changes: 7 additions & 16 deletions rust/src/bin/client.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use futures::prelude::*;
use libp2p::swarm::{SwarmBuilder, SwarmEvent};
use libp2p::{identity, Multiaddr, PeerId};
use libp2p_perf::{build_transport, Perf, TransportSecurity};
use log::warn;
use libp2p_perf::{build_transport, Perf, TcpTransportSecurity};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
Expand All @@ -15,7 +14,7 @@ struct Opt {
server_address: Multiaddr,

#[structopt(long)]
transport_security: Option<TransportSecurity>,
tcp_transport_security: Option<TcpTransportSecurity>,
}

#[async_std::main]
Expand All @@ -26,10 +25,12 @@ async fn main() {
let key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(key.public());

println!("Local peer id: {:?}", local_peer_id);

let transport = build_transport(
false,
key,
opt.transport_security.unwrap_or(TransportSecurity::Noise),
opt.tcp_transport_security
.unwrap_or(TcpTransportSecurity::Noise),
)
.unwrap();
let perf = Perf::default();
Expand All @@ -39,17 +40,7 @@ async fn main() {
}))
.build();

// Hack as Swarm::dial_addr does not accept Multiaddr with PeerId.
let mut server_address = opt.server_address;
if matches!(
server_address.iter().last(),
Some(libp2p::core::multiaddr::Protocol::P2p(_))
) {
warn!("Ignoring provided PeerId.");
server_address.pop().unwrap();
}

client.dial_addr(server_address).unwrap();
client.dial_addr(opt.server_address).unwrap();

loop {
match client.next().await.expect("Infinite stream.") {
Expand Down
6 changes: 4 additions & 2 deletions rust/src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use futures::future::poll_fn;
use futures::prelude::*;
use libp2p::swarm::SwarmBuilder;
use libp2p::{identity, Multiaddr, PeerId, Swarm};
use libp2p_perf::{build_transport, Perf, TransportSecurity};
use libp2p_perf::{build_transport, Perf, TcpTransportSecurity};
use std::path::PathBuf;
use std::task::Poll;
use structopt::StructOpt;
Expand Down Expand Up @@ -33,7 +33,9 @@ async fn main() {
};
let local_peer_id = PeerId::from(key.public());

let transport = build_transport(false, key, TransportSecurity::All).unwrap();
println!("Local peer id: {:?}", local_peer_id);

let transport = build_transport(key, TcpTransportSecurity::All).unwrap();
let perf = Perf::default();
let mut server = SwarmBuilder::new(transport, perf, local_peer_id.clone())
.executor(Box::new(|f| {
Expand Down
Loading