@libp2p/identify 3.0.35-451e011d4 → 3.0.35
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 +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/consts.d.ts +0 -1
- package/dist/src/consts.d.ts.map +1 -1
- package/dist/src/consts.js +0 -1
- package/dist/src/consts.js.map +1 -1
- package/dist/src/identify-push.d.ts +0 -2
- package/dist/src/identify-push.d.ts.map +1 -1
- package/dist/src/identify-push.js +52 -65
- package/dist/src/identify-push.js.map +1 -1
- package/dist/src/index.d.ts +0 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/typedoc-urls.json +18 -0
- package/package.json +8 -8
- package/src/consts.ts +0 -2
- package/src/identify-push.ts +58 -73
- package/src/index.ts +0 -9
package/dist/src/consts.d.ts
CHANGED
|
@@ -8,5 +8,4 @@ export declare const MULTICODEC_IDENTIFY_PROTOCOL_VERSION = "1.0.0";
|
|
|
8
8
|
export declare const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION = "1.0.0";
|
|
9
9
|
export declare const MAX_IDENTIFY_MESSAGE_SIZE: number;
|
|
10
10
|
export declare const MAX_PUSH_CONCURRENCY = 32;
|
|
11
|
-
export declare const PUSH_DEBOUNCE_MS = 1000;
|
|
12
11
|
//# sourceMappingURL=consts.d.ts.map
|
package/dist/src/consts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,eAAe,CAAA;AAC5C,eAAO,MAAM,mBAAmB,mBAAmB,CAAA;AACnD,eAAO,MAAM,wBAAwB,wBAAwB,CAAA;AAE7D,eAAO,MAAM,yBAAyB,UAAU,CAAA;AAChD,eAAO,MAAM,iCAAiC,OAAO,CAAA;AACrD,eAAO,MAAM,sCAAsC,YAAY,CAAA;AAC/D,eAAO,MAAM,oCAAoC,UAAU,CAAA;AAC3D,eAAO,MAAM,yCAAyC,UAAU,CAAA;AAGhE,eAAO,MAAM,yBAAyB,QAAW,CAAA;AAGjD,eAAO,MAAM,oBAAoB,KAAK,CAAA
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,eAAe,CAAA;AAC5C,eAAO,MAAM,mBAAmB,mBAAmB,CAAA;AACnD,eAAO,MAAM,wBAAwB,wBAAwB,CAAA;AAE7D,eAAO,MAAM,yBAAyB,UAAU,CAAA;AAChD,eAAO,MAAM,iCAAiC,OAAO,CAAA;AACrD,eAAO,MAAM,sCAAsC,YAAY,CAAA;AAC/D,eAAO,MAAM,oCAAoC,UAAU,CAAA;AAC3D,eAAO,MAAM,yCAAyC,UAAU,CAAA;AAGhE,eAAO,MAAM,yBAAyB,QAAW,CAAA;AAGjD,eAAO,MAAM,oBAAoB,KAAK,CAAA"}
|
package/dist/src/consts.js
CHANGED
|
@@ -10,5 +10,4 @@ export const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION = '1.0.0';
|
|
|
10
10
|
export const MAX_IDENTIFY_MESSAGE_SIZE = 1024 * 8;
|
|
11
11
|
// https://github.com/libp2p/go-libp2p/blob/0385ec924bad172f74a74db09939e97c079b1420/p2p/protocol/identify/id.go#L47C7-L47C25
|
|
12
12
|
export const MAX_PUSH_CONCURRENCY = 32;
|
|
13
|
-
export const PUSH_DEBOUNCE_MS = 1_000;
|
|
14
13
|
//# sourceMappingURL=consts.js.map
|
package/dist/src/consts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAA,CAAC,aAAa;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAA,CAAC,aAAa;AACjE,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAA,CAAC,aAAa;AAE3E,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAA;AAChD,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,CAAA;AACrD,MAAM,CAAC,MAAM,sCAAsC,GAAG,SAAS,CAAA;AAC/D,MAAM,CAAC,MAAM,oCAAoC,GAAG,OAAO,CAAA;AAC3D,MAAM,CAAC,MAAM,yCAAyC,GAAG,OAAO,CAAA;AAEhE,oHAAoH;AACpH,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC,CAAA;AAEjD,6HAA6H;AAC7H,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAA
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../src/consts.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAA,CAAC,aAAa;AAC1D,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAA,CAAC,aAAa;AACjE,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAA,CAAC,aAAa;AAE3E,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAA;AAChD,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,CAAA;AACrD,MAAM,CAAC,MAAM,sCAAsC,GAAG,SAAS,CAAA;AAC/D,MAAM,CAAC,MAAM,oCAAoC,GAAG,OAAO,CAAA;AAC3D,MAAM,CAAC,MAAM,yCAAyC,GAAG,OAAO,CAAA;AAEhE,oHAAoH;AACpH,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAC,CAAA;AAEjD,6HAA6H;AAC7H,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAA"}
|
|
@@ -5,14 +5,12 @@ import type { Startable, IncomingStreamData } from '@libp2p/interface';
|
|
|
5
5
|
export declare class IdentifyPush extends AbstractIdentify implements Startable, IdentifyPushInterface {
|
|
6
6
|
private readonly connectionManager;
|
|
7
7
|
private readonly concurrency;
|
|
8
|
-
private _push;
|
|
9
8
|
constructor(components: IdentifyPushComponents, init?: IdentifyPushInit);
|
|
10
9
|
[serviceCapabilities]: string[];
|
|
11
10
|
/**
|
|
12
11
|
* Calls `push` on all peer connections
|
|
13
12
|
*/
|
|
14
13
|
push(): Promise<void>;
|
|
15
|
-
private sendPushMessage;
|
|
16
14
|
/**
|
|
17
15
|
* Reads the Identify Push message from the given `connection`
|
|
18
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identify-push.d.ts","sourceRoot":"","sources":["../../src/identify-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"identify-push.d.ts","sourceRoot":"","sources":["../../src/identify-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAcvD,OAAO,EAAE,gBAAgB,EAAyC,MAAM,YAAY,CAAA;AACpF,OAAO,KAAK,EAAE,YAAY,IAAI,qBAAqB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACjH,OAAO,KAAK,EAAU,SAAS,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAG9E,qBAAa,YAAa,SAAQ,gBAAiB,YAAW,SAAS,EAAE,qBAAqB;IAC5F,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;gBAEvB,UAAU,EAAE,sBAAsB,EAAE,IAAI,GAAE,gBAAqB;IAkB5E,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAE9B;IAED;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;IAqE5B;;OAEG;IACG,cAAc,CAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B/D"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { serviceCapabilities } from '@libp2p/interface';
|
|
2
2
|
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record';
|
|
3
|
-
import { debounce } from '@libp2p/utils/debounce';
|
|
4
3
|
import { protocols } from '@multiformats/multiaddr';
|
|
5
4
|
import drain from 'it-drain';
|
|
6
5
|
import parallel from 'it-parallel';
|
|
@@ -8,13 +7,12 @@ import { pbStream } from 'it-protobuf-stream';
|
|
|
8
7
|
import { setMaxListeners } from 'main-event';
|
|
9
8
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
10
9
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
11
|
-
import { MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME, MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION
|
|
10
|
+
import { MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME, MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION } from './consts.js';
|
|
12
11
|
import { Identify as IdentifyMessage } from './pb/message.js';
|
|
13
12
|
import { AbstractIdentify, consumeIdentifyMessage, defaultValues } from './utils.js';
|
|
14
13
|
export class IdentifyPush extends AbstractIdentify {
|
|
15
14
|
connectionManager;
|
|
16
15
|
concurrency;
|
|
17
|
-
_push;
|
|
18
16
|
constructor(components, init = {}) {
|
|
19
17
|
super(components, {
|
|
20
18
|
...init,
|
|
@@ -23,13 +21,10 @@ export class IdentifyPush extends AbstractIdentify {
|
|
|
23
21
|
});
|
|
24
22
|
this.connectionManager = components.connectionManager;
|
|
25
23
|
this.concurrency = init.concurrency ?? defaultValues.concurrency;
|
|
26
|
-
this._push = debounce(this.sendPushMessage.bind(this), init.debounce ?? PUSH_DEBOUNCE_MS);
|
|
27
24
|
if ((init.runOnSelfUpdate ?? defaultValues.runOnSelfUpdate)) {
|
|
28
25
|
// When self peer record changes, trigger identify-push
|
|
29
26
|
components.events.addEventListener('self:peer:update', (evt) => {
|
|
30
|
-
this.push().catch(err => {
|
|
31
|
-
this.log.error('error pushing updates to peers - %e', err);
|
|
32
|
-
});
|
|
27
|
+
void this.push().catch(err => { this.log.error(err); });
|
|
33
28
|
});
|
|
34
29
|
}
|
|
35
30
|
}
|
|
@@ -40,71 +35,63 @@ export class IdentifyPush extends AbstractIdentify {
|
|
|
40
35
|
* Calls `push` on all peer connections
|
|
41
36
|
*/
|
|
42
37
|
async push() {
|
|
43
|
-
this._push();
|
|
44
|
-
}
|
|
45
|
-
async sendPushMessage() {
|
|
46
38
|
// Do not try to push if we are not running
|
|
47
39
|
if (!this.isStarted()) {
|
|
48
40
|
return;
|
|
49
41
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
yield async () => {
|
|
69
|
-
let stream;
|
|
70
|
-
const signal = AbortSignal.timeout(self.timeout);
|
|
71
|
-
setMaxListeners(Infinity, signal);
|
|
72
|
-
try {
|
|
73
|
-
stream = await connection.newStream(self.protocol, {
|
|
74
|
-
signal,
|
|
75
|
-
runOnLimitedConnection: self.runOnLimitedConnection
|
|
76
|
-
});
|
|
77
|
-
const pb = pbStream(stream, {
|
|
78
|
-
maxDataLength: self.maxMessageSize
|
|
79
|
-
}).pb(IdentifyMessage);
|
|
80
|
-
await pb.write({
|
|
81
|
-
listenAddrs: listenAddresses.map(ma => ma.bytes),
|
|
82
|
-
signedPeerRecord: signedPeerRecord.marshal(),
|
|
83
|
-
protocols: supportedProtocols,
|
|
84
|
-
agentVersion,
|
|
85
|
-
protocolVersion
|
|
86
|
-
}, {
|
|
87
|
-
signal
|
|
88
|
-
});
|
|
89
|
-
await stream.close({
|
|
90
|
-
signal
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
catch (err) {
|
|
94
|
-
// Just log errors
|
|
95
|
-
self.log.error('could not push identify update to peer', err);
|
|
96
|
-
stream?.abort(err);
|
|
97
|
-
}
|
|
98
|
-
};
|
|
42
|
+
const listenAddresses = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code));
|
|
43
|
+
const peerRecord = new PeerRecord({
|
|
44
|
+
peerId: this.peerId,
|
|
45
|
+
multiaddrs: listenAddresses
|
|
46
|
+
});
|
|
47
|
+
const signedPeerRecord = await RecordEnvelope.seal(peerRecord, this.privateKey);
|
|
48
|
+
const supportedProtocols = this.registrar.getProtocols();
|
|
49
|
+
const peer = await this.peerStore.get(this.peerId);
|
|
50
|
+
const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') ?? uint8ArrayFromString(this.host.agentVersion));
|
|
51
|
+
const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') ?? uint8ArrayFromString(this.host.protocolVersion));
|
|
52
|
+
const self = this;
|
|
53
|
+
async function* pushToConnections() {
|
|
54
|
+
for (const connection of self.connectionManager.getConnections()) {
|
|
55
|
+
const peer = await self.peerStore.get(connection.remotePeer);
|
|
56
|
+
if (!peer.protocols.includes(self.protocol)) {
|
|
57
|
+
continue;
|
|
99
58
|
}
|
|
59
|
+
yield async () => {
|
|
60
|
+
let stream;
|
|
61
|
+
const signal = AbortSignal.timeout(self.timeout);
|
|
62
|
+
setMaxListeners(Infinity, signal);
|
|
63
|
+
try {
|
|
64
|
+
stream = await connection.newStream(self.protocol, {
|
|
65
|
+
signal,
|
|
66
|
+
runOnLimitedConnection: self.runOnLimitedConnection
|
|
67
|
+
});
|
|
68
|
+
const pb = pbStream(stream, {
|
|
69
|
+
maxDataLength: self.maxMessageSize
|
|
70
|
+
}).pb(IdentifyMessage);
|
|
71
|
+
await pb.write({
|
|
72
|
+
listenAddrs: listenAddresses.map(ma => ma.bytes),
|
|
73
|
+
signedPeerRecord: signedPeerRecord.marshal(),
|
|
74
|
+
protocols: supportedProtocols,
|
|
75
|
+
agentVersion,
|
|
76
|
+
protocolVersion
|
|
77
|
+
}, {
|
|
78
|
+
signal
|
|
79
|
+
});
|
|
80
|
+
await stream.close({
|
|
81
|
+
signal
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
// Just log errors
|
|
86
|
+
self.log.error('could not push identify update to peer', err);
|
|
87
|
+
stream?.abort(err);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
100
90
|
}
|
|
101
|
-
await drain(parallel(pushToConnections(), {
|
|
102
|
-
concurrency: this.concurrency
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
catch (err) {
|
|
106
|
-
this.log.error('error pushing updates to peers - %e', err);
|
|
107
91
|
}
|
|
92
|
+
await drain(parallel(pushToConnections(), {
|
|
93
|
+
concurrency: this.concurrency
|
|
94
|
+
}));
|
|
108
95
|
}
|
|
109
96
|
/**
|
|
110
97
|
* Reads the Identify Push message from the given `connection`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identify-push.js","sourceRoot":"","sources":["../../src/identify-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"identify-push.js","sourceRoot":"","sources":["../../src/identify-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,Q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AAC,CAAA;YACjB,OAAM;QACR,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,sBAAsB,EAAE,UAAU,CAAC,UAAU,CAAC,CAAA;IAC/D,CAAC;CACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -112,14 +112,6 @@ export interface IdentifyPushInit extends Omit<IdentifyInit, 'runOnConnectionOpe
|
|
|
112
112
|
* @default 32
|
|
113
113
|
*/
|
|
114
114
|
concurrency?: number;
|
|
115
|
-
/**
|
|
116
|
-
* To prevent rapid flurries of network activity when addresses/protocols
|
|
117
|
-
* change rapidly in succession, debounce the sending of push message by this
|
|
118
|
-
* amount in ms
|
|
119
|
-
*
|
|
120
|
-
* @default 1_000
|
|
121
|
-
*/
|
|
122
|
-
debounce?: number;
|
|
123
115
|
}
|
|
124
116
|
export interface IdentifyComponents {
|
|
125
117
|
peerId: PeerId;
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AACzJ,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC9F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;;OAIG;IACH,cAA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-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,eAAe,CAAA;AA4HzD,MAAM,UAAU,QAAQ,CAAE,OAAqB,EAAE;IAC/C,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC5D,CAAC;AAED,MAAM,UAAU,YAAY,CAAE,OAAyB,EAAE;IACvD,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,iBAAiB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Identify": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.Identify.html",
|
|
3
|
+
".:Identify": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.Identify.html",
|
|
4
|
+
"IdentifyComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyComponents.html",
|
|
5
|
+
".:IdentifyComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyComponents.html",
|
|
6
|
+
"IdentifyInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyInit.html",
|
|
7
|
+
".:IdentifyInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyInit.html",
|
|
8
|
+
"IdentifyPush": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPush.html",
|
|
9
|
+
".:IdentifyPush": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPush.html",
|
|
10
|
+
"IdentifyPushComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPushComponents.html",
|
|
11
|
+
".:IdentifyPushComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPushComponents.html",
|
|
12
|
+
"IdentifyPushInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPushInit.html",
|
|
13
|
+
".:IdentifyPushInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_identify.IdentifyPushInit.html",
|
|
14
|
+
"identify": "https://libp2p.github.io/js-libp2p/functions/_libp2p_identify.identify.html",
|
|
15
|
+
".:identify": "https://libp2p.github.io/js-libp2p/functions/_libp2p_identify.identify.html",
|
|
16
|
+
"identifyPush": "https://libp2p.github.io/js-libp2p/functions/_libp2p_identify.identifyPush.html",
|
|
17
|
+
".:identifyPush": "https://libp2p.github.io/js-libp2p/functions/_libp2p_identify.identifyPush.html"
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/identify",
|
|
3
|
-
"version": "3.0.35
|
|
3
|
+
"version": "3.0.35",
|
|
4
4
|
"description": "Implementation of the Identify Protocol",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-identify#readme",
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"doc-check": "aegir doc-check"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@libp2p/crypto": "5.1.6
|
|
49
|
-
"@libp2p/interface": "2.10.4
|
|
50
|
-
"@libp2p/interface-internal": "2.3.17
|
|
51
|
-
"@libp2p/peer-id": "5.1.7
|
|
52
|
-
"@libp2p/peer-record": "8.0.33
|
|
53
|
-
"@libp2p/utils": "6.7.0
|
|
48
|
+
"@libp2p/crypto": "^5.1.6",
|
|
49
|
+
"@libp2p/interface": "^2.10.4",
|
|
50
|
+
"@libp2p/interface-internal": "^2.3.17",
|
|
51
|
+
"@libp2p/peer-id": "^5.1.7",
|
|
52
|
+
"@libp2p/peer-record": "^8.0.33",
|
|
53
|
+
"@libp2p/utils": "^6.7.0",
|
|
54
54
|
"@multiformats/multiaddr": "^12.4.4",
|
|
55
55
|
"@multiformats/multiaddr-matcher": "^1.7.2",
|
|
56
56
|
"it-drain": "^3.0.9",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"uint8arrays": "^5.1.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@libp2p/logger": "5.1.20
|
|
65
|
+
"@libp2p/logger": "^5.1.20",
|
|
66
66
|
"aegir": "^47.0.14",
|
|
67
67
|
"delay": "^6.0.0",
|
|
68
68
|
"it-length-prefixed": "^10.0.1",
|
package/src/consts.ts
CHANGED
package/src/identify-push.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { serviceCapabilities } from '@libp2p/interface'
|
|
2
2
|
import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
|
|
3
|
-
import { debounce } from '@libp2p/utils/debounce'
|
|
4
3
|
import { protocols } from '@multiformats/multiaddr'
|
|
5
4
|
import drain from 'it-drain'
|
|
6
5
|
import parallel from 'it-parallel'
|
|
@@ -10,8 +9,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
|
10
9
|
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
|
|
11
10
|
import {
|
|
12
11
|
MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME,
|
|
13
|
-
MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION
|
|
14
|
-
PUSH_DEBOUNCE_MS
|
|
12
|
+
MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION
|
|
15
13
|
} from './consts.js'
|
|
16
14
|
import { Identify as IdentifyMessage } from './pb/message.js'
|
|
17
15
|
import { AbstractIdentify, consumeIdentifyMessage, defaultValues } from './utils.js'
|
|
@@ -22,7 +20,6 @@ import type { ConnectionManager } from '@libp2p/interface-internal'
|
|
|
22
20
|
export class IdentifyPush extends AbstractIdentify implements Startable, IdentifyPushInterface {
|
|
23
21
|
private readonly connectionManager: ConnectionManager
|
|
24
22
|
private readonly concurrency: number
|
|
25
|
-
private _push: () => void
|
|
26
23
|
|
|
27
24
|
constructor (components: IdentifyPushComponents, init: IdentifyPushInit = {}) {
|
|
28
25
|
super(components, {
|
|
@@ -34,14 +31,10 @@ export class IdentifyPush extends AbstractIdentify implements Startable, Identif
|
|
|
34
31
|
this.connectionManager = components.connectionManager
|
|
35
32
|
this.concurrency = init.concurrency ?? defaultValues.concurrency
|
|
36
33
|
|
|
37
|
-
this._push = debounce(this.sendPushMessage.bind(this), init.debounce ?? PUSH_DEBOUNCE_MS)
|
|
38
|
-
|
|
39
34
|
if ((init.runOnSelfUpdate ?? defaultValues.runOnSelfUpdate)) {
|
|
40
35
|
// When self peer record changes, trigger identify-push
|
|
41
36
|
components.events.addEventListener('self:peer:update', (evt) => {
|
|
42
|
-
this.push().catch(err => {
|
|
43
|
-
this.log.error('error pushing updates to peers - %e', err)
|
|
44
|
-
})
|
|
37
|
+
void this.push().catch(err => { this.log.error(err) })
|
|
45
38
|
})
|
|
46
39
|
}
|
|
47
40
|
}
|
|
@@ -54,80 +47,72 @@ export class IdentifyPush extends AbstractIdentify implements Startable, Identif
|
|
|
54
47
|
* Calls `push` on all peer connections
|
|
55
48
|
*/
|
|
56
49
|
async push (): Promise<void> {
|
|
57
|
-
this._push()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private async sendPushMessage (): Promise<void> {
|
|
61
50
|
// Do not try to push if we are not running
|
|
62
51
|
if (!this.isStarted()) {
|
|
63
52
|
return
|
|
64
53
|
}
|
|
65
54
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
55
|
+
const listenAddresses = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code))
|
|
56
|
+
const peerRecord = new PeerRecord({
|
|
57
|
+
peerId: this.peerId,
|
|
58
|
+
multiaddrs: listenAddresses
|
|
59
|
+
})
|
|
60
|
+
const signedPeerRecord = await RecordEnvelope.seal(peerRecord, this.privateKey)
|
|
61
|
+
const supportedProtocols = this.registrar.getProtocols()
|
|
62
|
+
const peer = await this.peerStore.get(this.peerId)
|
|
63
|
+
const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') ?? uint8ArrayFromString(this.host.agentVersion))
|
|
64
|
+
const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') ?? uint8ArrayFromString(this.host.protocolVersion))
|
|
65
|
+
const self = this
|
|
66
|
+
|
|
67
|
+
async function * pushToConnections (): AsyncGenerator<() => Promise<void>> {
|
|
68
|
+
for (const connection of self.connectionManager.getConnections()) {
|
|
69
|
+
const peer = await self.peerStore.get(connection.remotePeer)
|
|
70
|
+
|
|
71
|
+
if (!peer.protocols.includes(self.protocol)) {
|
|
72
|
+
continue
|
|
73
|
+
}
|
|
86
74
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
75
|
+
yield async () => {
|
|
76
|
+
let stream: Stream | undefined
|
|
77
|
+
const signal = AbortSignal.timeout(self.timeout)
|
|
78
|
+
|
|
79
|
+
setMaxListeners(Infinity, signal)
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
stream = await connection.newStream(self.protocol, {
|
|
83
|
+
signal,
|
|
84
|
+
runOnLimitedConnection: self.runOnLimitedConnection
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const pb = pbStream(stream, {
|
|
88
|
+
maxDataLength: self.maxMessageSize
|
|
89
|
+
}).pb(IdentifyMessage)
|
|
90
|
+
|
|
91
|
+
await pb.write({
|
|
92
|
+
listenAddrs: listenAddresses.map(ma => ma.bytes),
|
|
93
|
+
signedPeerRecord: signedPeerRecord.marshal(),
|
|
94
|
+
protocols: supportedProtocols,
|
|
95
|
+
agentVersion,
|
|
96
|
+
protocolVersion
|
|
97
|
+
}, {
|
|
98
|
+
signal
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
await stream.close({
|
|
102
|
+
signal
|
|
103
|
+
})
|
|
104
|
+
} catch (err: any) {
|
|
105
|
+
// Just log errors
|
|
106
|
+
self.log.error('could not push identify update to peer', err)
|
|
107
|
+
stream?.abort(err)
|
|
121
108
|
}
|
|
122
109
|
}
|
|
123
110
|
}
|
|
124
|
-
|
|
125
|
-
await drain(parallel(pushToConnections(), {
|
|
126
|
-
concurrency: this.concurrency
|
|
127
|
-
}))
|
|
128
|
-
} catch (err: any) {
|
|
129
|
-
this.log.error('error pushing updates to peers - %e', err)
|
|
130
111
|
}
|
|
112
|
+
|
|
113
|
+
await drain(parallel(pushToConnections(), {
|
|
114
|
+
concurrency: this.concurrency
|
|
115
|
+
}))
|
|
131
116
|
}
|
|
132
117
|
|
|
133
118
|
/**
|
package/src/index.ts
CHANGED
|
@@ -126,15 +126,6 @@ export interface IdentifyPushInit extends Omit<IdentifyInit, 'runOnConnectionOpe
|
|
|
126
126
|
* @default 32
|
|
127
127
|
*/
|
|
128
128
|
concurrency?: number
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* To prevent rapid flurries of network activity when addresses/protocols
|
|
132
|
-
* change rapidly in succession, debounce the sending of push message by this
|
|
133
|
-
* amount in ms
|
|
134
|
-
*
|
|
135
|
-
* @default 1_000
|
|
136
|
-
*/
|
|
137
|
-
debounce?: number
|
|
138
129
|
}
|
|
139
130
|
|
|
140
131
|
export interface IdentifyComponents {
|