@libp2p/identify 3.0.35 → 3.0.36-2d6079bc1

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.
@@ -8,4 +8,5 @@ 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;
11
12
  //# sourceMappingURL=consts.d.ts.map
@@ -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;AAEtC,eAAO,MAAM,gBAAgB,OAAQ,CAAA"}
@@ -10,4 +10,5 @@ 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;
13
14
  //# sourceMappingURL=consts.js.map
@@ -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;AAEtC,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAA"}
@@ -5,12 +5,14 @@ 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;
8
9
  constructor(components: IdentifyPushComponents, init?: IdentifyPushInit);
9
10
  [serviceCapabilities]: string[];
10
11
  /**
11
12
  * Calls `push` on all peer connections
12
13
  */
13
14
  push(): Promise<void>;
15
+ private sendPushMessage;
14
16
  /**
15
17
  * Reads the Identify Push message from the given `connection`
16
18
  */
@@ -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;AAcvD,OAAO,EAAE,gBAAgB,EAAyC,MAAM,YAAY,CAAA;AACpF,OAAO,KAAK,EAAE,YAAY,IAAI,qBAAqB,EAAE,sBAAsB,EAAE,gBAAg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IACG,cAAc,CAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CA4B/D"}
@@ -1,5 +1,6 @@
1
1
  import { serviceCapabilities } from '@libp2p/interface';
2
2
  import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record';
3
+ import { debounce } from '@libp2p/utils/debounce';
3
4
  import { protocols } from '@multiformats/multiaddr';
4
5
  import drain from 'it-drain';
5
6
  import parallel from 'it-parallel';
@@ -7,12 +8,13 @@ import { pbStream } from 'it-protobuf-stream';
7
8
  import { setMaxListeners } from 'main-event';
8
9
  import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
9
10
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
10
- import { MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME, MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION } from './consts.js';
11
+ import { MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME, MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION, PUSH_DEBOUNCE_MS } from './consts.js';
11
12
  import { Identify as IdentifyMessage } from './pb/message.js';
12
13
  import { AbstractIdentify, consumeIdentifyMessage, defaultValues } from './utils.js';
13
14
  export class IdentifyPush extends AbstractIdentify {
14
15
  connectionManager;
15
16
  concurrency;
17
+ _push;
16
18
  constructor(components, init = {}) {
17
19
  super(components, {
18
20
  ...init,
@@ -21,10 +23,13 @@ export class IdentifyPush extends AbstractIdentify {
21
23
  });
22
24
  this.connectionManager = components.connectionManager;
23
25
  this.concurrency = init.concurrency ?? defaultValues.concurrency;
26
+ this._push = debounce(this.sendPushMessage.bind(this), init.debounce ?? PUSH_DEBOUNCE_MS);
24
27
  if ((init.runOnSelfUpdate ?? defaultValues.runOnSelfUpdate)) {
25
28
  // When self peer record changes, trigger identify-push
26
29
  components.events.addEventListener('self:peer:update', (evt) => {
27
- void this.push().catch(err => { this.log.error(err); });
30
+ this.push().catch(err => {
31
+ this.log.error('error pushing updates to peers - %e', err);
32
+ });
28
33
  });
29
34
  }
30
35
  }
@@ -35,63 +40,71 @@ export class IdentifyPush extends AbstractIdentify {
35
40
  * Calls `push` on all peer connections
36
41
  */
37
42
  async push() {
43
+ this._push();
44
+ }
45
+ async sendPushMessage() {
38
46
  // Do not try to push if we are not running
39
47
  if (!this.isStarted()) {
40
48
  return;
41
49
  }
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;
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);
50
+ try {
51
+ const listenAddresses = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code));
52
+ const peerRecord = new PeerRecord({
53
+ peerId: this.peerId,
54
+ multiaddrs: listenAddresses
55
+ });
56
+ const signedPeerRecord = await RecordEnvelope.seal(peerRecord, this.privateKey);
57
+ const supportedProtocols = this.registrar.getProtocols();
58
+ const peer = await this.peerStore.get(this.peerId);
59
+ const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') ?? uint8ArrayFromString(this.host.agentVersion));
60
+ const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') ?? uint8ArrayFromString(this.host.protocolVersion));
61
+ const self = this;
62
+ async function* pushToConnections() {
63
+ for (const connection of self.connectionManager.getConnections()) {
64
+ const peer = await self.peerStore.get(connection.remotePeer);
65
+ if (!peer.protocols.includes(self.protocol)) {
66
+ continue;
88
67
  }
89
- };
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
+ };
99
+ }
90
100
  }
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);
91
107
  }
