diff --git a/bitswap/Cargo.toml b/bitswap/Cargo.toml index e171aefdc..c4995b441 100644 --- a/bitswap/Cargo.toml +++ b/bitswap/Cargo.toml @@ -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" } diff --git a/bitswap/src/behaviour.rs b/bitswap/src/behaviour.rs index 4b1caf8ac..33671f83a 100644 --- a/bitswap/src/behaviour.rs +++ b/bitswap/src/behaviour.rs @@ -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::{ @@ -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>, + events: VecDeque>>, /// List of prospect peers to connect to. target_peers: FnvHashSet, /// Ledger @@ -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) }); } } @@ -290,7 +294,7 @@ impl NetworkBehaviour for Bitswap { #[allow(clippy::type_complexity)] fn poll(&mut self, ctx: &mut Context, _: &mut impl PollParameters) - -> Poll::Handler as ProtocolsHandler>::InEvent, Self::OutEvent>> + -> Poll> { use futures::stream::StreamExt;