@libp2p/webrtc 1.1.11 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +2 -2
- package/dist/src/maconn.d.ts +9 -0
- package/dist/src/maconn.d.ts.map +1 -1
- package/dist/src/maconn.js +5 -0
- package/dist/src/maconn.js.map +1 -1
- package/dist/src/muxer.d.ts +12 -2
- package/dist/src/muxer.d.ts.map +1 -1
- package/dist/src/muxer.js +16 -4
- package/dist/src/muxer.js.map +1 -1
- package/dist/src/transport.d.ts +6 -3
- package/dist/src/transport.d.ts.map +1 -1
- package/dist/src/transport.js +17 -5
- package/dist/src/transport.js.map +1 -1
- package/package.json +6 -4
- package/src/maconn.ts +12 -1
- package/src/muxer.ts +23 -4
- package/src/transport.ts +24 -6
package/dist/src/maconn.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface-connection';
|
|
2
|
+
import type { CounterGroup } from '@libp2p/interface-metrics';
|
|
2
3
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
4
|
import type { Source, Sink } from 'it-stream-types';
|
|
4
5
|
interface WebRTCMultiaddrConnectionInit {
|
|
@@ -14,6 +15,10 @@ interface WebRTCMultiaddrConnectionInit {
|
|
|
14
15
|
* Holds the relevant events timestamps of the connection
|
|
15
16
|
*/
|
|
16
17
|
timeline: MultiaddrConnectionTimeline;
|
|
18
|
+
/**
|
|
19
|
+
* Optional metrics counter group for this connection
|
|
20
|
+
*/
|
|
21
|
+
metrics?: CounterGroup;
|
|
17
22
|
}
|
|
18
23
|
export declare class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
19
24
|
/**
|
|
@@ -28,6 +33,10 @@ export declare class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
28
33
|
* Holds the lifecycle times of the connection
|
|
29
34
|
*/
|
|
30
35
|
timeline: MultiaddrConnectionTimeline;
|
|
36
|
+
/**
|
|
37
|
+
* Optional metrics counter group for this connection
|
|
38
|
+
*/
|
|
39
|
+
metrics?: CounterGroup;
|
|
31
40
|
/**
|
|
32
41
|
* The stream source, a no-op as the transport natively supports multiplexing
|
|
33
42
|
*/
|
package/dist/src/maconn.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maconn.d.ts","sourceRoot":"","sources":["../../src/maconn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AACpG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAInD,UAAU,6BAA6B;IACrC;;OAEG;IACH,cAAc,EAAE,iBAAiB,CAAA;IAEjC;;OAEG;IACH,UAAU,EAAE,SAAS,CAAA;IAErB;;OAEG;IACH,QAAQ,EAAE,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"maconn.d.ts","sourceRoot":"","sources":["../../src/maconn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,MAAM,8BAA8B,CAAA;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAInD,UAAU,6BAA6B;IACrC;;OAEG;IACH,cAAc,EAAE,iBAAiB,CAAA;IAEjC;;OAEG;IACH,UAAU,EAAE,SAAS,CAAA;IAErB;;OAEG;IACH,QAAQ,EAAE,2BAA2B,CAAA;IAErC;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED,qBAAa,yBAA0B,YAAW,mBAAmB;IACnE;;OAEG;IACH,QAAQ,CAAC,cAAc,EAAE,iBAAiB,CAAA;IAE1C;;OAEG;IACH,UAAU,EAAE,SAAS,CAAA;IAErB;;OAEG;IACH,QAAQ,EAAE,2BAA2B,CAAA;IAErC;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAA;IAEtB;;OAEG;IACH,MAAM,EAAE,cAAc,CAAC,UAAU,EAAE,GAAG,EAAE,OAAO,CAAC,CAAc;IAE9D;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAU;gBAE1C,IAAI,EAAE,6BAA6B;IAM1C,KAAK,CAAE,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;CAUrD"}
|
package/dist/src/maconn.js
CHANGED
|
@@ -14,6 +14,10 @@ export class WebRTCMultiaddrConnection {
|
|
|
14
14
|
* Holds the lifecycle times of the connection
|
|
15
15
|
*/
|
|
16
16
|
timeline;
|
|
17
|
+
/**
|
|
18
|
+
* Optional metrics counter group for this connection
|
|
19
|
+
*/
|
|
20
|
+
metrics;
|
|
17
21
|
/**
|
|
18
22
|
* The stream source, a no-op as the transport natively supports multiplexing
|
|
19
23
|
*/
|
|
@@ -34,6 +38,7 @@ export class WebRTCMultiaddrConnection {
|
|
|
34
38
|
log.trace('closing connection');
|
|
35
39
|
this.timeline.close = Date.now();
|
|
36
40
|
this.peerConnection.close();
|
|
41
|
+
this.metrics?.increment({ close: true });
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
//# sourceMappingURL=maconn.js.map
|
package/dist/src/maconn.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"maconn.js","sourceRoot":"","sources":["../../src/maconn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"maconn.js","sourceRoot":"","sources":["../../src/maconn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAM9C,MAAM,GAAG,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAA;AAwB9C,MAAM,OAAO,yBAAyB;IACpC;;OAEG;IACM,cAAc,CAAmB;IAE1C;;OAEG;IACH,UAAU,CAAW;IAErB;;OAEG;IACH,QAAQ,CAA6B;IAErC;;OAEG;IACH,OAAO,CAAe;IAEtB;;OAEG;IACH,MAAM,GAA6C,SAAS,EAAE,CAAA;IAE9D;;OAEG;IACH,IAAI,GAA4C,OAAO,CAAA;IAEvD,YAAa,IAAmC;QAC9C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAA;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;QAC7B,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,KAAK,CAAE,GAAuB;QAClC,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,GAAG,CAAC,KAAK,CAAC,0BAA0B,EAAE,GAAG,CAAC,CAAA;SAC3C;QACD,GAAG,CAAC,KAAK,CAAC,oBAAoB,CAAC,CAAA;QAE/B,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAChC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAA;QAC3B,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAC1C,CAAC;CACF"}
|
package/dist/src/muxer.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { Stream } from '@libp2p/interface-connection';
|
|
2
|
+
import type { CounterGroup } from '@libp2p/interface-metrics';
|
|
2
3
|
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer';
|
|
3
4
|
import type { Source, Sink } from 'it-stream-types';
|
|
4
5
|
import type { Uint8ArrayList } from 'uint8arraylist';
|
|
6
|
+
export interface DataChannelMuxerFactoryInit {
|
|
7
|
+
peerConnection: RTCPeerConnection;
|
|
8
|
+
metrics?: CounterGroup;
|
|
9
|
+
}
|
|
5
10
|
export declare class DataChannelMuxerFactory implements StreamMuxerFactory {
|
|
6
11
|
readonly protocol: string;
|
|
7
12
|
/**
|
|
@@ -9,7 +14,8 @@ export declare class DataChannelMuxerFactory implements StreamMuxerFactory {
|
|
|
9
14
|
*/
|
|
10
15
|
private readonly peerConnection;
|
|
11
16
|
private streamBuffer;
|
|
12
|
-
|
|
17
|
+
private readonly metrics?;
|
|
18
|
+
constructor(peerConnection: RTCPeerConnection, metrics?: CounterGroup, protocol?: string);
|
|
13
19
|
createStreamMuxer(init?: StreamMuxerInit | undefined): StreamMuxer;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
@@ -21,6 +27,10 @@ export declare class DataChannelMuxer implements StreamMuxer {
|
|
|
21
27
|
* WebRTC Peer Connection
|
|
22
28
|
*/
|
|
23
29
|
private readonly peerConnection;
|
|
30
|
+
/**
|
|
31
|
+
* Optional metrics for this data channel muxer
|
|
32
|
+
*/
|
|
33
|
+
private readonly metrics?;
|
|
24
34
|
/**
|
|
25
35
|
* Array of streams in the data channel
|
|
26
36
|
*/
|
|
@@ -41,7 +51,7 @@ export declare class DataChannelMuxer implements StreamMuxer {
|
|
|
41
51
|
* The stream destination, a no-op as the transport natively supports multiplexing
|
|
42
52
|
*/
|
|
43
53
|
sink: Sink<Source<Uint8Array | Uint8ArrayList>, Promise<void>>;
|
|
44
|
-
constructor(peerConnection: RTCPeerConnection, streams: Stream[], protocol?: string, init?: StreamMuxerInit);
|
|
54
|
+
constructor(peerConnection: RTCPeerConnection, streams: Stream[], protocol?: string, init?: StreamMuxerInit, metrics?: CounterGroup);
|
|
45
55
|
newStream(): Stream;
|
|
46
56
|
private wrapStreamEnd;
|
|
47
57
|
}
|
package/dist/src/muxer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"muxer.d.ts","sourceRoot":"","sources":["../../src/muxer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AACtG,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,qBAAa,uBAAwB,YAAW,kBAAkB;
|
|
1
|
+
{"version":3,"file":"muxer.d.ts","sourceRoot":"","sources":["../../src/muxer.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AACtG,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAEpD,MAAM,WAAW,2BAA2B;IAC1C,cAAc,EAAE,iBAAiB,CAAA;IACjC,OAAO,CAAC,EAAE,YAAY,CAAA;CACvB;AAED,qBAAa,uBAAwB,YAAW,kBAAkB;IAQQ,QAAQ,CAAC,QAAQ;IAPzF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmB;IAClD,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAc;gBAE1B,cAAc,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,YAAY,EAAW,QAAQ,SAAY;IAmBrG,iBAAiB,CAAE,IAAI,CAAC,EAAE,eAAe,GAAG,SAAS,GAAG,WAAW;CAGpE;AAED;;GAEG;AACH,qBAAa,gBAAiB,YAAW,WAAW;IAoCiB,QAAQ,CAAC,QAAQ,EAAE,MAAM;IAnC5F;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmB;IAElD;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAc;IAEvC;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAK;IAEtB;;OAEG;IACH,IAAI,CAAC,EAAE,eAAe,CAAA;IAEtB;;OAEG;IACH,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAY;IAEpD;;OAEG;IACH,MAAM,EAAE,cAAc,CAAC,UAAU,EAAE,GAAG,EAAE,OAAO,CAAC,CAAc;IAE9D;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,GAAG,cAAc,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAU;gBAE3D,cAAc,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAW,QAAQ,GAAE,MAAkB,EAAE,IAAI,CAAC,EAAE,eAAe,EAAE,OAAO,CAAC,EAAE,YAAY;IAiDxJ,SAAS,IAAK,MAAM;IAuBpB,OAAO,CAAC,aAAa;CAStB"}
|
package/dist/src/muxer.js
CHANGED
|
@@ -7,7 +7,8 @@ export class DataChannelMuxerFactory {
|
|
|
7
7
|
*/
|
|
8
8
|
peerConnection;
|
|
9
9
|
streamBuffer = [];
|
|
10
|
-
|
|
10
|
+
metrics;
|
|
11
|
+
constructor(peerConnection, metrics, protocol = '/webrtc') {
|
|
11
12
|
this.protocol = protocol;
|
|
12
13
|
this.peerConnection = peerConnection;
|
|
13
14
|
// store any datachannels opened before upgrade has been completed
|
|
@@ -24,9 +25,10 @@ export class DataChannelMuxerFactory {
|
|
|
24
25
|
});
|
|
25
26
|
this.streamBuffer.push(stream);
|
|
26
27
|
};
|
|
28
|
+
this.metrics = metrics;
|
|
27
29
|
}
|
|
28
30
|
createStreamMuxer(init) {
|
|
29
|
-
return new DataChannelMuxer(this.peerConnection, this.streamBuffer, this.protocol, init);
|
|
31
|
+
return new DataChannelMuxer(this.peerConnection, this.streamBuffer, this.protocol, init, this.metrics);
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
@@ -38,6 +40,10 @@ export class DataChannelMuxer {
|
|
|
38
40
|
* WebRTC Peer Connection
|
|
39
41
|
*/
|
|
40
42
|
peerConnection;
|
|
43
|
+
/**
|
|
44
|
+
* Optional metrics for this data channel muxer
|
|
45
|
+
*/
|
|
46
|
+
metrics;
|
|
41
47
|
/**
|
|
42
48
|
* Array of streams in the data channel
|
|
43
49
|
*/
|
|
@@ -58,7 +64,7 @@ export class DataChannelMuxer {
|
|
|
58
64
|
* The stream destination, a no-op as the transport natively supports multiplexing
|
|
59
65
|
*/
|
|
60
66
|
sink = nopSink;
|
|
61
|
-
constructor(peerConnection, streams, protocol = '/webrtc', init) {
|
|
67
|
+
constructor(peerConnection, streams, protocol = '/webrtc', init, metrics) {
|
|
62
68
|
this.protocol = protocol;
|
|
63
69
|
/**
|
|
64
70
|
* Initialized stream muxer
|
|
@@ -87,6 +93,7 @@ export class DataChannelMuxer {
|
|
|
87
93
|
});
|
|
88
94
|
this.streams.push(stream);
|
|
89
95
|
if ((init?.onIncomingStream) != null) {
|
|
96
|
+
this.metrics?.increment({ incoming_stream: true });
|
|
90
97
|
init.onIncomingStream(stream);
|
|
91
98
|
}
|
|
92
99
|
};
|
|
@@ -105,6 +112,10 @@ export class DataChannelMuxer {
|
|
|
105
112
|
newStream() {
|
|
106
113
|
// The spec says the label SHOULD be an empty string: https://github.com/libp2p/specs/blob/master/webrtc/README.md#rtcdatachannel-label
|
|
107
114
|
const channel = this.peerConnection.createDataChannel('');
|
|
115
|
+
const closeCb = (stream) => {
|
|
116
|
+
this.metrics?.increment({ stream_end: true });
|
|
117
|
+
this.init?.onStreamEnd?.(stream);
|
|
118
|
+
};
|
|
108
119
|
const stream = new WebRTCStream({
|
|
109
120
|
channel,
|
|
110
121
|
stat: {
|
|
@@ -113,9 +124,10 @@ export class DataChannelMuxer {
|
|
|
113
124
|
open: 0
|
|
114
125
|
}
|
|
115
126
|
},
|
|
116
|
-
closeCb: this.wrapStreamEnd(
|
|
127
|
+
closeCb: this.wrapStreamEnd(closeCb)
|
|
117
128
|
});
|
|
118
129
|
this.streams.push(stream);
|
|
130
|
+
this.metrics?.increment({ outgoing_stream: true });
|
|
119
131
|
return stream;
|
|
120
132
|
}
|
|
121
133
|
wrapStreamEnd(onStreamEnd) {
|
package/dist/src/muxer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"muxer.js","sourceRoot":"","sources":["../../src/muxer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"muxer.js","sourceRoot":"","sources":["../../src/muxer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAY9C,MAAM,OAAO,uBAAuB;IAQ+C;IAPjF;;OAEG;IACc,cAAc,CAAmB;IAC1C,YAAY,GAAmB,EAAE,CAAA;IACxB,OAAO,CAAe;IAEvC,YAAa,cAAiC,EAAE,OAAsB,EAAW,WAAW,SAAS;QAApB,aAAQ,GAAR,QAAQ,CAAY;QACnG,IAAI,CAAC,cAAc,GAAG,cAAc,CAA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-1,6 +1,7 @@
|
|
|
1
1
|
import { type CreateListenerOptions, type Listener, symbol, type Transport } from '@libp2p/interface-transport';
|
|
2
2
|
import type { WebRTCDialOptions } from './options.js';
|
|
3
3
|
import type { Connection } from '@libp2p/interface-connection';
|
|
4
|
+
import type { CounterGroup, Metrics } from '@libp2p/interface-metrics';
|
|
4
5
|
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
5
6
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
6
7
|
/**
|
|
@@ -20,11 +21,13 @@ export declare const CERTHASH_CODE: number;
|
|
|
20
21
|
*/
|
|
21
22
|
export interface WebRTCDirectTransportComponents {
|
|
22
23
|
peerId: PeerId;
|
|
24
|
+
metrics?: Metrics;
|
|
25
|
+
}
|
|
26
|
+
export interface WebRTCMetrics {
|
|
27
|
+
dialerEvents: CounterGroup;
|
|
23
28
|
}
|
|
24
29
|
export declare class WebRTCDirectTransport implements Transport {
|
|
25
|
-
|
|
26
|
-
* The peer for this transport
|
|
27
|
-
*/
|
|
30
|
+
private readonly metrics?;
|
|
28
31
|
private readonly components;
|
|
29
32
|
constructor(components: WebRTCDirectTransportComponents);
|
|
30
33
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,QAAQ,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAc/G,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AASxD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,MAAwC,CAAA;AAElE;;;;GA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I7C;;OAEG;IACH,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,2BAA0B;IAEvD;;OAEG;IACH,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAO;IAExB;;OAEG;IACG,QAAQ,CAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;IA0I/E;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CAkB9B"}
|
package/dist/src/transport.js
CHANGED
|
@@ -31,12 +31,18 @@ export const WEBRTC_CODE = protocols('webrtc-direct').code;
|
|
|
31
31
|
*/
|
|
32
32
|
export const CERTHASH_CODE = protocols('certhash').code;
|
|
33
33
|
export class WebRTCDirectTransport {
|
|
34
|
-
|
|
35
|
-
* The peer for this transport
|
|
36
|
-
*/
|
|
34
|
+
metrics;
|
|
37
35
|
components;
|
|
38
36
|
constructor(components) {
|
|
39
37
|
this.components = components;
|
|
38
|
+
if (components.metrics != null) {
|
|
39
|
+
this.metrics = {
|
|
40
|
+
dialerEvents: components.metrics.registerCounterGroup('libp2p_webrtc_dialer_events_total', {
|
|
41
|
+
label: 'event',
|
|
42
|
+
help: 'Total count of WebRTC dial events by type'
|
|
43
|
+
})
|
|
44
|
+
};
|
|
45
|
+
}
|
|
40
46
|
}
|
|
41
47
|
/**
|
|
42
48
|
* Dial a given multiaddr
|
|
@@ -96,6 +102,7 @@ export class WebRTCDirectTransport {
|
|
|
96
102
|
const handshakeTimeout = setTimeout(() => {
|
|
97
103
|
const error = `Data channel was never opened: state: ${handshakeDataChannel.readyState}`;
|
|
98
104
|
log.error(error);
|
|
105
|
+
this.metrics?.dialerEvents.increment({ open_error: true });
|
|
99
106
|
reject(dataChannelError('data', error));
|
|
100
107
|
}, HANDSHAKE_TIMEOUT_MS);
|
|
101
108
|
handshakeDataChannel.onopen = (_) => {
|
|
@@ -108,6 +115,8 @@ export class WebRTCDirectTransport {
|
|
|
108
115
|
const errorTarget = event.target?.toString() ?? 'not specified';
|
|
109
116
|
const error = `Error opening a data channel for handshaking: ${errorTarget}`;
|
|
110
117
|
log.error(error);
|
|
118
|
+
// NOTE: We use unknown error here but this could potentially be considered a reset by some standards.
|
|
119
|
+
this.metrics?.dialerEvents.increment({ unknown_error: true });
|
|
111
120
|
reject(dataChannelError('data', error));
|
|
112
121
|
};
|
|
113
122
|
});
|
|
@@ -153,7 +162,8 @@ export class WebRTCDirectTransport {
|
|
|
153
162
|
remoteAddr: ma,
|
|
154
163
|
timeline: {
|
|
155
164
|
open: Date.now()
|
|
156
|
-
}
|
|
165
|
+
},
|
|
166
|
+
metrics: this.metrics?.dialerEvents
|
|
157
167
|
});
|
|
158
168
|
const eventListeningName = isFirefox ? 'iceconnectionstatechange' : 'connectionstatechange';
|
|
159
169
|
peerConnection.addEventListener(eventListeningName, () => {
|
|
@@ -172,7 +182,9 @@ export class WebRTCDirectTransport {
|
|
|
172
182
|
break;
|
|
173
183
|
}
|
|
174
184
|
}, { signal });
|
|
175
|
-
|
|
185
|
+
// Track opened peer connection
|
|
186
|
+
this.metrics?.dialerEvents.increment({ peer_connection: true });
|
|
187
|
+
const muxerFactory = new DataChannelMuxerFactory(peerConnection, this.metrics?.dialerEvents);
|
|
176
188
|
// For outbound connections, the remote is expected to start the noise handshake.
|
|
177
189
|
// Therefore, we need to secure an inbound noise connection from the remote.
|
|
178
190
|
await noise.secureInbound(myPeerId, wrappedDuplex, theirPeerId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAA6C,MAAM,EAAkB,MAAM,6BAA6B,CAAA;AAC/G,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,CAAC,MAAM,iBAAiB,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAy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AAa,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,CAAA;AACjJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/webrtc",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A libp2p transport using WebRTC connections",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
|
@@ -133,12 +133,13 @@
|
|
|
133
133
|
"lint": "aegir lint",
|
|
134
134
|
"lint:fix": "aegir lint --fix",
|
|
135
135
|
"clean": "aegir clean",
|
|
136
|
-
"dep-check": "aegir dep-check",
|
|
136
|
+
"dep-check": "aegir dep-check -i protons",
|
|
137
137
|
"release": "aegir release"
|
|
138
138
|
},
|
|
139
139
|
"dependencies": {
|
|
140
140
|
"@chainsafe/libp2p-noise": "^11.0.4",
|
|
141
141
|
"@libp2p/interface-connection": "^5.0.2",
|
|
142
|
+
"@libp2p/interface-metrics": "^4.0.8",
|
|
142
143
|
"@libp2p/interface-peer-id": "^2.0.2",
|
|
143
144
|
"@libp2p/interface-peer-store": "^2.0.2",
|
|
144
145
|
"@libp2p/interface-registrar": "^2.0.12",
|
|
@@ -169,10 +170,11 @@
|
|
|
169
170
|
"@libp2p/peer-id-factory": "^2.0.3",
|
|
170
171
|
"@protobuf-ts/protoc": "^2.9.0",
|
|
171
172
|
"@types/sinon": "^10.0.14",
|
|
172
|
-
"aegir": "^39.0.
|
|
173
|
+
"aegir": "^39.0.6",
|
|
173
174
|
"eslint-plugin-etc": "^2.0.2",
|
|
174
175
|
"it-pair": "^2.0.6",
|
|
175
176
|
"protons": "^7.0.2",
|
|
176
|
-
"sinon": "^15.0.4"
|
|
177
|
+
"sinon": "^15.0.4",
|
|
178
|
+
"sinon-ts": "^1.0.0"
|
|
177
179
|
}
|
|
178
180
|
}
|
package/src/maconn.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import { nopSink, nopSource } from './util.js'
|
|
3
3
|
import type { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface-connection'
|
|
4
|
+
import type { CounterGroup } from '@libp2p/interface-metrics'
|
|
4
5
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
5
6
|
import type { Source, Sink } from 'it-stream-types'
|
|
6
7
|
|
|
@@ -21,6 +22,11 @@ interface WebRTCMultiaddrConnectionInit {
|
|
|
21
22
|
* Holds the relevant events timestamps of the connection
|
|
22
23
|
*/
|
|
23
24
|
timeline: MultiaddrConnectionTimeline
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Optional metrics counter group for this connection
|
|
28
|
+
*/
|
|
29
|
+
metrics?: CounterGroup
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
@@ -39,6 +45,11 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
39
45
|
*/
|
|
40
46
|
timeline: MultiaddrConnectionTimeline
|
|
41
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Optional metrics counter group for this connection
|
|
50
|
+
*/
|
|
51
|
+
metrics?: CounterGroup
|
|
52
|
+
|
|
42
53
|
/**
|
|
43
54
|
* The stream source, a no-op as the transport natively supports multiplexing
|
|
44
55
|
*/
|
|
@@ -59,10 +70,10 @@ export class WebRTCMultiaddrConnection implements MultiaddrConnection {
|
|
|
59
70
|
if (err !== undefined) {
|
|
60
71
|
log.error('error closing connection', err)
|
|
61
72
|
}
|
|
62
|
-
|
|
63
73
|
log.trace('closing connection')
|
|
64
74
|
|
|
65
75
|
this.timeline.close = Date.now()
|
|
66
76
|
this.peerConnection.close()
|
|
77
|
+
this.metrics?.increment({ close: true })
|
|
67
78
|
}
|
|
68
79
|
}
|
package/src/muxer.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { WebRTCStream } from './stream.js'
|
|
2
2
|
import { nopSink, nopSource } from './util.js'
|
|
3
3
|
import type { Stream } from '@libp2p/interface-connection'
|
|
4
|
+
import type { CounterGroup } from '@libp2p/interface-metrics'
|
|
4
5
|
import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface-stream-muxer'
|
|
5
6
|
import type { Source, Sink } from 'it-stream-types'
|
|
6
7
|
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
7
8
|
|
|
9
|
+
export interface DataChannelMuxerFactoryInit {
|
|
10
|
+
peerConnection: RTCPeerConnection
|
|
11
|
+
metrics?: CounterGroup
|
|
12
|
+
}
|
|
13
|
+
|
|
8
14
|
export class DataChannelMuxerFactory implements StreamMuxerFactory {
|
|
9
15
|
/**
|
|
10
16
|
* WebRTC Peer Connection
|
|
11
17
|
*/
|
|
12
18
|
private readonly peerConnection: RTCPeerConnection
|
|
13
19
|
private streamBuffer: WebRTCStream[] = []
|
|
20
|
+
private readonly metrics?: CounterGroup
|
|
14
21
|
|
|
15
|
-
constructor (peerConnection: RTCPeerConnection, readonly protocol = '/webrtc') {
|
|
22
|
+
constructor (peerConnection: RTCPeerConnection, metrics?: CounterGroup, readonly protocol = '/webrtc') {
|
|
16
23
|
this.peerConnection = peerConnection
|
|
17
24
|
// store any datachannels opened before upgrade has been completed
|
|
18
25
|
this.peerConnection.ondatachannel = ({ channel }) => {
|
|
@@ -28,10 +35,11 @@ export class DataChannelMuxerFactory implements StreamMuxerFactory {
|
|
|
28
35
|
})
|
|
29
36
|
this.streamBuffer.push(stream)
|
|
30
37
|
}
|
|
38
|
+
this.metrics = metrics
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
createStreamMuxer (init?: StreamMuxerInit | undefined): StreamMuxer {
|
|
34
|
-
return new DataChannelMuxer(this.peerConnection, this.streamBuffer, this.protocol, init)
|
|
42
|
+
return new DataChannelMuxer(this.peerConnection, this.streamBuffer, this.protocol, init, this.metrics)
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
|
|
@@ -44,6 +52,11 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
44
52
|
*/
|
|
45
53
|
private readonly peerConnection: RTCPeerConnection
|
|
46
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Optional metrics for this data channel muxer
|
|
57
|
+
*/
|
|
58
|
+
private readonly metrics?: CounterGroup
|
|
59
|
+
|
|
47
60
|
/**
|
|
48
61
|
* Array of streams in the data channel
|
|
49
62
|
*/
|
|
@@ -69,7 +82,7 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
69
82
|
*/
|
|
70
83
|
sink: Sink<Source<Uint8Array | Uint8ArrayList>, Promise<void>> = nopSink
|
|
71
84
|
|
|
72
|
-
constructor (peerConnection: RTCPeerConnection, streams: Stream[], readonly protocol = '/webrtc', init?: StreamMuxerInit) {
|
|
85
|
+
constructor (peerConnection: RTCPeerConnection, streams: Stream[], readonly protocol: string = '/webrtc', init?: StreamMuxerInit, metrics?: CounterGroup) {
|
|
73
86
|
/**
|
|
74
87
|
* Initialized stream muxer
|
|
75
88
|
*/
|
|
@@ -100,6 +113,7 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
100
113
|
|
|
101
114
|
this.streams.push(stream)
|
|
102
115
|
if ((init?.onIncomingStream) != null) {
|
|
116
|
+
this.metrics?.increment({ incoming_stream: true })
|
|
103
117
|
init.onIncomingStream(stream)
|
|
104
118
|
}
|
|
105
119
|
}
|
|
@@ -120,6 +134,10 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
120
134
|
newStream (): Stream {
|
|
121
135
|
// The spec says the label SHOULD be an empty string: https://github.com/libp2p/specs/blob/master/webrtc/README.md#rtcdatachannel-label
|
|
122
136
|
const channel = this.peerConnection.createDataChannel('')
|
|
137
|
+
const closeCb = (stream: Stream): void => {
|
|
138
|
+
this.metrics?.increment({ stream_end: true })
|
|
139
|
+
this.init?.onStreamEnd?.(stream)
|
|
140
|
+
}
|
|
123
141
|
const stream = new WebRTCStream({
|
|
124
142
|
channel,
|
|
125
143
|
stat: {
|
|
@@ -128,9 +146,10 @@ export class DataChannelMuxer implements StreamMuxer {
|
|
|
128
146
|
open: 0
|
|
129
147
|
}
|
|
130
148
|
},
|
|
131
|
-
closeCb: this.wrapStreamEnd(
|
|
149
|
+
closeCb: this.wrapStreamEnd(closeCb)
|
|
132
150
|
})
|
|
133
151
|
this.streams.push(stream)
|
|
152
|
+
this.metrics?.increment({ outgoing_stream: true })
|
|
134
153
|
|
|
135
154
|
return stream
|
|
136
155
|
}
|
package/src/transport.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { WebRTCStream } from './stream.js'
|
|
|
15
15
|
import { genUfrag } from './util.js'
|
|
16
16
|
import type { WebRTCDialOptions } from './options.js'
|
|
17
17
|
import type { Connection } from '@libp2p/interface-connection'
|
|
18
|
+
import type { CounterGroup, Metrics } from '@libp2p/interface-metrics'
|
|
18
19
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
19
20
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
20
21
|
|
|
@@ -42,19 +43,29 @@ export const CERTHASH_CODE: number = protocols('certhash').code
|
|
|
42
43
|
/**
|
|
43
44
|
* The peer for this transport
|
|
44
45
|
*/
|
|
45
|
-
// @TODO(ddimaria): seems like an unnessary abstraction, consider removing
|
|
46
46
|
export interface WebRTCDirectTransportComponents {
|
|
47
47
|
peerId: PeerId
|
|
48
|
+
metrics?: Metrics
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface WebRTCMetrics {
|
|
52
|
+
dialerEvents: CounterGroup
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export class WebRTCDirectTransport implements Transport {
|
|
51
|
-
|
|
52
|
-
* The peer for this transport
|
|
53
|
-
*/
|
|
56
|
+
private readonly metrics?: WebRTCMetrics
|
|
54
57
|
private readonly components: WebRTCDirectTransportComponents
|
|
55
58
|
|
|
56
59
|
constructor (components: WebRTCDirectTransportComponents) {
|
|
57
60
|
this.components = components
|
|
61
|
+
if (components.metrics != null) {
|
|
62
|
+
this.metrics = {
|
|
63
|
+
dialerEvents: components.metrics.registerCounterGroup('libp2p_webrtc_dialer_events_total', {
|
|
64
|
+
label: 'event',
|
|
65
|
+
help: 'Total count of WebRTC dial events by type'
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
/**
|
|
@@ -125,6 +136,7 @@ export class WebRTCDirectTransport implements Transport {
|
|
|
125
136
|
const handshakeTimeout = setTimeout(() => {
|
|
126
137
|
const error = `Data channel was never opened: state: ${handshakeDataChannel.readyState}`
|
|
127
138
|
log.error(error)
|
|
139
|
+
this.metrics?.dialerEvents.increment({ open_error: true })
|
|
128
140
|
reject(dataChannelError('data', error))
|
|
129
141
|
}, HANDSHAKE_TIMEOUT_MS)
|
|
130
142
|
|
|
@@ -139,6 +151,8 @@ export class WebRTCDirectTransport implements Transport {
|
|
|
139
151
|
const errorTarget = event.target?.toString() ?? 'not specified'
|
|
140
152
|
const error = `Error opening a data channel for handshaking: ${errorTarget}`
|
|
141
153
|
log.error(error)
|
|
154
|
+
// NOTE: We use unknown error here but this could potentially be considered a reset by some standards.
|
|
155
|
+
this.metrics?.dialerEvents.increment({ unknown_error: true })
|
|
142
156
|
reject(dataChannelError('data', error))
|
|
143
157
|
}
|
|
144
158
|
})
|
|
@@ -193,7 +207,8 @@ export class WebRTCDirectTransport implements Transport {
|
|
|
193
207
|
remoteAddr: ma,
|
|
194
208
|
timeline: {
|
|
195
209
|
open: Date.now()
|
|
196
|
-
}
|
|
210
|
+
},
|
|
211
|
+
metrics: this.metrics?.dialerEvents
|
|
197
212
|
})
|
|
198
213
|
|
|
199
214
|
const eventListeningName = isFirefox ? 'iceconnectionstatechange' : 'connectionstatechange'
|
|
@@ -215,7 +230,10 @@ export class WebRTCDirectTransport implements Transport {
|
|
|
215
230
|
}
|
|
216
231
|
}, { signal })
|
|
217
232
|
|
|
218
|
-
|
|
233
|
+
// Track opened peer connection
|
|
234
|
+
this.metrics?.dialerEvents.increment({ peer_connection: true })
|
|
235
|
+
|
|
236
|
+
const muxerFactory = new DataChannelMuxerFactory(peerConnection, this.metrics?.dialerEvents)
|
|
219
237
|
|
|
220
238
|
// For outbound connections, the remote is expected to start the noise handshake.
|
|
221
239
|
// Therefore, we need to secure an inbound noise connection from the remote.
|