92
- await drain(parallel(pushToConnections(), {
93
- concurrency: this.concurrency
94
- }));
95
108
  }
96
109
  /**
97
110
  * 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,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,QAAQ,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EACL,sCAAsC,EACtC,yCAAyC,EAC1C,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAKpF,MAAM,OAAO,YAAa,SAAQ,gBAAgB;IAC/B,iBAAiB,CAAmB;IACpC,WAAW,CAAQ;IAEpC,YAAa,UAAkC,EAAE,OAAyB,EAAE;QAC1E,KAAK,CAAC,UAAU,EAAE;YAChB,GAAG,IAAI;YACP,QAAQ,EAAE,IAAI,IAAI,CAAC,cAAc,IAAI,aAAa,CAAC,cAAc,IAAI,sCAAsC,IAAI,yCAAyC,EAAE;YAC1J,GAAG,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,sBAAsB,CAAC;SAC5D,CAAC,CAAA;QAEF,IAAI,CAAC,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAA;QACrD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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"}
@@ -112,6 +112,14 @@ 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;
115
123
  }
116
124
  export interface IdentifyComponents {
117
125
  peerId: PeerId;
@@ -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,cAAc,CAAC,EAAE,MAAM,CAAA;IAEvB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAE1B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACH,oBAAoB,CAAC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Root":"","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;AAqIzD,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/identify",
3
- "version": "3.0.35",
3
+ "version": "3.0.36-2d6079bc1",
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-2d6079bc1",
49
+ "@libp2p/interface": "2.10.4-2d6079bc1",
50
+ "@libp2p/interface-internal": "2.3.17-2d6079bc1",
51
+ "@libp2p/peer-id": "5.1.7-2d6079bc1",
52
+ "@libp2p/peer-record": "8.0.33-2d6079bc1",
53
+ "@libp2p/utils": "6.7.0-2d6079bc1",
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-2d6079bc1",
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
@@ -13,3 +13,5 @@ export const MAX_IDENTIFY_MESSAGE_SIZE = 1024 * 8
13
13
 
14
14
  // https://github.com/libp2p/go-libp2p/blob/0385ec924bad172f74a74db09939e97c079b1420/p2p/protocol/identify/id.go#L47C7-L47C25
15
15
  export const MAX_PUSH_CONCURRENCY = 32
16
+
17
+ export const PUSH_DEBOUNCE_MS = 1_000
@@ -1,5 +1,6 @@
1
1
  import { serviceCapabilities } from '@libp2p/interface'
2
2
  import { RecordEnvelope, PeerRecord } from '@libp2p/peer-record'
3
+ import { debounce } from '@libp2p/utils/debounce'
3
4
  import { protocols } from '@multiformats/multiaddr'
4
5
  import drain from 'it-drain'
5
6
  import parallel from 'it-parallel'
@@ -9,7 +10,8 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
9
10
  import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
10
11
  import {
11
12
  MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME,
12
- MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION
13
+ MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION,
14
+ PUSH_DEBOUNCE_MS
13
15
  } from './consts.js'
14
16
  import { Identify as IdentifyMessage } from './pb/message.js'
15
17
  import { AbstractIdentify, consumeIdentifyMessage, defaultValues } from './utils.js'
@@ -20,6 +22,7 @@ import type { ConnectionManager } from '@libp2p/interface-internal'
20
22
  export class IdentifyPush extends AbstractIdentify implements Startable, IdentifyPushInterface {
21
23
  private readonly connectionManager: ConnectionManager
22
24
  private readonly concurrency: number
25
+ private _push: () => void
23
26
 
24
27
  constructor (components: IdentifyPushComponents, init: IdentifyPushInit = {}) {
25
28
  super(components, {
@@ -31,10 +34,14 @@ export class IdentifyPush extends AbstractIdentify implements Startable, Identif
31
34
  this.connectionManager = components.connectionManager
32
35
  this.concurrency = init.concurrency ?? defaultValues.concurrency
33
36
 
37
+ this._push = debounce(this.sendPushMessage.bind(this), init.debounce ?? PUSH_DEBOUNCE_MS)
38
+
34
39
  if ((init.runOnSelfUpdate ?? defaultValues.runOnSelfUpdate)) {
35
40
  // When self peer record changes, trigger identify-push
36
41
  components.events.addEventListener('self:peer:update', (evt) => {
37
- void this.push().catch(err => { this.log.error(err) })
42
+ this.push().catch(err => {
43
+ this.log.error('error pushing updates to peers - %e', err)
44
+ })
38
45
  })
39
46
  }
40
47
  }
@@ -47,72 +54,80 @@ export class IdentifyPush extends AbstractIdentify implements Startable, Identif
47
54
  * Calls `push` on all peer connections
48
55
  */
