@@ -2,9 +2,9 @@ use super::pubsub::Pubsub;
2
2
use super :: swarm:: { Connection , Disconnector , SwarmApi } ;
3
3
use crate :: config:: BOOTSTRAP_NODES ;
4
4
use crate :: p2p:: { MultiaddrWithPeerId , SwarmOptions } ;
5
- use crate :: repo:: BlockPut ;
5
+ use crate :: repo:: { BlockPut , Repo } ;
6
6
use crate :: subscription:: { SubscriptionFuture , SubscriptionRegistry } ;
7
- use crate :: { Ipfs , IpfsTypes } ;
7
+ use crate :: IpfsTypes ;
8
8
use anyhow:: anyhow;
9
9
use bitswap:: { Bitswap , BitswapEvent } ;
10
10
use cid:: Cid ;
@@ -16,16 +16,15 @@ use libp2p::mdns::{MdnsEvent, TokioMdns};
16
16
use libp2p:: ping:: { Ping , PingEvent } ;
17
17
use libp2p:: swarm:: toggle:: Toggle ;
18
18
use libp2p:: swarm:: { NetworkBehaviour , NetworkBehaviourEventProcess } ;
19
- use libp2p:: NetworkBehaviour ;
20
19
use multibase:: Base ;
21
20
use std:: { convert:: TryInto , sync:: Arc } ;
22
21
use tokio:: task;
23
22
24
23
/// Behaviour type.
25
- #[ derive( NetworkBehaviour ) ]
24
+ #[ derive( libp2p :: NetworkBehaviour ) ]
26
25
pub struct Behaviour < Types : IpfsTypes > {
27
26
#[ behaviour( ignore) ]
28
- ipfs : Ipfs < Types > ,
27
+ repo : Arc < Repo < Types > > ,
29
28
mdns : Toggle < TokioMdns > ,
30
29
kademlia : Kademlia < MemoryStore > ,
31
30
#[ behaviour( ignore) ]
@@ -314,11 +313,11 @@ impl<Types: IpfsTypes> NetworkBehaviourEventProcess<BitswapEvent> for Behaviour<
314
313
fn inject_event ( & mut self , event : BitswapEvent ) {
315
314
match event {
316
315
BitswapEvent :: ReceivedBlock ( peer_id, block) => {
317
- let ipfs = self . ipfs . clone ( ) ;
316
+ let repo = self . repo . clone ( ) ;
318
317
let peer_stats = Arc :: clone ( & self . bitswap . stats . get ( & peer_id) . unwrap ( ) ) ;
319
318
task:: spawn ( async move {
320
319
let bytes = block. data ( ) . len ( ) as u64 ;
321
- let res = ipfs . repo . put_block ( block. clone ( ) ) . await ;
320
+ let res = repo. put_block ( block. clone ( ) ) . await ;
322
321
match res {
323
322
Ok ( ( _, uniqueness) ) => match uniqueness {
324
323
BlockPut :: NewBlock => peer_stats. update_incoming_unique ( bytes) ,
@@ -343,10 +342,10 @@ impl<Types: IpfsTypes> NetworkBehaviourEventProcess<BitswapEvent> for Behaviour<
343
342
) ;
344
343
345
344
let queued_blocks = self . bitswap ( ) . queued_blocks . clone ( ) ;
346
- let ipfs = self . ipfs . clone ( ) ;
345
+ let repo = self . repo . clone ( ) ;
347
346
348
347
task:: spawn ( async move {
349
- match ipfs . repo . get_block_now ( & cid) . await {
348
+ match repo. get_block_now ( & cid) . await {
350
349
Ok ( Some ( block) ) => {
351
350
let _ = queued_blocks. unbounded_send ( ( peer_id, block) ) ;
352
351
}
@@ -413,7 +412,7 @@ impl<Types: IpfsTypes> NetworkBehaviourEventProcess<IdentifyEvent> for Behaviour
413
412
414
413
impl < Types : IpfsTypes > Behaviour < Types > {
415
414
/// Create a Kademlia behaviour with the IPFS bootstrap nodes.
416
- pub async fn new ( options : SwarmOptions , ipfs : Ipfs < Types > ) -> Self {
415
+ pub async fn new ( options : SwarmOptions , repo : Arc < Repo < Types > > ) -> Self {
417
416
info ! ( "net: starting with peer id {}" , options. peer_id) ;
418
417
419
418
let mdns = if options. mdns {
@@ -454,7 +453,7 @@ impl<Types: IpfsTypes> Behaviour<Types> {
454
453
}
455
454
456
455
Behaviour {
457
- ipfs ,
456
+ repo ,
458
457
mdns,
459
458
kademlia,
460
459
kad_subscriptions : Default :: default ( ) ,
@@ -646,7 +645,7 @@ impl<Types: IpfsTypes> Behaviour<Types> {
646
645
/// Create a IPFS behaviour with the IPFS bootstrap nodes.
647
646
pub async fn build_behaviour < TIpfsTypes : IpfsTypes > (
648
647
options : SwarmOptions ,
649
- ipfs : Ipfs < TIpfsTypes > ,
648
+ repo : Arc < Repo < TIpfsTypes > > ,
650
649
) -> Behaviour < TIpfsTypes > {
651
- Behaviour :: new ( options, ipfs ) . await
650
+ Behaviour :: new ( options, repo ) . await
652
651
}
0 commit comments