Skip to content

Fix: fallback interface down/up logic#31

Merged
mxinden merged 2 commits into
libp2p:masterfrom
cafedetal:cafedetal-fallback-downup
Mar 30, 2023
Merged

Fix: fallback interface down/up logic#31
mxinden merged 2 commits into
libp2p:masterfrom
cafedetal:cafedetal-fallback-downup

Conversation

@cafedetal

Copy link
Copy Markdown
Contributor

Reverse the logic when checking if a recorded interface still exists in the new list to avoid reporting all interfaces as down and then up in the same resync().

Tested on Android, which uses the fallback code.

Reverse the logic when checking if a recorded interface still exists in the new list to avoid reporting all interfaces as down and then up in the same resync()

@thomaseizinger thomaseizinger left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Thank you!

@mxinden mxinden left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cafedetal for your work on this! Great debugging work.

Also curious what you are building with if-watch on Android in case you want to share.

Comment thread src/fallback.rs
Comment on lines 50 to 56
fn resync(&mut self) -> Result<()> {
let addrs = if_addrs::get_if_addrs()?;
for old_addr in self.addrs.clone() {
if addrs.iter().any(|addr| addr.ip() == old_addr.addr()) {
if !addrs.iter().any(|addr| addr.ip() == old_addr.addr()) {
self.addrs.remove(&old_addr);
self.queue.push_back(IfEvent::Down(old_addr));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A neat idea, though not needed for this patch:

Collect the new addresses into a new set and use HashSet::difference first in one and then the other direction to report Down and Up events:

for down in old.difference(new) {
  self.queue.push_back(IfEvent::Down(down))
}

for up in new.difference(old) {
  self.queue.push_back(IfEvent::Up(up));
}

@mxinden
mxinden merged commit fe2a2cd into libp2p:master Mar 30, 2023
@mxinden

mxinden commented Mar 30, 2023

Copy link
Copy Markdown
Member

Tagged and published.

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

Successfully merging this pull request may close these issues.

3 participants