@libp2p/webrtc 3.2.10 → 3.2.11-0b4a2ee79
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 +1 -1
- package/dist/index.min.js +12 -12
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/maconn.d.ts +6 -1
- package/dist/src/maconn.d.ts.map +1 -1
- package/dist/src/maconn.js +6 -6
- package/dist/src/maconn.js.map +1 -1
- package/dist/src/muxer.d.ts +13 -2
- package/dist/src/muxer.d.ts.map +1 -1
- package/dist/src/muxer.js +36 -7
- package/dist/src/muxer.js.map +1 -1
- package/dist/src/private-to-private/initiate-connection.d.ts +3 -2
- package/dist/src/private-to-private/initiate-connection.d.ts.map +1 -1
- package/dist/src/private-to-private/initiate-connection.js +3 -4
- package/dist/src/private-to-private/initiate-connection.js.map +1 -1
- package/dist/src/private-to-private/signaling-stream-handler.d.ts +3 -1
- package/dist/src/private-to-private/signaling-stream-handler.d.ts.map +1 -1
- package/dist/src/private-to-private/signaling-stream-handler.js +3 -4
- package/dist/src/private-to-private/signaling-stream-handler.js.map +1 -1
- package/dist/src/private-to-private/transport.d.ts +3 -0
- package/dist/src/private-to-private/transport.d.ts.map +1 -1
- package/dist/src/private-to-private/transport.js +13 -11
- package/dist/src/private-to-private/transport.js.map +1 -1
- package/dist/src/private-to-private/util.d.ts +2 -1
- package/dist/src/private-to-private/util.d.ts.map +1 -1
- package/dist/src/private-to-private/util.js +25 -40
- package/dist/src/private-to-private/util.js.map +1 -1
- package/dist/src/private-to-public/sdp.d.ts +2 -1
- package/dist/src/private-to-public/sdp.d.ts.map +1 -1
- package/dist/src/private-to-public/sdp.js +3 -6
- package/dist/src/private-to-public/sdp.js.map +1 -1
- package/dist/src/private-to-public/transport.d.ts +3 -0
- package/dist/src/private-to-public/transport.d.ts.map +1 -1
- package/dist/src/private-to-public/transport.js +21 -10
- package/dist/src/private-to-public/transport.js.map +1 -1
- package/dist/src/stream.d.ts +10 -3
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/stream.js +18 -32
- package/dist/src/stream.js.map +1 -1
- package/dist/src/util.d.ts +2 -1
- package/dist/src/util.d.ts.map +1 -1
- package/dist/src/util.js +4 -6
- package/dist/src/util.js.map +1 -1
- package/package.json +21 -20
- package/src/index.ts +6 -0
- package/src/maconn.ts +12 -7
- package/src/muxer.ts +57 -8
- package/src/private-to-private/initiate-connection.ts +5 -6
- package/src/private-to-private/signaling-stream-handler.ts +5 -5
- package/src/private-to-private/transport.ts +15 -12
- package/src/private-to-private/util.ts +29 -44
- package/src/private-to-public/sdp.ts +4 -8
- package/src/private-to-public/transport.ts +23 -11
- package/src/stream.ts +26 -37
- package/src/util.ts +5 -7
- package/dist/typedoc-urls.json +0 -8
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,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,cAAc,EAA2B,MAAM,
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,cAAc,EAA2B,MAAM,+BAA+B,CAAA;AACvF,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAiB,QAAQ,EAAE,MAAM,aAAa,CAAA;AACrD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,QAAQ,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAA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,CAAC,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,EAAE,EAAE;QACnE,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,wBAAwB,SAAS,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;QACnF,GAAG,OAAO;KACX,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/src/util.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { LoggerOptions } from '@libp2p/interface';
|
|
1
2
|
export declare const isFirefox: boolean;
|
|
2
3
|
export declare const nopSource: () => AsyncGenerator<Uint8Array, any, unknown>;
|
|
3
4
|
export declare const nopSink: (_: any) => Promise<void>;
|
|
4
5
|
export declare const DATA_CHANNEL_DRAIN_TIMEOUT: number;
|
|
5
|
-
export declare function drainAndClose(channel: RTCDataChannel, direction: string, drainTimeout
|
|
6
|
+
export declare function drainAndClose(channel: RTCDataChannel, direction: string, drainTimeout: number | undefined, options: LoggerOptions): void;
|
|
6
7
|
export interface AbortPromiseOptions {
|
|
7
8
|
signal?: AbortSignal;
|
|
8
9
|
message?: string;
|
package/dist/src/util.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGtD,eAAO,MAAM,SAAS,SAAoD,CAAA;AAE1E,eAAO,MAAM,SAAS,QAA4B,eAAe,UAAU,EAAE,GAAG,EAAE,OAAO,CAAI,CAAA;AAE7F,eAAO,MAAM,OAAO,MAAa,GAAG,KAAG,QAAQ,IAAI,CAAO,CAAA;AAE1D,eAAO,MAAM,0BAA0B,QAAY,CAAA;AAEnD,wBAAgB,aAAa,CAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,oBAAqC,EAAE,OAAO,EAAE,aAAa,GAAG,IAAI,CA8C1J;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB"}
|
package/dist/src/util.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger';
|
|
2
1
|
import { detect } from 'detect-browser';
|
|
3
2
|
import pDefer from 'p-defer';
|
|
4
3
|
import pTimeout from 'p-timeout';
|
|
5
|
-
const log = logger('libp2p:webrtc:utils');
|
|
6
4
|
const browser = detect();
|
|
7
5
|
export const isFirefox = ((browser != null) && browser.name === 'firefox');
|
|
8
6
|
export const nopSource = async function* nop() { };
|
|
9
7
|
export const nopSink = async (_) => { };
|
|
10
8
|
export const DATA_CHANNEL_DRAIN_TIMEOUT = 30 * 1000;
|
|
11
|
-
export function drainAndClose(channel, direction, drainTimeout = DATA_CHANNEL_DRAIN_TIMEOUT) {
|
|
9
|
+
export function drainAndClose(channel, direction, drainTimeout = DATA_CHANNEL_DRAIN_TIMEOUT, options) {
|
|
12
10
|
if (channel.readyState !== 'open') {
|
|
13
11
|
return;
|
|
14
12
|
}
|
|
@@ -16,13 +14,13 @@ export function drainAndClose(channel, direction, drainTimeout = DATA_CHANNEL_DR
|
|
|
16
14
|
.then(async () => {
|
|
17
15
|
// wait for bufferedAmount to become zero
|
|
18
16
|
if (channel.bufferedAmount > 0) {
|
|
19
|
-
log('%s drain channel with %d buffered bytes', direction, channel.bufferedAmount);
|
|
17
|
+
options.log('%s drain channel with %d buffered bytes', direction, channel.bufferedAmount);
|
|
20
18
|
const deferred = pDefer();
|
|
21
19
|
let drained = false;
|
|
22
20
|
channel.bufferedAmountLowThreshold = 0;
|
|
23
21
|
const closeListener = () => {
|
|
24
22
|
if (!drained) {
|
|
25
|
-
log('%s drain channel closed before drain', direction);
|
|
23
|
+
options.log('%s drain channel closed before drain', direction);
|
|
26
24
|
deferred.resolve();
|
|
27
25
|
}
|
|
28
26
|
};
|
|
@@ -46,7 +44,7 @@ export function drainAndClose(channel, direction, drainTimeout = DATA_CHANNEL_DR
|
|
|
46
44
|
}
|
|
47
45
|
})
|
|
48
46
|
.catch(err => {
|
|
49
|
-
log.error('error closing outbound stream', err);
|
|
47
|
+
options.log.error('error closing outbound stream', err);
|
|
50
48
|
});
|
|
51
49
|
}
|
|
52
50
|
//# sourceMappingURL=util.js.map
|
package/dist/src/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,QAAQ,MAAM,WAAW,CAAA;AAGhC,MAAM,OAAO,GAAG,MAAM,EAAE,CAAA;AACxB,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;AAE1E,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,SAAU,CAAC,CAAC,GAAG,KAA+C,CAAC,CAAA;AAE7F,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,CAAM,EAAiB,EAAE,GAAE,CAAC,CAAA;AAE1D,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,GAAG,IAAI,CAAA;AAEnD,MAAM,UAAU,aAAa,CAAE,OAAuB,EAAE,SAAiB,EAAE,eAAuB,0BAA0B,EAAE,OAAsB;IAClJ,IAAI,OAAO,CAAC,UAAU,KAAK,MAAM,EAAE;QACjC,OAAM;KACP;IAED,KAAK,OA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CAAC,CAAC,CAAA;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webrtc",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.11-0b4a2ee79",
|
|
4
4
|
"description": "A libp2p transport using WebRTC connections",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p/tree/
|
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/libp2p/js-libp2p.git"
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"generate": "protons src/private-to-private/pb/message.proto src/pb/message.proto",
|
|
37
37
|
"build": "aegir build",
|
|
38
|
-
"test": "aegir test -t node -t browser
|
|
38
|
+
"test": "aegir test -t node -t browser -- --exit",
|
|
39
39
|
"test:node": "aegir test -t node --cov -- --exit",
|
|
40
40
|
"test:chrome": "aegir test -t browser --cov",
|
|
41
41
|
"test:firefox": "aegir test -t browser -- --browser firefox",
|
|
@@ -46,23 +46,23 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@chainsafe/libp2p-noise": "^13.0.0",
|
|
49
|
-
"@libp2p/interface": "
|
|
50
|
-
"@libp2p/interface-internal": "
|
|
51
|
-
"@libp2p/logger": "
|
|
52
|
-
"@libp2p/peer-id": "
|
|
53
|
-
"@
|
|
54
|
-
"@multiformats/
|
|
55
|
-
"@multiformats/multiaddr
|
|
56
|
-
"
|
|
49
|
+
"@libp2p/interface": "0.1.6-0b4a2ee79",
|
|
50
|
+
"@libp2p/interface-internal": "0.1.9-0b4a2ee79",
|
|
51
|
+
"@libp2p/logger": "3.1.0-0b4a2ee79",
|
|
52
|
+
"@libp2p/peer-id": "3.0.6-0b4a2ee79",
|
|
53
|
+
"@libp2p/utils": "4.0.7-0b4a2ee79",
|
|
54
|
+
"@multiformats/mafmt": "^12.1.6",
|
|
55
|
+
"@multiformats/multiaddr": "^12.1.10",
|
|
56
|
+
"@multiformats/multiaddr-matcher": "^1.1.0",
|
|
57
57
|
"any-signal": "^4.1.1",
|
|
58
58
|
"detect-browser": "^5.3.0",
|
|
59
|
-
"it-length-prefixed": "^9.0.
|
|
59
|
+
"it-length-prefixed": "^9.0.3",
|
|
60
60
|
"it-pipe": "^3.0.1",
|
|
61
|
-
"it-protobuf-stream": "^1.0.
|
|
62
|
-
"it-pushable": "^3.2.
|
|
61
|
+
"it-protobuf-stream": "^1.0.2",
|
|
62
|
+
"it-pushable": "^3.2.1",
|
|
63
63
|
"it-stream-types": "^2.0.1",
|
|
64
64
|
"it-to-buffer": "^4.0.2",
|
|
65
|
-
"multiformats": "^12.
|
|
65
|
+
"multiformats": "^12.1.3",
|
|
66
66
|
"multihashes": "^4.0.3",
|
|
67
67
|
"node-datachannel": "^0.5.0-dev",
|
|
68
68
|
"p-defer": "^4.0.0",
|
|
@@ -75,9 +75,10 @@
|
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@chainsafe/libp2p-yamux": "^5.0.0",
|
|
78
|
-
"@libp2p/
|
|
79
|
-
"@libp2p/
|
|
80
|
-
"@libp2p/
|
|
78
|
+
"@libp2p/circuit-relay-v2": "0.0.0-0b4a2ee79",
|
|
79
|
+
"@libp2p/interface-compliance-tests": "4.1.5-0b4a2ee79",
|
|
80
|
+
"@libp2p/peer-id-factory": "3.0.8-0b4a2ee79",
|
|
81
|
+
"@libp2p/websockets": "7.0.13-0b4a2ee79",
|
|
81
82
|
"@types/sinon": "^17.0.0",
|
|
82
83
|
"aegir": "^41.0.2",
|
|
83
84
|
"delay": "^6.0.0",
|
|
@@ -85,9 +86,9 @@
|
|
|
85
86
|
"it-length": "^3.0.2",
|
|
86
87
|
"it-map": "^3.0.3",
|
|
87
88
|
"it-pair": "^2.0.6",
|
|
88
|
-
"libp2p": "
|
|
89
|
+
"libp2p": "0.46.21-0b4a2ee79",
|
|
89
90
|
"p-retry": "^6.1.0",
|
|
90
|
-
"protons": "^7.0
|
|
91
|
+
"protons": "^7.3.0",
|
|
91
92
|
"sinon": "^17.0.0",
|
|
92
93
|
"sinon-ts": "^2.0.0"
|
|
93
94
|
},
|
package/src/index.ts
CHANGED
|
@@ -66,6 +66,12 @@ export interface DataChannelOptions {
|
|
|
66
66
|
* controls how long we wait for the acknowledgement in ms (default: 5s)
|
|
67
67
|
*/
|
|
68
68
|
closeTimeout?: number
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* When sending the first data message, if the channel is not in the "open"
|
|
72
|
+
* state, wait this long for the "open" event to fire.
|
|
73
|
+
*/
|
|
74
|
+
openTimeout?: number
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
/**
|
package/src/maconn.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger'
|
|
2
1
|
import { nopSink, nopSource } from './util.js'
|
|
2
|
+
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
|
3
3
|
import type { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface/connection'
|
|
4
4
|
import type { CounterGroup } from '@libp2p/interface/metrics'
|
|
5
5
|
import type { AbortOptions, Multiaddr } from '@multiformats/multiaddr'
|
|
6
6
|
import type { Source, Sink } from 'it-stream-types'
|
|
7
7
|
|
|
8
|
-
const log = logger('libp2p:webrtc:maconn')
|
|
9
|
-
|
|
10
8
|
interface WebRTCMultiaddrConnectionInit {
|
|
11
9
|
/**
|
|
12
10
|
* WebRTC Peer Connection
|
|
@@ -29,7 +27,13 @@ interface WebRTCMultiaddrConnectionInit {
|
|
|
29
27
|
metrics?: CounterGroup
|
|
30
28
|
}
|
|
31
29
|
|
|
30
|
+
export interface WebRTCMultiaddrConnectionComponents {
|
|
31
|
+
logger: ComponentLogger
|
|
32
|
+
}
|
|
33
|
+
|
|
32
34
|
export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
35
|
+
readonly log: Logger
|
|
36
|
+
|
|
33
37
|
/**
|
|
34
38
|
* WebRTC Peer Connection
|
|
35
39
|
*/
|
|
@@ -60,7 +64,8 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
60
64
|
*/
|
|
61
65
|
sink: Sink<Source<Uint8Array>, Promise<void>> = nopSink
|
|
62
66
|
|
|
63
|
-
constructor (init: WebRTCMultiaddrConnectionInit) {
|
|
67
|
+
constructor (components: WebRTCMultiaddrConnectionComponents, init: WebRTCMultiaddrConnectionInit) {
|
|
68
|
+
this.log = components.logger.forComponent('libp2p:webrtc:maconn')
|
|
64
69
|
this.remoteAddr = init.remoteAddr
|
|
65
70
|
this.timeline = init.timeline
|
|
66
71
|
this.peerConnection = init.peerConnection
|
|
@@ -68,7 +73,7 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
68
73
|
const initialState = this.peerConnection.connectionState
|
|
69
74
|
|
|
70
75
|
this.peerConnection.onconnectionstatechange = () => {
|
|
71
|
-
log.trace('peer connection state change', this.peerConnection.connectionState, 'initial state', initialState)
|
|
76
|
+
this.log.trace('peer connection state change', this.peerConnection.connectionState, 'initial state', initialState)
|
|
72
77
|
|
|
73
78
|
if (this.peerConnection.connectionState === 'disconnected' || this.peerConnection.connectionState === 'failed' || this.peerConnection.connectionState === 'closed') {
|
|
74
79
|
// nothing else to do but close the connection
|
|
@@ -78,7 +83,7 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
async close (options?: AbortOptions): Promise<void> {
|
|
81
|
-
log.trace('closing connection')
|
|
86
|
+
this.log.trace('closing connection')
|
|
82
87
|
|
|
83
88
|
this.peerConnection.close()
|
|
84
89
|
this.timeline.close = Date.now()
|
|
@@ -86,7 +91,7 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
abort (err: Error): void {
|
|
89
|
-
log.error('closing connection due to error', err)
|
|
94
|
+
this.log.error('closing connection due to error', err)
|
|
90
95
|
|
|
91
96
|
this.peerConnection.close()
|
|
92
97
|
this.timeline.close = Date.now()
|
package/src/muxer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { logger } from '@libp2p/logger'
|
|
2
1
|
import { createStream } from './stream.js'
|
|
3
2
|
import { drainAndClose, nopSink, nopSource } from './util.js'
|
|
4
3
|
import type { DataChannelOptions } from './index.js'
|
|
4
|
+
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
|
5
5
|
import type { Stream } from '@libp2p/interface/connection'
|
|
6
6
|
import type { CounterGroup } from '@libp2p/interface/metrics'
|
|
7
7
|
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface/stream-muxer'
|
|
@@ -9,8 +9,6 @@ import type { AbortOptions } from '@multiformats/multiaddr'
|
|
|
9
9
|
import type { Source, Sink } from 'it-stream-types'
|
|
10
10
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
11
11
|
|
|
12
|
-
const log = logger('libp2p:webrtc:muxer')
|
|
13
|
-
|
|
14
12
|
const PROTOCOL = '/webrtc'
|
|
15
13
|
|
|
16
14
|
export interface DataChannelMuxerFactoryInit {
|
|
@@ -32,6 +30,10 @@ export interface DataChannelMuxerFactoryInit {
|
|
|
32
30
|
dataChannelOptions?: DataChannelOptions
|
|
33
31
|
}
|
|
34
32
|
|
|
33
|
+
export interface DataChannelMuxerFactoryComponents {
|
|
34
|
+
logger: ComponentLogger
|
|
35
|
+
}
|
|
36
|
+
|
|
35
37
|
interface BufferedStream {
|
|
36
38
|
stream: Stream
|
|
37
39
|
channel: RTCDataChannel
|
|
@@ -48,15 +50,29 @@ export class DataChannelMuxerFactory implements StreamMuxerFactory {
|
|
|
48
50
|
private bufferedStreams: BufferedStream[] = []
|
|
49
51
|
private readonly metrics?: CounterGroup
|
|
50
52
|
private readonly dataChannelOptions?: DataChannelOptions
|
|
53
|
+
private readonly components: DataChannelMuxerFactoryComponents
|
|
54
|
+
private readonly log: Logger
|
|
51
55
|
|
|
52
|
-
constructor (init: DataChannelMuxerFactoryInit) {
|
|
56
|
+
constructor (components: DataChannelMuxerFactoryComponents, init: DataChannelMuxerFactoryInit) {
|
|
57
|
+
this.components = components
|
|
53
58
|
this.peerConnection = init.peerConnection
|
|
54
59
|
this.metrics = init.metrics
|
|
55
60
|
this.protocol = init.protocol ?? PROTOCOL
|
|
56
61
|
this.dataChannelOptions = init.dataChannelOptions ?? {}
|
|
62
|
+
this.log = components.logger.forComponent('libp2p:webrtc:datachannelmuxerfactory')
|
|
57
63
|
|
|
58
64
|
// store any datachannels opened before upgrade has been completed
|
|
59
65
|
this.peerConnection.ondatachannel = ({ channel }) => {
|
|
66
|
+
this.log.trace('incoming early datachannel with channel id %d and label "%s"', channel.id)
|
|
67
|
+
|
|
68
|
+
// 'init' channel is only used during connection establishment
|
|
69
|
+
if (channel.label === 'init') {
|
|
70
|
+
this.log.trace('closing early init channel')
|
|
71
|
+
channel.close()
|
|
72
|
+
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
60
76
|
// @ts-expect-error fields are set below
|
|
61
77
|
const bufferedStream: BufferedStream = {}
|
|
62
78
|
|
|
@@ -66,6 +82,7 @@ export class DataChannelMuxerFactory implements StreamMuxerFactory {
|
|
|
66
82
|
onEnd: (err) => {
|
|
67
83
|
bufferedStream.onEnd(err)
|
|
68
84
|
},
|
|
85
|
+
logger: components.logger,
|
|
69
86
|
...this.dataChannelOptions
|
|
70
87
|
})
|
|
71
88
|
|
|
@@ -80,7 +97,7 @@ export class DataChannelMuxerFactory implements StreamMuxerFactory {
|
|
|
80
97
|
}
|
|
81
98
|
|
|
82
99
|
createStreamMuxer (init?: StreamMuxerInit): StreamMuxer {
|
|
83
|
-
return new DataChannelMuxer({
|
|
100
|
+
return new DataChannelMuxer(this.components, {
|
|
84
101
|
...init,
|
|
85
102
|
peerConnection: this.peerConnection,
|
|
86
103
|
dataChannelOptions: this.dataChannelOptions,
|
|
@@ -95,6 +112,10 @@ export interface DataChannelMuxerInit extends DataChannelMuxerFactoryInit, Strea
|
|
|
95
112
|
streams: BufferedStream[]
|
|
96
113
|
}
|
|
97
114
|
|
|
115
|
+
export interface DataChannelMuxerComponents {
|
|
116
|
+
logger: ComponentLogger
|
|
117
|
+
}
|
|
118
|
+
|
|
98
119
|
/**
|
|
99
120
|
* A libp2p data channel stream muxer
|
|
100
121
|
*/
|
|
@@ -105,11 +126,15 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
105
126
|
public streams: Stream[]
|
|
106
127
|
public protocol: string
|
|
107
128
|
|
|
129
|
+
private readonly log: Logger
|
|
108
130
|
private readonly peerConnection: RTCPeerConnection
|
|
109
131
|
private readonly dataChannelOptions: DataChannelOptions
|
|
110
132
|
private readonly metrics?: CounterGroup
|
|
133
|
+
private readonly logger: ComponentLogger
|
|
111
134
|
|
|
112
|
-
constructor (readonly init: DataChannelMuxerInit) {
|
|
135
|
+
constructor (components: DataChannelMuxerComponents, readonly init: DataChannelMuxerInit) {
|
|
136
|
+
this.log = components.logger.forComponent('libp2p:webrtc:muxer')
|
|
137
|
+
this.logger = components.logger
|
|
113
138
|
this.streams = init.streams.map(s => s.stream)
|
|
114
139
|
this.peerConnection = init.peerConnection
|
|
115
140
|
this.protocol = init.protocol ?? PROTOCOL
|
|
@@ -123,12 +148,24 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
123
148
|
* {@link https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection/datachannel_event}
|
|
124
149
|
*/
|
|
125
150
|
this.peerConnection.ondatachannel = ({ channel }) => {
|
|
151
|
+
this.log.trace('incoming datachannel with channel id %d', channel.id)
|
|
152
|
+
|
|
153
|
+
// 'init' channel is only used during connection establishment
|
|
154
|
+
if (channel.label === 'init') {
|
|
155
|
+
this.log.trace('closing init channel')
|
|
156
|
+
channel.close()
|
|
157
|
+
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
126
161
|
const stream = createStream({
|
|
127
162
|
channel,
|
|
128
163
|
direction: 'inbound',
|
|
129
164
|
onEnd: () => {
|
|
165
|
+
this.log('incoming channel %s ended with state %s', channel.id, channel.readyState)
|
|
130
166
|
this.#onStreamEnd(stream, channel)
|
|
131
167
|
},
|
|
168
|
+
logger: this.logger,
|
|
132
169
|
...this.dataChannelOptions
|
|
133
170
|
})
|
|
134
171
|
|
|
@@ -147,6 +184,7 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
147
184
|
queueMicrotask(() => {
|
|
148
185
|
this.init.streams.forEach(bufferedStream => {
|
|
149
186
|
bufferedStream.onEnd = () => {
|
|
187
|
+
this.log('incoming early channel %s ended with state %s', bufferedStream.channel.id, bufferedStream.channel.readyState)
|
|
150
188
|
this.#onStreamEnd(bufferedStream.stream, bufferedStream.channel)
|
|
151
189
|
}
|
|
152
190
|
|
|
@@ -158,8 +196,14 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
158
196
|
}
|
|
159
197
|
|
|
160
198
|
#onStreamEnd (stream: Stream, channel: RTCDataChannel): void {
|
|
161
|
-
log.trace('stream %s %s %s onEnd', stream.direction, stream.id, stream.protocol)
|
|
162
|
-
drainAndClose(
|
|
199
|
+
this.log.trace('stream %s %s %s onEnd', stream.direction, stream.id, stream.protocol)
|
|
200
|
+
drainAndClose(
|
|
201
|
+
channel,
|
|
202
|
+
`${stream.direction} ${stream.id} ${stream.protocol}`,
|
|
203
|
+
this.dataChannelOptions.drainTimeout, {
|
|
204
|
+
log: this.log
|
|
205
|
+
}
|
|
206
|
+
)
|
|
163
207
|
this.streams = this.streams.filter(s => s.id !== stream.id)
|
|
164
208
|
this.metrics?.increment({ stream_end: true })
|
|
165
209
|
this.init?.onStreamEnd?.(stream)
|
|
@@ -200,12 +244,17 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
200
244
|
newStream (): Stream {
|
|
201
245
|
// The spec says the label SHOULD be an empty string: https://github.com/libp2p/specs/blob/master/webrtc/README.md#rtcdatachannel-label
|
|
202
246
|
const channel = this.peerConnection.createDataChannel('')
|
|
247
|
+
|
|
248
|
+
this.log.trace('opened outgoing datachannel with channel id %s', channel.id)
|
|
249
|
+
|
|
203
250
|
const stream = createStream({
|
|
204
251
|
channel,
|
|
205
252
|
direction: 'outbound',
|
|
206
253
|
onEnd: () => {
|
|
254
|
+
this.log('outgoing channel %s ended with state %s', channel.id, channel.readyState)
|
|
207
255
|
this.#onStreamEnd(stream, channel)
|
|
208
256
|
},
|
|
257
|
+
logger: this.logger,
|
|
209
258
|
...this.dataChannelOptions
|
|
210
259
|
})
|
|
211
260
|
this.streams.push(stream)
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
-
import { logger } from '@libp2p/logger'
|
|
3
2
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
4
3
|
import { pbStream } from 'it-protobuf-stream'
|
|
5
4
|
import pDefer, { type DeferredPromise } from 'p-defer'
|
|
@@ -8,21 +7,20 @@ import { Message } from './pb/message.js'
|
|
|
8
7
|
import { SIGNALING_PROTO_ID, splitAddr, type WebRTCTransportMetrics } from './transport.js'
|
|
9
8
|
import { readCandidatesUntilConnected, resolveOnConnected } from './util.js'
|
|
10
9
|
import type { DataChannelOptions } from '../index.js'
|
|
10
|
+
import type { LoggerOptions } from '@libp2p/interface'
|
|
11
11
|
import type { Connection } from '@libp2p/interface/connection'
|
|
12
12
|
import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager'
|
|
13
13
|
import type { IncomingStreamData } from '@libp2p/interface-internal/registrar'
|
|
14
14
|
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
|
15
15
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
16
16
|
|
|
17
|
-
const log = logger('libp2p:webrtc:initiate-connection')
|
|
18
|
-
|
|
19
17
|
export interface IncomingStreamOpts extends IncomingStreamData {
|
|
20
18
|
rtcConfiguration?: RTCConfiguration
|
|
21
19
|
dataChannelOptions?: Partial<DataChannelOptions>
|
|
22
20
|
signal: AbortSignal
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
export interface ConnectOptions {
|
|
23
|
+
export interface ConnectOptions extends LoggerOptions {
|
|
26
24
|
peerConnection: RTCPeerConnection
|
|
27
25
|
multiaddr: Multiaddr
|
|
28
26
|
connectionManager: ConnectionManager
|
|
@@ -32,7 +30,7 @@ export interface ConnectOptions {
|
|
|
32
30
|
metrics?: WebRTCTransportMetrics
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
export async function initiateConnection ({ peerConnection, signal, metrics, multiaddr: ma, connectionManager, transportManager }: ConnectOptions): Promise<{ remoteAddress: Multiaddr }> {
|
|
33
|
+
export async function initiateConnection ({ peerConnection, signal, metrics, multiaddr: ma, connectionManager, transportManager, log }: ConnectOptions): Promise<{ remoteAddress: Multiaddr }> {
|
|
36
34
|
const { baseAddr } = splitAddr(ma)
|
|
37
35
|
|
|
38
36
|
metrics?.dialerEvents.increment({ open: true })
|
|
@@ -147,7 +145,8 @@ export async function initiateConnection ({ peerConnection, signal, metrics, mul
|
|
|
147
145
|
|
|
148
146
|
await readCandidatesUntilConnected(connectedPromise, peerConnection, messageStream, {
|
|
149
147
|
direction: 'initiator',
|
|
150
|
-
signal
|
|
148
|
+
signal,
|
|
149
|
+
log
|
|
151
150
|
})
|
|
152
151
|
|
|
153
152
|
log.trace('initiator connected, closing init channel')
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
2
|
-
import { logger } from '@libp2p/logger'
|
|
3
2
|
import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
4
3
|
import { pbStream } from 'it-protobuf-stream'
|
|
5
4
|
import pDefer, { type DeferredPromise } from 'p-defer'
|
|
6
5
|
import { type RTCPeerConnection, RTCSessionDescription } from '../webrtc/index.js'
|
|
7
6
|
import { Message } from './pb/message.js'
|
|
8
7
|
import { readCandidatesUntilConnected, resolveOnConnected } from './util.js'
|
|
8
|
+
import type { Logger } from '@libp2p/interface'
|
|
9
9
|
import type { IncomingStreamData } from '@libp2p/interface-internal/registrar'
|
|
10
10
|
|
|
11
|
-
const log = logger('libp2p:webrtc:signaling-stream-handler')
|
|
12
|
-
|
|
13
11
|
export interface IncomingStreamOpts extends IncomingStreamData {
|
|
14
12
|
peerConnection: RTCPeerConnection
|
|
15
13
|
signal: AbortSignal
|
|
14
|
+
log: Logger
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
export async function handleIncomingStream ({ peerConnection, stream, signal, connection }: IncomingStreamOpts): Promise<{ remoteAddress: Multiaddr }> {
|
|
17
|
+
export async function handleIncomingStream ({ peerConnection, stream, signal, connection, log }: IncomingStreamOpts): Promise<{ remoteAddress: Multiaddr }> {
|
|
19
18
|
log.trace('new inbound signaling stream')
|
|
20
19
|
|
|
21
20
|
const messageStream = pbStream(stream).pb(Message)
|
|
@@ -104,7 +103,8 @@ export async function handleIncomingStream ({ peerConnection, stream, signal, co
|
|
|
104
103
|
// wait until candidates are connected
|
|
105
104
|
await readCandidatesUntilConnected(connectedPromise, peerConnection, messageStream, {
|
|
106
105
|
direction: 'recipient',
|
|
107
|
-
signal
|
|
106
|
+
signal,
|
|
107
|
+
log
|
|
108
108
|
})
|
|
109
109
|
|
|
110
110
|
log.trace('recipient connected, closing signaling stream')
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { CodeError } from '@libp2p/interface/errors'
|
|
2
2
|
import { type CreateListenerOptions, type DialOptions, symbol, type Transport, type Listener, type Upgrader } from '@libp2p/interface/transport'
|
|
3
|
-
import { logger } from '@libp2p/logger'
|
|
4
3
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
5
4
|
import { multiaddr, type Multiaddr } from '@multiformats/multiaddr'
|
|
6
5
|
import { WebRTC } from '@multiformats/multiaddr-matcher'
|
|
@@ -12,6 +11,7 @@ import { initiateConnection } from './initiate-connection.js'
|
|
|
12
11
|
import { WebRTCPeerListener } from './listener.js'
|
|
13
12
|
import { handleIncomingStream } from './signaling-stream-handler.js'
|
|
14
13
|
import type { DataChannelOptions } from '../index.js'
|
|
14
|
+
import type { ComponentLogger, Logger } from '@libp2p/interface'
|
|
15
15
|
import type { Connection } from '@libp2p/interface/connection'
|
|
16
16
|
import type { PeerId } from '@libp2p/interface/peer-id'
|
|
17
17
|
import type { CounterGroup, Metrics } from '@libp2p/interface/src/metrics/index.js'
|
|
@@ -20,8 +20,6 @@ import type { IncomingStreamData, Registrar } from '@libp2p/interface-internal/r
|
|
|
20
20
|
import type { ConnectionManager } from '@libp2p/interface-internal/src/connection-manager/index.js'
|
|
21
21
|
import type { TransportManager } from '@libp2p/interface-internal/transport-manager'
|
|
22
22
|
|
|
23
|
-
const log = logger('libp2p:webrtc:peer')
|
|
24
|
-
|
|
25
23
|
const WEBRTC_TRANSPORT = '/webrtc'
|
|
26
24
|
const CIRCUIT_RELAY_TRANSPORT = '/p2p-circuit'
|
|
27
25
|
export const SIGNALING_PROTO_ID = '/webrtc-signaling/0.0.1'
|
|
@@ -45,6 +43,7 @@ export interface WebRTCTransportComponents {
|
|
|
45
43
|
transportManager: TransportManager
|
|
46
44
|
connectionManager: ConnectionManager
|
|
47
45
|
metrics?: Metrics
|
|
46
|
+
logger: ComponentLogger
|
|
48
47
|
}
|
|
49
48
|
|
|
50
49
|
export interface WebRTCTransportMetrics {
|
|
@@ -53,6 +52,7 @@ export interface WebRTCTransportMetrics {
|
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
export class WebRTCTransport implements Transport, Startable {
|
|
55
|
+
private readonly log: Logger
|
|
56
56
|
private _started = false
|
|
57
57
|
private readonly metrics?: WebRTCTransportMetrics
|
|
58
58
|
private readonly shutdownController: AbortController
|
|
@@ -61,6 +61,7 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
61
61
|
private readonly components: WebRTCTransportComponents,
|
|
62
62
|
private readonly init: WebRTCTransportInit = {}
|
|
63
63
|
) {
|
|
64
|
+
this.log = components.logger.forComponent('libp2p:webrtc')
|
|
64
65
|
this.shutdownController = new AbortController()
|
|
65
66
|
|
|
66
67
|
if (components.metrics != null) {
|
|
@@ -83,7 +84,7 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
83
84
|
|
|
84
85
|
async start (): Promise<void> {
|
|
85
86
|
await this.components.registrar.handle(SIGNALING_PROTO_ID, (data: IncomingStreamData) => {
|
|
86
|
-
this._onProtocol(data).catch(err => { log.error('failed to handle incoming connect from %p', data.connection.remotePeer, err) })
|
|
87
|
+
this._onProtocol(data).catch(err => { this.log.error('failed to handle incoming connect from %p', data.connection.remotePeer, err) })
|
|
87
88
|
}, {
|
|
88
89
|
runOnTransientConnection: true
|
|
89
90
|
})
|
|
@@ -118,10 +119,10 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
118
119
|
* <relay address>/p2p/<relay-peer>/p2p-circuit/webrtc/p2p/<destination-peer>
|
|
119
120
|
*/
|
|
120
121
|
async dial (ma: Multiaddr, options: DialOptions): Promise<Connection> {
|
|
121
|
-
log.trace('dialing address: %a', ma)
|
|
122
|
+
this.log.trace('dialing address: %a', ma)
|
|
122
123
|
|
|
123
124
|
const peerConnection = new RTCPeerConnection(this.init.rtcConfiguration)
|
|
124
|
-
const muxerFactory = new DataChannelMuxerFactory({
|
|
125
|
+
const muxerFactory = new DataChannelMuxerFactory(this.components, {
|
|
125
126
|
peerConnection,
|
|
126
127
|
dataChannelOptions: this.init.dataChannel
|
|
127
128
|
})
|
|
@@ -132,10 +133,11 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
132
133
|
dataChannelOptions: this.init.dataChannel,
|
|
133
134
|
signal: options.signal,
|
|
134
135
|
connectionManager: this.components.connectionManager,
|
|
135
|
-
transportManager: this.components.transportManager
|
|
136
|
+
transportManager: this.components.transportManager,
|
|
137
|
+
log: this.log
|
|
136
138
|
})
|
|
137
139
|
|
|
138
|
-
const webRTCConn = new WebRTCMultiaddrConnection({
|
|
140
|
+
const webRTCConn = new WebRTCMultiaddrConnection(this.components, {
|
|
139
141
|
peerConnection,
|
|
140
142
|
timeline: { open: Date.now() },
|
|
141
143
|
remoteAddr: remoteAddress,
|
|
@@ -157,7 +159,7 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
157
159
|
async _onProtocol ({ connection, stream }: IncomingStreamData): Promise<void> {
|
|
158
160
|
const signal = AbortSignal.timeout(this.init.inboundConnectionTimeout ?? INBOUND_CONNECTION_TIMEOUT)
|
|
159
161
|
const peerConnection = new RTCPeerConnection(this.init.rtcConfiguration)
|
|
160
|
-
const muxerFactory = new DataChannelMuxerFactory({
|
|
162
|
+
const muxerFactory = new DataChannelMuxerFactory(this.components, {
|
|
161
163
|
peerConnection,
|
|
162
164
|
dataChannelOptions: this.init.dataChannel
|
|
163
165
|
})
|
|
@@ -167,10 +169,11 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
167
169
|
peerConnection,
|
|
168
170
|
connection,
|
|
169
171
|
stream,
|
|
170
|
-
signal
|
|
172
|
+
signal,
|
|
173
|
+
log: this.log
|
|
171
174
|
})
|
|
172
175
|
|
|
173
|
-
const webRTCConn = new WebRTCMultiaddrConnection({
|
|
176
|
+
const webRTCConn = new WebRTCMultiaddrConnection(this.components, {
|
|
174
177
|
peerConnection,
|
|
175
178
|
timeline: { open: (new Date()).getTime() },
|
|
176
179
|
remoteAddr: remoteAddress,
|
|
@@ -201,7 +204,7 @@ export class WebRTCTransport implements Transport, Startable {
|
|
|
201
204
|
const shutDownListener = (): void => {
|
|
202
205
|
webRTCConn.close()
|
|
203
206
|
.catch(err => {
|
|
204
|
-
log.error('could not close WebRTCMultiaddrConnection', err)
|
|
207
|
+
this.log.error('could not close WebRTCMultiaddrConnection', err)
|
|
205
208
|
})
|
|
206
209
|
}
|
|
207
210
|
|