rust-libp2p: MdnsEvent::Expired (ExpiredAddrsIter) is never called
I wrote a small program. I expected that when a node exits, other nodes will receive the MdnsEvent :: Expired event, but this does not happen. I looked at the code for a long time, and I realized that the problem is:
if let Some(ref mut closest_expiration) = self.closest_expiration {
if let Poll::Ready(now) = Pin::new(closest_expiration).poll(cx) {
let mut expired = SmallVec::<[(PeerId, Multiaddr); 4]>::new();
while let Some(pos) = self
.discovered_nodes
.iter()
.position(|(_, _, exp)| *exp < now)
{
let (peer_id, addr, _) = self.discovered_nodes.remove(pos);
expired.push((peer_id, addr));
}
if !expired.is_empty() {
let event = MdnsEvent::Expired(ExpiredAddrsIter {
inner: expired.into_iter(),
});
return Poll::Ready(NetworkBehaviourAction::GenerateEvent(event));
}
}
}
i wrapped expired in dbg!
dbg!(expired);
it turned out that it is always empty
[/home/golubevmt/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-mdns-0.31.0/src/behaviour.rs:369] &expired = []
[/home/golubevmt/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-mdns-0.31.0/src/behaviour.rs:369] &expired = []
[/home/golubevmt/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-mdns-0.31.0/src/behaviour.rs:369] &expired = []
[/home/golubevmt/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-mdns-0.31.0/src/behaviour.rs:369] &expired = []
i changed `
*exp < now
to
ext <= &now
and it worked for me
Oct 23 00:47:04.706 INFO p2p_test: Discovered: 12D3KooWSK4J25g3WNFWo8n7DRxNK5Rwz3dsgDdRKHwowDgr1cbR /ip4/192.168.199.16/udp/57229/quic
Oct 23 00:47:04.706 INFO p2p_test: Discovered: 12D3KooWSK4J25g3WNFWo8n7DRxNK5Rwz3dsgDdRKHwowDgr1cbR /ip4/127.0.0.1/udp/57229/quic
[/home/golubevmt/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-mdns-0.31.0/src/behaviour.rs:364] exp <= &now = true
[/home/golubevmt/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-mdns-0.31.0/src/behaviour.rs:364] exp <= &now = true
Oct 23 00:47:10.711 INFO p2p_test: Expired: 12D3KooWSK4J25g3WNFWo8n7DRxNK5Rwz3dsgDdRKHwowDgr1cbR /ip4/192.168.199.16/udp/57229/quic
Oct 23 00:47:10.712 INFO p2p_test: Expired: 12D3KooWSK4J25g3WNFWo8n7DRxNK5Rwz3dsgDdRKHwowDgr1cbR /ip4/127.0.0.1/udp/57229/quic
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 18 (15 by maintainers)
I haven’t looked here for a long time. The work done surprised me pleasantly. I’m glad @vnermolaev has looked into this issue. Thank you