-
Notifications
You must be signed in to change notification settings - Fork 519
Description
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.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status