add: bitswap wantlist getters
compared to original version, attempt to differentiate peer vs. local at method level. could probably be at the ipfs level as well?
This commit is contained in:
parent
cd26d39857
commit
868f4a8722
@ -45,6 +45,16 @@ impl<TStrategy> Bitswap<TStrategy> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the wantlist of the local node
|
||||
pub fn local_wantlist(&self) -> Vec<(Cid, Priority)> {
|
||||
self.wanted_blocks.iter().map(|(cid, prio)| (cid.clone(), *prio)).collect()
|
||||
}
|
||||
|
||||
/// Return the wantlist of a peer, if known
|
||||
pub fn peer_wantlist(&self, peer: &PeerId) -> Option<Vec<(Cid, Priority)>> {
|
||||
self.connected_peers.get(peer).map(Ledger::wantlist)
|
||||
}
|
||||
|
||||
/// Connect to peer.
|
||||
///
|
||||
/// Called from Kademlia behaviour.
|
||||
|
@ -70,6 +70,11 @@ impl Ledger {
|
||||
self.received_want_list.insert(cid.to_owned(), *priority);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the blocks wanted by the peer in unspecified order
|
||||
pub fn wantlist(&self) -> Vec<(Cid, Priority)> {
|
||||
self.received_want_list.iter().map(|(cid, prio)| (cid.clone(), *prio)).collect()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
@ -635,7 +635,12 @@ impl<Types: SwarmTypes> Future for IpfsFuture<Types> {
|
||||
let _ = ret.send(self.swarm.pubsub().subscribed_topics());
|
||||
}
|
||||
IpfsEvent::WantList(peer, ret) => {
|
||||
todo!()
|
||||
let list = if let Some(peer) = peer {
|
||||
self.swarm.bitswap().peer_wantlist(&peer).unwrap_or_default()
|
||||
} else {
|
||||
self.swarm.bitswap().local_wantlist()
|
||||
};
|
||||
let _ = ret.send(list);
|
||||
}
|
||||
IpfsEvent::BitswapStats(ret) => {
|
||||
todo!()
|
||||
|
@ -236,6 +236,10 @@ impl<TSwarmTypes: SwarmTypes> Behaviour<TSwarmTypes> {
|
||||
pub fn pubsub(&mut self) -> &mut Pubsub {
|
||||
&mut self.pubsub
|
||||
}
|
||||
|
||||
pub fn bitswap(&mut self) -> &mut Bitswap<TSwarmTypes::TStrategy> {
|
||||
&mut self.bitswap
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a IPFS behaviour with the IPFS bootstrap nodes.
|
||||
|
Loading…
Reference in New Issue
Block a user