49
56
  async push (): Promise<void> {
57
+ this._push()
58
+ }
59
+
60
+ private async sendPushMessage (): Promise<void> {
50
61
  // Do not try to push if we are not running
51
62
  if (!this.isStarted()) {
52
63
  return
53
64
  }
54
65
 
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
- }
66
+ try {
67
+ const listenAddresses = this.addressManager.getAddresses().map(ma => ma.decapsulateCode(protocols('p2p').code))
68
+ const peerRecord = new PeerRecord({
69
+ peerId: this.peerId,
70
+ multiaddrs: listenAddresses
71
+ })
72
+ const signedPeerRecord = await RecordEnvelope.seal(peerRecord, this.privateKey)
73
+ const supportedProtocols = this.registrar.getProtocols()
74
+ const peer = await this.peerStore.get(this.peerId)
75
+ const agentVersion = uint8ArrayToString(peer.metadata.get('AgentVersion') ?? uint8ArrayFromString(this.host.agentVersion))
76
+ const protocolVersion = uint8ArrayToString(peer.metadata.get('ProtocolVersion') ?? uint8ArrayFromString(this.host.protocolVersion))
77
+ const self = this
78
+
79
+ async function * pushToConnections (): AsyncGenerator<() => Promise<void>> {
80
+ for (const connection of self.connectionManager.getConnections()) {
81
+ const peer = await self.peerStore.get(connection.remotePeer)
82
+
83
+ if (!peer.protocols.includes(self.protocol)) {
84
+ continue
85
+ }
74
86
 
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)
87
+ yield async () => {
88
+ let stream: Stream | undefined
89
+ const signal = AbortSignal.timeout(self.timeout)
90
+
91
+ setMaxListeners(Infinity, signal)
92
+
93
+ try {
94
+ stream = await connection.newStream(self.protocol, {
95
+ signal,
96
+ runOnLimitedConnection: self.runOnLimitedConnection
97
+ })
98
+
99
+ const pb = pbStream(stream, {
100
+ maxDataLength: self.maxMessageSize
101
+ }).pb(IdentifyMessage)
102
+
103
+ await pb.write({
104
+ listenAddrs: listenAddresses.map(ma => ma.bytes),
105
+ signedPeerRecord: signedPeerRecord.marshal(),
106
+ protocols: supportedProtocols,
107
+ agentVersion,
108
+ protocolVersion
109
+ }, {
110
+ signal
111
+ })
112
+
113
+ await stream.close({
114
+ signal
115
+ })
116
+ } catch (err: any) {
117
+ // Just log errors
118
+ self.log.error('could not push identify update to peer', err)
119
+ stream?.abort(err)
120
+ }
108
121
  }
109
122
  }
110
123
  }
111
- }
112
124
 
113
- await drain(parallel(pushToConnections(), {
114
- concurrency: this.concurrency
115
- }))
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
+ }
116
131
  }
117
132
 
118
133
  /**
package/src/index.ts CHANGED
@@ -126,6 +126,15 @@ 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
129
138
  }
130
139
 
131
140
  export interface IdentifyComponents {
@@ -1,18 +0,0 @@
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
- }