Skip to content

Commit

Permalink
Fix concerns by clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
umgefahren committed Mar 7, 2024
1 parent 5d24d03 commit 41804be
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 32 deletions.
13 changes: 12 additions & 1 deletion muxers/mplex/benches/split_send_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use futures::prelude::*;
use futures::{channel::oneshot, future::join};
use libp2p_core::muxing::StreamMuxerExt;
use libp2p_core::transport::ListenerId;
use libp2p_core::Endpoint;
use libp2p_core::{multiaddr::multiaddr, muxing, transport, upgrade, Multiaddr, Transport};
use libp2p_identity as identity;
use libp2p_identity::PeerId;
Expand Down Expand Up @@ -146,7 +147,17 @@ fn run(
// Spawn and block on the sender, i.e. until all data is sent.
let sender = async move {
let addr = addr_receiver.await.unwrap();
let (_peer, mut conn) = sender_trans.dial(addr).unwrap().await.unwrap();
let (_peer, mut conn) = sender_trans
.dial(
addr,
transport::DialOpts {
role: Endpoint::Dialer,
port_use: transport::PortUse::Reuse,
},
)
.unwrap()
.await
.unwrap();
// Just calling `poll_outbound` without `poll` is fine here because mplex makes progress through all `poll_` functions. It is hacky though.
let mut stream = poll_fn(|cx| conn.poll_outbound_unpin(cx)).await.unwrap();
let mut off = 0;
Expand Down
61 changes: 30 additions & 31 deletions protocols/autonat/tests/autonatv2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ async fn confirm_successful() {
.try_init();
let (mut alice, mut bob) = start_and_connect().await;

let cor_server_peer = alice.local_peer_id().clone();
let cor_client_peer = bob.local_peer_id().clone();
let cor_server_peer = *alice.local_peer_id();
let cor_client_peer = *bob.local_peer_id();
let bob_external_addrs = Arc::new(bob.external_addresses().cloned().collect::<Vec<_>>());
let alice_bob_external_addrs = bob_external_addrs.clone();

Expand Down Expand Up @@ -76,7 +76,7 @@ async fn confirm_successful() {
})
.await;

assert_eq!(tested_addr, bob_external_addrs.get(0).cloned().unwrap());
assert_eq!(tested_addr, bob_external_addrs.first().cloned().unwrap());
assert_eq!(data_amount, 0);
assert_eq!(client, cor_client_peer);
assert_eq!(&all_addrs[..], &bob_external_addrs[..]);
Expand All @@ -96,14 +96,16 @@ async fn confirm_successful() {
})
.await;

let _ = bob.wait(|event| match event {
SwarmEvent::ConnectionEstablished {
connection_id,
peer_id,
..
} if incoming_conn_id == connection_id && peer_id == cor_server_peer => Some(()),
_ => None,
});
let _ = bob
.wait(|event| match event {
SwarmEvent::ConnectionEstablished {
connection_id,
peer_id,
..
} if incoming_conn_id == connection_id && peer_id == cor_server_peer => Some(()),
_ => None,
})
.await;

let client::Event {
tested_addr,
Expand All @@ -120,7 +122,7 @@ async fn confirm_successful() {
.await;
assert_eq!(
tested_addr,
alice_bob_external_addrs.get(0).cloned().unwrap()
alice_bob_external_addrs.first().cloned().unwrap()
);
assert_eq!(bytes_sent, 0);
assert_eq!(server, cor_server_peer);
Expand Down Expand Up @@ -282,7 +284,7 @@ async fn dial_back_to_non_libp2p() {
panic!("No outgoing connection errors");
}

let data_amount = alice
alice
.wait(|event| match event {
SwarmEvent::Behaviour(CombinedServerEvent::Autonat(server::Event {
all_addrs,
Expand All @@ -298,22 +300,19 @@ async fn dial_back_to_non_libp2p() {
}
_ => None,
})
.await;
data_amount
.await
};
let bob_task = async {
let data_amount = bob
.wait(|event| match event {
SwarmEvent::Behaviour(CombinedClientEvent::Autonat(client::Event {
tested_addr,
bytes_sent,
server,
result: Err(_),
})) if tested_addr == bob_addr && server == alice_peer_id => Some(bytes_sent),
_ => None,
})
.await;
data_amount
bob.wait(|event| match event {
SwarmEvent::Behaviour(CombinedClientEvent::Autonat(client::Event {
tested_addr,
bytes_sent,
server,
result: Err(_),
})) if tested_addr == bob_addr && server == alice_peer_id => Some(bytes_sent),
_ => None,
})
.await
};

let (alice_bytes_sent, bob_bytes_sent) = tokio::join!(alice_task, bob_task);
Expand Down Expand Up @@ -392,7 +391,7 @@ async fn dial_back_to_not_supporting() {
.await;
tokio::select! {
_ = bob_done_rx => {
return data_amount;
data_amount
}
_ = alice.loop_on_next() => {
unreachable!();
Expand Down Expand Up @@ -487,8 +486,8 @@ async fn start_and_connect() -> (Swarm<CombinedServer>, Swarm<CombinedClient>) {
async fn bootstrap() -> (Swarm<CombinedServer>, Swarm<CombinedClient>) {
let (mut alice, mut bob) = start_and_connect().await;

let cor_server_peer = alice.local_peer_id().clone();
let cor_client_peer = bob.local_peer_id().clone();
let cor_server_peer = *alice.local_peer_id();
let cor_client_peer = *bob.local_peer_id();

let alice_task = async {
let _ = alice
Expand Down Expand Up @@ -553,7 +552,7 @@ async fn bootstrap() -> (Swarm<CombinedServer>, Swarm<CombinedClient>) {
..
} if incoming_conn_id == connection_id && peer_id == cor_server_peer => Some(()),
_ => None,
});
}).await;

bob.wait(|event| match event {
SwarmEvent::Behaviour(CombinedClientEvent::Autonat(_)) => Some(()),
Expand Down

0 comments on commit 41804be

Please sign in to comment.