Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit c7a7998

Browse files
committed
fix: code review - rework
1 parent a8851eb commit c7a7998

File tree

3 files changed

+11
-23
lines changed

3 files changed

+11
-23
lines changed

bitswap/src/protocol.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ use crate::ledger::Message;
88
use core::future::Future;
99
use core::iter;
1010
use core::pin::Pin;
11-
use futures::io::{AsyncRead, AsyncWrite};
11+
use futures::{
12+
io::{AsyncRead, AsyncWrite},
13+
AsyncWriteExt,
14+
};
1215
use libp2p_core::{upgrade, InboundUpgrade, OutboundUpgrade, UpgradeInfo};
1316
use std::io;
1417

@@ -71,7 +74,8 @@ where
7174
fn upgrade_outbound(self, mut socket: TSocket, _info: Self::Info) -> Self::Future {
7275
Box::pin(async move {
7376
let bytes = self.to_bytes();
74-
upgrade::write_length_prefixed(&mut socket, bytes).await
77+
upgrade::write_length_prefixed(&mut socket, bytes).await?;
78+
socket.close().await
7579
})
7680
}
7781
}

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ impl<TRepoTypes: RepoTypes> Future for IpfsFuture<TRepoTypes> {
13691369
loop {
13701370
let inner = {
13711371
use futures::StreamExt;
1372-
let next = self.swarm.next();
1372+
let next = self.swarm.select_next_some();
13731373
futures::pin_mut!(next);
13741374
match next.poll(ctx) {
13751375
Poll::Ready(inner) => inner,
@@ -1382,7 +1382,7 @@ impl<TRepoTypes: RepoTypes> Future for IpfsFuture<TRepoTypes> {
13821382
// off the events from Ipfs and ... this looping goes on for a while.
13831383
done = false;
13841384
match inner {
1385-
Some(SwarmEvent::NewListenAddr { address, .. }) => {
1385+
SwarmEvent::NewListenAddr { address, .. } => {
13861386
self.complete_listening_address_adding(address);
13871387
}
13881388
_ => trace!("{:?}", inner),

src/p2p/addr.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,26 +217,10 @@ pub(crate) fn could_be_bound_from_ephemeral(
217217

218218
// Checks if two instances of multiaddr are equal comparing as many protocol segments as possible
219219
pub(crate) fn eq_greedy(addr0: &Multiaddr, addr1: &Multiaddr) -> bool {
220-
match (addr0.is_empty(), addr1.is_empty()) {
221-
(true, true) => true,
222-
(false, false) => {
223-
let mut it1 = addr1.iter();
224-
225-
for i0 in addr0.iter() {
226-
if let Some(i1) = it1.next() {
227-
if i0 != i1 {
228-
return false;
229-
}
230-
} else {
231-
// All previous segments were equal
232-
return true;
233-
}
234-
}
235-
236-
true
237-
}
238-
_ => false,
220+
if addr0.is_empty() != addr1.is_empty() {
221+
return false;
239222
}
223+
addr0.iter().zip(addr1.iter()).all(|(a, b)| a == b)
240224
}
241225

242226
#[cfg(test)]

0 commit comments

Comments
 (0)