Skip to content
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.

make it possible to skip the handshake negotiation #87

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

marten-seemann
Copy link
Contributor

This PR makes changes to the upgrader, so we can use it to handle both multiaddrs with and without the security protocol.
Depends on libp2p/go-libp2p-core#215.

For multiaddrs not containing the security protocol:

  • Upgrader.SecureMuxer needs to be set (this is the same as it is now). The upgrader will then use multistream to negotiate the security protocol.

For multiaddrs containing the security protocol:

  • Upgrader.SecureTransport needs to be set (and Upgrader.SecureMuxer must not be set). In that case, the upgrader will jump into the cryptographic handshake right after having dialed / accepted the net.Conn.

This PR also adds a Upgrader.SecurityProtocol() ma.Protocol method, which returns the security protocol of the SecureTransport. Perhaps a bit surprisingly, this returns the zero-value of ma.Protocol in case a SecureMuxer is set. We could have introduced a valid bool here, but I chose not to do so, as we'll be dropping support for the SecureMuxer soon-ish, and having just a single return value will be nicer then.

listener.go Outdated
if secProto.Code == 0 {
return l.Listener.Multiaddr()
}
return l.Listener.Multiaddr().Encapsulate(ma.StringCast("/" + secProto.Name))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there any better solution for this? This is... ugly.

@marten-seemann marten-seemann marked this pull request as ready for review September 21, 2021 21:41
Copy link
Member

@raulk raulk left a comment

Choose a reason for hiding this comment

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

What's the plan for exposing multiple handshakes over a single endpoint?

@marten-seemann
Copy link
Contributor Author

What's the plan for exposing multiple handshakes over a single endpoint?

The idea is that every instance of a Transport supports exactly one cryptographic handshake. That means we’ll have one Transport for TLS/TCP and one for Noise/TCP.
During the transition period, we’ll have one more Transport that uses multistream for handshake negotiation (that’s the one where SecureMuxer is set instead of SecureTransport).

@BigLep BigLep requested a review from a team October 24, 2021 04:34
@marten-seemann marten-seemann marked this pull request as draft December 20, 2021 07:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants