Better logging.

This commit is contained in:
David Craven 2019-02-05 22:37:01 +01:00
parent ad1b1e1132
commit b21d9c39ca
No known key found for this signature in database
GPG Key ID: DF438712EA50DBB1
2 changed files with 5 additions and 1 deletions

View File

@ -3,8 +3,9 @@ use ipfs::{Block, Ipfs, run_ipfs};
fn main() {
let mut ipfs = Ipfs::new();
let block = Block::from("hello block2\n");
ipfs.put_block(block);
let cid = Block::from("hello block\n").cid();
println!("Looking for block {}", cid.to_string());
let future = ipfs.get_block(cid).map(|block| {
println!("Received block with contents: '{:?}'",
String::from_utf8_lossy(&block.data()));

View File

@ -93,17 +93,20 @@ impl<TSubstream: AsyncRead + AsyncWrite, TStrategy: Strategy> Behaviour<TSubstre
}
pub fn want_block(&mut self, cid: Cid) {
println!("Want block {}", cid.to_string());
let hash = Multihash::from_bytes(cid.to_bytes()).unwrap();
self.kademlia.get_providers(hash);
self.bitswap.want_block(cid, 1);
}
pub fn provide_block(&mut self, cid: &Cid) {
println!("Providing block {}", cid.to_string());
let hash = Multihash::from_bytes(cid.hash.clone()).unwrap();
self.kademlia.add_providing(PeerId::from_multihash(hash).unwrap());
}
pub fn stop_providing_block(&mut self, cid: &Cid) {
println!("Finished providing block {}", cid.to_string());
let hash = Multihash::from_bytes(cid.hash.clone()).unwrap();
self.kademlia.remove_providing(&hash);
}