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

protocols/mdns: Support multiple network interfaces #2383

Merged
merged 9 commits into from
Dec 29, 2021

Conversation

dvc94ch
Copy link
Contributor

@dvc94ch dvc94ch commented Dec 14, 2021

so had some issues with mdns between my laptop and my phone when android was acting as a hotspot. this is due to binding to 0.0.0.0 which selects the iface with internet connectivity leading to failure for the devices to detect each other. this fixes that by properly handling multiple interfaces in mdns. the socket logic was moved into an instance while the mdns behaviour watches for interface changes and creates new instances with a dedicated send/recv socket.

protocols/mdns/src/instance.rs Outdated Show resolved Hide resolved
protocols/mdns/src/instance.rs Outdated Show resolved Hide resolved
protocols/mdns/tests/smoke.rs Show resolved Hide resolved
protocols/mdns/tests/smoke.rs Show resolved Hide resolved
protocols/mdns/src/instance.rs Outdated Show resolved Hide resolved
protocols/mdns/src/instance.rs Outdated Show resolved Hide resolved
@dvc94ch
Copy link
Contributor Author

dvc94ch commented Dec 18, 2021

ping @mxinden do you have some time to review? Think it's pretty reliable now.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Listening and sending via multiple interfaces sounds good to me. Split into InterfaceState makes sense to me.

I will need a bit more time to give this an in-depth review.

transports/tcp/Cargo.toml Outdated Show resolved Hide resolved
protocols/mdns/src/iface.rs Outdated Show resolved Hide resolved
protocols/mdns/src/iface.rs Outdated Show resolved Hide resolved
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Couple of comments and missing a changelog entry. Looks good to me otherwise. Thank you for the contribution.

protocols/mdns/src/behaviour.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,238 @@
// Copyright 2018 Parity Technologies (UK) Ltd.
Copy link
Member

Choose a reason for hiding this comment

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

Should this file not rather live in src/behaviour/iface.rs? It is only used within src/behaviour.rs, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure how adding more directories for a small crate helps. is there some "policy" for the rust-libp2p repo somewhere?

Copy link
Member

Choose a reason for hiding this comment

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

I am following the convention: If module B is used in module A only, move it into a/b.rs. I think we are doing a decent job following this convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, I don't like large nested repos. some directories make sense sometimes when organizing files, but if a crate has 4 files, I don't think it's helpful. Made the change (still open to reverting if you change your mind)

protocols/mdns/src/behaviour.rs Outdated Show resolved Hide resolved
protocols/mdns/src/behaviour.rs Outdated Show resolved Hide resolved
@dvc94ch dvc94ch force-pushed the mdns-multi-iface branch 2 times, most recently from b454fdf to 24ae235 Compare December 29, 2021 15:38
@mxinden
Copy link
Member

mxinden commented Dec 29, 2021

Mind running a final rustfmt @dvc94ch?

@mxinden mxinden changed the title Fix mdns with multiple interfaces. protocols/mdns: Support multiple network interfaces Dec 29, 2021
@mxinden mxinden merged commit df2e5a5 into libp2p:master Dec 29, 2021
laptou pushed a commit to laptou/rust-libp2p that referenced this pull request Dec 30, 2021
Handling multiple interfaces in mdns. The socket logic was moved into an
instance while the mdns behaviour watches for interface changes and creates new
instances with a dedicated send/recv socket.

Co-authored-by: Max Inden <mail@max-inden.de>
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