diff --git a/src/p2p/behaviour.rs b/src/p2p/behaviour.rs index ceb230cd3..50f0ce56c 100644 --- a/src/p2p/behaviour.rs +++ b/src/p2p/behaviour.rs @@ -410,7 +410,21 @@ impl NetworkBehaviourEventProcess for Behaviour NetworkBehaviourEventProcess for Behaviour { fn inject_event(&mut self, event: IdentifyEvent) { - trace!("identify: {:?}", event); + match event { + IdentifyEvent::Received { + peer_id, + observed_addr, + .. + } => { + trace!("identify from {} at {}", peer_id, observed_addr); + } + IdentifyEvent::Sent { peer_id } => { + trace!("identify info sent to {}", peer_id); + } + IdentifyEvent::Error { peer_id, error } => { + trace!("identify error with {}: {}", peer_id, error); + } + } } } diff --git a/tests/block_exchange.rs b/tests/block_exchange.rs index 6f4f26820..212853899 100644 --- a/tests/block_exchange.rs +++ b/tests/block_exchange.rs @@ -2,7 +2,7 @@ use cid::{Cid, Codec}; use ipfs::Block; use multihash::Sha2_256; use std::time::Duration; -use tokio::time::timeout; +use tokio::time::{sleep, timeout}; mod common; use common::{spawn_nodes, Topology}; @@ -29,10 +29,49 @@ async fn two_node_put_get() { assert_eq!(block.data, found_block.data); } +// start fetching the cid before storing the block on the source, causing a need for a retry which +// we dont yet have. +#[tokio::test] +async fn two_node_get_put() { + let nodes = spawn_nodes(2, Topology::Line).await; + let block = create_block(); + + let downloaded = nodes[1].get_block(&block.cid); + tokio::pin!(downloaded); + + { + let deadline = sleep(Duration::from_secs(1)); + tokio::pin!(deadline); + loop { + tokio::select! { + _ = &mut deadline => { + // FIXME(flaky time assumption): we now assume that the want has been + // propagated, and that our nodes[0] has not found it locally. perhaps if swarm + // could propagate all of the events up, we could notify this via event. alas, + // we dont have such an event, nor can we hope to get this information over + // bitswap 1.0 + break; + }, + _ = &mut downloaded => unreachable!("cannot complete get_block before block exists"), + } + } + } + + nodes[0].put_block(block.clone()).await.unwrap(); + + let found_block = timeout(Duration::from_secs(10), downloaded) + .await + .expect("get_block did not complete in time") + .unwrap(); + + assert_eq!(block.data, found_block.data); +} + // check that a long line of nodes still works with get_block #[tokio::test] #[ignore] async fn long_get_block() { + tracing_subscriber::fmt::init(); // this number could be higher, but it starts hanging above ~24 const N: usize = 10; let nodes = spawn_nodes(N, Topology::Line).await;