Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The fallback.rs implementation generates incorrect down/up events on a loop #30

Closed
cafedetal opened this issue Mar 22, 2023 · 6 comments

Comments

@cafedetal
Copy link
Contributor

The fallback implementation is always reporting down/up events for all interfaces due to a bug in the code:

if-watch/src/fallback.rs

Lines 53 to 56 in 31c4780

if addrs.iter().any(|addr| addr.ip() == old_addr.addr()) {
self.addrs.remove(&old_addr);
self.queue.push_back(IfEvent::Down(old_addr));
}

Line 53 will return true if the interface is in both the stored old address list and the newly reported list, therefore generating an IfEvent::Down for all of the addresses in the old list. The addresses then get re-added with a IfEvent::Up in the next block.

A simple reversal of the logic fixes the bug

            if !addrs.iter().any(|addr| addr.ip() == old_addr.addr()) {

Tested on android - no more interface spam after fixing that logic.

@thomaseizinger
Copy link

Tested on android - no more interface spam after fixing that logic.

Sweet! Can you send a PR? :)

@cafedetal
Copy link
Contributor Author

#31

@cafedetal
Copy link
Contributor Author

@mxinden Since I see there was a new point release for libp2p, any chance this could be approved/added for the next one? I am using my own dependency patch but it's a cpu/battery concern for other Android users, especially depending on the processing they do of the spurious notifications.

@mxinden
Copy link
Owner

mxinden commented Mar 30, 2023

Just released your patch. Thanks @cafedetal. Again, impressive find.

Given that this is a patch release, downstream dependencies can update to it without intermediaries having to update. Does that make sense?

@stormshield-gt
Copy link

As #31 has been merged and a new version released, can we consider this issue closed?

@mxinden
Copy link
Owner

mxinden commented Sep 6, 2023

Thank you @stormshield-gt for the ping.

@mxinden mxinden closed this as completed Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants