Better logging.
This commit is contained in:
parent
ad1b1e1132
commit
b21d9c39ca
@ -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()));
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user