Skip to content

Commit

Permalink
chore: Replace tokio-stream StreamMap with pollable-map StreamMap (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 authored Sep 23, 2024
1 parent 6da06c1 commit 4240539
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- refactor: Remove redundant static lifetime. [PR 301](https://github.com/dariusc93/rust-ipfs/pull/301)
- refactor: Remove optional error from `UnixfsStatus`.
- refactor: Remove sled and redb datastore and dependency. [PR 304](https://github.com/dariusc93/rust-ipfs/pull/304)
- chore: Replace tokio-stream `StreamMap` with pollable-map `StreamMap`. [PR 306](https://github.com/dariusc93/rust-ipfs/pull/306)

# 0.11.21
- chore: Put libp2p-webrtc-websys behind feature.
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ multihash-derive = "0.9.0"
p256 = { version = "0.13.2", default-features = false, features = ["ecdsa", "std", "pem"] }
parking_lot = "0.12.3"
pem = { version = "3.0.4" }
pollable-map = "0.1.0-alpha"
quick-protobuf = { version = "0.8.1" }
quick-protobuf-codec = "0.3.1"
rand = "0.8.5"
Expand Down Expand Up @@ -118,6 +119,7 @@ multihash-derive.workspace = true
p256.workspace = true
parking_lot.workspace = true
pem.workspace = true
pollable-map.workspace = true
quick-protobuf-codec.workspace = true
quick-protobuf.workspace = true
rand.workspace = true
Expand Down
23 changes: 4 additions & 19 deletions src/p2p/bitswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use libp2p::{
},
Multiaddr, PeerId,
};
use tokio_stream::StreamMap;
use pollable_map::stream::StreamMap;

mod bitswap_pb {
pub use super::pb::bitswap_pb::Message;
Expand Down Expand Up @@ -280,12 +280,7 @@ impl Behaviour {
match cids.is_empty() {
false => {
for cid in cids {
let Some(session) = self
.want_session
.iter_mut()
.find(|(session_cid, _)| *session_cid == cid)
.map(|(_, session)| session)
else {
let Some(session) = self.want_session.get_mut(&cid) else {
continue;
};
for peer_id in &peers {
Expand Down Expand Up @@ -416,12 +411,7 @@ impl NetworkBehaviour for Behaviour {
self.have_session.insert(*cid, have_session);
}

let Some(session) = self
.have_session
.iter_mut()
.find(|(session_cid, _)| session_cid == cid)
.map(|(_, session)| session)
else {
let Some(session) = self.have_session.get_mut(cid) else {
if !*cancel {
tracing::warn!(block = %cid, %peer_id, %connection_id, "have session does not exist. Skipping request");
}
Expand All @@ -444,12 +434,7 @@ impl NetworkBehaviour for Behaviour {
}

for (cid, response) in responses {
let Some(session) = self
.want_session
.iter_mut()
.find(|(session_cid, _)| *session_cid == cid)
.map(|(_, session)| session)
else {
let Some(session) = self.want_session.get_mut(&cid) else {
tracing::warn!(block = %cid, %peer_id, %connection_id, "want session does not exist. Skipping response");
continue;
};
Expand Down

0 comments on commit 4240539

Please sign in to comment.