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

bitswap: Update libp2p #490

Closed
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
6 changes: 3 additions & 3 deletions bitswap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ cid = { default-features = false, version = "0.5" }
fnv = { default-features = false, version = "1.0" }
futures = { default-features = false, version = "0.3" }
hash_hasher = "2.0.3"
libp2p-core = { default-features = false, version = "0.29" }
libp2p-swarm = { default-features = false, version = "0.30" }
libp2p-core = { default-features = false, version = "0.30" }
libp2p-swarm = { default-features = false, version = "0.32" }
multihash = { default-features = false, version = "0.11" }
prost = { default-features = false, version = "0.8" }
prost = { default-features = false, version = "0.9" }
thiserror = { default-features = false, version = "1.0" }
tokio = { default-features = false, version = "1", features = ["rt"] }
tracing = { default-features = false, version = "0.1" }
Expand Down
18 changes: 11 additions & 7 deletions bitswap/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ use fnv::FnvHashSet;
use futures::channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender};
use hash_hasher::HashedMap;
use libp2p_core::{connection::ConnectionId, Multiaddr, PeerId};
use libp2p_swarm::protocols_handler::{IntoProtocolsHandler, OneShotHandler, ProtocolsHandler};
use libp2p_swarm::protocols_handler::{OneShotHandler, OneShotHandlerConfig, SubstreamProtocol};
use libp2p_swarm::dial_opts::DialOpts;
use libp2p_swarm::{
DialPeerCondition, NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
NetworkBehaviour, NetworkBehaviourAction, NotifyHandler, PollParameters,
};
use std::task::{Context, Poll};
use std::{
Expand Down Expand Up @@ -88,7 +89,7 @@ impl Stats {
/// Network behaviour that handles sending and receiving IPFS blocks.
pub struct Bitswap {
/// Queue of events to report to the user.
events: VecDeque<NetworkBehaviourAction<Message, BitswapEvent>>,
events: VecDeque<NetworkBehaviourAction<BitswapEvent, OneShotHandler<BitswapConfig, Message, MessageWrapper>>>,
/// List of prospect peers to connect to.
target_peers: FnvHashSet<PeerId>,
/// Ledger
Expand Down Expand Up @@ -150,9 +151,12 @@ impl Bitswap {
/// Called from Kademlia behaviour.
pub fn connect(&mut self, peer_id: PeerId) {
if self.target_peers.insert(peer_id) {
self.events.push_back(NetworkBehaviourAction::DialPeer {
peer_id,
condition: DialPeerCondition::Disconnected,
let osh_config = OneShotHandlerConfig::default();
let subsprot = SubstreamProtocol::new(BitswapConfig::default(), ());

self.events.push_back(NetworkBehaviourAction::Dial {
opts: DialOpts::peer_id(peer_id).build(),
handler: OneShotHandler::new(subsprot, osh_config)
});
}
}
Expand Down Expand Up @@ -290,7 +294,7 @@ impl NetworkBehaviour for Bitswap {

#[allow(clippy::type_complexity)]
fn poll(&mut self, ctx: &mut Context, _: &mut impl PollParameters)
-> Poll<NetworkBehaviourAction<<<Self::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, Self::OutEvent>>
-> Poll<NetworkBehaviourAction<Self::OutEvent, Self::ProtocolsHandler>>
{
use futures::stream::StreamExt;

Expand Down