@@ -90,6 +90,12 @@ export class TLS implements ConnectionEncrypter {
90
90
async _encrypt < Stream extends Duplex < AsyncGenerator < Uint8Array | Uint8ArrayList > > = MultiaddrConnection > ( conn : Stream , isServer : boolean , options ?: SecureConnectionOptions ) : Promise < SecuredConnection < Stream > > {
91
91
let streamMuxer : StreamMuxerFactory | undefined
92
92
93
+ let streamMuxers : string [ ] = [ ]
94
+
95
+ if ( options ?. skipStreamMuxerNegotiation !== true ) {
96
+ streamMuxers = [ ...this . components . upgrader . getStreamMuxers ( ) . keys ( ) ]
97
+ }
98
+
93
99
const opts : TLSSocketOptions = {
94
100
...await generateCertificate ( this . components . privateKey ) ,
95
101
isServer,
@@ -101,7 +107,7 @@ export class TLS implements ConnectionEncrypter {
101
107
102
108
// early negotiation of muxer via ALPN protocols
103
109
ALPNProtocols : [
104
- ...this . components . upgrader . getStreamMuxers ( ) . keys ( ) ,
110
+ ...streamMuxers ,
105
111
'libp2p'
106
112
] ,
107
113
ALPNCallback : ( { protocols } ) => {
@@ -158,17 +164,9 @@ export class TLS implements ConnectionEncrypter {
158
164
. then ( remotePeer => {
159
165
this . log ( 'remote certificate ok, remote peer %p' , remotePeer )
160
166
161
- if ( ! isServer && typeof socket . alpnProtocol === 'string' ) {
162
- streamMuxer = this . components . upgrader . getStreamMuxers ( ) . get ( socket . alpnProtocol )
163
-
164
- if ( streamMuxer == null ) {
165
- this . log . error ( 'selected muxer that did not exist' )
166
- }
167
- }
168
-
169
167
// 'libp2p' is a special protocol - if it's sent the remote does not
170
168
// support early muxer negotiation
171
- if ( ! isServer && typeof socket . alpnProtocol === 'string' && socket . alpnProtocol !== 'libp2p' ) {
169
+ if ( ! isServer && typeof socket . alpnProtocol === 'string' && socket . alpnProtocol !== 'libp2p' && options ?. skipStreamMuxerNegotiation !== true ) {
172
170
this . log . trace ( 'got early muxer' , socket . alpnProtocol )
173
171
streamMuxer = this . components . upgrader . getStreamMuxers ( ) . get ( socket . alpnProtocol )
174
172
0 commit comments