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

Handshake #125

Draft
wants to merge 33 commits into
base: unstable
Choose a base branch
from
Draft

Handshake #125

wants to merge 33 commits into from

Conversation

diegomrsantos
Copy link

Issue Addressed

Which issue # does this PR address?

Proposed Changes

Please list or describe the changes introduced by this PR.

Additional Info

Please provide any additional information. For example, future considerations
or information useful for reviewers.

false,
);

let domain = format!("0x{}", hex::encode(vec![0x0, 0x0, 0x5, 0x2]));
Copy link
Author

@diegomrsantos diegomrsantos Feb 4, 2025

Choose a reason for hiding this comment

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

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

Hi Diego, thanks for starting this.
Left some comments

task_executor = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
types = { workspace = true }
version = { workspace = true }
serde_json = "1.0.137"
thiserror = "1.0.69"
prost = "0.13.4"
Copy link
Member

Choose a reason for hiding this comment

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

we use quick-protobuf in libp2p which is also available in the dependency chain, so you shouldn't need to depend on prost which is also helpful as you don't need to specifiy prost-build in the build dependencies

}

#[derive(Default)]
struct DummyPeerInfoStore {}
Copy link
Member

Choose a reason for hiding this comment

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

this and the PeerInfoStore trait are not required right? As I see them commented in the HandshakeBehaviour impl


/// Event emitted on handshake completion or failure.
#[derive(Debug)]
pub enum HandshakeEvent {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
pub enum HandshakeEvent {
pub enum Event {

the module already gives out the namespace, no need for redundancy

Copy link
Author

Choose a reason for hiding this comment

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

done

}

/// Network behaviour handling the handshake protocol.
pub struct HandshakeBehaviour {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
pub struct HandshakeBehaviour {
pub struct Behaviour {

Copy link
Author

Choose a reason for hiding this comment

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

done

/// Request-response behaviour for the handshake protocol.
behaviour: Behaviour<EnvelopeCodec>,
/// Pending outgoing handshake requests.
pending_handshakes: HashMap<OutboundRequestId, PeerId>,
Copy link
Member

Choose a reason for hiding this comment

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

do we need to keep track of the established connections which haven't completed the handshake yet?

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure yet. The idea was to know if a response is for a previous request.

Copy link
Author

Choose a reason for hiding this comment

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

Removed as this is already handled by libp2p

}

/// Network behaviour handling the handshake protocol.
pub struct HandshakeBehaviour {
Copy link
Member

Choose a reason for hiding this comment

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

skimming through the NetworkBehaviour implementation, and without knowing much about the requirements I wonder if we can suffice our needs by just implementing the Codec trait and not needing to have request-response as a sub behaviour

Copy link
Author

Choose a reason for hiding this comment

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

What would this approach look like?

Copy link
Member

Choose a reason for hiding this comment

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

using the request-response Behaviour and then doing the validation envelope signing validation logic in the Codec implementation.
Does that make sense Diego?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, having the validation in the codec is the way to go. About only one behavior, I'll need to think more about it.

use thiserror::Error;

#[derive(Error, Debug)]
pub enum HandshakeError {
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
pub enum HandshakeError {
pub enum Error {

use thiserror::Error;

#[derive(Error, Debug)]
pub enum HandshakeError {
Copy link
Member

Choose a reason for hiding this comment

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

do we need thiserror::Error for our Errors?
We are probably fine having an Enum and impl'ing Display and Error for it like request_response::OutboundFailure does it for example.
Nonetheless since it's probably already in the dependency chain feel free to ignore this

Copy link
Author

Choose a reason for hiding this comment

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

This needs to be revisited, but It'll probably be removed.

Copy link
Author

@diegomrsantos diegomrsantos Feb 7, 2025

Choose a reason for hiding this comment

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

Another advantage is the #[from] see dc79ba7


/// A `Codec` that reads/writes an **`Envelope`**
#[derive(Clone, Debug, Default)]
pub struct EnvelopeCodec;
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
pub struct EnvelopeCodec;
pub struct Codec;

Copy link
Author

Choose a reason for hiding this comment

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

done

/// - Provide a domain (for signing separation)
/// - Provide a "codec" (payload type)
/// - Marshal to bytes, unmarshal from bytes
pub trait Record {
Copy link
Member

Choose a reason for hiding this comment

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

this seems necessary right? As we are only using NodeInfo

Copy link
Author

Choose a reason for hiding this comment

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

I'll probably remove it.

Copy link
Author

Choose a reason for hiding this comment

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

removed

@diegomrsantos diegomrsantos force-pushed the handshake branch 2 times, most recently from a383724 to 9e8c770 Compare February 5, 2025 19:05
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.

2 participants