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

chore(*): Run rustfmt 1.7.0 and clippy 0.1.76 #4907

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
55 changes: 28 additions & 27 deletions core/src/peer_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,40 +168,41 @@
#[test]
fn mismatched_signature() {
use quick_protobuf::MessageWrite;

Check failure on line 171 in core/src/peer_record.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/core/src/peer_record.rs
let addr: Multiaddr = HOME.parse().unwrap();

let envelope = {
let identity_a = Keypair::generate_ed25519();
let identity_b = Keypair::generate_ed25519();

let payload = {
let record = proto::PeerRecord {
peer_id: identity_a.public().to_peer_id().to_bytes(),
seq: 0,
addresses: vec![proto::AddressInfo {
multiaddr: addr.to_vec(),
}],
let envelope =
{
let identity_a = Keypair::generate_ed25519();
let identity_b = Keypair::generate_ed25519();

let payload = {
let record = proto::PeerRecord {
peer_id: identity_a.public().to_peer_id().to_bytes(),
seq: 0,
addresses: vec![proto::AddressInfo {
multiaddr: addr.to_vec(),
}],
};

let mut buf = Vec::with_capacity(record.get_size());
let mut writer = Writer::new(&mut buf);
record
.write_message(&mut writer)
.expect("Encoding to succeed");

buf
};

let mut buf = Vec::with_capacity(record.get_size());
let mut writer = Writer::new(&mut buf);
record
.write_message(&mut writer)
.expect("Encoding to succeed");

buf
SignedEnvelope::new(
&identity_b,
String::from(DOMAIN_SEP),
PAYLOAD_TYPE.as_bytes().to_vec(),
payload,
)
.unwrap()
};

SignedEnvelope::new(
&identity_b,
String::from(DOMAIN_SEP),
PAYLOAD_TYPE.as_bytes().to_vec(),
payload,
)
.unwrap()
};

assert!(matches!(
PeerRecord::from_signed_envelope(envelope),
Err(FromEnvelopeError::MismatchedSignature)
Expand Down
17 changes: 9 additions & 8 deletions core/src/signed_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,18 @@
let payload_type_length =
unsigned_varint::encode::usize(payload_type.len(), &mut payload_type_length_buffer);

let mut payload_length_buffer = usize_buffer();

Check failure on line 120 in core/src/signed_envelope.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/core/src/signed_envelope.rs
let payload_length = unsigned_varint::encode::usize(payload.len(), &mut payload_length_buffer);

let mut buffer = Vec::with_capacity(
domain_sep_length.len()
+ domain_separation.len()
+ payload_type_length.len()
+ payload_type.len()
+ payload_length.len()
+ payload.len(),
);
let mut buffer =
Vec::with_capacity(
domain_sep_length.len()
+ domain_separation.len()
+ payload_type_length.len()
+ payload_type.len()
+ payload_length.len()
+ payload.len(),
);

buffer.extend_from_slice(domain_sep_length);
buffer.extend_from_slice(domain_separation.as_bytes());
Expand Down
42 changes: 22 additions & 20 deletions core/src/transport/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,25 +547,26 @@
let rand_port = rand::random::<u64>().saturating_add(1);
let t1_addr: Multiaddr = format!("/memory/{rand_port}").parse().unwrap();
let cloned_t1_addr = t1_addr.clone();

Check failure on line 550 in core/src/transport/memory.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/core/src/transport/memory.rs
let mut t1 = MemoryTransport::default().boxed();

let listener = async move {
t1.listen_on(ListenerId::next(), t1_addr.clone()).unwrap();
let upgrade = loop {
let event = t1.select_next_some().await;
if let Some(upgrade) = event.into_incoming() {
break upgrade;
}
};
let listener =
async move {
t1.listen_on(ListenerId::next(), t1_addr.clone()).unwrap();
let upgrade = loop {
let event = t1.select_next_some().await;
if let Some(upgrade) = event.into_incoming() {
break upgrade;
}
};

let mut socket = upgrade.0.await.unwrap();
let mut socket = upgrade.0.await.unwrap();

let mut buf = [0; 3];
socket.read_exact(&mut buf).await.unwrap();
let mut buf = [0; 3];
socket.read_exact(&mut buf).await.unwrap();

assert_eq!(buf, msg);
};
assert_eq!(buf, msg);
};

// Setup dialer.

Expand Down Expand Up @@ -602,16 +603,17 @@
);
return;
}
}

Check failure on line 606 in core/src/transport/memory.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/core/src/transport/memory.rs
};

let dialer = async move {
MemoryTransport::default()
.dial(listener_addr_cloned)
.unwrap()
.await
.unwrap();
};
let dialer =
async move {
MemoryTransport::default()
.dial(listener_addr_cloned)
.unwrap()
.await
.unwrap();
};

futures::executor::block_on(futures::future::join(listener, dialer));
}
Expand Down
50 changes: 24 additions & 26 deletions core/src/transport/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,10 @@
C: AsyncRead + AsyncWrite + Unpin,
D: AsyncRead + AsyncWrite + Unpin,
U: InboundConnectionUpgrade<Negotiated<C>, Output = D, Error = E>,
U: OutboundConnectionUpgrade<Negotiated<C>, Output = D, Error = E> + Clone,

Check failure on line 212 in core/src/transport/upgrade.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/core/src/transport/upgrade.rs
E: Error + 'static,
{
Authenticated(Builder::new(
Upgrade::new(self.0.inner, upgrade),
self.0.version,
))
Authenticated(Builder::new(Upgrade::new(self.0.inner, upgrade), self.0.version))
}

/// Upgrades the transport with a (sub)stream multiplexer.
Expand Down Expand Up @@ -521,32 +518,33 @@
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// We use a `this` variable because the compiler can't mutably borrow multiple times
// accross a `Deref`.
let this = &mut *self;

Check failure on line 521 in core/src/transport/upgrade.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/core/src/transport/upgrade.rs

loop {
this.upgrade = match this.upgrade {
future::Either::Left(ref mut up) => {
let (i, c) = match ready!(TryFuture::try_poll(this.future.as_mut(), cx)
.map_err(TransportUpgradeError::Transport))
{
Ok(v) => v,
Err(err) => return Poll::Ready(Err(err)),
};
let u = up
.take()
.expect("DialUpgradeFuture is constructed with Either::Left(Some).");
future::Either::Right((i, apply_outbound(c, u, upgrade::Version::V1)))
this.upgrade =
match this.upgrade {
future::Either::Left(ref mut up) => {
let (i, c) = match ready!(TryFuture::try_poll(this.future.as_mut(), cx)
.map_err(TransportUpgradeError::Transport))
{
Ok(v) => v,
Err(err) => return Poll::Ready(Err(err)),
};
let u = up
.take()
.expect("DialUpgradeFuture is constructed with Either::Left(Some).");
future::Either::Right((i, apply_outbound(c, u, upgrade::Version::V1)))
}
future::Either::Right((i, ref mut up)) => {
let d = match ready!(Future::poll(Pin::new(up), cx)
.map_err(TransportUpgradeError::Upgrade))
{
Ok(d) => d,
Err(err) => return Poll::Ready(Err(err)),
};
return Poll::Ready(Ok((i, d)));
}
}
future::Either::Right((i, ref mut up)) => {
let d = match ready!(
Future::poll(Pin::new(up), cx).map_err(TransportUpgradeError::Upgrade)
) {
Ok(d) => d,
Err(err) => return Poll::Ready(Err(err)),
};
return Poll::Ready(Ok((i, d)));
}
}
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions examples/autonat/src/bin/autonat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@
auto_nat: autonat::Behaviour,
}

impl Behaviour {

Check failure on line 91 in examples/autonat/src/bin/autonat_client.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/examples/autonat/src/bin/autonat_client.rs
fn new(local_public_key: identity::PublicKey) -> Self {
Self {
identify: identify::Behaviour::new(identify::Config::new(
"/ipfs/0.1.0".into(),
local_public_key.clone(),
)),
identify: identify::Behaviour::new(
identify::Config::new("/ipfs/0.1.0".into(), local_public_key.clone())
),
auto_nat: autonat::Behaviour::new(
local_public_key.to_peer_id(),
autonat::Config {
Expand Down
7 changes: 3 additions & 4 deletions examples/autonat/src/bin/autonat_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,12 @@
auto_nat: autonat::Behaviour,
}

impl Behaviour {

Check failure on line 78 in examples/autonat/src/bin/autonat_server.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/examples/autonat/src/bin/autonat_server.rs
fn new(local_public_key: identity::PublicKey) -> Self {
Self {
identify: identify::Behaviour::new(identify::Config::new(
"/ipfs/0.1.0".into(),
local_public_key.clone(),
)),
identify: identify::Behaviour::new(
identify::Config::new("/ipfs/0.1.0".into(), local_public_key.clone())
),
auto_nat: autonat::Behaviour::new(
local_public_key.to_peer_id(),
autonat::Config {
Expand Down
17 changes: 9 additions & 8 deletions examples/browser-webrtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
pub async fn run(libp2p_endpoint: String) -> Result<(), JsError> {
wasm_logger::init(wasm_logger::Config::default());

let body = Body::from_current_window()?;

Check failure on line 18 in examples/browser-webrtc/src/lib.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/examples/browser-webrtc/src/lib.rs
body.append_p("Let's ping the WebRTC Server!")?;

let mut swarm = libp2p::SwarmBuilder::with_new_identity()
.with_wasm_bindgen()
.with_other_transport(|key| {
webrtc_websys::Transport::new(webrtc_websys::Config::new(&key))
})?
.with_behaviour(|_| ping::Behaviour::new(ping::Config::new()))?
.with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(5)))
.build();
let mut swarm =
libp2p::SwarmBuilder::with_new_identity()
.with_wasm_bindgen()
.with_other_transport(
|key| webrtc_websys::Transport::new(webrtc_websys::Config::new(&key))
)?
.with_behaviour(|_| ping::Behaviour::new(ping::Config::new()))?
.with_swarm_config(|c| c.with_idle_connection_timeout(Duration::from_secs(5)))
.build();

let addr = libp2p_endpoint.parse::<Multiaddr>()?;
tracing::info!("Dialing {addr}");
Expand Down
33 changes: 17 additions & 16 deletions examples/browser-webrtc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,27 @@
let address_webrtc = Multiaddr::from(Ipv4Addr::UNSPECIFIED)
.with(Protocol::Udp(0))
.with(Protocol::WebRTCDirect);

Check failure on line 49 in examples/browser-webrtc/src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt

Diff in /home/runner/work/rust-libp2p/rust-libp2p/examples/browser-webrtc/src/main.rs
swarm.listen_on(address_webrtc.clone())?;

let address = loop {
if let SwarmEvent::NewListenAddr { address, .. } = swarm.select_next_some().await {
if address
.iter()
.any(|e| e == Protocol::Ip4(Ipv4Addr::LOCALHOST))
{
tracing::debug!(
"Ignoring localhost address to make sure the example works in Firefox"
);
continue;
let address =
loop {
if let SwarmEvent::NewListenAddr { address, .. } = swarm.select_next_some().await {
if address
.iter()
.any(|e| e == Protocol::Ip4(Ipv4Addr::LOCALHOST))
{
tracing::debug!(
"Ignoring localhost address to make sure the example works in Firefox"
);
continue;
}

tracing::info!(%address, "Listening");

break address;
}

tracing::info!(%address, "Listening");

break address;
}
};
};

let addr = address.with(Protocol::P2p(*swarm.local_peer_id()));

Expand Down
10 changes: 4 additions & 6 deletions examples/dcutr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
SwarmEvent::Dialing { .. } => {}
SwarmEvent::ConnectionEstablished { .. } => {}
SwarmEvent::Behaviour(BehaviourEvent::Ping(_)) => {}
SwarmEvent::Behaviour(BehaviourEvent::Identify(identify::Event::Sent {
..
})) => {
SwarmEvent::Behaviour(BehaviourEvent::Identify(identify::Event::Sent { .. })) => {
tracing::info!("Told relay its public address");
told_relay_observed_addr = true;
}
Expand Down Expand Up @@ -193,9 +191,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
SwarmEvent::NewListenAddr { address, .. } => {
tracing::info!(%address, "Listening on address");
}
SwarmEvent::Behaviour(BehaviourEvent::RelayClient(
relay::client::Event::ReservationReqAccepted { .. },
)) => {
SwarmEvent::Behaviour(
BehaviourEvent::RelayClient(relay::client::Event::ReservationReqAccepted { .. })
) => {
assert!(opts.mode == Mode::Listen);
tracing::info!("Relay accepted our reservation request");
}
Expand Down
18 changes: 9 additions & 9 deletions examples/file-sharing/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,16 @@ impl EventLoop {
SwarmEvent::Behaviour(BehaviourEvent::Kademlia(
kad::Event::OutboundQueryProgressed {
result:
kad::QueryResult::GetProviders(Ok(
kad::GetProvidersOk::FinishedWithNoAdditionalRecord { .. },
)),
kad::QueryResult::GetProviders(
Ok(kad::GetProvidersOk::FinishedWithNoAdditionalRecord { .. })
),
..
},
)) => {}
SwarmEvent::Behaviour(BehaviourEvent::Kademlia(_)) => {}
SwarmEvent::Behaviour(BehaviourEvent::RequestResponse(
request_response::Event::Message { message, .. },
)) => match message {
SwarmEvent::Behaviour(
BehaviourEvent::RequestResponse(request_response::Event::Message { message, .. })
) => match message {
request_response::Message::Request {
request, channel, ..
} => {
Expand Down Expand Up @@ -290,9 +290,9 @@ impl EventLoop {
.expect("Request to still be pending.")
.send(Err(Box::new(error)));
}
SwarmEvent::Behaviour(BehaviourEvent::RequestResponse(
request_response::Event::ResponseSent { .. },
)) => {}
SwarmEvent::Behaviour(
BehaviourEvent::RequestResponse(request_response::Event::ResponseSent { .. })
) => {}
SwarmEvent::NewListenAddr { address, .. } => {
let local_peer_id = *self.swarm.local_peer_id();
eprintln!(
Expand Down
Loading