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

Supporting transports with native encryption/multiplexing #1382

Closed
MarcoPolo opened this issue Sep 16, 2022 · 1 comment
Closed

Supporting transports with native encryption/multiplexing #1382

MarcoPolo opened this issue Sep 16, 2022 · 1 comment
Labels
status/ready Ready to be worked

Comments

@MarcoPolo
Copy link
Collaborator

Context

js-libp2p upgrader makes assumptions that the upgradee needs security and multiplexing. For webtransport we don't need to add multiplexing/security because we already get this natively. How can I get the benefits of using the upgrader (connection gater, metrics, limits) without it adding encryption/multiplexing? Along with WebRTC, this might be one of the first time in JS we don't want to stack a muxer/security protocol on top of a transport.

Suggestion

Here are some changes I would suggest that would be pretty minimal and compatible with existing transports:

diff --git a/packages/interface-transport/src/index.ts b/packages/interface-transport/src/index.ts
index 49c8260..bad3dc7 100644
--- a/packages/interface-transport/src/index.ts
+++ b/packages/interface-transport/src/index.ts
@@ -1,6 +1,7 @@
 import type { AbortOptions } from '@libp2p/interfaces'
 import type { EventEmitter } from '@libp2p/interfaces/events'
 import type { Multiaddr } from '@multiformats/multiaddr'
+import type { StreamMuxerFactory } from '@libp2p/interface-stream-muxer'
 import type { Connection, MultiaddrConnection } from '@libp2p/interface-connection'
 import type { Duplex } from 'it-stream-types'
 
@@ -78,11 +79,18 @@ export interface UpgraderEvents {
   'connectionEnd': CustomEvent<Connection>
 }
 
+export interface UpgradeOptions {
+  // Enable only if your transporter natively supports encryption and you've authenticated the remote peer manually
+  skipEncryption?: boolean
+  // Use a custom muxerfactory to upgrade the connection
+  withStreamMuxer?: StreamMuxerFactory
+}
+
 export interface Upgrader extends EventEmitter<UpgraderEvents> {
   /**
    * Upgrades an outbound connection on `transport.dial`.
    */
-  upgradeOutbound: (maConn: MultiaddrConnection) => Promise<Connection>
+  upgradeOutbound: (maConn: MultiaddrConnection, opts?: UpgradeOptions) => Promise<Connection>
 
   /**
    * Upgrades an inbound connection on transport listener.

This allows a transport to skip the encryption step if it's already supporting it, and set a custom muxer factory to use for this connection. For example, WebTransport would have its own stream muxer implementation that uses the native multiplexing of webtransport, but this stream muxer doesn't make sense for any other transport.

@MarcoPolo MarcoPolo added the need/triage Needs initial labeling and prioritization label Sep 16, 2022
@mpetrunic mpetrunic added status/ready Ready to be worked and removed need/triage Needs initial labeling and prioritization labels Sep 20, 2022
@mpetrunic
Copy link
Member

resolved via #1411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/ready Ready to be worked
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants