fix(ci): ensure all examples compile with the specified feature-set

Due to cargo's feature unification, a full build of our workspace doesn't actually check whether the examples compile as standalone projects.

We add a new CI check that iterates through all crates in the `examples/` directory and runs a plain `cargo check` on them. Any failure is bubbled up via `set -e`, thus failing CI in case one of the `cargo check` commands fails.

To fix the current failures, we construct a simple TCP transport everywhere where we were previously using `development_transport`. That is because `development_transport` requires `mplex` which is now deprecated.

Related #3657.
Related #3809.

Pull-Request: #3811.
This commit is contained in:
Thomas Eizinger
2023-04-21 11:58:08 +02:00
committed by GitHub
parent 0fe9791829
commit 28da3d4180
16 changed files with 60 additions and 21 deletions

View File

@ -195,6 +195,28 @@ jobs:
- name: Run ipfs-kad example
run: cd ./examples/ipfs-kad/ && RUST_LOG=libp2p_swarm=debug,libp2p_kad=trace,libp2p_tcp=debug cargo run
examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: r7kamura/rust-problem-matchers@d58b70c4a13c4866d96436315da451d8106f8f08 #v1.3.0
- uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
with:
shared-key: stable-cache
save-if: false
- name: Compile all examples
run: |
set -e;
for toml in examples/**/Cargo.toml; do
cargo check --manifest-path "$toml";
done
rustfmt:
runs-on: ubuntu-latest
steps:

View File

@ -63,7 +63,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("Local peer id: {local_peer_id:?}");
let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

View File

@ -52,7 +52,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("Local peer id: {local_peer_id:?}");
let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

View File

@ -76,7 +76,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Set up an encrypted DNS-enabled TCP Transport over the Mplex protocol.
let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1)
.upgrade(upgrade::Version::V1Lazy)
.authenticate(
noise::NoiseAuthenticated::xx(&id_keys).expect("signing libp2p-noise static keypair"),
)

View File

@ -96,7 +96,7 @@ fn main() -> Result<(), Box<dyn Error>> {
)))
.unwrap(),
)
.upgrade(upgrade::Version::V1)
.upgrade(upgrade::Version::V1Lazy)
.authenticate(
noise::NoiseAuthenticated::xx(&local_key)
.expect("Signing libp2p-noise static DH keypair failed."),

View File

@ -42,15 +42,16 @@
use async_std::io;
use futures::{prelude::*, select};
use libp2p::core::upgrade::Version;
use libp2p::kad::record::store::MemoryStore;
use libp2p::kad::{
record::Key, AddProviderOk, GetProvidersOk, GetRecordOk, Kademlia, KademliaEvent, PeerRecord,
PutRecordOk, QueryResult, Quorum, Record,
};
use libp2p::{
development_transport, identity, mdns,
identity, mdns, noise,
swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent},
PeerId,
tcp, yamux, PeerId, Transport,
};
use std::error::Error;
@ -62,8 +63,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_key = identity::Keypair::generate_ed25519();
let local_peer_id = PeerId::from(local_key.public());
// Set up a an encrypted DNS-enabled TCP Transport over the Mplex protocol.
let transport = development_transport(local_key).await?;
let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();
// We create a custom network behaviour that combines Kademlia and mDNS.
#[derive(NetworkBehaviour)]

View File

@ -14,11 +14,13 @@ use libp2p::{
record::store::MemoryStore, GetProvidersOk, Kademlia, KademliaEvent, QueryId, QueryResult,
},
multiaddr::Protocol,
noise,
request_response::{self, ProtocolSupport, RequestId, ResponseChannel},
swarm::{ConnectionHandlerUpgrErr, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent},
PeerId,
tcp, yamux, PeerId, Transport,
};
use libp2p::core::upgrade::Version;
use std::collections::{hash_map, HashMap, HashSet};
use std::error::Error;
use std::iter;
@ -45,10 +47,16 @@ pub async fn new(
};
let peer_id = id_keys.public().to_peer_id();
let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&id_keys)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();
// Build the Swarm, connecting the lower layer transport logic with the
// higher layer network behaviour logic.
let swarm = SwarmBuilder::with_async_std_executor(
libp2p::development_transport(id_keys).await?,
transport,
ComposedBehaviour {
kademlia: Kademlia::new(peer_id, MemoryStore::new(peer_id)),
request_response: request_response::Behaviour::new(

View File

@ -52,7 +52,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!("Local peer id: {local_peer_id:?}");
let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed();

View File

@ -63,7 +63,7 @@ pub fn build_transport(
None => Either::Right(base_transport),
};
maybe_encrypted
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise_config)
.multiplex(yamux_config)
.timeout(Duration::from_secs(20))

View File

@ -73,7 +73,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut swarm = SwarmBuilder::without_executor(
tcp::async_io::Transport::default()
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed(),

View File

@ -41,10 +41,11 @@
//! and begin pinging each other.
use futures::prelude::*;
use libp2p::core::upgrade::Version;
use libp2p::{
identity, ping,
identity, noise, ping,
swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent},
Multiaddr, PeerId,
tcp, yamux, Multiaddr, PeerId, Transport,
};
use std::error::Error;
@ -54,7 +55,11 @@ async fn main() -> Result<(), Box<dyn Error>> {
let local_peer_id = PeerId::from(local_key.public());
println!("Local peer id: {local_peer_id:?}");
let transport = libp2p::development_transport(local_key).await?;
let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();
let mut swarm =
SwarmBuilder::with_async_std_executor(transport, Behaviour::default(), local_peer_id)

View File

@ -49,7 +49,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let tcp_transport = tcp::async_io::Transport::default();
let transport = tcp_transport
.upgrade(upgrade::Version::V1)
.upgrade(upgrade::Version::V1Lazy)
.authenticate(
noise::NoiseAuthenticated::xx(&local_key)
.expect("Signing libp2p-noise static DH keypair failed."),

View File

@ -43,7 +43,7 @@ async fn main() {
let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed(),

View File

@ -39,7 +39,7 @@ async fn main() {
let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed(),

View File

@ -39,7 +39,7 @@ async fn main() {
let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed(),

View File

@ -53,7 +53,7 @@ async fn main() {
let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1)
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed(),