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

Allow adding prologue to noise connections #1663

Merged
merged 5 commits into from
Aug 9, 2022

Conversation

ckousik
Copy link
Contributor

@ckousik ckousik commented Aug 1, 2022

Allows adding the prologue to an existing noise transport. This is for potential use in implementing the webrtc transport.
Related discussion: libp2p/specs#412 (comment)

@marten-seemann marten-seemann self-requested a review August 1, 2022 13:25
return newSecureSession(i.t, ctx, insecure, p, i.prologue, true)
}

func (t *Transport) WithNoiseOptions(opts NoiseOptions) sec.SecureTransport {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't this be a normal constructor option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because the noise transport has both transport level and session level options. eg. The private key could be shared among multiple different connections, but the prologue can be unique to each connection.

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 can rename this to WithSessionOptions

manet "github.com/multiformats/go-multiaddr/net"
)

type NoiseOptions struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid config structs and use the normal config function pattern.

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 considered that but want to avoid exposing the intermediate transport.

Copy link
Contributor

@marten-seemann marten-seemann left a comment

Choose a reason for hiding this comment

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

lgtm, module a minor nit in the test case.

go func() {
defer close(done)
tpt, err := initTransport.
WithSessionOptions(Prologue([]byte("testtesttest")))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: no line break.

Your choice of this prologue doesn't make this easy to read.

@ckousik
Copy link
Contributor Author

ckousik commented Aug 3, 2022

@marten-seemann It looks like the previous commit failed the tests because TestSingleRelay in p2p/host/autorelay failed. I pulled the master branch and it also fails on master.
go-libp2p-autorelay-error

@marten-seemann
Copy link
Contributor

Yeah, that's a known flaky test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants