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

Adding example for Identify protocol #2689

Merged
merged 16 commits into from
Jun 27, 2022
Merged

Conversation

dadepo
Copy link
Contributor

@dadepo dadepo commented Jun 2, 2022

Description

Added example for the Identify protocol.

Links to any relevant issues

Part of #2684

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

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.

Appreciate the help here. Though still a couple of comments.

@@ -0,0 +1,82 @@
// 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.

Given that this example is focused on libp2p-identify, how about moving it to protocols/identify/examples/? To make sure one can still discover it, it can be mentioned in https://github.com/libp2p/rust-libp2p/blob/master/examples/README.md.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not even aware that there are some examples placed together with some of the individual protocols. Is there a reason why not to have all the examples listed in https://github.com/libp2p/rust-libp2p/tree/master/examples/*?

Having one canonical place where all the examples are listed, IMHO makes discovery easier.

Copy link
Member

Choose a reason for hiding this comment

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

No strong opinion on my end. I see /examples as a folder for examples that combine many protocols and protocols/xxx/examples as a folder for examples targeting a single protocol.

Having one canonical place where all the examples are listed, IMHO makes discovery easier.

I see your point.

Maybe @elenaf9 or @thomaseizinger have an opinion here.

Copy link
Contributor

@elenaf9 elenaf9 Jun 8, 2022

Choose a reason for hiding this comment

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

I am leaning towards having examples focused on a single protocol in that protocol's folder. Since they are individual crates, imo they should "own" their own examples.

I was not even aware that there are some examples placed together with some of the individual protocols.

We should definitely mention this in the top-level examples/README.md, which is currently not the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am leaning towards having examples focused on a single protocol in that protocol's folder. Since they are individual crates, imo they should "own" their own examples.

I share the same view. These protocols are individual crates and I think we should follow cargo conventions despite this being a large workspace.

I was not even aware that there are some examples placed together with some of the individual protocols.

We should definitely mention this in the top-level examples/README.md, which is currently not the case.

Another solution to this would be to do away with the current meta crate being "special" by being a workspace manifest and a crate at the same time. i.e. we could create a directory meta which could house the libp2p crate. This would also move the top-level examples/ directory which might make it more obvious to users that they will find examples within each crate.

//! cargo run --example identify
//! ```
//! It will print the PeerId and the listening addresses, e.g. `Listening on
//! "/ip4/0.0.0.0/tcp/24915"`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
//! "/ip4/0.0.0.0/tcp/24915"`
//! "/ip6/2001:db8:: /tcp/24915"`

Let's not use a wildcard address here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we called swarm.listen_on with a ipv4 wildcard address, this can never result in a ipv6 listen address, right? Thus think "/ip4/127.0.0.1/tcp/24915" would make more sense here.

examples/identify.rs Outdated Show resolved Hide resolved
examples/identify.rs Outdated Show resolved Hide resolved
examples/identify.rs Outdated Show resolved Hide resolved
examples/identify.rs Outdated Show resolved Hide resolved
examples/identify.rs Outdated Show resolved Hide resolved
@dadepo dadepo changed the title Added identify example Adding more examples Jun 3, 2022
dadepo and others added 6 commits June 3, 2022 21:09
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Max Inden <mail@max-inden.de>
Co-authored-by: Max Inden <mail@max-inden.de>
@dadepo
Copy link
Contributor Author

dadepo commented Jun 3, 2022

Appreciate the help here. Though still a couple of comments.

Gladly done. I will resolve/respond the comments in a bit.

Quick question, seeing you already approved, do you prefer I create individual PR for each example added?
My initial thought was to include all the added examples in a single PR, hence why I set this PR to draft for now. Plan was to update it to ready PR once all the examples have been added

Let me know which approach the team finds more convenient.

@mxinden
Copy link
Member

mxinden commented Jun 8, 2022

Quick question, seeing you already approved

That was a mistake. Sorry.

do you prefer I create individual PR for each example added?

Yes. I prefer small atomic pull requests. Makes my life as a maintainer a lot easier. Thanks.

@@ -0,0 +1,82 @@
// 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.

No strong opinion on my end. I see /examples as a folder for examples that combine many protocols and protocols/xxx/examples as a folder for examples targeting a single protocol.

Having one canonical place where all the examples are listed, IMHO makes discovery easier.

I see your point.

Maybe @elenaf9 or @thomaseizinger have an opinion here.

examples/identify.rs Outdated Show resolved Hide resolved
dadepo and others added 2 commits June 23, 2022 18:06
@dadepo dadepo changed the title Adding more examples Adding example for Identify protocol Jun 23, 2022
@dadepo dadepo marked this pull request as ready for review June 23, 2022 16:23
mxinden
mxinden previously approved these changes Jun 24, 2022
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.

🚀 Thank you!

@mxinden mxinden dismissed their stale review June 24, 2022 03:29

CI failing

@mxinden
Copy link
Member

mxinden commented Jun 24, 2022

CI failures are due to mxinden/if-watch#19.

@mxinden
Copy link
Member

mxinden commented Jun 24, 2022

CI failures are due to mxinden/if-watch#19.

This is fixed now.

To make CI green you would need to:

  • Run rustfmt
  • Add libp2p as an explicit dev-dependency to protocols/identify/Cargo.toml similar to
    libp2p = { path = "../..", default-features = false, features = ["dcutr", "relay", "plaintext", "identify", "tcp-async-io", "ping", "noise", "dns-async-std"] }

Copy link
Contributor

@elenaf9 elenaf9 left a comment

Choose a reason for hiding this comment

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

Thanks @dadepo! Two comments, otherwise looks good to me.

//! cargo run --example identify
//! ```
//! It will print the PeerId and the listening addresses, e.g. `Listening on
//! "/ip4/0.0.0.0/tcp/24915"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we called swarm.listen_on with a ipv4 wildcard address, this can never result in a ipv6 listen address, right? Thus think "/ip4/127.0.0.1/tcp/24915" would make more sense here.

Comment on lines 37 to 38
//! The dialing node prints out the `PeerId` of the node it is sending identify info to
//! The other node prints out the received identify info.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think not only the dialer, but instead both peers will sent each other identify info once they establish a connection, no?

@mxinden mxinden merged commit 40744be into libp2p:master Jun 27, 2022
@dadepo dadepo deleted the extend-examples branch June 28, 2022 06:39
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.

4 participants