Skip to content

Commit

Permalink
updates to the test-plans:
Browse files Browse the repository at this point in the history
- update the ping testcase to follow the ones on the test-plans repo.
- update project to use parent rust-libp2p intead of fetching it from
  git.
  • Loading branch information
jxs committed Jan 17, 2023
1 parent 1bead15 commit 2eafb06
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 49 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/interop-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ jobs:
name: Run multidimensional interoperability tests
needs: build-ping-container
uses: "libp2p/test-plans/.github/workflows/run-testplans.yml@master"
env:
GIT_TARGET: github.com/${{ github.event.pull_request.head.repo.full_name || github.event.repository.full_name }}
GIT_REF: ${{ github.event.pull_request.head.sha || github.sha }}
with:
dir: "multidim-interop"
dir: "test-plans"
extra-versions: ping-versions
image-tar: ping-image
test-filter: "rust-libp2p-head"
2 changes: 1 addition & 1 deletion test-plans/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ log = "0.4"
redis = { version = "0.22.1", features = ["tokio-native-tls-comp", "tokio-comp"] }
tokio = { version = "1.24.1", features = ["full"] }

libp2p = { git = "https://github.com/libp2p/rust-libp2p", branch = "master", default_features = false, features = ["websocket", "quic", "mplex", "yamux", "tcp", "tokio", "ping", "noise", "tls", "dns", "rsa", "macros", "webrtc"] }
libp2p = { path = "../", default_features = false, features = ["websocket", "quic", "mplex", "yamux", "tcp", "tokio", "ping", "noise", "tls", "dns", "rsa", "macros", "webrtc"] }
testplan = { version = "0.2.0", git = "https://github.com/jxs/test-plans/", branch = "add-webrtc-transport-multidim-interop" }
rand = "0.8.5"
22 changes: 5 additions & 17 deletions test-plans/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
FROM rust:1.65-bullseye as builder
WORKDIR /usr/src/testplan
WORKDIR /usr/src/libp2p

# TODO fix this, it breaks reproducibility
RUN apt-get update && apt-get install -y cmake protobuf-compiler

RUN mkdir -p ./plan/src
COPY ./src/main.rs ./plan/src/main.rs
COPY ./Cargo.toml ./plan/Cargo.toml
COPY ./Cargo.lock ./plan/Cargo.lock
COPY ./ ./

RUN cd ./plan/ && cargo build # Initial build acts as a cache.
RUN cd ./test-plans/ && cargo build # Initial build acts as a cache.

ARG GIT_TARGET=""
RUN if [ ! -z "${GIT_TARGET}" ]; then sed -i "s,^git.*,git = \"https://${GIT_TARGET}\"," ./plan/Cargo.toml; fi

ARG GIT_REF=""
RUN if [ "master" = "${GIT_REF}" ]; then sed -i "s/^rev.*/branch= \"master\"/" ./plan/Cargo.toml; elif [ ! -z "${GIT_REF}" ]; then sed -i "s/^rev.*/rev = \"${GIT_REF}\"/" ./plan/Cargo.toml; fi

COPY ./src/bin/ ./plan/src/bin/

# Build the requested binary: Cargo will update lockfile on changed manifest (i.e. if one of the above `sed`s patched it).
ARG BINARY_NAME
RUN cd ./plan/ \
RUN cd ./test-plans/ \
&& cargo build --bin=${BINARY_NAME} \
&& mv /usr/src/testplan/plan/target/debug/${BINARY_NAME} /usr/local/bin/testplan
&& mv /usr/src/libp2p/test-plans/target/debug/${BINARY_NAME} /usr/local/bin/testplan

FROM debian:bullseye-slim
COPY --from=builder /usr/local/bin/testplan /usr/local/bin/testplan
Expand Down
3 changes: 1 addition & 2 deletions test-plans/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
all: ping-image.tar

ping-image.tar: Dockerfile Cargo.toml src
docker build -t rust-libp2p-head -f Dockerfile --build-arg BINARY_NAME=ping \
--build-arg GIT_REF=$GIT_REF --build-arg GIT_TARGET=$GIT_TARGET .
cd .. && docker build -t rust-libp2p-head -f test-plans/Dockerfile --build-arg BINARY_NAME=ping .
docker image save -o $@ rust-libp2p-head

.PHONY: clean
Expand Down
62 changes: 37 additions & 25 deletions test-plans/src/bin/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,41 @@ use libp2p::core::upgrade::EitherUpgrade;
use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmEvent};
use libp2p::websocket::WsConfig;
use libp2p::{
core, identity, mplex, noise, ping, webrtc, yamux, Multiaddr, PeerId, Swarm, Transport,
core, identity, mplex, noise, ping, webrtc, yamux, Multiaddr, PeerId, Swarm, Transport as _,
};
use testplan::{run_ping, PingSwarm};
use testplan::{run_ping, Muxer, PingSwarm, SecProtocol, Transport};

