@libp2p/webrtc 6.0.33 → 6.1.0-4a416447c
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/README.md +35 -1
- package/dist/index.min.js +9 -9
- package/dist/index.min.js.map +4 -4
- package/dist/src/constants.d.ts +2 -1
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +2 -1
- package/dist/src/constants.js.map +1 -1
- package/dist/src/index.d.ts +35 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +35 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/private-to-public/listener.d.ts.map +1 -1
- package/dist/src/private-to-public/listener.js +9 -7
- package/dist/src/private-to-public/listener.js.map +1 -1
- package/dist/src/private-to-public/transport.browser.d.ts +9 -0
- package/dist/src/private-to-public/transport.browser.d.ts.map +1 -1
- package/dist/src/private-to-public/transport.browser.js +33 -5
- package/dist/src/private-to-public/transport.browser.js.map +1 -1
- package/dist/src/private-to-public/utils/connect.d.ts +16 -0
- package/dist/src/private-to-public/utils/connect.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/connect.js +77 -16
- package/dist/src/private-to-public/utils/connect.js.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts +4 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.js +18 -11
- package/dist/src/private-to-public/utils/get-rtcpeerconnection.js.map +1 -1
- package/dist/src/private-to-public/utils/sdp.d.ts +3 -1
- package/dist/src/private-to-public/utils/sdp.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/sdp.js +16 -2
- package/dist/src/private-to-public/utils/sdp.js.map +1 -1
- package/dist/src/private-to-public/utils/stun-listener.browser.d.ts +9 -0
- package/dist/src/private-to-public/utils/stun-listener.browser.d.ts.map +1 -0
- package/dist/src/private-to-public/utils/stun-listener.browser.js +6 -0
- package/dist/src/private-to-public/utils/stun-listener.browser.js.map +1 -0
- package/dist/src/private-to-public/utils/stun-listener.d.ts +2 -4
- package/dist/src/private-to-public/utils/stun-listener.d.ts.map +1 -1
- package/dist/src/private-to-public/utils/stun-listener.js +8 -2
- package/dist/src/private-to-public/utils/stun-listener.js.map +1 -1
- package/dist/src/private-to-public/utils/stun.d.ts +34 -0
- package/dist/src/private-to-public/utils/stun.d.ts.map +1 -0
- package/dist/src/private-to-public/utils/stun.js +107 -0
- package/dist/src/private-to-public/utils/stun.js.map +1 -0
- package/dist/src/util.d.ts +3 -5
- package/dist/src/util.d.ts.map +1 -1
- package/dist/src/util.js +3 -24
- package/dist/src/util.js.map +1 -1
- package/dist/src/webrtc/node-datachannel.browser.d.ts +7 -0
- package/dist/src/webrtc/node-datachannel.browser.d.ts.map +1 -0
- package/dist/src/webrtc/node-datachannel.browser.js +16 -0
- package/dist/src/webrtc/node-datachannel.browser.js.map +1 -0
- package/package.json +22 -11
- package/src/constants.ts +2 -1
- package/src/index.ts +35 -1
- package/src/private-to-public/listener.ts +9 -7
- package/src/private-to-public/transport.browser.ts +48 -5
- package/src/private-to-public/utils/connect.ts +112 -17
- package/src/private-to-public/utils/get-rtcpeerconnection.ts +20 -11
- package/src/private-to-public/utils/sdp.ts +21 -2
- package/src/private-to-public/utils/stun-listener.browser.ts +14 -0
- package/src/private-to-public/utils/stun-listener.ts +9 -7
- package/src/private-to-public/utils/stun.ts +128 -0
- package/src/util.ts +5 -32
- package/src/webrtc/node-datachannel.browser.ts +17 -0
- package/dist/typedoc-urls.json +0 -14
package/dist/src/constants.d.ts
CHANGED
|
@@ -14,7 +14,8 @@ export declare const UFRAG_ALPHABET: string[];
|
|
|
14
14
|
/**
|
|
15
15
|
* Used to detect the version of the WebRTC Direct connection protocol in use
|
|
16
16
|
*/
|
|
17
|
-
export declare const
|
|
17
|
+
export declare const UFRAG_PREFIX_V1 = "libp2p+webrtc+v1/";
|
|
18
|
+
export declare const UFRAG_PREFIX_V2 = "libp2p+webrtc+v2/";
|
|
18
19
|
/**
|
|
19
20
|
* How much can be buffered to the DataChannel at once
|
|
20
21
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,UAK/B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,UAA+E,CAAA;AAE1G;;GAEG;AACH,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,UAK/B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,UAA+E,CAAA;AAE1G;;GAEG;AACH,eAAO,MAAM,eAAe,sBAAsB,CAAA;AAClD,eAAO,MAAM,eAAe,sBAAsB,CAAA;AAElD;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAkB,CAAA;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,QAAY,CAAA;AAEzC;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,4BAA4B,QAAmB,CAAA;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,KAAK,CAAA;AAE3C;;;;;GAKG;AACH,eAAO,MAAM,+BAA+B,IAAI,CAAA;AAsBhD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAA8B,CAAA;AAE5D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAS,CAAA;AAEhD;;GAEG;AACH,eAAO,MAAM,uBAAuB,QAAS,CAAA;AAE7C;;GAEG;AACH,eAAO,MAAM,cAAc,YAAY,CAAA;AAEvC;;GAEG;AACH,eAAO,MAAM,kBAAkB,4BAA4B,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,iCAAiC,sCAAsC,CAAA;AAEpF;;GAEG;AACH,eAAO,MAAM,oCAAoC,0CAA0C,CAAA;AAE3F;;GAEG;AACH,eAAO,MAAM,oCAAoC,UAAU,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,4BAA4B,aAAgB,CAAA;AAEzD;;GAEG;AACH,eAAO,MAAM,qCAAqC,WAAa,CAAA"}
|
package/dist/src/constants.js
CHANGED
|
@@ -21,7 +21,8 @@ export const UFRAG_ALPHABET = Array.from('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL
|
|
|
21
21
|
/**
|
|
22
22
|
* Used to detect the version of the WebRTC Direct connection protocol in use
|
|
23
23
|
*/
|
|
24
|
-
export const
|
|
24
|
+
export const UFRAG_PREFIX_V1 = 'libp2p+webrtc+v1/';
|
|
25
|
+
export const UFRAG_PREFIX_V2 = 'libp2p+webrtc+v2/';
|
|
25
26
|
/**
|
|
26
27
|
* How much can be buffered to the DataChannel at once
|
|
27
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAE3D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,8BAA8B;IAC9B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;CACtC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,gEAAgE,CAAC,CAAA;AAE1G;;GAEG;AACH,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAE3D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,8BAA8B;IA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AED;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,yBAAyB,EAAE,CAAA;AAE5D;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAA;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAA;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAA;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,mCAAmC,CAAA;AAEpF;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,uCAAuC,CAAA;AAE3F;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,OAAO,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,aAAa,CAAA;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,UAAU,CAAA"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -7,6 +7,19 @@
|
|
|
7
7
|
*
|
|
8
8
|
* There are two transports exposed by this module, [webRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md) and [webRTCDirect](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md).
|
|
9
9
|
*
|
|
10
|
+
* ## React Native installation
|
|
11
|
+
*
|
|
12
|
+
* React Native applications must install the optional `react-native-webrtc`
|
|
13
|
+
* peer dependency explicitly:
|
|
14
|
+
*
|
|
15
|
+
* ```sh
|
|
16
|
+
* npm install @libp2p/webrtc react-native-webrtc@^124.0.6
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Follow the [react-native-webrtc installation instructions](https://github.com/react-native-webrtc/react-native-webrtc#getting-started)
|
|
20
|
+
* to configure the native module. Node.js and browser applications do not
|
|
21
|
+
* need this dependency.
|
|
22
|
+
*
|
|
10
23
|
* ## WebRTC vs WebRTC Direct
|
|
11
24
|
*
|
|
12
25
|
* The connection establishment phase of WebRTC involves a handshake using [SDP](https://en.wikipedia.org/wiki/Session_Description_Protocol) during which two peers will exchange information such as open ports, network addresses and required capabilities.
|
|
@@ -15,7 +28,7 @@
|
|
|
15
28
|
*
|
|
16
29
|
* The WebRTC transport uses libp2p [Circuit Relay](https://libp2p.io/docs/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange.
|
|
17
30
|
*
|
|
18
|
-
* WebRTC Direct
|
|
31
|
+
* WebRTC Direct skips the handshake step, instead encoding enough information in the connection request that the responder can derive what would have been in the handshake messages and so requires no third parties to establish a connection. Version 1 of the protocol does this with a technique known as [SDP munging](https://webrtchacks.com/not-a-guide-to-sdp-munging/); version 2 avoids munging, which browsers are removing support for. See WebRTC Direct versions below.
|
|
19
32
|
*
|
|
20
33
|
* A WebRTC Direct multiaddr also includes a certhash of the target peer - this is used to allow opening a connection to the remote, which would otherwise be denied due to use of a self-signed certificate.
|
|
21
34
|
*
|
|
@@ -197,6 +210,27 @@
|
|
|
197
210
|
* })
|
|
198
211
|
* ```
|
|
199
212
|
*
|
|
213
|
+
* ## WebRTC Direct versions
|
|
214
|
+
*
|
|
215
|
+
* There are two versions of the WebRTC Direct connection flow. Both use the
|
|
216
|
+
* same `/webrtc-direct` multiaddr and certificate hash; they differ in how the
|
|
217
|
+
* client's ICE credentials reach the server.
|
|
218
|
+
*
|
|
219
|
+
* Version 1 munges the client's SDP offer so that the server can predict the
|
|
220
|
+
* client's ICE credentials. Browsers are removing the ability to do this, so
|
|
221
|
+
* v1 will stop working for browser clients.
|
|
222
|
+
*
|
|
223
|
+
* Version 2 leaves the local SDP offer untouched and instead carries the
|
|
224
|
+
* client's ICE password in the ICE username fragment of the synthetic server
|
|
225
|
+
* answer, where the server reads it back from the incoming STUN request.
|
|
226
|
+
*
|
|
227
|
+
* No configuration is needed for either version. Listeners accept both on the
|
|
228
|
+
* same port and select the version from the incoming username fragment prefix.
|
|
229
|
+
* The first dial tries v1 and, if the runtime does not apply the munged ICE
|
|
230
|
+
* credentials, continues as v2; later dials then start at v2. The
|
|
231
|
+
* `dialerVersion` option skips this and forces one version, for example `2`
|
|
232
|
+
* for a server known to support it (go-libp2p does from v0.49.0).
|
|
233
|
+
*
|
|
200
234
|
* ## WebRTC Direct certificate hashes
|
|
201
235
|
*
|
|
202
236
|
* WebRTC Direct listeners publish the hash of their TLS certificate as part of
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8RG;AAIH,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvG,OAAO,KAAK,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAA;AAClH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAElD,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;;;;;OAMG;IACH,6BAA6B,CAAC,EAAE,MAAM,CAAA;IAEtC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IAEX;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,YAAY,EAAE,yBAAyB,EAAE,+BAA+B,EAAE,CAAA;AAE1E,iBAAS,YAAY,CAAE,IAAI,CAAC,EAAE,yBAAyB,GAAG,CAAC,UAAU,EAAE,+BAA+B,KAAK,SAAS,CAEnH;AAED,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,CAAA;AAE9D,iBAAS,MAAM,CAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG,CAAC,UAAU,EAAE,yBAAyB,KAAK,SAAS,CAEjG;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAA"}
|
package/dist/src/index.js
CHANGED
|
@@ -7,6 +7,19 @@
|
|
|
7
7
|
*
|
|
8
8
|
* There are two transports exposed by this module, [webRTC](https://github.com/libp2p/specs/blob/master/webrtc/webrtc.md) and [webRTCDirect](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md).
|
|
9
9
|
*
|
|
10
|
+
* ## React Native installation
|
|
11
|
+
*
|
|
12
|
+
* React Native applications must install the optional `react-native-webrtc`
|
|
13
|
+
* peer dependency explicitly:
|
|
14
|
+
*
|
|
15
|
+
* ```sh
|
|
16
|
+
* npm install @libp2p/webrtc react-native-webrtc@^124.0.6
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Follow the [react-native-webrtc installation instructions](https://github.com/react-native-webrtc/react-native-webrtc#getting-started)
|
|
20
|
+
* to configure the native module. Node.js and browser applications do not
|
|
21
|
+
* need this dependency.
|
|
22
|
+
*
|
|
10
23
|
* ## WebRTC vs WebRTC Direct
|
|
11
24
|
*
|
|
12
25
|
* The connection establishment phase of WebRTC involves a handshake using [SDP](https://en.wikipedia.org/wiki/Session_Description_Protocol) during which two peers will exchange information such as open ports, network addresses and required capabilities.
|
|
@@ -15,7 +28,7 @@
|
|
|
15
28
|
*
|
|
16
29
|
* The WebRTC transport uses libp2p [Circuit Relay](https://libp2p.io/docs/circuit-relay/)s to forward SDP messages. Once a direct connection is formed the relay plays no further part in the exchange.
|
|
17
30
|
*
|
|
18
|
-
* WebRTC Direct
|
|
31
|
+
* WebRTC Direct skips the handshake step, instead encoding enough information in the connection request that the responder can derive what would have been in the handshake messages and so requires no third parties to establish a connection. Version 1 of the protocol does this with a technique known as [SDP munging](https://webrtchacks.com/not-a-guide-to-sdp-munging/); version 2 avoids munging, which browsers are removing support for. See WebRTC Direct versions below.
|
|
19
32
|
*
|
|
20
33
|
* A WebRTC Direct multiaddr also includes a certhash of the target peer - this is used to allow opening a connection to the remote, which would otherwise be denied due to use of a self-signed certificate.
|
|
21
34
|
*
|
|
@@ -197,6 +210,27 @@
|
|
|
197
210
|
* })
|
|
198
211
|
* ```
|
|
199
212
|
*
|
|
213
|
+
* ## WebRTC Direct versions
|
|
214
|
+
*
|
|
215
|
+
* There are two versions of the WebRTC Direct connection flow. Both use the
|
|
216
|
+
* same `/webrtc-direct` multiaddr and certificate hash; they differ in how the
|
|
217
|
+
* client's ICE credentials reach the server.
|
|
218
|
+
*
|
|
219
|
+
* Version 1 munges the client's SDP offer so that the server can predict the
|
|
220
|
+
* client's ICE credentials. Browsers are removing the ability to do this, so
|
|
221
|
+
* v1 will stop working for browser clients.
|
|
222
|
+
*
|
|
223
|
+
* Version 2 leaves the local SDP offer untouched and instead carries the
|
|
224
|
+
* client's ICE password in the ICE username fragment of the synthetic server
|
|
225
|
+
* answer, where the server reads it back from the incoming STUN request.
|
|
226
|
+
*
|
|
227
|
+
* No configuration is needed for either version. Listeners accept both on the
|
|
228
|
+
* same port and select the version from the incoming username fragment prefix.
|
|
229
|
+
* The first dial tries v1 and, if the runtime does not apply the munged ICE
|
|
230
|
+
* credentials, continues as v2; later dials then start at v2. The
|
|
231
|
+
* `dialerVersion` option skips this and forces one version, for example `2`
|
|
232
|
+
* for a server known to support it (go-libp2p does from v0.49.0).
|
|
233
|
+
*
|
|
200
234
|
* ## WebRTC Direct certificate hashes
|
|
201
235
|
*
|
|
202
236
|
* WebRTC Direct listeners publish the hash of their TLS certificate as part of
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8RG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAwFxE,SAAS,YAAY,CAAE,IAAgC;IACrD,OAAO,CAAC,UAA2C,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACrG,CAAC;AAID,SAAS,MAAM,CAAE,IAA0B;IACzC,OAAO,CAAC,UAA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AC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAsC;IAClE,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA0B;IAC/C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgC;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAuB;IAChD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAiB;gBAEvC,UAAU,EAAE,8BAA8B,EAAE,IAAI,EAAE,wBAAwB;IA4BjF,MAAM,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IA6C3C,OAAO,CAAC,iBAAiB;YAgCX,kBAAkB;IA4DhC,QAAQ,IAAK,SAAS,EAAE;IAYxB,mBAAmB,CAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAgC7C,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;CA8B9B"}
|
|
@@ -97,9 +97,9 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
|
97
97
|
port = await getPort();
|
|
98
98
|
this.log.trace('listening on free port %d', port);
|
|
99
99
|
}
|
|
100
|
-
return stunListener(host, port, this.log, (
|
|
100
|
+
return stunListener(host, port, this.log, (serverUfrag, clientUfrag, clientPwd, remoteHost, remotePort) => {
|
|
101
101
|
const signal = this.components.upgrader.createInboundAbortSignal(this.shutdownController.signal);
|
|
102
|
-
this.incomingConnection(
|
|
102
|
+
this.incomingConnection(serverUfrag, clientUfrag, clientPwd, remoteHost, remotePort, signal)
|
|
103
103
|
.catch(err => {
|
|
104
104
|
this.log.error('error processing incoming STUN request - %e', err);
|
|
105
105
|
})
|
|
@@ -110,8 +110,8 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
|
110
110
|
})
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
async incomingConnection(
|
|
114
|
-
const key = `${remoteHost}:${remotePort}:${
|
|
113
|
+
async incomingConnection(serverUfrag, clientUfrag, clientPwd, remoteHost, remotePort, signal) {
|
|
114
|
+
const key = `${remoteHost}:${remotePort}:${serverUfrag}:${clientUfrag}`;
|
|
115
115
|
let peerConnection = this.connections.get(key);
|
|
116
116
|
if (peerConnection != null) {
|
|
117
117
|
this.log.trace('already got peer connection for %s', key);
|
|
@@ -120,8 +120,8 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
|
120
120
|
this.log('create peer connection for %s', key);
|
|
121
121
|
// do not create RTCPeerConnection objects if the signal has aborted already
|
|
122
122
|
signal.throwIfAborted();
|
|
123
|
-
// https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md
|
|
124
|
-
const results = await createDialerRTCPeerConnection('server',
|
|
123
|
+
// https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md
|
|
124
|
+
const results = await createDialerRTCPeerConnection('server', serverUfrag, {
|
|
125
125
|
rtcConfiguration: this.init.rtcConfiguration,
|
|
126
126
|
certificate: this.certificate,
|
|
127
127
|
events: this.metrics?.listenerEvents,
|
|
@@ -143,12 +143,14 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
|
143
143
|
}
|
|
144
144
|
});
|
|
145
145
|
try {
|
|
146
|
-
await connect(peerConnection, results.muxerFactory,
|
|
146
|
+
await connect(peerConnection, results.muxerFactory, serverUfrag, {
|
|
147
147
|
role: 'server',
|
|
148
148
|
log: this.log,
|
|
149
149
|
logger: this.components.logger,
|
|
150
150
|
events: this.metrics?.listenerEvents,
|
|
151
151
|
signal,
|
|
152
|
+
remoteUfrag: clientUfrag,
|
|
153
|
+
remotePwd: clientPwd,
|
|
152
154
|
remoteAddr: multiaddr(`/ip${isIPv4(remoteHost) ? 4 : 6}/${remoteHost}/udp/${remotePort}/webrtc-direct`),
|
|
153
155
|
dataChannel: this.init.dataChannel,
|
|
154
156
|
upgrader: this.init.upgrader,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../../src/private-to-public/list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CAAsC;QACtC,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAA;QAE/B,yEAAyE;QACzE,8DAA8D;QAC9D,MAAM,QAAQ,CAAC,GAAG,EAAE;YAClB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,CAAC,CAAA;QACpC,CAAC,CAAC,CAAA;QAEF,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;CACF"}
|
|
@@ -20,6 +20,14 @@ export interface WebRTCMetrics {
|
|
|
20
20
|
dialerEvents: CounterGroup;
|
|
21
21
|
}
|
|
22
22
|
export interface WebRTCTransportDirectInit {
|
|
23
|
+
/**
|
|
24
|
+
* Force the version of the WebRTC Direct connection flow to dial with. When
|
|
25
|
+
* not set, the first dial tries v1 and continues as v2 if the runtime does
|
|
26
|
+
* not apply the munged ICE credentials in the local SDP offer, and later
|
|
27
|
+
* dials start at whichever version that showed the runtime supports. The
|
|
28
|
+
* server must support the version in use, listeners accept both.
|
|
29
|
+
*/
|
|
30
|
+
dialerVersion?: 1 | 2;
|
|
23
31
|
/**
|
|
24
32
|
* The default configuration used by all created RTCPeerConnections
|
|
25
33
|
*/
|
|
@@ -41,6 +49,7 @@ export declare class WebRTCDirectTransport implements Transport {
|
|
|
41
49
|
protected readonly metrics?: WebRTCMetrics;
|
|
42
50
|
protected readonly components: WebRTCDirectTransportComponents;
|
|
43
51
|
protected readonly init: WebRTCTransportDirectInit;
|
|
52
|
+
private mungeable?;
|
|
44
53
|
constructor(components: WebRTCDirectTransportComponents, init?: WebRTCTransportDirectInit);
|
|
45
54
|
readonly [transportSymbol] = true;
|
|
46
55
|
readonly [Symbol.toStringTag] = "@libp2p/webrtc-direct";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.browser.d.ts","sourceRoot":"","sources":["../../../src/private-to-public/transport.browser.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"transport.browser.d.ts","sourceRoot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EG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAEhC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED,qBAAa,qBAAsB,YAAW,SAAS;IACrD,SAAS,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IAC9B,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAA;IAC1C,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,+BAA+B,CAAA;IAC9D,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,yBAAyB,CAAA;IAClD,OAAO,CAAC,SAAS,CAAC,CAAS;gBAEd,UAAU,EAAE,+BAA+B,EAAE,IAAI,GAAE,yBAA8B;IAqB9F,QAAQ,CAAC,CAAC,eAAe,CAAC,QAAO;IAEjC,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,2BAA0B;IAEvD,QAAQ,CAAC,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAEvC;IAED;;OAEG;IACG,IAAI,CAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAuEhG;;OAEG;IACH,cAAc,CAAE,OAAO,EAAE,qBAAqB,GAAG,QAAQ;IAIzD;;OAEG;IACH,YAAY,CAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE;IAInD;;OAEG;IACH,UAAU,CAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE;CAGlD"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { serviceCapabilities, transportSymbol } from '@libp2p/interface';
|
|
1
|
+
import { InvalidParametersError, serviceCapabilities, transportSymbol } from '@libp2p/interface';
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
3
3
|
import { CODE_P2P } from '@multiformats/multiaddr';
|
|
4
4
|
import { WebRTCDirect } from '@multiformats/multiaddr-matcher';
|
|
5
|
+
import { UFRAG_PREFIX_V1 } from "../constants.js";
|
|
5
6
|
import { UnimplementedError } from "../error.js";
|
|
6
7
|
import { genUfrag } from "../util.js";
|
|
7
8
|
import { connect } from "./utils/connect.js";
|
|
@@ -11,10 +12,15 @@ export class WebRTCDirectTransport {
|
|
|
11
12
|
metrics;
|
|
12
13
|
components;
|
|
13
14
|
init;
|
|
15
|
+
mungeable;
|
|
14
16
|
constructor(components, init = {}) {
|
|
15
17
|
this.log = components.logger.forComponent('libp2p:webrtc-direct');
|
|
16
18
|
this.components = components;
|
|
17
19
|
this.init = init;
|
|
20
|
+
const dialerVersion = init.dialerVersion;
|
|
21
|
+
if (dialerVersion != null && dialerVersion !== 1 && dialerVersion !== 2) {
|
|
22
|
+
throw new InvalidParametersError(`Unknown WebRTC Direct dialer version "${String(dialerVersion)}"`);
|
|
23
|
+
}
|
|
18
24
|
if (components.metrics != null) {
|
|
19
25
|
this.metrics = {
|
|
20
26
|
dialerEvents: components.metrics.registerCounterGroup('libp2p_webrtc-direct_dialer_events_total', {
|
|
@@ -41,22 +47,42 @@ export class WebRTCDirectTransport {
|
|
|
41
47
|
if (remotePeerString != null) {
|
|
42
48
|
theirPeerId = peerIdFromString(remotePeerString);
|
|
43
49
|
}
|
|
44
|
-
|
|
45
|
-
//
|
|
50
|
+
// an explicit dialer version is always used, otherwise start at v1 until a
|
|
51
|
+
// dial shows this runtime does not apply munged ICE credentials
|
|
52
|
+
const version = this.init.dialerVersion ?? (this.mungeable === false ? 2 : 1);
|
|
53
|
+
const ufrag = version === 2
|
|
54
|
+
? genUfrag(32, '')
|
|
55
|
+
: genUfrag(32, UFRAG_PREFIX_V1);
|
|
56
|
+
const pwd = version === 2 ? genUfrag(22, '') : ufrag;
|
|
57
|
+
// the version actually dialed, v1 may continue as v2
|
|
58
|
+
let dialedVersion = version;
|
|
59
|
+
this.log('dial %a starting as WebRTC Direct v%d', ma, version);
|
|
60
|
+
// https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md
|
|
46
61
|
const { peerConnection, muxerFactory } = await createDialerRTCPeerConnection('client', ufrag, {
|
|
47
62
|
rtcConfiguration: typeof this.init.rtcConfiguration === 'function' ? await this.init.rtcConfiguration() : this.init.rtcConfiguration ?? {},
|
|
48
63
|
events: this.metrics?.dialerEvents,
|
|
49
64
|
log: this.log,
|
|
50
65
|
dataChannel: this.init.dataChannel,
|
|
51
|
-
maxEarlyStreams: this.init.maxEarlyStreams
|
|
66
|
+
maxEarlyStreams: this.init.maxEarlyStreams,
|
|
67
|
+
pwd
|
|
52
68
|
});
|
|
53
69
|
try {
|
|
54
|
-
|
|
70
|
+
const connection = await connect(peerConnection, muxerFactory, ufrag, {
|
|
55
71
|
role: 'client',
|
|
56
72
|
log: this.log,
|
|
57
73
|
logger: this.components.logger,
|
|
58
74
|
events: this.metrics?.dialerEvents,
|
|
59
75
|
signal: options.signal,
|
|
76
|
+
version,
|
|
77
|
+
fallback: this.init.dialerVersion == null,
|
|
78
|
+
onMungeable: (mungeable) => {
|
|
79
|
+
// munging support belongs to the runtime, not the remote, so it is
|
|
80
|
+
// remembered even if this dial fails
|
|
81
|
+
this.mungeable ??= mungeable;
|
|
82
|
+
if (!mungeable && this.init.dialerVersion == null) {
|
|
83
|
+
dialedVersion = 2;
|
|
84
|
+
}
|
|
85
|
+
},
|
|
60
86
|
remoteAddr: ma,
|
|
61
87
|
dataChannel: this.init.dataChannel,
|
|
62
88
|
upgrader: options.upgrader,
|
|
@@ -64,8 +90,10 @@ export class WebRTCDirectTransport {
|
|
|
64
90
|
remotePeer: theirPeerId,
|
|
65
91
|
privateKey: this.components.privateKey
|
|
66
92
|
});
|
|
93
|
+
return connection;
|
|
67
94
|
}
|
|
68
95
|
catch (err) {
|
|
96
|
+
this.log('dial %a failed as WebRTC Direct v%d - %e', ma, dialedVersion, err);
|
|
69
97
|
peerConnection.close();
|
|
70
98
|
throw err;
|
|
71
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.browser.js","sourceRoot":"","sources":["../../../src/private-to-public/transport.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"transport.browser.js","sourceRoot":"","sources":["../../../src/private-to-public/transport.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAA;AAqDhF,MAAM,OAAO,qBAAqB;IACb,GAAG,CAAQ;IACX,OAAO,CAAgB;IACvB,UAAU,CAAiC;IAC3C,IAAI,CAA2B;IAC1C,SAAS,CAAU;IAE3B,YAAa,UAA2C,EAAE,OAAkC,EAAE;QAC5F,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAA;QACjE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAEhB,MAAM,aAAa,GAAY,IAAI,CAAC,aAAa,CAAA;QAEjD,IAAI,aAAa,IAAI,IAAI,IAAI,aAAa,KAAK,CAAC,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;YACxE,MAAM,IAAI,sBAAsB,CAAC,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,EAAE;oBACzB,mEAAmE;oBACnE,qCAAqC;oBACrC,IAAI,CAAC,SAAS,KAAK,SAAS,CAAA;oBAE5B,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,IAAI,EAAE,CAAC;wBAClD,aAAa,GAAG,CAAC,CAAA;oBACnB,CAAC;gBACH,CAAC;gBACD,UAAU,EAAE,EAAE;gBACd,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW;gBAClC,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,MAAM,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;gBAC9B,UAAU,EAAE,WAAW;gBACvB,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU;aACvC,CAAC,CAAA;YAEF,OAAO,UAAU,CAAA;QACnB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,CAAC,0CAA0C,EAAE,EAAE,EAAE,aAAa,EAAE,GAAG,CAAC,CAAA;YAC5E,cAAc,CAAC,KAAK,EAAE,CAAA;YACtB,MAAM,GAAG,CAAA;QACX,CAAC;IACH,CAAC;IAED;;OAEG;IACH,cAAc,CAAE,OAA8B;QAC5C,MAAM,IAAI,kBAAkB,CAAC,sCAAsC,CAAC,CAAA;IACtE,CAAC;IAED;;OAEG;IACH,YAAY,CAAE,UAAuB;QACnC,OAAO,EAAE,CAAA;IACX,CAAC;IAED;;OAEG;IACH,UAAU,CAAE,UAAuB;QACjC,OAAO,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,CAAA;IACnD,CAAC;CACF"}
|
|
@@ -15,9 +15,25 @@ export interface ConnectOptions {
|
|
|
15
15
|
remotePeer?: PeerId;
|
|
16
16
|
signal: AbortSignal;
|
|
17
17
|
privateKey: PrivateKey;
|
|
18
|
+
remoteUfrag?: string;
|
|
19
|
+
remotePwd?: string;
|
|
18
20
|
}
|
|
19
21
|
export interface ClientOptions extends ConnectOptions {
|
|
20
22
|
role: 'client';
|
|
23
|
+
/**
|
|
24
|
+
* Which version of the connection flow to dial with
|
|
25
|
+
*/
|
|
26
|
+
version: 1 | 2;
|
|
27
|
+
/**
|
|
28
|
+
* Continue as v2 when the runtime does not apply the munged ICE credentials
|
|
29
|
+
* a v1 dial needs
|
|
30
|
+
*/
|
|
31
|
+
fallback?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Called once a v1 attempt shows whether the runtime applies munged ICE
|
|
34
|
+
* credentials, even if the dial later fails
|
|
35
|
+
*/
|
|
36
|
+
onMungeable?(mungeable: boolean): void;
|
|
21
37
|
}
|
|
22
38
|
export interface ServerOptions extends ConnectOptions {
|
|
23
39
|
role: 'server';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../../src/private-to-public/utils/connect.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../../../src/private-to-public/utils/connect.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAMxD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAA;AACzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACxH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,UAAU,EAAE,SAAS,CAAA;IACrB,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAA;IACzB,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,QAAQ,EAAE,QAAQ,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,WAAW,CAAA;IACnB,UAAU,EAAE,UAAU,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,aAAc,SAAQ,cAAc;IACnD,IAAI,EAAE,QAAQ,CAAA;IAEd;;OAEG;IACH,OAAO,EAAE,CAAC,GAAG,CAAC,CAAA;IAEd;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAElB;;;OAGG;IACH,WAAW,CAAC,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAA;CACvC;AAED,MAAM,WAAW,aAAc,SAAQ,cAAc;IACnD,IAAI,EAAE,QAAQ,CAAA;CACf;AAsFD,wBAAsB,OAAO,CAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;AACpK,wBAAsB,OAAO,CAAE,cAAc,EAAE,uBAAuB,EAAE,YAAY,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA"}
|
|
@@ -6,9 +6,76 @@ import { toMultiaddrConnection } from "../../rtcpeerconnection-to-conn.js";
|
|
|
6
6
|
import { createStream } from "../../stream.js";
|
|
7
7
|
import { generateNoisePrologue } from "./generate-noise-prologue.js";
|
|
8
8
|
import * as sdp from "./sdp.js";
|
|
9
|
+
import { isIcePwd, isIceUfrag, serverUfragV2 } from "./stun.js";
|
|
9
10
|
function isServer(options, peerConnection) {
|
|
10
11
|
return options.role === 'server';
|
|
11
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Set `offer` as the local description with its ICE ufrag and password munged
|
|
15
|
+
* to `ufrag`, as WebRTC Direct v1 requires, and report whether the runtime
|
|
16
|
+
* applied them. Browsers are removing support for this, in which case
|
|
17
|
+
* setLocalDescription either rejects the offer with an InvalidModificationError
|
|
18
|
+
* or keeps the generated credentials.
|
|
19
|
+
*/
|
|
20
|
+
async function setMungedLocalOffer(peerConnection, offer, ufrag, log) {
|
|
21
|
+
const mungedOffer = sdp.munge({ type: offer.type, sdp: offer.sdp }, ufrag);
|
|
22
|
+
try {
|
|
23
|
+
log.trace('client setting munged local offer %s', mungedOffer.sdp);
|
|
24
|
+
await peerConnection.setLocalDescription(mungedOffer);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
// any other rejection is a real failure, not the runtime refusing the munge
|
|
28
|
+
if (err.name !== 'InvalidModificationError') {
|
|
29
|
+
throw err;
|
|
30
|
+
}
|
|
31
|
+
log('runtime rejected the munged local offer - %e', err);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const localSdp = peerConnection.localDescription?.sdp;
|
|
35
|
+
return sdp.getIceUfragFromSdp(localSdp) === ufrag && sdp.getIcePwdFromSdp(localSdp) === ufrag;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set the local offer for the requested version and return the ufrag for the
|
|
39
|
+
* synthetic server answer.
|
|
40
|
+
*
|
|
41
|
+
* v1 munges the offer so ice-ufrag and ice-pwd both equal `ufrag`, letting the
|
|
42
|
+
* server infer the client's credentials from the STUN USERNAME alone. v2 keeps
|
|
43
|
+
* the credentials the runtime generated and carries the client's ICE password
|
|
44
|
+
* in the server ufrag instead. When a v1 attempt does not stick and fallback
|
|
45
|
+
* is allowed, the dial continues as v2.
|
|
46
|
+
*/
|
|
47
|
+
async function setClientOffer(peerConnection, offer, ufrag, options) {
|
|
48
|
+
if (options.version === 1) {
|
|
49
|
+
const mungeable = await setMungedLocalOffer(peerConnection, offer, ufrag, options.log);
|
|
50
|
+
options.onMungeable?.(mungeable);
|
|
51
|
+
if (mungeable) {
|
|
52
|
+
return ufrag;
|
|
53
|
+
}
|
|
54
|
+
if (options.fallback !== true) {
|
|
55
|
+
throw new WebRTCTransportError('SDP munging is not available in this runtime so WebRTC Direct v1 cannot be used');
|
|
56
|
+
}
|
|
57
|
+
options.log('SDP munging is not available in this runtime, continuing as WebRTC Direct v2');
|
|
58
|
+
}
|
|
59
|
+
// a rejected munged offer leaves no local description, an ignored one leaves
|
|
60
|
+
// the runtime's own credentials in place, which is what v2 needs
|
|
61
|
+
if (peerConnection.localDescription == null) {
|
|
62
|
+
options.log.trace('client setting local offer %s', offer.sdp);
|
|
63
|
+
await peerConnection.setLocalDescription(offer);
|
|
64
|
+
}
|
|
65
|
+
// encode the client's ICE password in the synthetic server ufrag
|
|
66
|
+
const localPwd = sdp.getIcePwdFromSdp(peerConnection.localDescription?.sdp);
|
|
67
|
+
if (localPwd == null || !isIcePwd(localPwd)) {
|
|
68
|
+
// without a valid local ICE password we cannot build a valid v2 server
|
|
69
|
+
// ufrag; fail loudly instead of dialing with a ufrag the server would reject
|
|
70
|
+
throw new WebRTCTransportError('Could not read a valid local ICE password from local description for v2 dial');
|
|
71
|
+
}
|
|
72
|
+
const serverUfrag = serverUfragV2(localPwd);
|
|
73
|
+
if (!isIceUfrag(serverUfrag)) {
|
|
74
|
+
// the prefix counts towards the 256 character ufrag limit
|
|
75
|
+
throw new WebRTCTransportError('Local ICE password is too long to encode in a v2 server ufrag');
|
|
76
|
+
}
|
|
77
|
+
return serverUfrag;
|
|
78
|
+
}
|
|
12
79
|
export async function connect(peerConnection, muxerFactory, ufrag, options) {
|
|
13
80
|
// create data channel for running the noise handshake. Once the data
|
|
14
81
|
// channel is opened, the listener will initiate the noise handshake. This
|
|
@@ -17,35 +84,28 @@ export async function connect(peerConnection, muxerFactory, ufrag, options) {
|
|
|
17
84
|
try {
|
|
18
85
|
if (options.role === 'client') {
|
|
19
86
|
// the client has to set the local offer before the remote answer
|
|
20
|
-
// Create offer and munge sdp with ufrag == pwd. This allows the remote to
|
|
21
|
-
// respond to STUN messages without performing an actual SDP exchange.
|
|
22
|
-
// This is because it can infer the passwd field by reading the USERNAME
|
|
23
|
-
// attribute of the STUN message.
|
|
24
87
|
options.log.trace('client creating local offer');
|
|
25
88
|
const offerSdp = await peerConnection.createOffer();
|
|
26
89
|
options.log.trace('client created local offer %s', offerSdp.sdp);
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
await peerConnection.setLocalDescription(mungedOfferSdp);
|
|
30
|
-
const answerSdp = sdp.serverAnswerFromMultiaddr(options.remoteAddr, ufrag);
|
|
90
|
+
const serverUfrag = await setClientOffer(peerConnection, offerSdp, ufrag, options);
|
|
91
|
+
const answerSdp = sdp.serverAnswerFromMultiaddr(options.remoteAddr, serverUfrag);
|
|
31
92
|
options.log.trace('client setting server description %s', answerSdp.sdp);
|
|
32
93
|
await peerConnection.setRemoteDescription(answerSdp);
|
|
33
94
|
}
|
|
34
95
|
else {
|
|
35
96
|
// the server has to set the remote offer before the local answer
|
|
36
|
-
const
|
|
97
|
+
const remoteUfrag = options.remoteUfrag ?? ufrag;
|
|
98
|
+
const remotePwd = options.remotePwd ?? remoteUfrag;
|
|
99
|
+
const offerSdp = sdp.clientOfferFromMultiAddr(options.remoteAddr, remoteUfrag, remotePwd);
|
|
37
100
|
options.log.trace('server setting client %s %s', offerSdp.type, offerSdp.sdp);
|
|
38
101
|
await peerConnection.setRemoteDescription(offerSdp);
|
|
39
|
-
// Create offer and munge sdp with ufrag == pwd. This allows the remote to
|
|
40
|
-
// respond to STUN messages without performing an actual SDP exchange.
|
|
41
|
-
// This is because it can infer the passwd field by reading the USERNAME
|
|
42
|
-
// attribute of the STUN message.
|
|
43
102
|
options.log.trace('server creating local answer');
|
|
44
103
|
const answerSdp = await peerConnection.createAnswer();
|
|
45
104
|
options.log.trace('server created local answer');
|
|
46
|
-
|
|
105
|
+
// the answer credentials were pinned to the server ufrag when the peer
|
|
106
|
+
// connection was created, so it needs no munging for either version
|
|
47
107
|
options.log.trace('server setting local description %s', answerSdp.sdp);
|
|
48
|
-
await peerConnection.setLocalDescription(
|
|
108
|
+
await peerConnection.setLocalDescription(answerSdp);
|
|
49
109
|
}
|
|
50
110
|
if (handshakeDataChannel.readyState !== 'open') {
|
|
51
111
|
options.log.trace('%s wait for handshake channel to open, starting status %s', options.role, handshakeDataChannel.readyState);
|
|
@@ -116,13 +176,14 @@ export async function connect(peerConnection, muxerFactory, ufrag, options) {
|
|
|
116
176
|
skipStreamMuxerNegotiation: true
|
|
117
177
|
});
|
|
118
178
|
options.log.trace('%s upgrade outbound', options.role);
|
|
119
|
-
|
|
179
|
+
const connection = await options.upgrader.upgradeOutbound(maConn, {
|
|
120
180
|
skipProtection: true,
|
|
121
181
|
skipEncryption: true,
|
|
122
182
|
remotePeer: result.remotePeer,
|
|
123
183
|
muxerFactory,
|
|
124
184
|
signal: options.signal
|
|
125
185
|
});
|
|
186
|
+
return connection;
|
|
126
187
|
}
|
|
127
188
|
// For inbound connections, the server is are expected to start the noise
|
|
128
189
|
// handshake. Therefore, we need to secure an outbound noise connection from
|