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

transports/noise: Change protobuf files to proto2 #3007

Closed

Conversation

nloadholtes
Copy link
Contributor

@nloadholtes nloadholtes commented Oct 10, 2022

This is the same format as used in go-libp2p

Description

To keep with the structure defined in go-libp2p here, I changed the syntax to proto2 and set the fields to optional.

Links to any relevant issues

Issue #2924

Open Questions

This is my first time messing with a rust project, and I'm new to libp2p. I used cargo test to test things locally and it reported errors in src/tutorials/ping.rs. I am still figuring things out, so any feedback/advice is welcomed. 😃

Also, I did a search for documentation and didn't see any that referenced this change, if there's something I missed please let me know.

I also did not add an entry to the changelog, I wanted to get feedback on this first before getting ahead of myself.

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

@nloadholtes nloadholtes force-pushed the nloadholtes/noise-use-proto2 branch from 97974db to 0e761ef Compare October 15, 2022 16:41
@thomaseizinger thomaseizinger linked an issue Oct 16, 2022 that may be closed by this pull request
@thomaseizinger thomaseizinger changed the title Setting transports/noise proto to use proto2 transports/noise: Change protobuf files to proto2 Oct 16, 2022
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

This looks good to me!

Can you please:

  • Add a changelog entry
  • Make a patch version bump
  • Pull the version bump through to all crates that depend on libp2p-noise
  • Run a test where you connect a node with this version against the latest release.

Thank you!

@thomaseizinger
Copy link
Contributor

I kicked CI and it does show up with errors in libp2p-noise. That is expected because the generated code from the protobufs is now different. You'll have to amend the code to handle the now optional fields in the deserialised message :)

@thomaseizinger
Copy link
Contributor

This is my first time messing with a rust project, and I'm new to libp2p. I used cargo test to test things locally and it reported errors in src/tutorials/ping.rs. I am still figuring things out, so any feedback/advice is welcomed. smiley

I typically run cargo clippy --workspace --all-targets --all-features locally to validate my code. That will run the type-checker with some useful lints which is much faster than actually compiling the code. Once that is passing, you can probably focus on running the tests in transports/noise.

For this particular PR, you can probably amend the above clippy command to just be: cargo clippy --package libp2p-noise --all-targets --all-features. I don't expect any other code to need modification!

@nloadholtes nloadholtes force-pushed the nloadholtes/noise-use-proto2 branch from 0e761ef to 0b7f11d Compare October 17, 2022 02:27
@nloadholtes
Copy link
Contributor Author

Thank you for the great feedback! I've made those changes and I think the changes to transports/noise/src/io/handshake.rs are what was needed. (I'm not used to the compiler giving such useful feedback, it kinda made me nervous! 😆)

If there's anything I missed or could make better, please let me know. Thanks!

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Thanks! A few more comments :)

@@ -207,8 +207,8 @@ where
}
let pb = pb_result?;

if !pb.identity_key.is_empty() {
let pk = identity::PublicKey::from_protobuf_encoding(&pb.identity_key)
if !pb.identity_key.as_ref().expect("optional").is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can't just panic here :)

We need more graceful error handling to check whether or not the key is actually present. Probably best done with a match and a match-arm guard so you can do the existing if and the destructing in one go.

Have a google around if some of these terms don't mean anything to you (yet)! :)

if !pb.identity_key.is_empty() {
let pk = identity::PublicKey::from_protobuf_encoding(&pb.identity_key)
if !pb.identity_key.as_ref().expect("optional").is_empty() {
let pk = identity::PublicKey::from_protobuf_encoding(&pb.identity_key.unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. Look into ok_or_else.

@@ -218,8 +218,8 @@ where
state.id_remote_pubkey = Some(pk);
}

if !pb.identity_sig.is_empty() {
state.dh_remote_pubkey_sig = Some(pb.identity_sig);
if !pb.identity_sig.as_ref().expect("optional").is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, we need to gracefully handle the None case.

…elds are optional. If they are missing, nothing happens (which is what was happening before just with an if statement instead of a match).
}
state.id_remote_pubkey = Some(pk);
None => {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thomaseizinger Thanks for the tips on panic/error checking/match, that was a a good bit to read up on as I lean rust. I think this code both fulfills the spirit of what was happening before (if there was no key, just keep going) but now does it without the panic (I think).

Again, thank you for your guidance on this. I really appreciate it.

Please let me know if I'm moving in the right direction, or if any other changes are needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you run clippy, it will tell you that you can replace this with an if let Some(identity_key) construct :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤯 😮 whoa. That is really cool. Thanks for the tip about that, you just really flattened my learning curve with that one!

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

LGTM!

I'll kick CI again. Let's see what it says!

transports/noise/CHANGELOG.md Outdated Show resolved Hide resolved
}
state.id_remote_pubkey = Some(pk);
None => {}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you run clippy, it will tell you that you can replace this with an if let Some(identity_key) construct :)

Comment on lines 224 to 229
match pb.identity_sig {
Some(identity_sig) => {
state.dh_remote_pubkey_sig = Some(identity_sig);
}
None => {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here!

CHANGELOG.md Outdated Show resolved Hide resolved
transports/noise/CHANGELOG.md Outdated Show resolved Hide resolved
nloadholtes and others added 3 commits October 18, 2022 21:33
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

Thanks! This LGTM :)

A discussion started in the meantime on whether we actually want this: libp2p/specs#465

I'll hold off with merging until that is settled. Sorry for that.

@nloadholtes
Copy link
Contributor Author

hahaha, I have great timing! Its totally cool and I understand on holding off on merging this. I'm going to go look for another help-wanted ticket and see if I can help out some more. Thanks for all your mentoring on this PR, I really appreciate it!

@thomaseizinger
Copy link
Contributor

hahaha, I have great timing! Its totally cool and I understand on holding off on merging this. I'm going to go look for another help-wanted ticket and see if I can help out some more.

Thank you! There should be plenty around :)

Thanks for all your mentoring on this PR, I really appreciate it!

You are welcome!

@jxs
Copy link
Member

jxs commented Dec 16, 2022

this PR was probably lost in the transition to mergify :D @nloadholtes can you solve the merge conflicts?

@mxinden
Copy link
Member

mxinden commented Dec 19, 2022

A discussion started in the meantime on whether we actually want this: libp2p/specs#465

I'll hold off with merging until that is settled. Sorry for that.

@jxs I think the above comment by @thomaseizinger still applies here.

@jxs
Copy link
Member

jxs commented Dec 19, 2022

A discussion started in the meantime on whether we actually want this: libp2p/specs#465
I'll hold off with merging until that is settled. Sorry for that.

@jxs I think the above comment by @thomaseizinger still applies here.

ah right sorry, I missed it!

@mergify
Copy link
Contributor

mergify bot commented Mar 19, 2023

This pull request has merge conflicts. Could you please resolve them @nloadholtes? 🙏

@thomaseizinger
Copy link
Contributor

I think we settled on moving to proto3.

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.

transports/noise: Use proto2
4 participants