@libp2p/devtools-metrics 1.0.1 → 1.1.0-7f7ec82ae
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 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +38 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/rpc/index.d.ts +35 -14
- package/dist/src/rpc/index.d.ts.map +1 -1
- package/dist/src/rpc/rpc.d.ts.map +1 -1
- package/dist/src/rpc/rpc.js +22 -2
- package/dist/src/rpc/rpc.js.map +1 -1
- package/dist/src/utils/find-capability.d.ts +2 -0
- package/dist/src/utils/find-capability.d.ts.map +1 -0
- package/dist/src/utils/find-capability.js +9 -0
- package/dist/src/utils/find-capability.js.map +1 -0
- package/dist/src/utils/gather-capabilities.d.ts +2 -0
- package/dist/src/utils/gather-capabilities.d.ts.map +1 -0
- package/dist/src/utils/gather-capabilities.js +12 -0
- package/dist/src/utils/gather-capabilities.js.map +1 -0
- package/dist/src/utils/get-pubsub.d.ts +3 -0
- package/dist/src/utils/get-pubsub.d.ts.map +1 -0
- package/dist/src/utils/get-pubsub.js +9 -0
- package/dist/src/utils/get-pubsub.js.map +1 -0
- package/package.json +9 -8
- package/src/index.ts +48 -2
- package/src/rpc/index.ts +42 -17
- package/src/rpc/rpc.ts +25 -7
- package/src/utils/find-capability.ts +9 -0
- package/src/utils/gather-capabilities.ts +14 -0
- package/src/utils/get-pubsub.ts +12 -0
- package/dist/typedoc-urls.json +0 -50
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;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAeH,OAAO,KAAK,EAAE,eA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;AAEvE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,sBAAsB,GAAG,UAAU,CAAA;AAEjE,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,eAAe,CAAA;IACvB,MAAM,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAA;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,SAAS,EAAE,SAAS,CAAA;IACpB,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,SAAS,EAAE,SAAS,CAAA;IAEpB,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,EAAE,WAAW,CAAA;IACxB,cAAc,EAAE,cAAc,CAAA;CAC/B;AAkND,wBAAgB,eAAe,CAAE,IAAI,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,GAAG,CAAC,UAAU,EAAE,yBAAyB,KAAK,OAAO,CAIxH"}
|
package/dist/src/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* Then use the [DevTools plugin](https://github.com/ipfs-shipyard/js-libp2p-devtools)
|
|
16
16
|
* for Chrome or Firefox to inspect the state of your running node.
|
|
17
17
|
*/
|
|
18
|
-
import { serviceCapabilities, start, stop } from '@libp2p/interface';
|
|
18
|
+
import { isPubSub, serviceCapabilities, start, stop } from '@libp2p/interface';
|
|
19
19
|
import { simpleMetrics } from '@libp2p/simple-metrics';
|
|
20
20
|
import { pipe } from 'it-pipe';
|
|
21
21
|
import { pushable } from 'it-pushable';
|
|
@@ -24,6 +24,7 @@ import { base64 } from 'multiformats/bases/base64';
|
|
|
24
24
|
import { valueCodecs } from './rpc/index.js';
|
|
25
25
|
import { metricsRpc } from './rpc/rpc.js';
|
|
26
26
|
import { debounce } from './utils/debounce.js';
|
|
27
|
+
import { findCapability } from './utils/find-capability.js';
|
|
27
28
|
import { getPeers } from './utils/get-peers.js';
|
|
28
29
|
import { getSelf } from './utils/get-self.js';
|
|
29
30
|
export * from './rpc/index.js';
|
|
@@ -60,6 +61,9 @@ class DevToolsMetrics {
|
|
|
60
61
|
this.onPeersUpdate = debounce(this.onPeersUpdate.bind(this), 1000);
|
|
61
62
|
this.onSelfUpdate = debounce(this.onSelfUpdate.bind(this), 1000);
|
|
62
63
|
this.onIncomingMessage = this.onIncomingMessage.bind(this);
|
|
64
|
+
// relay pubsub messages to dev tools panel
|
|
65
|
+
this.onPubSubMessage = this.onPubSubMessage.bind(this);
|
|
66
|
+
this.onPubSubSubscriptionChange = this.onPubSubSubscriptionChange.bind(this);
|
|
63
67
|
// collect metrics
|
|
64
68
|
this.simpleMetrics = simpleMetrics({
|
|
65
69
|
intervalMs: this.intervalMs,
|
|
@@ -94,6 +98,18 @@ class DevToolsMetrics {
|
|
|
94
98
|
registerCounterGroup(name, options) {
|
|
95
99
|
return this.simpleMetrics.registerCounterGroup(name, options);
|
|
96
100
|
}
|
|
101
|
+
registerHistogram(name, options) {
|
|
102
|
+
return this.simpleMetrics.registerHistogram(name, options);
|
|
103
|
+
}
|
|
104
|
+
registerHistogramGroup(name, options) {
|
|
105
|
+
return this.simpleMetrics.registerHistogramGroup(name, options);
|
|
106
|
+
}
|
|
107
|
+
registerSummary(name, options) {
|
|
108
|
+
return this.simpleMetrics.registerSummary(name, options);
|
|
109
|
+
}
|
|
110
|
+
registerSummaryGroup(name, options) {
|
|
111
|
+
return this.simpleMetrics.registerSummaryGroup(name, options);
|
|
112
|
+
}
|
|
97
113
|
async start() {
|
|
98
114
|
// send peer updates
|
|
99
115
|
this.components.events.addEventListener('peer:connect', this.onPeersUpdate);
|
|
@@ -124,6 +140,11 @@ class DevToolsMetrics {
|
|
|
124
140
|
.catch(err => {
|
|
125
141
|
this.log.error('error while reading RPC messages', err);
|
|
126
142
|
});
|
|
143
|
+
const pubsub = findCapability('@libp2p/pubsub', this.components);
|
|
144
|
+
if (isPubSub(pubsub)) {
|
|
145
|
+
pubsub.addEventListener('message', this.onPubSubMessage);
|
|
146
|
+
pubsub.addEventListener('subscription-change', this.onPubSubSubscriptionChange);
|
|
147
|
+
}
|
|
127
148
|
}
|
|
128
149
|
async stop() {
|
|
129
150
|
window.removeEventListener('message', this.onIncomingMessage);
|
|
@@ -148,6 +169,22 @@ class DevToolsMetrics {
|
|
|
148
169
|
this.rpcQueue.push(base64.decode(message.message));
|
|
149
170
|
}
|
|
150
171
|
}
|
|
172
|
+
onPubSubMessage(event) {
|
|
173
|
+
this.devTools.safeDispatchEvent('pubsub:message', {
|
|
174
|
+
detail: event.detail
|
|
175
|
+
})
|
|
176
|
+
.catch(err => {
|
|
177
|
+
this.log.error('error relaying pubsub message', err);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
onPubSubSubscriptionChange(event) {
|
|
181
|
+
this.devTools.safeDispatchEvent('pubsub:subscription-change', {
|
|
182
|
+
detail: event.detail
|
|
183
|
+
})
|
|
184
|
+
.catch(err => {
|
|
185
|
+
this.log.error('error relaying pubsub subscription change', err);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
151
188
|
onSelfUpdate() {
|
|
152
189
|
Promise.resolve()
|
|
153
190
|
.then(async () => {
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;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G,CAAC,CAAA;QAClE,CAAC,CAAC,CAAA;IACN,CAAC;IAEO,YAAY;QAClB,OAAO,CAAC,OAAO,EAAE;aACd,IAAI,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,MAAM,EAAE;gBAC5C,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;aACvC,CAAC,CAAA;QACJ,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,CAAC,EAAE;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;IACN,CAAC;IAEO,aAAa;QACnB,OAAO,CAAC,OAAO,EAAE;aACd,IAAI,CAAC,KAAK,IAAI,EAAE;YACf,MAAM,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,OAAO,EAAE;gBAC7C,MAAM,EAAE,MAAM,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC;aAClD,CAAC,CAAA;QACJ,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,CAAC,EAAE;YACX,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;QACpD,CAAC,CAAC,CAAA;IACN,CAAC;CACF;AAED,MAAM,UAAU,eAAe,CAAE,IAAmC;IAClE,OAAO,CAAC,UAAU,EAAE,EAAE;QACpB,OAAO,IAAI,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC,CAAA;AACH,CAAC"}
|
package/dist/src/rpc/index.d.ts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
import type { ContentRouting, PeerId, PeerRouting, AbortOptions } from '@libp2p/interface';
|
|
1
|
+
import type { ContentRouting, PeerId, PeerRouting, AbortOptions, PubSubRPCMessage, SubscriptionChangeData } from '@libp2p/interface';
|
|
2
2
|
import type { OpenConnectionOptions } from '@libp2p/interface-internal';
|
|
3
3
|
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
4
4
|
import type { ValueCodec } from 'it-rpc';
|
|
5
5
|
export declare const valueCodecs: Array<ValueCodec<any>>;
|
|
6
|
-
export interface NodeAddress {
|
|
7
|
-
multiaddr: Multiaddr;
|
|
8
|
-
listen?: boolean;
|
|
9
|
-
announce?: boolean;
|
|
10
|
-
observed?: boolean;
|
|
11
|
-
default?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface NodeStatus {
|
|
14
|
-
peerId: PeerId;
|
|
15
|
-
agent?: string;
|
|
16
|
-
addresses: NodeAddress[];
|
|
17
|
-
protocols: string[];
|
|
18
|
-
}
|
|
19
6
|
export interface PeerAddress {
|
|
20
7
|
multiaddr: Multiaddr;
|
|
21
8
|
isConnected?: boolean;
|
|
@@ -54,6 +41,7 @@ export interface MetricsRPC {
|
|
|
54
41
|
self: Peer;
|
|
55
42
|
peers: Peer[];
|
|
56
43
|
debug: string;
|
|
44
|
+
capabilities: Record<string, string[]>;
|
|
57
45
|
}>;
|
|
58
46
|
/**
|
|
59
47
|
* Update the currently active debugging namespaces
|
|
@@ -75,6 +63,31 @@ export interface MetricsRPC {
|
|
|
75
63
|
* Make peer routing queries
|
|
76
64
|
*/
|
|
77
65
|
peerRouting: PeerRouting;
|
|
66
|
+
/**
|
|
67
|
+
* PubSub operations
|
|
68
|
+
*/
|
|
69
|
+
pubsub: {
|
|
70
|
+
/**
|
|
71
|
+
* Subscribe to a PubSub topic
|
|
72
|
+
*/
|
|
73
|
+
subscribe(component: string, topic: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Unsubscribe from a PubSub topic
|
|
76
|
+
*/
|
|
77
|
+
unsubscribe(component: string, topic: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Get the list of subscriptions for the current node
|
|
80
|
+
*/
|
|
81
|
+
getTopics(component: string): Promise<string[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Get the list of peers we know about who subscribe to the topic
|
|
84
|
+
*/
|
|
85
|
+
getSubscribers(component: string, topic: string): Promise<PeerId[]>;
|
|
86
|
+
/**
|
|
87
|
+
* Publish a message to a given topic
|
|
88
|
+
*/
|
|
89
|
+
publish(component: string, topic: string, message: Uint8Array): Promise<void>;
|
|
90
|
+
};
|
|
78
91
|
}
|
|
79
92
|
export interface DevToolsEvents {
|
|
80
93
|
/**
|
|
@@ -89,6 +102,14 @@ export interface DevToolsEvents {
|
|
|
89
102
|
* The node's connected peers have changed
|
|
90
103
|
*/
|
|
91
104
|
'peers': CustomEvent<Peer[]>;
|
|
105
|
+
/**
|
|
106
|
+
* A pubsub message was received
|
|
107
|
+
*/
|
|
108
|
+
'pubsub:message': CustomEvent<PubSubRPCMessage>;
|
|
109
|
+
/**
|
|
110
|
+
* The subscriptions of a peer have changed
|
|
111
|
+
*/
|
|
112
|
+
'pubsub:subscription-change': CustomEvent<SubscriptionChangeData>;
|
|
92
113
|
}
|
|
93
114
|
/**
|
|
94
115
|
* RPC operations exposed by the DevTools
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rpc/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/rpc/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AACpI,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAExC,eAA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../../../src/rpc/rpc.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../../src/rpc/rpc.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAI5D,wBAAgB,UAAU,CAAE,UAAU,EAAE,yBAAyB,GAAG,UAAU,CAgE7E"}
|
package/dist/src/rpc/rpc.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { enable, disable } from '@libp2p/logger';
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id';
|
|
3
3
|
import { multiaddr } from '@multiformats/multiaddr';
|
|
4
|
+
import { gatherCapabilities } from '../utils/gather-capabilities.js';
|
|
4
5
|
import { getPeers } from '../utils/get-peers.js';
|
|
6
|
+
import { getPubSub } from '../utils/get-pubsub.js';
|
|
5
7
|
import { getSelf } from '../utils/get-self.js';
|
|
6
8
|
export function metricsRpc(components) {
|
|
7
9
|
const log = components.logger.forComponent('libp2p:devtools-metrics:metrics-rpc');
|
|
@@ -10,7 +12,8 @@ export function metricsRpc(components) {
|
|
|
10
12
|
return {
|
|
11
13
|
self: await getSelf(components),
|
|
12
14
|
peers: await getPeers(components, log),
|
|
13
|
-
debug: localStorage.getItem('debug') ?? ''
|
|
15
|
+
debug: localStorage.getItem('debug') ?? '',
|
|
16
|
+
capabilities: gatherCapabilities(components)
|
|
14
17
|
};
|
|
15
18
|
},
|
|
16
19
|
setDebug: async (namespace) => {
|
|
@@ -45,7 +48,24 @@ export function metricsRpc(components) {
|
|
|
45
48
|
}));
|
|
46
49
|
},
|
|
47
50
|
contentRouting: components.contentRouting,
|
|
48
|
-
peerRouting: components.peerRouting
|
|
51
|
+
peerRouting: components.peerRouting,
|
|
52
|
+
pubsub: {
|
|
53
|
+
async getTopics(component) {
|
|
54
|
+
return getPubSub(component, components).getTopics();
|
|
55
|
+
},
|
|
56
|
+
async subscribe(component, topic) {
|
|
57
|
+
getPubSub(component, components).subscribe(topic);
|
|
58
|
+
},
|
|
59
|
+
async unsubscribe(component, topic) {
|
|
60
|
+
getPubSub(component, components).unsubscribe(topic);
|
|
61
|
+
},
|
|
62
|
+
async publish(component, topic, message) {
|
|
63
|
+
await getPubSub(component, components).publish(topic, message);
|
|
64
|
+
},
|
|
65
|
+
async getSubscribers(component, topic) {
|
|
66
|
+
return getPubSub(component, components).getSubscribers(topic);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
49
69
|
};
|
|
50
70
|
}
|
|
51
71
|
//# sourceMappingURL=rpc.js.map
|
package/dist/src/rpc/rpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/rpc/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"rpc.js","sourceRoot":"","sources":["../../../src/rpc/rpc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAClD,OAAO,EAAE,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-capability.d.ts","sourceRoot":"","sources":["../../../src/utils/find-capability.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,SAAS,CAMpF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { gatherCapabilities } from './gather-capabilities.js';
|
|
2
|
+
export function findCapability(capability, components) {
|
|
3
|
+
for (const [name, capabilities] of Object.entries(gatherCapabilities(components))) {
|
|
4
|
+
if (capabilities.includes(capability)) {
|
|
5
|
+
return components[name];
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=find-capability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-capability.js","sourceRoot":"","sources":["../../../src/utils/find-capability.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE7D,MAAM,UAAU,cAAc,CAAE,UAAkB,EAAE,UAAe;IACjE,KAAK,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;QAClF,IAAI,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACtC,OAAO,UAAU,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gather-capabilities.d.ts","sourceRoot":"","sources":["../../../src/utils/gather-capabilities.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAE,UAAU,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAW7E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { serviceCapabilities } from '@libp2p/interface';
|
|
2
|
+
export function gatherCapabilities(components) {
|
|
3
|
+
const capabilities = {};
|
|
4
|
+
const services = components.components ?? components;
|
|
5
|
+
Object.entries(services).forEach(([name, component]) => {
|
|
6
|
+
if (component?.[serviceCapabilities] != null && Array.isArray(component[serviceCapabilities])) {
|
|
7
|
+
capabilities[name] = component[serviceCapabilities];
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
return capabilities;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=gather-capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gather-capabilities.js","sourceRoot":"","sources":["../../../src/utils/gather-capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvD,MAAM,UAAU,kBAAkB,CAAE,UAAe;IACjD,MAAM,YAAY,GAA6B,EAAE,CAAA;IACjD,MAAM,QAAQ,GAAwB,UAAU,CAAC,UAAU,IAAI,UAAU,CAAA;IAEzE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE;QACrD,IAAI,SAAS,EAAE,CAAC,mBAAmB,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC,EAAE,CAAC;YAC9F,YAAY,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAA;QACrD,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,YAAY,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-pubsub.d.ts","sourceRoot":"","sources":["../../../src/utils/get-pubsub.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,wBAAgB,SAAS,CAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,MAAM,CAQrE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InvalidParametersError, isPubSub } from '@libp2p/interface';
|
|
2
|
+
export function getPubSub(component, components) {
|
|
3
|
+
const pubsub = components[component];
|
|
4
|
+
if (!isPubSub(pubsub)) {
|
|
5
|
+
throw new InvalidParametersError(`Component ${component} did not implement the PubSub interface`);
|
|
6
|
+
}
|
|
7
|
+
return pubsub;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=get-pubsub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-pubsub.js","sourceRoot":"","sources":["../../../src/utils/get-pubsub.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAGpE,MAAM,UAAU,SAAS,CAAE,SAAiB,EAAE,UAAe;IAC3D,MAAM,MAAM,GAAG,UAAU,CAAC,SAAS,CAAC,CAAA;IAEpC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,sBAAsB,CAAC,aAAa,SAAS,yCAAyC,CAAC,CAAA;IACnG,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/devtools-metrics",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0-7f7ec82ae",
|
|
4
4
|
"description": "Collect libp2p metrics and send them to browser DevTools",
|
|
5
5
|
"author": "",
|
|
6
6
|
"license": "Apache-2.0 OR MIT",
|
|
@@ -64,14 +64,15 @@
|
|
|
64
64
|
"doc-check": "aegir doc-check",
|
|
65
65
|
"build": "aegir build",
|
|
66
66
|
"test": "aegir test -t browser",
|
|
67
|
-
"test:chrome": "aegir test -t browser --cov"
|
|
67
|
+
"test:chrome": "aegir test -t browser --cov",
|
|
68
|
+
"test:firefox": "aegir test -t browser --browser firefox"
|
|
68
69
|
},
|
|
69
70
|
"dependencies": {
|
|
70
|
-
"@libp2p/interface": "
|
|
71
|
-
"@libp2p/interface-internal": "
|
|
72
|
-
"@libp2p/logger": "
|
|
73
|
-
"@libp2p/peer-id": "
|
|
74
|
-
"@libp2p/simple-metrics": "
|
|
71
|
+
"@libp2p/interface": "2.1.0-7f7ec82ae",
|
|
72
|
+
"@libp2p/interface-internal": "2.0.2-7f7ec82ae",
|
|
73
|
+
"@libp2p/logger": "5.0.2-7f7ec82ae",
|
|
74
|
+
"@libp2p/peer-id": "5.0.2-7f7ec82ae",
|
|
75
|
+
"@libp2p/simple-metrics": "1.2.0-7f7ec82ae",
|
|
75
76
|
"@multiformats/multiaddr": "^12.3.0",
|
|
76
77
|
"cborg": "^4.2.2",
|
|
77
78
|
"it-pipe": "^3.0.1",
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
"progress-events": "^1.0.0"
|
|
82
83
|
},
|
|
83
84
|
"devDependencies": {
|
|
84
|
-
"@libp2p/crypto": "
|
|
85
|
+
"@libp2p/crypto": "5.0.2-7f7ec82ae",
|
|
85
86
|
"aegir": "^44.0.1",
|
|
86
87
|
"sinon-ts": "^2.0.0"
|
|
87
88
|
},
|
package/src/index.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* for Chrome or Firefox to inspect the state of your running node.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import { serviceCapabilities, start, stop } from '@libp2p/interface'
|
|
19
|
+
import { isPubSub, serviceCapabilities, start, stop } from '@libp2p/interface'
|
|
20
20
|
import { simpleMetrics } from '@libp2p/simple-metrics'
|
|
21
21
|
import { pipe } from 'it-pipe'
|
|
22
22
|
import { pushable } from 'it-pushable'
|
|
@@ -25,10 +25,11 @@ import { base64 } from 'multiformats/bases/base64'
|
|
|
25
25
|
import { valueCodecs } from './rpc/index.js'
|
|
26
26
|
import { metricsRpc } from './rpc/rpc.js'
|
|
27
27
|
import { debounce } from './utils/debounce.js'
|
|
28
|
+
import { findCapability } from './utils/find-capability.js'
|
|
28
29
|
import { getPeers } from './utils/get-peers.js'
|
|
29
30
|
import { getSelf } from './utils/get-self.js'
|
|
30
31
|
import type { DevToolsRPC } from './rpc/index.js'
|
|
31
|
-
import type { ComponentLogger, Connection, Libp2pEvents, Logger, Metrics, MultiaddrConnection, PeerId, PeerStore, Stream, ContentRouting, PeerRouting, TypedEventTarget, Startable } from '@libp2p/interface'
|
|
32
|
+
import type { ComponentLogger, Connection, Libp2pEvents, Logger, Metrics, MultiaddrConnection, PeerId, PeerStore, Stream, ContentRouting, PeerRouting, TypedEventTarget, Startable, Message, SubscriptionChangeData } from '@libp2p/interface'
|
|
32
33
|
import type { TransportManager, Registrar, ConnectionManager, AddressManager } from '@libp2p/interface-internal'
|
|
33
34
|
import type { Pushable } from 'it-pushable'
|
|
34
35
|
|
|
@@ -175,6 +176,10 @@ class DevToolsMetrics implements Metrics, Startable {
|
|
|
175
176
|
this.onSelfUpdate = debounce(this.onSelfUpdate.bind(this), 1000)
|
|
176
177
|
this.onIncomingMessage = this.onIncomingMessage.bind(this)
|
|
177
178
|
|
|
179
|
+
// relay pubsub messages to dev tools panel
|
|
180
|
+
this.onPubSubMessage = this.onPubSubMessage.bind(this)
|
|
181
|
+
this.onPubSubSubscriptionChange = this.onPubSubSubscriptionChange.bind(this)
|
|
182
|
+
|
|
178
183
|
// collect metrics
|
|
179
184
|
this.simpleMetrics = simpleMetrics({
|
|
180
185
|
intervalMs: this.intervalMs,
|
|
@@ -218,6 +223,22 @@ class DevToolsMetrics implements Metrics, Startable {
|
|
|
218
223
|
return this.simpleMetrics.registerCounterGroup(name, options)
|
|
219
224
|
}
|
|
220
225
|
|
|
226
|
+
registerHistogram (name: any, options: any): any {
|
|
227
|
+
return this.simpleMetrics.registerHistogram(name, options)
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
registerHistogramGroup (name: any, options: any): any {
|
|
231
|
+
return this.simpleMetrics.registerHistogramGroup(name, options)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
registerSummary (name: any, options: any): any {
|
|
235
|
+
return this.simpleMetrics.registerSummary(name, options)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
registerSummaryGroup (name: any, options: any): any {
|
|
239
|
+
return this.simpleMetrics.registerSummaryGroup(name, options)
|
|
240
|
+
}
|
|
241
|
+
|
|
221
242
|
async start (): Promise<void> {
|
|
222
243
|
// send peer updates
|
|
223
244
|
this.components.events.addEventListener('peer:connect', this.onPeersUpdate)
|
|
@@ -257,6 +278,13 @@ class DevToolsMetrics implements Metrics, Startable {
|
|
|
257
278
|
.catch(err => {
|
|
258
279
|
this.log.error('error while reading RPC messages', err)
|
|
259
280
|
})
|
|
281
|
+
|
|
282
|
+
const pubsub = findCapability('@libp2p/pubsub', this.components)
|
|
283
|
+
|
|
284
|
+
if (isPubSub(pubsub)) {
|
|
285
|
+
pubsub.addEventListener('message', this.onPubSubMessage)
|
|
286
|
+
pubsub.addEventListener('subscription-change', this.onPubSubSubscriptionChange)
|
|
287
|
+
}
|
|
260
288
|
}
|
|
261
289
|
|
|
262
290
|
async stop (): Promise<void> {
|
|
@@ -287,6 +315,24 @@ class DevToolsMetrics implements Metrics, Startable {
|
|
|
287
315
|
}
|
|
288
316
|
}
|
|
289
317
|
|
|
318
|
+
private onPubSubMessage (event: CustomEvent<Message>): void {
|
|
319
|
+
this.devTools.safeDispatchEvent('pubsub:message', {
|
|
320
|
+
detail: event.detail
|
|
321
|
+
})
|
|
322
|
+
.catch(err => {
|
|
323
|
+
this.log.error('error relaying pubsub message', err)
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private onPubSubSubscriptionChange (event: CustomEvent<SubscriptionChangeData>): void {
|
|
328
|
+
this.devTools.safeDispatchEvent('pubsub:subscription-change', {
|
|
329
|
+
detail: event.detail
|
|
330
|
+
})
|
|
331
|
+
.catch(err => {
|
|
332
|
+
this.log.error('error relaying pubsub subscription change', err)
|
|
333
|
+
})
|
|
334
|
+
}
|
|
335
|
+
|
|
290
336
|
private onSelfUpdate (): void {
|
|
291
337
|
Promise.resolve()
|
|
292
338
|
.then(async () => {
|
package/src/rpc/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { cidCodec } from './codecs/cid.js'
|
|
|
2
2
|
import { customProgressEventCodec } from './codecs/custom-progress-event.js'
|
|
3
3
|
import { multiaddrCodec } from './codecs/multiaddr.js'
|
|
4
4
|
import { peerIdCodec } from './codecs/peer-id.js'
|
|
5
|
-
import type { ContentRouting, PeerId, PeerRouting, AbortOptions } from '@libp2p/interface'
|
|
5
|
+
import type { ContentRouting, PeerId, PeerRouting, AbortOptions, PubSubRPCMessage, SubscriptionChangeData } from '@libp2p/interface'
|
|
6
6
|
import type { OpenConnectionOptions } from '@libp2p/interface-internal'
|
|
7
7
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
8
8
|
import type { ValueCodec } from 'it-rpc'
|
|
@@ -14,21 +14,6 @@ export const valueCodecs: Array<ValueCodec<any>> = [
|
|
|
14
14
|
customProgressEventCodec
|
|
15
15
|
]
|
|
16
16
|
|
|
17
|
-
export interface NodeAddress {
|
|
18
|
-
multiaddr: Multiaddr
|
|
19
|
-
listen?: boolean
|
|
20
|
-
announce?: boolean
|
|
21
|
-
observed?: boolean
|
|
22
|
-
default?: boolean
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface NodeStatus {
|
|
26
|
-
peerId: PeerId
|
|
27
|
-
agent?: string
|
|
28
|
-
addresses: NodeAddress[]
|
|
29
|
-
protocols: string[]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
17
|
export interface PeerAddress {
|
|
33
18
|
multiaddr: Multiaddr
|
|
34
19
|
isConnected?: boolean
|
|
@@ -69,7 +54,7 @@ export interface MetricsRPC {
|
|
|
69
54
|
/**
|
|
70
55
|
* Called by DevTools on initial connect
|
|
71
56
|
*/
|
|
72
|
-
init(options?: AbortOptions): Promise<{ self: Peer, peers: Peer[], debug: string }>
|
|
57
|
+
init(options?: AbortOptions): Promise<{ self: Peer, peers: Peer[], debug: string, capabilities: Record<string, string[]> }>
|
|
73
58
|
|
|
74
59
|
/**
|
|
75
60
|
* Update the currently active debugging namespaces
|
|
@@ -95,6 +80,36 @@ export interface MetricsRPC {
|
|
|
95
80
|
* Make peer routing queries
|
|
96
81
|
*/
|
|
97
82
|
peerRouting: PeerRouting
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* PubSub operations
|
|
86
|
+
*/
|
|
87
|
+
pubsub: {
|
|
88
|
+
/**
|
|
89
|
+
* Subscribe to a PubSub topic
|
|
90
|
+
*/
|
|
91
|
+
subscribe(component: string, topic: string): Promise<void>
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Unsubscribe from a PubSub topic
|
|
95
|
+
*/
|
|
96
|
+
unsubscribe(component: string, topic: string): Promise<void>
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get the list of subscriptions for the current node
|
|
100
|
+
*/
|
|
101
|
+
getTopics (component: string): Promise<string[]>
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Get the list of peers we know about who subscribe to the topic
|
|
105
|
+
*/
|
|
106
|
+
getSubscribers (component: string, topic: string): Promise<PeerId[]>
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Publish a message to a given topic
|
|
110
|
+
*/
|
|
111
|
+
publish (component: string, topic: string, message: Uint8Array): Promise<void>
|
|
112
|
+
}
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
export interface DevToolsEvents {
|
|
@@ -112,6 +127,16 @@ export interface DevToolsEvents {
|
|
|
112
127
|
* The node's connected peers have changed
|
|
113
128
|
*/
|
|
114
129
|
'peers': CustomEvent<Peer[]>
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* A pubsub message was received
|
|
133
|
+
*/
|
|
134
|
+
'pubsub:message': CustomEvent<PubSubRPCMessage>
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The subscriptions of a peer have changed
|
|
138
|
+
*/
|
|
139
|
+
'pubsub:subscription-change': CustomEvent<SubscriptionChangeData>
|
|
115
140
|
}
|
|
116
141
|
|
|
117
142
|
/**
|
package/src/rpc/rpc.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { enable, disable } from '@libp2p/logger'
|
|
2
2
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
3
3
|
import { multiaddr } from '@multiformats/multiaddr'
|
|
4
|
+
import { gatherCapabilities } from '../utils/gather-capabilities.js'
|
|
4
5
|
import { getPeers } from '../utils/get-peers.js'
|
|
6
|
+
import { getPubSub } from '../utils/get-pubsub.js'
|
|
5
7
|
import { getSelf } from '../utils/get-self.js'
|
|
6
8
|
import type { MetricsRPC } from './index.js'
|
|
7
9
|
import type { DevToolsMetricsComponents } from '../index.js'
|
|
8
10
|
import type { PeerId } from '@libp2p/interface'
|
|
9
|
-
import type { OpenConnectionOptions } from '@libp2p/interface-internal'
|
|
10
11
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
11
|
-
import type { AbortOptions } from 'it-pushable'
|
|
12
12
|
|
|
13
13
|
export function metricsRpc (components: DevToolsMetricsComponents): MetricsRPC {
|
|
14
14
|
const log = components.logger.forComponent('libp2p:devtools-metrics:metrics-rpc')
|
|
@@ -18,10 +18,11 @@ export function metricsRpc (components: DevToolsMetricsComponents): MetricsRPC {
|
|
|
18
18
|
return {
|
|
19
19
|
self: await getSelf(components),
|
|
20
20
|
peers: await getPeers(components, log),
|
|
21
|
-
debug: localStorage.getItem('debug') ?? ''
|
|
21
|
+
debug: localStorage.getItem('debug') ?? '',
|
|
22
|
+
capabilities: gatherCapabilities(components)
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
|
-
setDebug: async (namespace
|
|
25
|
+
setDebug: async (namespace?) => {
|
|
25
26
|
if (namespace?.length != null && namespace?.length > 0) {
|
|
26
27
|
enable(namespace)
|
|
27
28
|
localStorage.setItem('debug', namespace)
|
|
@@ -30,7 +31,7 @@ export function metricsRpc (components: DevToolsMetricsComponents): MetricsRPC {
|
|
|
30
31
|
localStorage.removeItem('debug')
|
|
31
32
|
}
|
|
32
33
|
},
|
|
33
|
-
openConnection: async (peerIdOrMultiaddr
|
|
34
|
+
openConnection: async (peerIdOrMultiaddr, options?) => {
|
|
34
35
|
let peer: PeerId | Multiaddr
|
|
35
36
|
|
|
36
37
|
try {
|
|
@@ -41,7 +42,7 @@ export function metricsRpc (components: DevToolsMetricsComponents): MetricsRPC {
|
|
|
41
42
|
|
|
42
43
|
await components.connectionManager.openConnection(peer, options)
|
|
43
44
|
},
|
|
44
|
-
closeConnection: async (peerId
|
|
45
|
+
closeConnection: async (peerId, options?) => {
|
|
45
46
|
await Promise.all(
|
|
46
47
|
components.connectionManager.getConnections(peerId)
|
|
47
48
|
.map(async connection => {
|
|
@@ -54,6 +55,23 @@ export function metricsRpc (components: DevToolsMetricsComponents): MetricsRPC {
|
|
|
54
55
|
)
|
|
55
56
|
},
|
|
56
57
|
contentRouting: components.contentRouting,
|
|
57
|
-
peerRouting: components.peerRouting
|
|
58
|
+
peerRouting: components.peerRouting,
|
|
59
|
+
pubsub: {
|
|
60
|
+
async getTopics (component) {
|
|
61
|
+
return getPubSub(component, components).getTopics()
|
|
62
|
+
},
|
|
63
|
+
async subscribe (component, topic) {
|
|
64
|
+
getPubSub(component, components).subscribe(topic)
|
|
65
|
+
},
|
|
66
|
+
async unsubscribe (component, topic) {
|
|
67
|
+
getPubSub(component, components).unsubscribe(topic)
|
|
68
|
+
},
|
|
69
|
+
async publish (component, topic, message) {
|
|
70
|
+
await getPubSub(component, components).publish(topic, message)
|
|
71
|
+
},
|
|
72
|
+
async getSubscribers (component: string, topic: string) {
|
|
73
|
+
return getPubSub(component, components).getSubscribers(topic)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
58
76
|
}
|
|
59
77
|
}
|