@libp2p/webrtc 5.2.0 → 5.2.1-2a3cec922
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 +12 -4
- package/dist/index.min.js +18 -18
- package/dist/src/index.d.ts +12 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +12 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/private-to-private/listener.js +1 -1
- package/dist/src/private-to-private/listener.js.map +1 -1
- package/dist/src/private-to-public/listener.d.ts +0 -1
- package/dist/src/private-to-public/listener.d.ts.map +1 -1
- package/dist/src/private-to-public/listener.js +31 -13
- package/dist/src/private-to-public/listener.js.map +1 -1
- package/package.json +9 -9
- package/src/index.ts +12 -4
- package/src/private-to-private/listener.ts +1 -1
- package/src/private-to-public/listener.ts +40 -16
- package/dist/typedoc-urls.json +0 -14
package/dist/src/index.d.ts
CHANGED
@@ -33,7 +33,6 @@
|
|
33
33
|
* import { identify } from '@libp2p/identify'
|
34
34
|
* import { webRTC } from '@libp2p/webrtc'
|
35
35
|
* import { webSockets } from '@libp2p/websockets'
|
36
|
-
* import * as filters from '@libp2p/websockets/filters'
|
37
36
|
* import { WebRTC } from '@multiformats/multiaddr-matcher'
|
38
37
|
* import delay from 'delay'
|
39
38
|
* import { pipe } from 'it-pipe'
|
@@ -47,10 +46,13 @@
|
|
47
46
|
* listen: ['/ip4/127.0.0.1/tcp/0/ws']
|
48
47
|
* },
|
49
48
|
* transports: [
|
50
|
-
* webSockets(
|
49
|
+
* webSockets()
|
51
50
|
* ],
|
52
51
|
* connectionEncrypters: [noise()],
|
53
52
|
* streamMuxers: [yamux()],
|
53
|
+
* connectionGater: {
|
54
|
+
* denyDialMultiaddr: () => false
|
55
|
+
* },
|
54
56
|
* services: {
|
55
57
|
* identify: identify(),
|
56
58
|
* relay: circuitRelayServer()
|
@@ -68,12 +70,15 @@
|
|
68
70
|
* ]
|
69
71
|
* },
|
70
72
|
* transports: [
|
71
|
-
* webSockets(
|
73
|
+
* webSockets(),
|
72
74
|
* webRTC(),
|
73
75
|
* circuitRelayTransport()
|
74
76
|
* ],
|
75
77
|
* connectionEncrypters: [noise()],
|
76
78
|
* streamMuxers: [yamux()],
|
79
|
+
* connectionGater: {
|
80
|
+
* denyDialMultiaddr: () => false
|
81
|
+
* },
|
77
82
|
* services: {
|
78
83
|
* identify: identify(),
|
79
84
|
* echo: echo()
|
@@ -105,12 +110,15 @@
|
|
105
110
|
* // direct WebRTC connection
|
106
111
|
* const dialer = await createLibp2p({
|
107
112
|
* transports: [
|
108
|
-
* webSockets(
|
113
|
+
* webSockets(),
|
109
114
|
* webRTC(),
|
110
115
|
* circuitRelayTransport()
|
111
116
|
* ],
|
112
117
|
* connectionEncrypters: [noise()],
|
113
118
|
* streamMuxers: [yamux()],
|
119
|
+
* connectionGater: {
|
120
|
+
* denyDialMultiaddr: () => false
|
121
|
+
* },
|
114
122
|
* services: {
|
115
123
|
* identify: identify(),
|
116
124
|
* echo: echo()
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgNG;AAGH,OAAO,EAAyB,KAAK,yBAAyB,EAAE,KAAK,+BAA+B,EAAE,MAAM,kCAAkC,CAAA;AAC9I,OAAO,KAAK,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AACvG,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;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;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
@@ -33,7 +33,6 @@
|
|
33
33
|
* import { identify } from '@libp2p/identify'
|
34
34
|
* import { webRTC } from '@libp2p/webrtc'
|
35
35
|
* import { webSockets } from '@libp2p/websockets'
|
36
|
-
* import * as filters from '@libp2p/websockets/filters'
|
37
36
|
* import { WebRTC } from '@multiformats/multiaddr-matcher'
|
38
37
|
* import delay from 'delay'
|
39
38
|
* import { pipe } from 'it-pipe'
|
@@ -47,10 +46,13 @@
|
|
47
46
|
* listen: ['/ip4/127.0.0.1/tcp/0/ws']
|
48
47
|
* },
|
49
48
|
* transports: [
|
50
|
-
* webSockets(
|
49
|
+
* webSockets()
|
51
50
|
* ],
|
52
51
|
* connectionEncrypters: [noise()],
|
53
52
|
* streamMuxers: [yamux()],
|
53
|
+
* connectionGater: {
|
54
|
+
* denyDialMultiaddr: () => false
|
55
|
+
* },
|
54
56
|
* services: {
|
55
57
|
* identify: identify(),
|
56
58
|
* relay: circuitRelayServer()
|
@@ -68,12 +70,15 @@
|
|
68
70
|
* ]
|
69
71
|
* },
|
70
72
|
* transports: [
|
71
|
-
* webSockets(
|
73
|
+
* webSockets(),
|
72
74
|
* webRTC(),
|
73
75
|
* circuitRelayTransport()
|
74
76
|
* ],
|
75
77
|
* connectionEncrypters: [noise()],
|
76
78
|
* streamMuxers: [yamux()],
|
79
|
+
* connectionGater: {
|
80
|
+
* denyDialMultiaddr: () => false
|
81
|
+
* },
|
77
82
|
* services: {
|
78
83
|
* identify: identify(),
|
79
84
|
* echo: echo()
|
@@ -105,12 +110,15 @@
|
|
105
110
|
* // direct WebRTC connection
|
106
111
|
* const dialer = await createLibp2p({
|
107
112
|
* transports: [
|
108
|
-
* webSockets(
|
113
|
+
* webSockets(),
|
109
114
|
* webRTC(),
|
110
115
|
* circuitRelayTransport()
|
111
116
|
* ],
|
112
117
|
* connectionEncrypters: [noise()],
|
113
118
|
* streamMuxers: [yamux()],
|
119
|
+
* connectionGater: {
|
120
|
+
* denyDialMultiaddr: () => false
|
121
|
+
* },
|
114
122
|
* services: {
|
115
123
|
* identify: identify(),
|
116
124
|
* echo: echo()
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgNG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAwE,MAAM,kCAAkC,CAAA;AA2E9I,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,UAAqC,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACzF,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAA"}
|
@@ -18,7 +18,7 @@ export class WebRTCPeerListener extends TypedEventEmitter {
|
|
18
18
|
getAddrs() {
|
19
19
|
return this.transportManager
|
20
20
|
.getListeners()
|
21
|
-
.filter(l => l
|
21
|
+
.filter(l => !(l instanceof WebRTCPeerListener))
|
22
22
|
.map(l => l.getAddrs()
|
23
23
|
.filter(ma => Circuit.exactMatch(ma))
|
24
24
|
.map(ma => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../../src/private-to-private/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,iCAAiC,CAAA;AACrD,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,uCAAuC,CAAA;AAKpE,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,Q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K,CAAC,MAAM;QACV,cAAc,CAAC,GAAG,EAAE;YAClB,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAA;QACrC,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,gBAAgB;aACzB,YAAY,EAAE;aACd,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,kBAAkB,CAAC,CAAC;aAC/C,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE;aACnB,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;aACpC,GAAG,CAAC,EAAE,CAAC,EAAE;YACR,OAAO,EAAE,CAAC,WAAW,CAAC,SAAS,CAAC,CAAA;QAClC,CAAC,CAAC,CACH;aACA,IAAI,EAAE,CAAA;IACX,CAAC;IAED,mBAAmB;IAEnB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAA;QAC/B,cAAc,CAAC,GAAG,EAAE;YAClB,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
@@ -20,7 +20,6 @@ export interface WebRTCListenerMetrics {
|
|
20
20
|
listenerEvents: CounterGroup;
|
21
21
|
}
|
22
22
|
export declare class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> implements Listener {
|
23
|
-
private readonly servers;
|
24
23
|
private readonly multiaddrs;
|
25
24
|
private certificate?;
|
26
25
|
private readonly connections;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/private-to-public/listener.ts"],"names":[],"mappings":"AAEA,OAAO,
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/private-to-public/listener.ts"],"names":[],"mappings":"AAEA,OAAO,E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,OAAO,CAAC,CAAuB;gBAEnC,UAAU,EAAE,8BAA8B,EAAE,IAAI,EAAE,wBAAwB;IAoBjF,MAAM,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IA6D3C,OAAO,CAAC,iBAAiB;YA2CX,kBAAkB;IAgDhC,QAAQ,IAAK,SAAS,EAAE;IAIxB,mBAAmB,CAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IA4B7C,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;CA0B9B"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { networkInterfaces } from 'node:os';
|
2
2
|
import { isIPv4, isIPv6 } from '@chainsafe/is-ip';
|
3
|
-
import { TypedEventEmitter } from '@libp2p/interface';
|
3
|
+
import { InvalidPeerIdError, TypedEventEmitter } from '@libp2p/interface';
|
4
4
|
import { multiaddr, protocols, fromStringTuples } from '@multiformats/multiaddr';
|
5
5
|
import { IP4, WebRTCDirect } from '@multiformats/multiaddr-matcher';
|
6
6
|
import { Crypto } from '@peculiar/webcrypto';
|
@@ -20,8 +20,8 @@ const CODEC_CERTHASH = 0x01d2;
|
|
20
20
|
const UDP_PROTOCOL = protocols('udp');
|
21
21
|
const IP4_PROTOCOL = protocols('ip4');
|
22
22
|
const IP6_PROTOCOL = protocols('ip6');
|
23
|
+
let UDP_MUX_LISTENERS = [];
|
23
24
|
export class WebRTCDirectListener extends TypedEventEmitter {
|
24
|
-
servers;
|
25
25
|
multiaddrs;
|
26
26
|
certificate;
|
27
27
|
connections;
|
@@ -34,7 +34,6 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
34
34
|
this.init = init;
|
35
35
|
this.components = components;
|
36
36
|
this.multiaddrs = [];
|
37
|
-
this.servers = [];
|
38
37
|
this.connections = new Map();
|
39
38
|
this.log = components.logger.forComponent('libp2p:webrtc-direct:listener');
|
40
39
|
this.certificate = init.certificates?.[0];
|
@@ -69,18 +68,29 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
69
68
|
// single mux listener. This is necessary because libjuice binds to all
|
70
69
|
// interfaces for a given port so we we need to key on just the port number
|
71
70
|
// not the host + the port number
|
72
|
-
let existingServer =
|
71
|
+
let existingServer = UDP_MUX_LISTENERS.find(s => s.port === port);
|
73
72
|
// if the server has not been started yet, or the port is a wildcard port
|
74
73
|
// and there is already a wildcard port for this address family, start a new
|
75
74
|
// UDP mux server
|
76
75
|
const wildcardPorts = port === 0 && existingServer?.port === 0;
|
77
76
|
const sameAddressFamily = (existingServer?.isIPv4 === true && isIPv4(host)) || (existingServer?.isIPv6 === true && isIPv6(host));
|
77
|
+
let createdMuxServer = false;
|
78
78
|
if (existingServer == null || (wildcardPorts && sameAddressFamily)) {
|
79
|
+
this.log('starting UDP mux server on %s:%p', host, port);
|
79
80
|
existingServer = this.startUDPMuxServer(host, port);
|
80
|
-
|
81
|
+
UDP_MUX_LISTENERS.push(existingServer);
|
82
|
+
createdMuxServer = true;
|
83
|
+
}
|
84
|
+
if (!existingServer.peerId.equals(this.components.peerId)) {
|
85
|
+
// this would have to be another in-process peer so we are likely in a
|
86
|
+
// testing environment
|
87
|
+
throw new InvalidPeerIdError(`Another peer is already performing UDP mux on ${host}:${existingServer.port}`);
|
81
88
|
}
|
82
89
|
const server = await existingServer.server;
|
83
90
|
const address = server.address();
|
91
|
+
if (!createdMuxServer) {
|
92
|
+
this.log('reused existing UDP mux server on %s:%p', host, address.port);
|
93
|
+
}
|
84
94
|
getNetworkAddresses(host, address.port, ipVersion).forEach((ma) => {
|
85
95
|
this.multiaddrs.push(multiaddr(`${ma}/webrtc-direct/certhash/${this.certificate?.certhash}`));
|
86
96
|
});
|
@@ -88,18 +98,16 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
88
98
|
}
|
89
99
|
startUDPMuxServer(host, port) {
|
90
100
|
return {
|
101
|
+
peerId: this.components.peerId,
|
102
|
+
owner: this,
|
91
103
|
port,
|
92
104
|
isIPv4: isIPv4(host),
|
93
105
|
isIPv6: isIPv6(host),
|
94
106
|
server: Promise.resolve()
|
95
107
|
.then(async () => {
|
96
|
-
if (port === 0) {
|
97
|
-
// libjuice doesn't map 0 to a random free port so we have to do it
|
98
|
-
// ourselves
|
99
|
-
port = await getPort();
|
100
|
-
}
|
101
108
|
// ensure we have a certificate
|
102
109
|
if (this.certificate == null) {
|
110
|
+
this.log.trace('creating TLS certificate');
|
103
111
|
const keyPair = await crypto.subtle.generateKey({
|
104
112
|
name: 'ECDSA',
|
105
113
|
namedCurve: 'P-256'
|
@@ -111,6 +119,12 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
111
119
|
this.certificate = certificate;
|
112
120
|
}
|
113
121
|
}
|
122
|
+
if (port === 0) {
|
123
|
+
// libjuice doesn't map 0 to a random free port so we have to do it
|
124
|
+
// ourselves
|
125
|
+
this.log.trace('searching for free port');
|
126
|
+
port = await getPort();
|
127
|
+
}
|
114
128
|
return stunListener(host, port, this.log, (ufrag, remoteHost, remotePort) => {
|
115
129
|
this.incomingConnection(ufrag, remoteHost, remotePort)
|
116
130
|
.catch(err => {
|
@@ -190,11 +204,15 @@ export class WebRTCDirectListener extends TypedEventEmitter {
|
|
190
204
|
for (const connection of this.connections.values()) {
|
191
205
|
connection.close();
|
192
206
|
}
|
193
|
-
// stop
|
194
|
-
await Promise.all(
|
195
|
-
|
207
|
+
// stop our UDP mux listeners
|
208
|
+
await Promise.all(UDP_MUX_LISTENERS
|
209
|
+
.filter(listener => listener.owner === this)
|
210
|
+
.map(async (listener) => {
|
211
|
+
const server = await listener.server;
|
196
212
|
await server.close();
|
197
213
|
}));
|
214
|
+
// remove our stopped UDP mux listeners
|
215
|
+
UDP_MUX_LISTENERS = UDP_MUX_LISTENERS.filter(listener => listener.owner !== this);
|
198
216
|
// RTCPeerConnections will be removed from the connections map when their
|
199
217
|
// connection state changes to 'closed'/'disconnected'/'failed
|
200
218
|
await pWaitFor(() => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../../src/private-to-public/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;
|
1
|
+
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../../src/private-to-public/listener.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAChF,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAA;AACnE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAC5C,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,QAAQ,MAAM,YAAY,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAA;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,kCAAkC,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAOvD,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAA;AAE3B;;GAEG;AACH,MAAM,oBAAoB,GAAG,MAAM,CAAA;AACnC,MAAM,mBAAmB,GAAG,MAAM,CAAA;AAClC,MAAM,cAAc,GAAG,MAAM,CAAA;AAsB7B,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC,CAAA;AACrC,MAAM,YAAY,GAAG,SAAS,CAAC,KAAK,C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iBAAiB,CAAC,OAAO,CAAC,CAAA;IACjC,CAAC;CACF;AAED,SAAS,mBAAmB,CAAE,IAAY,EAAE,IAAY,EAAE,OAAc;IACtE,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QACxC,4BAA4B;QAC5B,OAAO,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;aACvC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC;aACtC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;aAChC,MAAM,CAAC,OAAO,CAAC,EAAE;YAChB,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;gBACpB,OAAO,KAAK,CAAA;YACd,CAAC;YAED,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;gBAClB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAA;YACxB,CAAC;YAED,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;gBAClB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAA;YACxB,CAAC;YAED,OAAO,KAAK,CAAA;QACd,CAAC,CAAC;aACD,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,OAAO,IAAI,OAAO,QAAQ,IAAI,EAAE,CAAC,CAAA;IAC3D,CAAC;IAED,OAAO;QACL,MAAM,OAAO,IAAI,IAAI,QAAQ,IAAI,EAAE;KACpC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@libp2p/webrtc",
|
3
|
-
"version": "5.2.
|
3
|
+
"version": "5.2.1-2a3cec922",
|
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,10 +54,10 @@
|
|
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/interface": "
|
58
|
-
"@libp2p/interface-internal": "
|
59
|
-
"@libp2p/peer-id": "
|
60
|
-
"@libp2p/utils": "
|
57
|
+
"@libp2p/interface": "2.6.0-2a3cec922",
|
58
|
+
"@libp2p/interface-internal": "2.3.3-2a3cec922",
|
59
|
+
"@libp2p/peer-id": "5.0.13-2a3cec922",
|
60
|
+
"@libp2p/utils": "6.5.3-2a3cec922",
|
61
61
|
"@multiformats/multiaddr": "^12.4.0",
|
62
62
|
"@multiformats/multiaddr-matcher": "^1.6.0",
|
63
63
|
"@peculiar/webcrypto": "^1.5.0",
|
@@ -76,16 +76,16 @@
|
|
76
76
|
"progress-events": "^1.0.1",
|
77
77
|
"protons-runtime": "^5.5.0",
|
78
78
|
"race-event": "^1.3.0",
|
79
|
-
"race-signal": "^1.1.
|
79
|
+
"race-signal": "^1.1.2",
|
80
80
|
"react-native-webrtc": "^124.0.4",
|
81
81
|
"uint8-varint": "^2.0.4",
|
82
82
|
"uint8arraylist": "^2.4.8",
|
83
83
|
"uint8arrays": "^5.1.0"
|
84
84
|
},
|
85
85
|
"devDependencies": {
|
86
|
-
"@libp2p/crypto": "
|
87
|
-
"@libp2p/interface-compliance-tests": "
|
88
|
-
"@libp2p/logger": "
|
86
|
+
"@libp2p/crypto": "5.0.12-2a3cec922",
|
87
|
+
"@libp2p/interface-compliance-tests": "6.3.3-2a3cec922",
|
88
|
+
"@libp2p/logger": "5.1.9-2a3cec922",
|
89
89
|
"@types/sinon": "^17.0.3",
|
90
90
|
"aegir": "^45.0.5",
|
91
91
|
"delay": "^6.0.0",
|
package/src/index.ts
CHANGED
@@ -33,7 +33,6 @@
|
|
33
33
|
* import { identify } from '@libp2p/identify'
|
34
34
|
* import { webRTC } from '@libp2p/webrtc'
|
35
35
|
* import { webSockets } from '@libp2p/websockets'
|
36
|
-
* import * as filters from '@libp2p/websockets/filters'
|
37
36
|
* import { WebRTC } from '@multiformats/multiaddr-matcher'
|
38
37
|
* import delay from 'delay'
|
39
38
|
* import { pipe } from 'it-pipe'
|
@@ -47,10 +46,13 @@
|
|
47
46
|
* listen: ['/ip4/127.0.0.1/tcp/0/ws']
|
48
47
|
* },
|
49
48
|
* transports: [
|
50
|
-
* webSockets(
|
49
|
+
* webSockets()
|
51
50
|
* ],
|
52
51
|
* connectionEncrypters: [noise()],
|
53
52
|
* streamMuxers: [yamux()],
|
53
|
+
* connectionGater: {
|
54
|
+
* denyDialMultiaddr: () => false
|
55
|
+
* },
|
54
56
|
* services: {
|
55
57
|
* identify: identify(),
|
56
58
|
* relay: circuitRelayServer()
|
@@ -68,12 +70,15 @@
|
|
68
70
|
* ]
|
69
71
|
* },
|
70
72
|
* transports: [
|
71
|
-
* webSockets(
|
73
|
+
* webSockets(),
|
72
74
|
* webRTC(),
|
73
75
|
* circuitRelayTransport()
|
74
76
|
* ],
|
75
77
|
* connectionEncrypters: [noise()],
|
76
78
|
* streamMuxers: [yamux()],
|
79
|
+
* connectionGater: {
|
80
|
+
* denyDialMultiaddr: () => false
|
81
|
+
* },
|
77
82
|
* services: {
|
78
83
|
* identify: identify(),
|
79
84
|
* echo: echo()
|
@@ -105,12 +110,15 @@
|
|
105
110
|
* // direct WebRTC connection
|
106
111
|
* const dialer = await createLibp2p({
|
107
112
|
* transports: [
|
108
|
-
* webSockets(
|
113
|
+
* webSockets(),
|
109
114
|
* webRTC(),
|
110
115
|
* circuitRelayTransport()
|
111
116
|
* ],
|
112
117
|
* connectionEncrypters: [noise()],
|
113
118
|
* streamMuxers: [yamux()],
|
119
|
+
* connectionGater: {
|
120
|
+
* denyDialMultiaddr: () => false
|
121
|
+
* },
|
114
122
|
* services: {
|
115
123
|
* identify: identify(),
|
116
124
|
* echo: echo()
|
@@ -36,7 +36,7 @@ export class WebRTCPeerListener extends TypedEventEmitter<ListenerEvents> implem
|
|
36
36
|
getAddrs (): Multiaddr[] {
|
37
37
|
return this.transportManager
|
38
38
|
.getListeners()
|
39
|
-
.filter(l => l
|
39
|
+
.filter(l => !(l instanceof WebRTCPeerListener))
|
40
40
|
.map(l => l.getAddrs()
|
41
41
|
.filter(ma => Circuit.exactMatch(ma))
|
42
42
|
.map(ma => {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { networkInterfaces } from 'node:os'
|
2
2
|
import { isIPv4, isIPv6 } from '@chainsafe/is-ip'
|
3
|
-
import { TypedEventEmitter } from '@libp2p/interface'
|
3
|
+
import { InvalidPeerIdError, TypedEventEmitter } from '@libp2p/interface'
|
4
4
|
import { multiaddr, protocols, fromStringTuples } from '@multiformats/multiaddr'
|
5
5
|
import { IP4, WebRTCDirect } from '@multiformats/multiaddr-matcher'
|
6
6
|
import { Crypto } from '@peculiar/webcrypto'
|
@@ -54,10 +54,13 @@ interface UDPMuxServer {
|
|
54
54
|
isIPv4: boolean
|
55
55
|
isIPv6: boolean
|
56
56
|
port: number
|
57
|
+
owner: WebRTCDirectListener
|
58
|
+
peerId: PeerId
|
57
59
|
}
|
58
60
|
|
61
|
+
let UDP_MUX_LISTENERS: UDPMuxServer[] = []
|
62
|
+
|
59
63
|
export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> implements Listener {
|
60
|
-
private readonly servers: UDPMuxServer[]
|
61
64
|
private readonly multiaddrs: Multiaddr[]
|
62
65
|
private certificate?: TransportCertificate
|
63
66
|
private readonly connections: Map<string, DirectRTCPeerConnection>
|
@@ -72,7 +75,6 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
72
75
|
this.init = init
|
73
76
|
this.components = components
|
74
77
|
this.multiaddrs = []
|
75
|
-
this.servers = []
|
76
78
|
this.connections = new Map()
|
77
79
|
this.log = components.logger.forComponent('libp2p:webrtc-direct:listener')
|
78
80
|
this.certificate = init.certificates?.[0]
|
@@ -112,22 +114,35 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
112
114
|
// single mux listener. This is necessary because libjuice binds to all
|
113
115
|
// interfaces for a given port so we we need to key on just the port number
|
114
116
|
// not the host + the port number
|
115
|
-
let existingServer =
|
117
|
+
let existingServer = UDP_MUX_LISTENERS.find(s => s.port === port)
|
116
118
|
|
117
119
|
// if the server has not been started yet, or the port is a wildcard port
|
118
120
|
// and there is already a wildcard port for this address family, start a new
|
119
121
|
// UDP mux server
|
120
122
|
const wildcardPorts = port === 0 && existingServer?.port === 0
|
121
123
|
const sameAddressFamily = (existingServer?.isIPv4 === true && isIPv4(host)) || (existingServer?.isIPv6 === true && isIPv6(host))
|
124
|
+
let createdMuxServer = false
|
122
125
|
|
123
126
|
if (existingServer == null || (wildcardPorts && sameAddressFamily)) {
|
127
|
+
this.log('starting UDP mux server on %s:%p', host, port)
|
124
128
|
existingServer = this.startUDPMuxServer(host, port)
|
125
|
-
|
129
|
+
UDP_MUX_LISTENERS.push(existingServer)
|
130
|
+
createdMuxServer = true
|
131
|
+
}
|
132
|
+
|
133
|
+
if (!existingServer.peerId.equals(this.components.peerId)) {
|
134
|
+
// this would have to be another in-process peer so we are likely in a
|
135
|
+
// testing environment
|
136
|
+
throw new InvalidPeerIdError(`Another peer is already performing UDP mux on ${host}:${existingServer.port}`)
|
126
137
|
}
|
127
138
|
|
128
139
|
const server = await existingServer.server
|
129
140
|
const address = server.address()
|
130
141
|
|
142
|
+
if (!createdMuxServer) {
|
143
|
+
this.log('reused existing UDP mux server on %s:%p', host, address.port)
|
144
|
+
}
|
145
|
+
|
131
146
|
getNetworkAddresses(host, address.port, ipVersion).forEach((ma) => {
|
132
147
|
this.multiaddrs.push(multiaddr(`${ma}/webrtc-direct/certhash/${this.certificate?.certhash}`))
|
133
148
|
})
|
@@ -137,19 +152,16 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
137
152
|
|
138
153
|
private startUDPMuxServer (host: string, port: number): UDPMuxServer {
|
139
154
|
return {
|
155
|
+
peerId: this.components.peerId,
|
156
|
+
owner: this,
|
140
157
|
port,
|
141
158
|
isIPv4: isIPv4(host),
|
142
159
|
isIPv6: isIPv6(host),
|
143
160
|
server: Promise.resolve()
|
144
161
|
.then(async (): Promise<StunServer> => {
|
145
|
-
if (port === 0) {
|
146
|
-
// libjuice doesn't map 0 to a random free port so we have to do it
|
147
|
-
// ourselves
|
148
|
-
port = await getPort()
|
149
|
-
}
|
150
|
-
|
151
162
|
// ensure we have a certificate
|
152
163
|
if (this.certificate == null) {
|
164
|
+
this.log.trace('creating TLS certificate')
|
153
165
|
const keyPair = await crypto.subtle.generateKey({
|
154
166
|
name: 'ECDSA',
|
155
167
|
namedCurve: 'P-256'
|
@@ -164,6 +176,13 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
164
176
|
}
|
165
177
|
}
|
166
178
|
|
179
|
+
if (port === 0) {
|
180
|
+
// libjuice doesn't map 0 to a random free port so we have to do it
|
181
|
+
// ourselves
|
182
|
+
this.log.trace('searching for free port')
|
183
|
+
port = await getPort()
|
184
|
+
}
|
185
|
+
|
167
186
|
return stunListener(host, port, this.log, (ufrag, remoteHost, remotePort) => {
|
168
187
|
this.incomingConnection(ufrag, remoteHost, remotePort)
|
169
188
|
.catch(err => {
|
@@ -259,14 +278,19 @@ export class WebRTCDirectListener extends TypedEventEmitter<ListenerEvents> impl
|
|
259
278
|
connection.close()
|
260
279
|
}
|
261
280
|
|
262
|
-
// stop
|
281
|
+
// stop our UDP mux listeners
|
263
282
|
await Promise.all(
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
283
|
+
UDP_MUX_LISTENERS
|
284
|
+
.filter(listener => listener.owner === this)
|
285
|
+
.map(async listener => {
|
286
|
+
const server = await listener.server
|
287
|
+
await server.close()
|
288
|
+
})
|
268
289
|
)
|
269
290
|
|
291
|
+
// remove our stopped UDP mux listeners
|
292
|
+
UDP_MUX_LISTENERS = UDP_MUX_LISTENERS.filter(listener => listener.owner !== this)
|
293
|
+
|
270
294
|
// RTCPeerConnections will be removed from the connections map when their
|
271
295
|
// connection state changes to 'closed'/'disconnected'/'failed
|
272
296
|
await pWaitFor(() => {
|
package/dist/typedoc-urls.json
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"DataChannelOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.DataChannelOptions.html",
|
3
|
-
".:DataChannelOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.DataChannelOptions.html",
|
4
|
-
"TransportCertificate": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.TransportCertificate.html",
|
5
|
-
".:TransportCertificate": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.TransportCertificate.html",
|
6
|
-
"WebRTCDirectTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.WebRTCDirectTransportComponents.html",
|
7
|
-
"WebRTCTransportComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.WebRTCTransportComponents.html",
|
8
|
-
"WebRTCTransportDirectInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.WebRTCTransportDirectInit.html",
|
9
|
-
"WebRTCTransportInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_webrtc.WebRTCTransportInit.html",
|
10
|
-
"webRTC": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTC.html",
|
11
|
-
".:webRTC": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTC.html",
|
12
|
-
"webRTCDirect": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTCDirect.html",
|
13
|
-
".:webRTCDirect": "https://libp2p.github.io/js-libp2p/functions/_libp2p_webrtc.webRTCDirect.html"
|
14
|
-
}
|