mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 20:01:08 +00:00
Network sync refactoring (part 1) (#11303)
* Remove unnecessary imports, move one internal re-export into where it is actually used, make one import explicit * Move a few data structures down into modules * Use generic parameters in `sc-network` instead of `chain::Client` trait * Remove unnecessary bound
This commit is contained in:
@@ -20,12 +20,9 @@
|
||||
//! Only supports bitswap 1.2.0.
|
||||
//! CID is expected to reference 256-bit Blake2b transaction hash.
|
||||
|
||||
use crate::{
|
||||
chain::Client,
|
||||
schema::bitswap::{
|
||||
message::{wantlist::WantType, Block as MessageBlock, BlockPresence, BlockPresenceType},
|
||||
Message as BitswapMessage,
|
||||
},
|
||||
use crate::schema::bitswap::{
|
||||
message::{wantlist::WantType, Block as MessageBlock, BlockPresence, BlockPresenceType},
|
||||
Message as BitswapMessage,
|
||||
};
|
||||
use cid::Version;
|
||||
use core::pin::Pin;
|
||||
@@ -44,10 +41,12 @@ use libp2p::{
|
||||
};
|
||||
use log::{debug, error, trace};
|
||||
use prost::Message;
|
||||
use sc_client_api::BlockBackend;
|
||||
use sp_runtime::traits::Block as BlockT;
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
io,
|
||||
marker::PhantomData,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
@@ -181,19 +180,24 @@ impl Prefix {
|
||||
}
|
||||
|
||||
/// Network behaviour that handles sending and receiving IPFS blocks.
|
||||
pub struct Bitswap<B> {
|
||||
client: Arc<dyn Client<B>>,
|
||||
pub struct Bitswap<B, Client> {
|
||||
client: Arc<Client>,
|
||||
ready_blocks: VecDeque<(PeerId, BitswapMessage)>,
|
||||
_block: PhantomData<B>,
|
||||
}
|
||||
|
||||
impl<B: BlockT> Bitswap<B> {
|
||||
impl<B, Client> Bitswap<B, Client> {
|
||||
/// Create a new instance of the bitswap protocol handler.
|
||||
pub fn new(client: Arc<dyn Client<B>>) -> Self {
|
||||
Self { client, ready_blocks: Default::default() }
|
||||
pub fn new(client: Arc<Client>) -> Self {
|
||||
Self { client, ready_blocks: Default::default(), _block: PhantomData::default() }
|
||||
}
|
||||
}
|
||||
|
||||
impl<B: BlockT> NetworkBehaviour for Bitswap<B> {
|
||||
impl<B, Client> NetworkBehaviour for Bitswap<B, Client>
|
||||
where
|
||||
B: BlockT,
|
||||
Client: BlockBackend<B> + Send + Sync + 'static,
|
||||
{
|
||||
type ConnectionHandler = OneShotHandler<BitswapConfig, BitswapMessage, HandlerEvent>;
|
||||
type OutEvent = void::Void;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user