fn build_builder<T, C>(
builder: core::transport::upgrade::Builder<T>,
secure_channel_param: &str,
muxer_param: &str,
secure_channel_param: SecProtocol,
muxer_param: Muxer,
local_key: &identity::Keypair,
) -> Boxed<(libp2p::PeerId, StreamMuxerBox)>
where
T: Transport<Output = C> + Send + Unpin + 'static,
T: libp2p::Transport<Output = C> + Send + Unpin + 'static,
<T as libp2p::Transport>::Error: Sync + Send + 'static,
<T as libp2p::Transport>::ListenerUpgrade: Send,
<T as libp2p::Transport>::Dial: Send,
C: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{
let mux_upgrade = match muxer_param {
"yamux" => EitherUpgrade::A(yamux::YamuxConfig::default()),
"mplex" => EitherUpgrade::B(mplex::MplexConfig::default()),
_ => panic!("Unsupported muxer"),
Muxer::Yamux => EitherUpgrade::A(yamux::YamuxConfig::default()),
Muxer::Mplex => EitherUpgrade::B(mplex::MplexConfig::default()),
};

let timeout = Duration::from_secs(5);

match secure_channel_param {
"noise" => builder
SecProtocol::Noise => builder
.authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap())
.multiplex(mux_upgrade)
.timeout(timeout)
.boxed(),
"tls" => builder
SecProtocol::Tls => builder
.authenticate(libp2p::tls::Config::new(&local_key).unwrap())
.multiplex(mux_upgrade)
.timeout(timeout)
.boxed(),
_ => panic!("Unsupported secure channel"),
}
}

Expand All @@ -56,46 +54,61 @@ async fn main() -> Result<()> {
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());

let transport_param =
env::var("transport").context("transport environment variable is not set")?;
let secure_channel_param =
env::var("security").context("security environment variable is not set")?;
let muxer_param = env::var("muxer").context("muxer environment variable is not set")?;
let transport_param: Transport =
testplan::from_env("transport").context("unsupported transport")?;

let ip = env::var("ip").context("ip environment variable is not set")?;

let is_dialer = env::var("is_dialer")
.unwrap_or("true".into())
.parse::<bool>()?;

let redis_addr = env::var("REDIS_ADDR")
.map(|addr| format!("redis://{addr}"))
.unwrap_or("redis://redis:6379".into());

let client = redis::Client::open(redis_addr).context("Could not connect to redis")?;

let (boxed_transport, local_addr) = match transport_param.as_str() {
"quic-v1" => {
let (boxed_transport, local_addr) = match transport_param {
Transport::QuicV1 => {
let builder =
libp2p::quic::tokio::Transport::new(libp2p::quic::Config::new(&local_key))
.map(|(p, c), _| (p, StreamMuxerBox::new(c)));
(builder.boxed(), format!("/ip4/{ip}/udp/0/quic-v1"))
}
"tcp" => {
Transport::Tcp => {
let builder = libp2p::tcp::tokio::Transport::new(libp2p::tcp::Config::new())
.upgrade(libp2p::core::upgrade::Version::V1Lazy);

let secure_channel_param: SecProtocol =
testplan::from_env("security").context("unsupported secure channel")?;

let muxer_param: Muxer =
testplan::from_env("muxer").context("unsupported multiplexer")?;

(
build_builder(builder, &secure_channel_param, &muxer_param, &local_key),
build_builder(builder, secure_channel_param, muxer_param, &local_key),
format!("/ip4/{ip}/tcp/0"),
)
}
"ws" => {
Transport::Ws => {
let builder = WsConfig::new(libp2p::tcp::tokio::Transport::new(
libp2p::tcp::Config::new(),
))
.upgrade(libp2p::core::upgrade::Version::V1Lazy);

let secure_channel_param: SecProtocol =
testplan::from_env("security").context("unsupported secure channel")?;

let muxer_param: Muxer =
testplan::from_env("muxer").context("unsupported multiplexer")?;

(
build_builder(builder, &secure_channel_param, &muxer_param, &local_key),
build_builder(builder, secure_channel_param, muxer_param, &local_key),
format!("/ip4/{ip}/tcp/0/ws"),
)
}
"webrtc" => (
Transport::Webrtc => (
webrtc::tokio::Transport::new(
local_key,
webrtc::tokio::Certificate::generate(&mut rand::thread_rng())?,
Expand All @@ -104,7 +117,6 @@ async fn main() -> Result<()> {
.boxed(),
format!("/ip4/{ip}/udp/0/webrtc"),
),
_ => panic!("Unsupported"),
};

let swarm = OrphanRuleWorkaround(Swarm::with_tokio_executor(
Expand All @@ -118,7 +130,7 @@ async fn main() -> Result<()> {

// Use peer id as a String so that `run_ping` does not depend on a specific libp2p version.
let local_peer_id = local_peer_id.to_string();
run_ping(client, swarm, &local_addr, &local_peer_id).await?;
run_ping(client, swarm, &local_addr, &local_peer_id, is_dialer).await?;

Ok(())
}
Expand Down

0 comments on commit 2eafb06

Please sign in to comment.