@libp2p/webrtc 5.2.10 → 5.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +13 -13
- package/dist/src/private-to-public/listener.d.ts.map +1 -1
- package/dist/src/private-to-public/listener.js +1 -0
- package/dist/src/private-to-public/listener.js.map +1 -1
- package/dist/src/private-to-public/transport.d.ts +1 -5
- package/dist/src/private-to-public/transport.d.ts.map +1 -1
- package/dist/src/private-to-public/transport.js +29 -37
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/dist/src/private-to-public/utils/connect.js +124 -124
- package/dist/src/private-to-public/utils/connect.js.map +1 -1
- package/dist/src/stream.d.ts +5 -0
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +15 -10
- package/dist/src/stream.js.map +1 -1
- package/package.json +9 -9
- package/src/private-to-public/listener.ts +1 -0
- package/src/private-to-public/transport.ts +33 -42
- package/src/private-to-public/utils/connect.ts +136 -135
- package/src/stream.ts +21 -12
package/dist/src/stream.js
CHANGED
@@ -37,7 +37,7 @@ export class WebRTCStream extends AbstractStream {
|
|
37
37
|
// override onEnd to send/receive FIN_ACK before closing the stream
|
38
38
|
const originalOnEnd = init.onEnd;
|
39
39
|
init.onEnd = (err) => {
|
40
|
-
this.log.trace('readable and writeable ends closed', this.status);
|
40
|
+
this.log.trace('readable and writeable ends closed with status "%s"', this.status);
|
41
41
|
void Promise.resolve(async () => {
|
42
42
|
if (this.timeline.abort != null || this.timeline.reset !== null) {
|
43
43
|
return;
|
@@ -55,12 +55,14 @@ export class WebRTCStream extends AbstractStream {
|
|
55
55
|
.then(() => {
|
56
56
|
// stop processing incoming messages
|
57
57
|
this.incomingData.end();
|
58
|
-
this.channel.close();
|
59
58
|
// final cleanup
|
60
59
|
originalOnEnd?.(err);
|
61
60
|
})
|
62
61
|
.catch(err => {
|
63
62
|
this.log.error('error ending stream', err);
|
63
|
+
})
|
64
|
+
.finally(() => {
|
65
|
+
this.channel.close();
|
64
66
|
});
|
65
67
|
};
|
66
68
|
super(init);
|
@@ -179,6 +181,7 @@ export class WebRTCStream extends AbstractStream {
|
|
179
181
|
}
|
180
182
|
}
|
181
183
|
try {
|
184
|
+
this.log.trace('sending message, channel state "%s"', this.channel.readyState);
|
182
185
|
// send message without copying data
|
183
186
|
this.channel.send(data.subarray());
|
184
187
|
}
|
@@ -187,7 +190,7 @@ export class WebRTCStream extends AbstractStream {
|
|
187
190
|
}
|
188
191
|
}
|
189
192
|
async sendData(data) {
|
190
|
-
|
193
|
+
const bytesTotal = data.byteLength;
|
191
194
|
// sending messages is an async operation so use a copy of the list as it
|
192
195
|
// may be changed beneath us
|
193
196
|
data = data.sublist();
|
@@ -196,12 +199,11 @@ export class WebRTCStream extends AbstractStream {
|
|
196
199
|
const buf = data.subarray(0, toSend);
|
197
200
|
const messageBuf = Message.encode({ message: buf });
|
198
201
|
const sendBuf = lengthPrefixed.encode.single(messageBuf);
|
199
|
-
this.log.trace('
|
202
|
+
this.log.trace('sending %d/%d bytes on channel', buf.byteLength, bytesTotal);
|
200
203
|
await this._sendMessage(sendBuf);
|
201
|
-
this.log.trace('-> sent message %s', this.channel.readyState);
|
202
204
|
data.consume(toSend);
|
203
205
|
}
|
204
|
-
this.log.trace('
|
206
|
+
this.log.trace('finished sending data, channel state "%s"', this.channel.readyState);
|
205
207
|
}
|
206
208
|
async sendReset() {
|
207
209
|
try {
|
@@ -210,6 +212,9 @@ export class WebRTCStream extends AbstractStream {
|
|
210
212
|
catch (err) {
|
211
213
|
this.log.error('failed to send reset - %e', err);
|
212
214
|
}
|
215
|
+
finally {
|
216
|
+
this.channel.close();
|
217
|
+
}
|
213
218
|
}
|
214
219
|
async sendCloseWrite(options) {
|
215
220
|
if (this.channel.readyState !== 'open') {
|
@@ -280,7 +285,7 @@ export class WebRTCStream extends AbstractStream {
|
|
280
285
|
// flags can be sent while we or the remote are closing the datachannel so
|
281
286
|
// if the channel isn't open, don't try to send it but return false to let
|
282
287
|
// the caller know and act if they need to
|
283
|
-
this.log.trace('not sending flag %s because channel is "%s" and not "open"', this.channel.readyState
|
288
|
+
this.log.trace('not sending flag %s because channel is "%s" and not "open"', flag.toString(), this.channel.readyState);
|
284
289
|
return false;
|
285
290
|
}
|
286
291
|
this.log.trace('sending flag %s', flag.toString());
|
@@ -297,10 +302,10 @@ export class WebRTCStream extends AbstractStream {
|
|
297
302
|
}
|
298
303
|
}
|
299
304
|
export function createStream(options) {
|
300
|
-
const { channel, direction } = options;
|
305
|
+
const { channel, direction, handshake } = options;
|
301
306
|
return new WebRTCStream({
|
302
|
-
id:
|
303
|
-
log: options.logger.forComponent(`libp2p:webrtc:stream:${direction}:${channel.id}`),
|
307
|
+
id: `${channel.id}`,
|
308
|
+
log: options.logger.forComponent(`libp2p:webrtc:stream:${handshake === true ? 'handshake' : direction}:${channel.id}`),
|
304
309
|
...options
|
305
310
|
});
|
306
311
|
}
|
package/dist/src/stream.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,EAAE,cAAc,EAA2B,MAAM,+BAA+B,CAAA;AACvF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAiB,QAAQ,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,2BAA2B,EAAE,eAAe,EAAE,mBAAmB,EAAE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AG,CAAC,KAAK,CAAC,6BAA6B,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAA;QACrE,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AA8BD,MAAM,UAAU,YAAY,CAAE,OAA4B;IACxD,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO,CAAA;IAEjD,OAAO,IAAI,YAAY,CAAC;QACtB,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,EAAE;QACnB,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,wBAAwB,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;QACtH,GAAG,OAAO;KACX,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/webrtc",
|
3
|
-
"version": "5.2.
|
3
|
+
"version": "5.2.11",
|
4
4
|
"description": "A libp2p transport using WebRTC connections",
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc#readme",
|
@@ -54,12 +54,12 @@
|
|
54
54
|
"@chainsafe/is-ip": "^2.0.2",
|
55
55
|
"@chainsafe/libp2p-noise": "^16.0.0",
|
56
56
|
"@ipshipyard/node-datachannel": "^0.26.4",
|
57
|
-
"@libp2p/crypto": "^5.1.
|
58
|
-
"@libp2p/interface": "^2.
|
59
|
-
"@libp2p/interface-internal": "^2.3.
|
60
|
-
"@libp2p/keychain": "^5.2.
|
61
|
-
"@libp2p/peer-id": "^5.1.
|
62
|
-
"@libp2p/utils": "^6.6.
|
57
|
+
"@libp2p/crypto": "^5.1.1",
|
58
|
+
"@libp2p/interface": "^2.9.0",
|
59
|
+
"@libp2p/interface-internal": "^2.3.11",
|
60
|
+
"@libp2p/keychain": "^5.2.1",
|
61
|
+
"@libp2p/peer-id": "^5.1.2",
|
62
|
+
"@libp2p/utils": "^6.6.2",
|
63
63
|
"@multiformats/multiaddr": "^12.4.0",
|
64
64
|
"@multiformats/multiaddr-matcher": "^1.6.0",
|
65
65
|
"@peculiar/webcrypto": "^1.5.0",
|
@@ -86,8 +86,8 @@
|
|
86
86
|
"uint8arrays": "^5.1.0"
|
87
87
|
},
|
88
88
|
"devDependencies": {
|
89
|
-
"@libp2p/interface-compliance-tests": "^6.4.
|
90
|
-
"@libp2p/logger": "^5.1.
|
89
|
+
"@libp2p/interface-compliance-tests": "^6.4.4",
|
90
|
+
"@libp2p/logger": "^5.1.15",
|
91
91
|
"@types/sinon": "^17.0.3",
|
92
92
|
"aegir": "^45.1.1",
|
93
93
|
"datastore-core": "^10.0.2",
|
@@ -145,6 +145,7 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
145
145
|
// ourselves
|
146
146
|
this.log.trace('searching for free port')
|
147
147
|
port = await getPort()
|
148
|
+
this.log.trace('listening on free port %d', port)
|
148
149
|
}
|
149
150
|
|
150
151
|
return stunListener(host, port, this.log, (ufrag, remoteHost, remotePort) => {
|
@@ -6,7 +6,6 @@ import { BasicConstraintsExtension, X509Certificate, X509CertificateGenerator }
|
|
6
6
|
import { Key } from 'interface-datastore'
|
7
7
|
import { base64url } from 'multiformats/bases/base64'
|
8
8
|
import { sha256 } from 'multiformats/hashes/sha2'
|
9
|
-
import { raceSignal } from 'race-signal'
|
10
9
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
11
10
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
12
11
|
import { DEFAULT_CERTIFICATE_DATASTORE_KEY, DEFAULT_CERTIFICATE_LIFESPAN, DEFAULT_CERTIFICATE_PRIVATE_KEY_NAME, DEFAULT_CERTIFICATE_RENEWAL_THRESHOLD } from '../constants.js'
|
@@ -158,45 +157,7 @@ export class WebRTCDirectTransport implements Transport, Startable {
|
|
158
157
|
* Dial a given multiaddr
|
159
158
|
*/
|
160
159
|
async dial (ma: Multiaddr, options: DialTransportOptions<WebRTCDialEvents>): Promise<Connection> {
|
161
|
-
|
162
|
-
this.log('dialing address: %a', ma)
|
163
|
-
return rawConn
|
164
|
-
}
|
165
|
-
|
166
|
-
/**
|
167
|
-
* Create transport listeners no supported by browsers
|
168
|
-
*/
|
169
|
-
createListener (options: CreateListenerOptions): Listener {
|
170
|
-
if (this.certificate == null) {
|
171
|
-
throw new NotStartedError()
|
172
|
-
}
|
173
|
-
|
174
|
-
return new WebRTCDirectListener(this.components, {
|
175
|
-
...this.init,
|
176
|
-
...options,
|
177
|
-
certificate: this.certificate,
|
178
|
-
emitter: this.emitter
|
179
|
-
})
|
180
|
-
}
|
181
|
-
|
182
|
-
/**
|
183
|
-
* Filter check for all Multiaddrs that this transport can listen on
|
184
|
-
*/
|
185
|
-
listenFilter (multiaddrs: Multiaddr[]): Multiaddr[] {
|
186
|
-
return multiaddrs.filter(WebRTCDirect.exactMatch)
|
187
|
-
}
|
188
|
-
|
189
|
-
/**
|
190
|
-
* Filter check for all Multiaddrs that this transport can dial
|
191
|
-
*/
|
192
|
-
dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] {
|
193
|
-
return this.listenFilter(multiaddrs)
|
194
|
-
}
|
195
|
-
|
196
|
-
/**
|
197
|
-
* Connect to a peer using a multiaddr
|
198
|
-
*/
|
199
|
-
async _connect (ma: Multiaddr, options: DialTransportOptions<WebRTCDialEvents>): Promise<Connection> {
|
160
|
+
this.log('dial %a', ma)
|
200
161
|
// do not create RTCPeerConnection if the signal has already been aborted
|
201
162
|
options.signal.throwIfAborted()
|
202
163
|
|
@@ -212,7 +173,7 @@ export class WebRTCDirectTransport implements Transport, Startable {
|
|
212
173
|
const peerConnection = await createDialerRTCPeerConnection('client', ufrag, typeof this.init.rtcConfiguration === 'function' ? await this.init.rtcConfiguration() : this.init.rtcConfiguration ?? {})
|
213
174
|
|
214
175
|
try {
|
215
|
-
return await
|
176
|
+
return await connect(peerConnection, ufrag, {
|
216
177
|
role: 'client',
|
217
178
|
log: this.log,
|
218
179
|
logger: this.components.logger,
|
@@ -225,13 +186,43 @@ export class WebRTCDirectTransport implements Transport, Startable {
|
|
225
186
|
peerId: this.components.peerId,
|
226
187
|
remotePeerId: theirPeerId,
|
227
188
|
privateKey: this.components.privateKey
|
228
|
-
})
|
189
|
+
})
|
229
190
|
} catch (err) {
|
230
191
|
peerConnection.close()
|
231
192
|
throw err
|
232
193
|
}
|
233
194
|
}
|
234
195
|
|
196
|
+
/**
|
197
|
+
* Create a transport listener - this will throw in browsers
|
198
|
+
*/
|
199
|
+
createListener (options: CreateListenerOptions): Listener {
|
200
|
+
if (this.certificate == null) {
|
201
|
+
throw new NotStartedError()
|
202
|
+
}
|
203
|
+
|
204
|
+
return new WebRTCDirectListener(this.components, {
|
205
|
+
...this.init,
|
206
|
+
...options,
|
207
|
+
certificate: this.certificate,
|
208
|
+
emitter: this.emitter
|
209
|
+
})
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Filter check for all Multiaddrs that this transport can listen on
|
214
|
+
*/
|
215
|
+
listenFilter (multiaddrs: Multiaddr[]): Multiaddr[] {
|
216
|
+
return multiaddrs.filter(WebRTCDirect.exactMatch)
|
217
|
+
}
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Filter check for all Multiaddrs that this transport can dial
|
221
|
+
*/
|
222
|
+
dialFilter (multiaddrs: Multiaddr[]): Multiaddr[] {
|
223
|
+
return this.listenFilter(multiaddrs)
|
224
|
+
}
|
225
|
+
|
235
226
|
private async getCertificate (forceRenew?: boolean): Promise<TransportCertificate> {
|
236
227
|
if (isTransportCertificate(this.init.certificate)) {
|
237
228
|
this.log('using provided TLS certificate')
|
@@ -41,161 +41,162 @@ export async function connect (peerConnection: DirectRTCPeerConnection, ufrag: s
|
|
41
41
|
export async function connect (peerConnection: DirectRTCPeerConnection, ufrag: string, options: ServerOptions): Promise<void>
|
42
42
|
export async function connect (peerConnection: DirectRTCPeerConnection, ufrag: string, options: ConnectOptions): Promise<any> {
|
43
43
|
// create data channel for running the noise handshake. Once the data
|
44
|
-
// channel is opened, the
|
44
|
+
// channel is opened, the listener will initiate the noise handshake. This
|
45
45
|
// is used to confirm the identity of the peer.
|
46
46
|
const handshakeDataChannel = peerConnection.createDataChannel('', { negotiated: true, id: 0 })
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
48
|
+
try {
|
49
|
+
if (options.role === 'client') {
|
50
|
+
// the client has to set the local offer before the remote answer
|
51
|
+
|
52
|
+
// Create offer and munge sdp with ufrag == pwd. This allows the remote to
|
53
|
+
// respond to STUN messages without performing an actual SDP exchange.
|
54
|
+
// This is because it can infer the passwd field by reading the USERNAME
|
55
|
+
// attribute of the STUN message.
|
56
|
+
options.log.trace('client creating local offer')
|
57
|
+
const offerSdp = await peerConnection.createOffer()
|
58
|
+
options.log.trace('client created local offer %s', offerSdp.sdp)
|
59
|
+
const mungedOfferSdp = sdp.munge(offerSdp, ufrag)
|
60
|
+
options.log.trace('client setting local offer %s', mungedOfferSdp.sdp)
|
61
|
+
await peerConnection.setLocalDescription(mungedOfferSdp)
|
62
|
+
|
63
|
+
const answerSdp = sdp.serverAnswerFromMultiaddr(options.remoteAddr, ufrag)
|
64
|
+
options.log.trace('client setting server description %s', answerSdp.sdp)
|
65
|
+
await peerConnection.setRemoteDescription(answerSdp)
|
66
|
+
} else {
|
67
|
+
// the server has to set the remote offer before the local answer
|
68
|
+
const offerSdp = sdp.clientOfferFromMultiAddr(options.remoteAddr, ufrag)
|
69
|
+
options.log.trace('server setting client %s %s', offerSdp.type, offerSdp.sdp)
|
70
|
+
await peerConnection.setRemoteDescription(offerSdp)
|
71
|
+
|
72
|
+
// Create offer and munge sdp with ufrag == pwd. This allows the remote to
|
73
|
+
// respond to STUN messages without performing an actual SDP exchange.
|
74
|
+
// This is because it can infer the passwd field by reading the USERNAME
|
75
|
+
// attribute of the STUN message.
|
76
|
+
options.log.trace('server creating local answer')
|
77
|
+
const answerSdp = await peerConnection.createAnswer()
|
78
|
+
options.log.trace('server created local answer')
|
79
|
+
const mungedAnswerSdp = sdp.munge(answerSdp, ufrag)
|
80
|
+
options.log.trace('server setting local description %s', answerSdp.sdp)
|
81
|
+
await peerConnection.setLocalDescription(mungedAnswerSdp)
|
82
|
+
}
|
82
83
|
|
83
|
-
|
84
|
-
|
84
|
+
if (handshakeDataChannel.readyState !== 'open') {
|
85
|
+
options.log.trace('%s wait for handshake channel to open, starting status %s', options.role, handshakeDataChannel.readyState)
|
86
|
+
await raceEvent(handshakeDataChannel, 'open', options.signal)
|
87
|
+
}
|
85
88
|
|
86
|
-
|
89
|
+
options.log.trace('%s handshake channel opened', options.role)
|
87
90
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
if (options.role === 'server') {
|
92
|
+
// now that the connection has been opened, add the remote's certhash to
|
93
|
+
// it's multiaddr so we can complete the noise handshake
|
94
|
+
const remoteFingerprint = peerConnection.remoteFingerprint()?.value ?? ''
|
95
|
+
options.remoteAddr = options.remoteAddr.encapsulate(sdp.fingerprint2Ma(remoteFingerprint))
|
96
|
+
}
|
94
97
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
98
|
+
// Do noise handshake.
|
99
|
+
// Set the Noise Prologue to libp2p-webrtc-noise:<FINGERPRINTS> before
|
100
|
+
// starting the actual Noise handshake.
|
101
|
+
// <FINGERPRINTS> is the concatenation of the of the two TLS fingerprints
|
102
|
+
// of A (responder) and B (initiator) in their byte representation.
|
103
|
+
const localFingerprint = sdp.getFingerprintFromSdp(peerConnection.localDescription?.sdp)
|
101
104
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
+
if (localFingerprint == null) {
|
106
|
+
throw new WebRTCTransportError('Could not get fingerprint from local description sdp')
|
107
|
+
}
|
108
|
+
|
109
|
+
options.log.trace('%s performing noise handshake', options.role)
|
110
|
+
const noisePrologue = generateNoisePrologue(localFingerprint, options.remoteAddr, options.role)
|
111
|
+
|
112
|
+
// Since we use the default crypto interface and do not use a static key
|
113
|
+
// or early data, we pass in undefined for these parameters.
|
114
|
+
const connectionEncrypter = noise({ prologueBytes: noisePrologue })(options)
|
105
115
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
116
|
+
const handshakeStream = createStream({
|
117
|
+
channel: handshakeDataChannel,
|
118
|
+
direction: 'outbound',
|
119
|
+
handshake: true,
|
120
|
+
logger: options.logger,
|
121
|
+
...(options.dataChannel ?? {})
|
122
|
+
})
|
123
|
+
|
124
|
+
// Creating the connection before completion of the noise
|
125
|
+
// handshake ensures that the stream opening callback is set up
|
126
|
+
const maConn = new WebRTCMultiaddrConnection(options, {
|
127
|
+
peerConnection,
|
128
|
+
remoteAddr: options.remoteAddr,
|
129
|
+
timeline: {
|
130
|
+
open: Date.now()
|
131
|
+
},
|
132
|
+
metrics: options.events
|
133
|
+
})
|
134
|
+
|
135
|
+
peerConnection.addEventListener(CONNECTION_STATE_CHANGE_EVENT, () => {
|
136
|
+
switch (peerConnection.connectionState) {
|
137
|
+
case 'failed':
|
138
|
+
case 'disconnected':
|
139
|
+
case 'closed':
|
140
|
+
maConn.close().catch((err) => {
|
141
|
+
options.log.error('error closing connection', err)
|
142
|
+
maConn.abort(err)
|
143
|
+
})
|
144
|
+
break
|
145
|
+
default:
|
146
|
+
break
|
127
147
|
}
|
128
|
-
}
|
129
|
-
|
148
|
+
})
|
149
|
+
|
150
|
+
// Track opened peer connection
|
151
|
+
options.events?.increment({ peer_connection: true })
|
152
|
+
|
153
|
+
const muxerFactory = new DataChannelMuxerFactory(options, {
|
154
|
+
peerConnection,
|
155
|
+
metrics: options.events,
|
156
|
+
dataChannelOptions: options.dataChannel
|
157
|
+
})
|
130
158
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
options.log.error('error closing connection', err)
|
149
|
-
maConn.abort(err)
|
150
|
-
})
|
151
|
-
break
|
152
|
-
default:
|
153
|
-
break
|
159
|
+
if (options.role === 'client') {
|
160
|
+
// For outbound connections, the remote is expected to start the noise
|
161
|
+
// handshake. Therefore, we need to secure an inbound noise connection
|
162
|
+
// from the server.
|
163
|
+
options.log.trace('%s secure inbound', options.role)
|
164
|
+
await connectionEncrypter.secureInbound(handshakeStream, {
|
165
|
+
remotePeer: options.remotePeerId,
|
166
|
+
signal: options.signal
|
167
|
+
})
|
168
|
+
|
169
|
+
options.log.trace('%s upgrade outbound', options.role)
|
170
|
+
return await options.upgrader.upgradeOutbound(maConn, {
|
171
|
+
skipProtection: true,
|
172
|
+
skipEncryption: true,
|
173
|
+
muxerFactory,
|
174
|
+
signal: options.signal
|
175
|
+
})
|
154
176
|
}
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
peerConnection,
|
162
|
-
metrics: options.events,
|
163
|
-
dataChannelOptions: options.dataChannel
|
164
|
-
})
|
165
|
-
|
166
|
-
if (options.role === 'client') {
|
167
|
-
// For outbound connections, the remote is expected to start the noise handshake.
|
168
|
-
// Therefore, we need to secure an inbound noise connection from the remote.
|
169
|
-
options.log.trace('%s secure inbound', options.role)
|
170
|
-
await connectionEncrypter.secureInbound(wrappedDuplex, {
|
177
|
+
|
178
|
+
// For inbound connections, the server is are expected to start the noise
|
179
|
+
// handshake. Therefore, we need to secure an outbound noise connection from
|
180
|
+
// the client.
|
181
|
+
options.log.trace('%s secure outbound', options.role)
|
182
|
+
const result = await connectionEncrypter.secureOutbound(handshakeStream, {
|
171
183
|
remotePeer: options.remotePeerId,
|
172
184
|
signal: options.signal
|
173
185
|
})
|
174
186
|
|
175
|
-
|
176
|
-
|
187
|
+
maConn.remoteAddr = maConn.remoteAddr.encapsulate(`/p2p/${result.remotePeer}`)
|
188
|
+
|
189
|
+
options.log.trace('%s upgrade inbound', options.role)
|
190
|
+
|
191
|
+
await options.upgrader.upgradeInbound(maConn, {
|
177
192
|
skipProtection: true,
|
178
193
|
skipEncryption: true,
|
179
194
|
muxerFactory,
|
180
195
|
signal: options.signal
|
181
196
|
})
|
182
|
-
}
|
197
|
+
} catch (err) {
|
198
|
+
handshakeDataChannel.close()
|
183
199
|
|
184
|
-
|
185
|
-
|
186
|
-
options.log.trace('%s secure outbound', options.role)
|
187
|
-
const result = await connectionEncrypter.secureOutbound(wrappedDuplex, {
|
188
|
-
remotePeer: options.remotePeerId,
|
189
|
-
signal: options.signal
|
190
|
-
})
|
191
|
-
maConn.remoteAddr = maConn.remoteAddr.encapsulate(`/p2p/${result.remotePeer}`)
|
192
|
-
|
193
|
-
options.log.trace('%s upgrade inbound', options.role)
|
194
|
-
|
195
|
-
await options.upgrader.upgradeInbound(maConn, {
|
196
|
-
skipProtection: true,
|
197
|
-
skipEncryption: true,
|
198
|
-
muxerFactory,
|
199
|
-
signal: options.signal
|
200
|
-
})
|
200
|
+
throw err
|
201
|
+
}
|
201
202
|
}
|