-
Notifications
You must be signed in to change notification settings - Fork 998
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
mdns: update if-watch to 3.0.0 #3096
Conversation
and rename TokioMdns to Mdns living in its own module, and move Mdns to async_io::Mdns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me for mDNS! Shall I do the TCP part or do you want to take it?
yeah, feel free to :) I didn't go for it yet as I wanted to clear the approach first, so if Thomas approves the approach feel free to implement for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tackling this @jxs!
protocols/mdns/CHANGELOG.md
Outdated
@@ -4,6 +4,9 @@ | |||
|
|||
- Update to `libp2p-swarm` `v0.41.0`. | |||
|
|||
- Update to `if-watch` `0.3.0` and both rename `TokioMdns` to `Mdns` living in `tokio::Mdns`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Update to `if-watch` `0.3.0` and both rename `TokioMdns` to `Mdns` living in `tokio::Mdns`, | |
- Update to `if-watch` `3.0.0` and both rename `TokioMdns` to `Mdns` living in `tokio::Mdns`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Thomas, updated.
protocols/mdns/src/behaviour.rs
Outdated
impl TryDefault for IfWatcher { | ||
fn try_default() -> Result<Self, std::io::Error> { | ||
Self::new() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative way of doing this which does not require a trait would be to say:
impl GenMdns<TokioUdpSocket, TokioTimer, IfWatcher> {
/// Builds a new `Mdns` behaviour.
pub fn new(config: MdnsConfig) -> io::Result<Self> {
Ok(Self {
config,
if_watch: IfWatcher::new(),
iface_states: Default::default(),
discovered_nodes: Default::default(),
closest_expiration: Default::default(),
})
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Untested but I think this should work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that works if we remove GenMdns::new
otherwise compiler complains regarding duplication. The disadvantage I see with that is that then methods (and its docs) are scattered between {tokio, async_io}::Mdns
and GenMdns
, would you prefer that approach? Tbh ideally I think it would be great if we could deprecate/hide GenMdns
and just present {tokio, async_io}::Mdns
to the end user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had a similar discussion in libp2p-tcp
: #2961 (review)
From what I remember, the functions don't show up for the type alias at all so probably best to not do this at all.
The need for another trait is a bit annoying though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me minus the outstanding comments.
This pull request has merge conflicts. Could you please resolve them @jxs? 🙏 |
instead of a Generic parameter
This pull request has merge conflicts. Could you please resolve them @jxs? 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jxs! A few comments.
protocols/mdns/CHANGELOG.md
Outdated
@@ -4,6 +4,16 @@ | |||
|
|||
- Update to `libp2p-swarm` `v0.41.0`. | |||
|
|||
- Update to `if-watch` `3.0.0` and both rename `TokioMdns` to `Behaviour` living in `tokio::Behaviour`, | |||
and move and rename `Mdns` to `async_io::Behaviour`. See [PR 3096] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and move and rename `Mdns` to `async_io::Behaviour`. See [PR 3096] | |
and move and rename `Mdns` to `async_io::Behaviour`. See [PR 3096]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, addressed.
protocols/mdns/src/behaviour.rs
Outdated
|
||
/// A `NetworkBehaviour` for mDNS. Automatically discovers peers on the local network and adds | ||
/// them to the topology. | ||
#[derive(Debug)] | ||
pub struct GenMdns<S, T> { | ||
pub struct Behaviour<S, T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to combine all type parameters here to a single one, i.e. P
and have a Provider
trait?
trait Provider {
type Socket;
type Timer;
type IfWatcher;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed it does! Thanks Thomas. 👍
We now have more than one Provider
trait among the protocols (tcp
and mdns
) but as they are namedspaced by the crates I don't think it's a problem, it can be considered akin to the tokio
and async_io
namespaces.
pub use crate::behaviour::{GenMdns, MdnsEvent}; | ||
pub use crate::behaviour::{Behaviour, Event}; | ||
|
||
#[cfg(feature = "async-io")] | ||
pub use crate::behaviour::Mdns; | ||
pub use crate::behaviour::async_io; | ||
|
||
#[cfg(feature = "tokio")] | ||
pub use crate::behaviour::TokioMdns; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you'd add type aliases for this too then users would only be presented with deprecation warnings instead of compile errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup, makes sense. When putting the types was thinking that since this is a breaking change putting the types would be redundant, but if we also add for Mdns
then it doesn't become a breaking change. Thanks Thomas :)
and set the AsyncSocket and AsyncTimer as associated types, so that the generic Behaviour only takes one parameter P which provides all these types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
This pull request has merge conflicts. Could you please resolve them @jxs? 🙏 |
- Remove trait bounds where they are redundant. - Improve documentation of `Provider` trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice & clean!
Good to go from my end :)
and rename TokioMdns to Mdns living in its own module, and move Mdns to async_io::Mdns.
Description
updates to
if-watch
3.0
. This was simplest I found to not touch the signature ofGenMdns::new
wdyt @thomaseizinger?@mxinden turns out
IfWatcher::new
returnsResult
so implementingDefault
for it wouldn't solve the problem, so I had to create a newTryDefault
trait to be able to abstract over it.We could also try put
GenMdns
methods and trait impls on a macro and generate it fortokio
andasync_io
code would be probably more complicated, but the doc would be cleaner andGenMdns
would no longer be required.CC @rkuhn
Links to any relevant issues
superseeds #3095
Open Questions
Change checklist
Commit message body