-
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
transports/noise: Change protobuf files to proto2 #3007
transports/noise: Change protobuf files to proto2 #3007
Conversation
97974db
to
0e761ef
Compare
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.
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!
I kicked CI and it does show up with errors in |
I typically run For this particular PR, you can probably amend the above clippy command to just be: |
This is the same format as used in go-libp2p
0e761ef
to
0b7f11d
Compare
Thank you for the great feedback! I've made those changes and I think the changes to If there's anything I missed or could make better, please let me know. Thanks! |
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! A few more comments :)
transports/noise/src/io/handshake.rs
Outdated
@@ -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() { |
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 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)! :)
transports/noise/src/io/handshake.rs
Outdated
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()) |
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 here. Look into ok_or_else
.
transports/noise/src/io/handshake.rs
Outdated
@@ -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() { |
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 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).
transports/noise/src/io/handshake.rs
Outdated
} | ||
state.id_remote_pubkey = Some(pk); | ||
None => {} |
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.
@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.
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 run clippy
, it will tell you that you can replace this with an if let Some(identity_key)
construct :)
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.
🤯 😮 whoa. That is really cool. Thanks for the tip about that, you just really flattened my learning curve with that one!
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.
LGTM!
I'll kick CI again. Let's see what it says!
transports/noise/src/io/handshake.rs
Outdated
} | ||
state.id_remote_pubkey = Some(pk); | ||
None => {} |
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 run clippy
, it will tell you that you can replace this with an if let Some(identity_key)
construct :)
transports/noise/src/io/handshake.rs
Outdated
match pb.identity_sig { | ||
Some(identity_sig) => { | ||
state.dh_remote_pubkey_sig = Some(identity_sig); | ||
} | ||
None => {} | ||
} |
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 here!
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
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! 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.
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! |
Thank you! There should be plenty around :)
You are welcome! |
this PR was probably lost in the transition to mergify :D @nloadholtes can you solve the merge conflicts? |
@jxs I think the above comment by @thomaseizinger still applies here. |
ah right sorry, I missed it! |
This pull request has merge conflicts. Could you please resolve them @nloadholtes? 🙏 |
I think we settled on moving to proto3. |
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 tooptional
.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 insrc/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