-
Notifications
You must be signed in to change notification settings - Fork 1k
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
refactor: move examples to common location #3509
Conversation
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.
Excellent start. I am pleased that Git recognizes these as "moved". That should make this fairly easy to review and merge.
b340780
to
e50dc79
Compare
Hi @thomaseizinger, I have moved all the examples to their crates. EDIT: Still have to resolve some naming collisions in binaries. |
Awesome, thanks a lot for this! Ping me once you've got CI passing or need help with it :) |
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 pushing this forward!
I made some comments, most of them a pretty minor. I really like the direction of this :)
[[example]] | ||
name = "chat" | ||
required-features = ["full"] | ||
|
||
[[example]] | ||
name = "chat-tokio" | ||
required-features = ["full"] | ||
|
||
[[example]] | ||
name = "file-sharing" | ||
required-features = ["full"] | ||
|
||
[[example]] | ||
name = "gossipsub-chat" | ||
required-features = ["full"] | ||
|
||
[[example]] | ||
name = "ipfs-private" | ||
required-features = ["full"] | ||
|
||
[[example]] | ||
name = "ipfs-kad" | ||
required-features = ["full"] | ||
|
||
[[example]] | ||
name = "ping" | ||
required-features = ["full"] | ||
|
||
[[example]] | ||
name = "mdns-passive-discovery" | ||
required-features = ["full"] | ||
|
||
[[example]] | ||
name = "distributed-key-value-store" | ||
required-features = ["full"] |
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.
🎉
examples/dcutr/Cargo.toml
Outdated
env_logger = "0.10.0" | ||
futures = "0.3.26" | ||
futures-timer = "3.0" | ||
libp2p = { path = "../../", features=["async-std", "dns", "dcutr", "identify", "macros", "mplex", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] } |
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.
libp2p = { path = "../../", features=["async-std", "dns", "dcutr", "identify", "macros", "mplex", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] } | |
libp2p = { path = "../../", features = ["async-std", "dns", "dcutr", "identify", "macros", "mplex", "noise", "ping", "relay", "rendezvous", "tcp", "tokio", "yamux"] } |
Formatting nit.
examples/dcutr/src/main.rs
Outdated
event_process = false, | ||
prelude = "libp2p_swarm::derive_prelude" | ||
)] | ||
#[behaviour(out_event = "Event", event_process = false, prelude = "derive_prelude")] |
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.
#[behaviour(out_event = "Event", event_process = false, prelude = "derive_prelude")] | |
#[behaviour(out_event = "Event", event_process = false)] |
When depending on the libp2p
crate, this is not needed!
examples/ipfs-kad/Cargo.toml
Outdated
env_logger = "0.10" | ||
futures = "0.3.26" | ||
libp2p = { path = "../../", features=["async-std", "dns", "kad", "mplex", "noise", "tcp", "websocket", "yamux"] } | ||
multiaddr = { version = "0.17.0" } |
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 should be able to import multiaddr
through libp2p::core::multiaddr
. Why is the separate dependency needed?
examples/rendezvous/Cargo.toml
Outdated
name = "rzv-discover" | ||
path = "src/bin/discover.rs" |
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.
I'd be in favor of just renaming the files and rely on auto-discover of the binaries. Convention over configuration.
examples/chat/Cargo.toml
Outdated
@@ -0,0 +1,12 @@ | |||
[package] | |||
name = "chat" |
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 append example
to these like chat-example
? Then it would show up as "Building chat-example" in the cargo logs which I'd mildly prefer.
libp2p::tcp::tokio::Transport::default() | ||
.upgrade(Version::V1) | ||
.authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap()) | ||
.multiplex(libp2p_yamux::YamuxConfig::default()) | ||
.authenticate(libp2p::noise::NoiseAuthenticated::xx(&key_pair).unwrap()) | ||
.multiplex(libp2p::yamux::YamuxConfig::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.
We are in the process of apply more consistent naming to all our crates to make usage easier and clearer. Can we import the submodules here please like use libp2p::tcp;
and then say tcp::tokio::Transport
?
void::unreachable(event) | ||
} | ||
} | ||
|
||
#[derive(NetworkBehaviour)] | ||
#[behaviour( | ||
out_event = "MyEvent", |
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.
In a recent version of the NetworkBehaviour
derive, we add the ability to auto-generate this enum. I think our examples should use that as we consider it the recommended way of using the derive. Can you adapt the examples please? The only thing that will needed changing is that the generated enum will be called MyBehaviourEvent
.
examples/pingpong/Cargo.toml
Outdated
@@ -0,0 +1,12 @@ | |||
[package] | |||
name = "pingpong" |
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.
name = "pingpong" | |
name = "ping-example" |
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, thank you for that! A few more minor comments.
let mut swarm = Swarm::with_tokio_executor( | ||
libp2p_tcp::tokio::Transport::default() | ||
libp2p::tcp::tokio::Transport::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.
libp2p::tcp::tokio::Transport::default() | |
tcp::tokio::Transport::default() |
Nit: Could we also align these please? i.e. add use libp2p::tcp
.
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.
Two more small requests, sorry for the back and forth!
examples/rendezvous/Cargo.toml
Outdated
@@ -0,0 +1,14 @@ | |||
[package] | |||
name = "rendezvous" |
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.
Can we consistently apply the naming of appending -example
here? Thanks!
.authenticate(libp2p::noise::NoiseAuthenticated::xx(&key_pair).unwrap()) | ||
.multiplex(libp2p::yamux::YamuxConfig::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.
Same with this topic here. I didn't explicitly comment on all lines but let's do this consistently across all examples and use yamux::
etc in the code and use libp2p::yamux
at the top. (For all libp2p
modules: noise, yamux, etc)
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.
sorry, missed it
This pull request has merge conflicts. Could you please resolve them @yellowred? 🙏 |
eef07e9
to
549e781
Compare
This pull request has merge conflicts. Could you please resolve them @yellowred? 🙏 |
``` error: document output filename collision The bin `ping` in package `ping v0.1.0 (/home/runner/work/rust-libp2p/rust-libp2p/examples/ping)` has the same name as the bin `ping` in package `interop-tests v0.1.0 (/home/runner/work/rust-libp2p/rust-libp2p/interop-tests)`. ```
549e781
to
6568b2d
Compare
@thomaseizinger there is one tiny check fails, not sure why, otherwise should be ok? |
A quick investigation leads to this: clap-rs/clap#4733 Seems like we need to update |
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.
Thank you for tackling this, I am convinced this makes our repository a bit more approachable :)
Description
Refactor examples into separate binary crates.
Fixes #3111.
Links to any relevant issues
Change checklist