libp2p 0.35.4 → 0.35.8-bf1fc32

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.
Files changed (93) hide show
  1. package/README.md +2 -2
  2. package/dist/index.min.js +55 -0
  3. package/dist/src/circuit/auto-relay.d.ts +8 -10
  4. package/dist/src/circuit/auto-relay.d.ts.map +1 -1
  5. package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
  6. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
  7. package/dist/src/connection-manager/index.d.ts +1 -2
  8. package/dist/src/connection-manager/index.d.ts.map +1 -1
  9. package/dist/src/content-routing/utils.d.ts +3 -3
  10. package/dist/src/content-routing/utils.d.ts.map +1 -1
  11. package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
  12. package/dist/src/dialer/dial-request.d.ts.map +1 -1
  13. package/dist/src/dialer/index.d.ts +20 -16
  14. package/dist/src/dialer/index.d.ts.map +1 -1
  15. package/dist/src/identify/index.d.ts +4 -4
  16. package/dist/src/identify/index.d.ts.map +1 -1
  17. package/dist/src/index.d.ts +14 -9
  18. package/dist/src/index.d.ts.map +1 -1
  19. package/dist/src/metrics/index.d.ts +9 -4
  20. package/dist/src/metrics/index.d.ts.map +1 -1
  21. package/dist/src/metrics/stats.d.ts +3 -1
  22. package/dist/src/metrics/stats.d.ts.map +1 -1
  23. package/dist/src/metrics/tracked-map.d.ts +8 -0
  24. package/dist/src/metrics/tracked-map.d.ts.map +1 -0
  25. package/dist/src/peer-routing.d.ts +1 -1
  26. package/dist/src/peer-routing.d.ts.map +1 -1
  27. package/dist/src/peer-store/address-book.d.ts +28 -84
  28. package/dist/src/peer-store/address-book.d.ts.map +1 -1
  29. package/dist/src/peer-store/index.d.ts +25 -94
  30. package/dist/src/peer-store/index.d.ts.map +1 -1
  31. package/dist/src/peer-store/key-book.d.ts +31 -15
  32. package/dist/src/peer-store/key-book.d.ts.map +1 -1
  33. package/dist/src/peer-store/metadata-book.d.ts +33 -29
  34. package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
  35. package/dist/src/peer-store/pb/peer.d.ts +222 -0
  36. package/dist/src/peer-store/proto-book.d.ts +27 -28
  37. package/dist/src/peer-store/proto-book.d.ts.map +1 -1
  38. package/dist/src/peer-store/store.d.ts +73 -0
  39. package/dist/src/peer-store/store.d.ts.map +1 -0
  40. package/dist/src/peer-store/types.d.ts +202 -0
  41. package/dist/src/peer-store/types.d.ts.map +1 -0
  42. package/dist/src/ping/index.d.ts.map +1 -1
  43. package/dist/src/record/peer-record/index.d.ts +2 -2
  44. package/dist/src/record/peer-record/index.d.ts.map +1 -1
  45. package/dist/src/registrar.d.ts +5 -5
  46. package/dist/src/registrar.d.ts.map +1 -1
  47. package/dist/src/upgrader.d.ts.map +1 -1
  48. package/package.json +26 -30
  49. package/src/circuit/auto-relay.js +19 -19
  50. package/src/connection-manager/auto-dialler.js +9 -4
  51. package/src/connection-manager/index.js +41 -31
  52. package/src/content-routing/utils.js +4 -4
  53. package/src/dht/dht-peer-routing.js +2 -6
  54. package/src/dialer/dial-request.js +4 -1
  55. package/src/dialer/index.js +33 -21
  56. package/src/identify/index.js +28 -23
  57. package/src/index.js +43 -35
  58. package/src/metrics/index.js +15 -8
  59. package/src/metrics/stats.js +1 -0
  60. package/src/metrics/tracked-map.js +94 -0
  61. package/src/peer-routing.js +11 -1
  62. package/src/peer-store/address-book.js +242 -227
  63. package/src/peer-store/index.js +77 -110
  64. package/src/peer-store/key-book.js +99 -54
  65. package/src/peer-store/metadata-book.js +171 -101
  66. package/src/peer-store/pb/peer.d.ts +222 -0
  67. package/src/peer-store/pb/peer.js +643 -0
  68. package/src/peer-store/pb/peer.proto +31 -0
  69. package/src/peer-store/proto-book.js +171 -105
  70. package/src/peer-store/store.js +250 -0
  71. package/src/peer-store/types.ts +245 -0
  72. package/src/ping/index.js +6 -0
  73. package/src/record/peer-record/index.js +1 -1
  74. package/src/record/utils.js +1 -1
  75. package/src/registrar.js +4 -4
  76. package/src/upgrader.js +3 -1
  77. package/dist/src/peer-store/book.d.ts +0 -81
  78. package/dist/src/peer-store/book.d.ts.map +0 -1
  79. package/dist/src/peer-store/persistent/consts.d.ts +0 -6
  80. package/dist/src/peer-store/persistent/consts.d.ts.map +0 -1
  81. package/dist/src/peer-store/persistent/index.d.ts +0 -129
  82. package/dist/src/peer-store/persistent/index.d.ts.map +0 -1
  83. package/dist/src/peer-store/persistent/pb/address-book.d.ts +0 -198
  84. package/dist/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
  85. package/src/peer-store/book.js +0 -124
  86. package/src/peer-store/persistent/consts.js +0 -15
  87. package/src/peer-store/persistent/index.js +0 -408
  88. package/src/peer-store/persistent/pb/address-book.d.ts +0 -198
  89. package/src/peer-store/persistent/pb/address-book.js +0 -522
  90. package/src/peer-store/persistent/pb/address-book.proto +0 -27
  91. package/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
  92. package/src/peer-store/persistent/pb/proto-book.js +0 -157
  93. package/src/peer-store/persistent/pb/proto-book.proto +0 -5
@@ -0,0 +1,245 @@
1
+ import type PeerId from 'peer-id'
2
+ import type { Multiaddr } from 'multiaddr'
3
+ import type Envelope from '../record/envelope'
4
+ import type { PublicKey } from 'libp2p-interfaces/src/keys/types'
5
+
6
+ export interface Address {
7
+ /**
8
+ * Peer multiaddr
9
+ */
10
+ multiaddr: Multiaddr
11
+
12
+ /**
13
+ * Obtained from a signed peer record
14
+ */
15
+ isCertified: boolean
16
+ }
17
+
18
+ export interface Peer {
19
+ /**
20
+ * Peer's peer-id instance
21
+ */
22
+ id: PeerId
23
+
24
+ /**
25
+ * Peer's addresses containing its multiaddrs and metadata
26
+ */
27
+ addresses: Address[]
28
+
29
+ /**
30
+ * Peer's supported protocols
31
+ */
32
+ protocols: string[]
33
+
34
+ /**
35
+ * Peer's metadata map
36
+ */
37
+ metadata: Map<string, Uint8Array>
38
+
39
+ /**
40
+ * May be set if the key that this Peer has is an RSA key
41
+ */
42
+ pubKey?: PublicKey
43
+
44
+ /**
45
+ * The last peer record envelope received
46
+ */
47
+ peerRecordEnvelope?: Uint8Array
48
+ }
49
+
50
+ export interface CertifiedRecord {
51
+ raw: Uint8Array
52
+ seqNumber: number
53
+ }
54
+
55
+ export interface AddressBookEntry {
56
+ addresses: Address[]
57
+ record: CertifiedRecord
58
+ }
59
+
60
+ export interface Book<Type> {
61
+ /**
62
+ * Get the known data of a peer
63
+ */
64
+ get: (peerId: PeerId) => Promise<Type>
65
+
66
+ /**
67
+ * Set the known data of a peer
68
+ */
69
+ set: (peerId: PeerId, data: Type) => Promise<void>
70
+
71
+ /**
72
+ * Remove the known data of a peer
73
+ */
74
+ delete: (peerId: PeerId) => Promise<void>
75
+ }
76
+
77
+ /**
78
+ * AddressBook containing a map of peerIdStr to Address.
79
+ */
80
+ export interface AddressBook {
81
+ /**
82
+ * ConsumePeerRecord adds addresses from a signed peer record contained in a record envelope.
83
+ * This will return a boolean that indicates if the record was successfully processed and added
84
+ * into the AddressBook
85
+ */
86
+ consumePeerRecord: (envelope: Envelope) => Promise<boolean>
87
+
88
+ /**
89
+ * Get the raw Envelope for a peer. Returns
90
+ * undefined if no Envelope is found
91
+ */
92
+ getRawEnvelope: (peerId: PeerId) => Promise<Uint8Array | undefined>
93
+
94
+ /**
95
+ * Get an Envelope containing a PeerRecord for the given peer.
96
+ * Returns undefined if no record exists.
97
+ */
98
+ getPeerRecord: (peerId: PeerId) => Promise<Envelope | undefined>
99
+
100
+ /**
101
+ * Add known addresses of a provided peer.
102
+ * If the peer is not known, it is set with the given addresses.
103
+ */
104
+ add: (peerId: PeerId, multiaddrs: Multiaddr[]) => Promise<void>
105
+
106
+ /**
107
+ * Set the known addresses of a peer
108
+ */
109
+ set: (peerId: PeerId, data: Multiaddr[]) => Promise<void>
110
+
111
+ /**
112
+ * Return the known addresses of a peer
113
+ */
114
+ get: (peerId: PeerId) => Promise<Address[]>
115
+
116
+ /**
117
+ * Get the known multiaddrs for a given peer. All returned multiaddrs
118
+ * will include the encapsulated `PeerId` of the peer.
119
+ */
120
+ getMultiaddrsForPeer: (peerId: PeerId, addressSorter?: (ms: Address[]) => Address[]) => Promise<Multiaddr[]>
121
+ }
122
+
123
+ /**
124
+ * KeyBook containing a map of peerIdStr to their PeerId with public keys.
125
+ */
126
+ export interface KeyBook {
127
+ /**
128
+ * Get the known data of a peer
129
+ */
130
+ get: (peerId: PeerId) => Promise<PublicKey | undefined>
131
+
132
+ /**
133
+ * Set the known data of a peer
134
+ */
135
+ set: (peerId: PeerId, data: PublicKey) => Promise<void>
136
+
137
+ /**
138
+ * Remove the known data of a peer
139
+ */
140
+ delete: (peerId: PeerId) => Promise<void>
141
+ }
142
+
143
+ /**
144
+ * MetadataBook containing a map of peerIdStr to their metadata Map.
145
+ */
146
+ export interface MetadataBook extends Book<Map<string, Uint8Array>> {
147
+ /**
148
+ * Set a specific metadata value
149
+ */
150
+ setValue: (peerId: PeerId, key: string, value: Uint8Array) => Promise<void>
151
+
152
+ /**
153
+ * Get specific metadata value, if it exists
154
+ */
155
+ getValue: (peerId: PeerId, key: string) => Promise<Uint8Array | undefined>
156
+
157
+ /**
158
+ * Deletes the provided peer metadata key from the book
159
+ */
160
+ deleteValue: (peerId: PeerId, key: string) => Promise<void>
161
+ }
162
+
163
+ /**
164
+ * ProtoBook containing a map of peerIdStr to supported protocols.
165
+ */
166
+ export interface ProtoBook extends Book<string[]> {
167
+ /**
168
+ * Adds known protocols of a provided peer.
169
+ * If the peer was not known before, it will be added.
170
+ */
171
+ add: (peerId: PeerId, protocols: string[]) => Promise<void>
172
+
173
+ /**
174
+ * Removes known protocols of a provided peer.
175
+ * If the protocols did not exist before, nothing will be done.
176
+ */
177
+ remove: (peerId: PeerId, protocols: string[]) => Promise<void>
178
+ }
179
+
180
+ export interface PeerProtocolsChangeEvent {
181
+ peerId: PeerId
182
+ protocols: string[]
183
+ }
184
+
185
+ export interface PeerMultiaddrsChangeEvent {
186
+ peerId: PeerId
187
+ multiaddrs: Multiaddr[]
188
+ }
189
+
190
+ export interface PeerPublicKeyChangeEvent {
191
+ peerId: PeerId
192
+ pubKey?: PublicKey
193
+ }
194
+
195
+ export interface PeerMetadataChangeEvent {
196
+ peerId: PeerId
197
+ metadata: Map<string, Uint8Array>
198
+ }
199
+
200
+ export type EventName = 'peer' | 'change:protocols' | 'change:multiaddrs' | 'change:pubkey' | 'change:metadata'
201
+
202
+ export interface PeerStoreEvents {
203
+ 'peer': (event: PeerId) => void
204
+ 'change:protocols': (event: PeerProtocolsChangeEvent) => void
205
+ 'change:multiaddrs': (event: PeerMultiaddrsChangeEvent) => void
206
+ 'change:pubkey': (event: PeerPublicKeyChangeEvent) => void
207
+ 'change:metadata': (event: PeerMetadataChangeEvent) => void
208
+ }
209
+
210
+ export interface PeerStore {
211
+ addressBook: AddressBook
212
+ keyBook: KeyBook
213
+ metadataBook: MetadataBook
214
+ protoBook: ProtoBook
215
+
216
+ getPeers: () => AsyncIterable<Peer>
217
+ delete: (peerId: PeerId) => Promise<void>
218
+ has: (peerId: PeerId) => Promise<boolean>
219
+ get: (peerId: PeerId) => Promise<Peer>
220
+ on: <U extends keyof PeerStoreEvents>(
221
+ event: U, listener: PeerStoreEvents[U]
222
+ ) => this
223
+ once: <U extends keyof PeerStoreEvents>(
224
+ event: U, listener: PeerStoreEvents[U]
225
+ ) => this
226
+ emit: <U extends keyof PeerStoreEvents>(
227
+ event: U, ...args: Parameters<PeerStoreEvents[U]>
228
+ ) => boolean
229
+ }
230
+
231
+ export interface Store {
232
+ has: (peerId: PeerId) => Promise<boolean>
233
+ save: (peer: Peer) => Promise<Peer>
234
+ load: (peerId: PeerId) => Promise<Peer>
235
+ merge: (peerId: PeerId, data: Partial<Peer>) => Promise<Peer>
236
+ mergeOrCreate: (peerId: PeerId, data: Partial<Peer>) => Promise<Peer>
237
+ patch: (peerId: PeerId, data: Partial<Peer>) => Promise<Peer>
238
+ patchOrCreate: (peerId: PeerId, data: Partial<Peer>) => Promise<Peer>
239
+ all: () => AsyncIterable<Peer>
240
+
241
+ lock: {
242
+ readLock: () => Promise<() => void>
243
+ writeLock: () => Promise<() => void>
244
+ }
245
+ }
package/src/ping/index.js CHANGED
@@ -63,6 +63,9 @@ async function ping (node, peer) {
63
63
  */
64
64
  function mount (node) {
65
65
  node.handle(`/${node._config.protocolPrefix}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`, ({ stream }) => pipe(stream, stream))
66
+ .catch(err => {
67
+ log.error(err)
68
+ })
66
69
  }
67
70
 
68
71
  /**
@@ -72,6 +75,9 @@ function mount (node) {
72
75
  */
73
76
  function unmount (node) {
74
77
  node.unhandle(`/${node._config.protocolPrefix}/${PROTOCOL_NAME}/${PROTOCOL_VERSION}`)
78
+ .catch(err => {
79
+ log.error(err)
80
+ })
75
81
  }
76
82
 
77
83
  exports = module.exports = ping
@@ -11,7 +11,7 @@ const {
11
11
  } = require('./consts')
12
12
 
13
13
  /**
14
- * @typedef {import('../../peer-store/address-book.js').Address} Address
14
+ * @typedef {import('../../peer-store/types').Address} Address
15
15
  * @typedef {import('libp2p-interfaces/src/record/types').Record} Record
16
16
  */
17
17
 
@@ -19,7 +19,7 @@ async function updateSelfPeerRecord (libp2p) {
19
19
  multiaddrs: libp2p.multiaddrs
20
20
  })
21
21
  const envelope = await Envelope.seal(peerRecord, libp2p.peerId)
22
- libp2p.peerStore.addressBook.consumePeerRecord(envelope)
22
+ await libp2p.peerStore.addressBook.consumePeerRecord(envelope)
23
23
  }
24
24
 
25
25
  module.exports.updateSelfPeerRecord = updateSelfPeerRecord
package/src/registrar.js CHANGED
@@ -13,7 +13,7 @@ const Topology = require('libp2p-interfaces/src/topology')
13
13
 
14
14
  /**
15
15
  * @typedef {import('peer-id')} PeerId
16
- * @typedef {import('./peer-store')} PeerStore
16
+ * @typedef {import('./peer-store/types').PeerStore} PeerStore
17
17
  * @typedef {import('./connection-manager')} ConnectionManager
18
18
  * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
19
19
  * @typedef {import('./').HandlerProps} HandlerProps
@@ -82,9 +82,9 @@ class Registrar {
82
82
  * Register handlers for a set of multicodecs given
83
83
  *
84
84
  * @param {Topology} topology - protocol topology
85
- * @returns {string} registrar identifier
85
+ * @returns {Promise<string>} registrar identifier
86
86
  */
87
- register (topology) {
87
+ async register (topology) {
88
88
  if (!Topology.isTopology(topology)) {
89
89
  log.error('topology must be an instance of interfaces/topology')
90
90
  throw errcode(new Error('topology must be an instance of interfaces/topology'), ERR_INVALID_PARAMETERS)
@@ -96,7 +96,7 @@ class Registrar {
96
96
  this.topologies.set(id, topology)
97
97
 
98
98
  // Set registrar
99
- topology.registrar = this
99
+ await topology.setRegistrar(this)
100
100
 
101
101
  return id
102
102
  }
package/src/upgrader.js CHANGED
@@ -288,7 +288,9 @@ class Upgrader {
288
288
  } finally {
289
289
  this.onConnectionEnd(connection)
290
290
  }
291
- })()
291
+ })().catch(err => {
292
+ log.error(err)
293
+ })
292
294
  }
293
295
 
294
296
  return Reflect.set(...args)
@@ -1,81 +0,0 @@
1
- export = Book;
2
- /**
3
- * @typedef {import('./')} PeerStore
4
- */
5
- declare class Book {
6
- /**
7
- * The Book is the skeleton for the PeerStore books.
8
- *
9
- * @class
10
- * @param {Object} properties
11
- * @param {PeerStore} properties.peerStore - PeerStore instance.
12
- * @param {string} properties.eventName - Name of the event to emit by the PeerStore.
13
- * @param {string} properties.eventProperty - Name of the property to emit by the PeerStore.
14
- * @param {(data: any) => any[]} [properties.eventTransformer] - Transformer function of the provided data for being emitted.
15
- */
16
- constructor({ peerStore, eventName, eventProperty, eventTransformer }: {
17
- peerStore: PeerStore;
18
- eventName: string;
19
- eventProperty: string;
20
- eventTransformer?: ((data: any) => any[]) | undefined;
21
- });
22
- _ps: import("./");
23
- eventName: string;
24
- eventProperty: string;
25
- eventTransformer: (data: any) => any[];
26
- /**
27
- * Map known peers to their data.
28
- *
29
- * @type {Map<string, any[]|any>}
30
- */
31
- data: Map<string, any[] | any>;
32
- /**
33
- * Set known data of a provided peer.
34
- *
35
- * @param {PeerId} peerId
36
- * @param {any[]|any} data
37
- */
38
- set(peerId: PeerId, data: any[] | any): void;
39
- /**
40
- * Set data into the datastructure, persistence and emit it using the provided transformers.
41
- *
42
- * @protected
43
- * @param {PeerId} peerId - peerId of the data to store
44
- * @param {any} data - data to store.
45
- * @param {Object} [options] - storing options.
46
- * @param {boolean} [options.emit = true] - emit the provided data.
47
- * @returns {void}
48
- */
49
- protected _setData(peerId: PeerId, data: any, { emit }?: {
50
- emit?: boolean | undefined;
51
- } | undefined): void;
52
- /**
53
- * Emit data.
54
- *
55
- * @protected
56
- * @param {PeerId} peerId
57
- * @param {any} [data]
58
- */
59
- protected _emit(peerId: PeerId, data?: any): void;
60
- /**
61
- * Get the known data of a provided peer.
62
- * Returns `undefined` if there is no available data for the given peer.
63
- *
64
- * @param {PeerId} peerId
65
- * @returns {any[]|any|undefined}
66
- */
67
- get(peerId: PeerId): any[] | any | undefined;
68
- /**
69
- * Deletes the provided peer from the book.
70
- *
71
- * @param {PeerId} peerId
72
- * @returns {boolean}
73
- */
74
- delete(peerId: PeerId): boolean;
75
- }
76
- declare namespace Book {
77
- export { PeerStore };
78
- }
79
- import PeerId = require("peer-id");
80
- type PeerStore = import('./');
81
- //# sourceMappingURL=book.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"book.d.ts","sourceRoot":"","sources":["../../../src/peer-store/book.js"],"names":[],"mappings":";AAWA;;GAEG;AAEH;IACE;;;;;;;;;OASG;IACH;QALiC,SAAS,EAA/B,SAAS;QACU,SAAS,EAA5B,MAAM;QACa,aAAa,EAAhC,MAAM;QAC4B,gBAAgB,WAA3C,GAAG,KAAK,GAAG,EAAE;OAc9B;IAXC,kBAAoB;IACpB,kBAA0B;IAC1B,sBAAkC;IAClC,yBANgB,GAAG,KAAK,GAAG,EAAE,CAMW;IAExC;;;;OAIG;IACH,MAFU,IAAI,MAAM,EAAE,GAAG,EAAE,GAAC,GAAG,CAAC,CAEX;IAGvB;;;;;OAKG;IACH,YAHW,MAAM,QACN,GAAG,EAAE,GAAC,GAAG,QAInB;IAED;;;;;;;;;OASG;IACH,2BANW,MAAM,QACN,GAAG;;oBAGD,IAAI,CAUhB;IAED;;;;;;OAMG;IACH,wBAHW,MAAM,SACN,GAAG,QAOb;IAED;;;;;;OAMG;IACH,YAHW,MAAM,GACJ,GAAG,EAAE,GAAC,GAAG,GAAC,SAAS,CAW/B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAcnB;CACF;;;;;iBA7GY,OAAO,IAAI,CAAC"}
@@ -1,6 +0,0 @@
1
- export var NAMESPACE_COMMON: string;
2
- export var NAMESPACE_ADDRESS: string;
3
- export var NAMESPACE_KEYS: string;
4
- export var NAMESPACE_METADATA: string;
5
- export var NAMESPACE_PROTOCOL: string;
6
- //# sourceMappingURL=consts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../../src/peer-store/persistent/consts.js"],"names":[],"mappings":""}
@@ -1,129 +0,0 @@
1
- export = PersistentPeerStore;
2
- /**
3
- * @typedef {import('interface-datastore').Batch} Batch
4
- * @typedef {import('../address-book.js').Address} Address
5
- */
6
- /**
7
- * @typedef {Object} PersistentPeerStoreProperties
8
- * @property {PeerId} peerId
9
- * @property {import('interface-datastore').Datastore} datastore
10
- *
11
- * @typedef {Object} PersistentPeerStoreOptions
12
- * @property {number} [threshold = 5] - Number of dirty peers allowed before commit data.
13
- */
14
- /**
15
- * Responsible for managing the persistence of data in the PeerStore.
16
- */
17
- declare class PersistentPeerStore extends PeerStore {
18
- /**
19
- * @class
20
- * @param {PersistentPeerStoreProperties & PersistentPeerStoreOptions} properties
21
- */
22
- constructor({ peerId, datastore, threshold }: PersistentPeerStoreProperties & PersistentPeerStoreOptions);
23
- /**
24
- * Backend datastore used to persist data.
25
- */
26
- _datastore: import("interface-datastore").Datastore;
27
- /**
28
- * Peers modified after the latest data persisted.
29
- */
30
- _dirtyPeers: Set<any>;
31
- /**
32
- * Peers metadata changed mapping peer identifers to metadata changed.
33
- *
34
- * @type {Map<string, Set<string>>}
35
- */
36
- _dirtyMetadata: Map<string, Set<string>>;
37
- threshold: number;
38
- /**
39
- * Add modified peer to the dirty set
40
- *
41
- * @private
42
- * @param {Object} params
43
- * @param {PeerId} params.peerId
44
- */
45
- private _addDirtyPeer;
46
- /**
47
- * Add modified peer key to the dirty set
48
- *
49
- * @private
50
- * @param {Object} params
51
- * @param {PeerId} params.peerId
52
- */
53
- private _addDirtyPeerKey;
54
- /**
55
- * Add modified metadata peer to the set.
56
- *
57
- * @private
58
- * @param {Object} params
59
- * @param {PeerId} params.peerId
60
- * @param {string} params.metadata
61
- */
62
- private _addDirtyPeerMetadata;
63
- /**
64
- * Add all the peers current data to a datastore batch and commit it.
65
- *
66
- * @private
67
- * @returns {Promise<void>}
68
- */
69
- private _commitData;
70
- /**
71
- * Add address book data of the peer to the batch.
72
- *
73
- * @private
74
- * @param {PeerId} peerId
75
- * @param {Batch} batch
76
- */
77
- private _batchAddressBook;
78
- /**
79
- * Add Key book data of the peer to the batch.
80
- *
81
- * @private
82
- * @param {PeerId} peerId
83
- * @param {Batch} batch
84
- */
85
- private _batchKeyBook;
86
- /**
87
- * Add metadata book data of the peer to the batch.
88
- *
89
- * @private
90
- * @param {PeerId} peerId
91
- * @param {Batch} batch
92
- */
93
- private _batchMetadataBook;
94
- /**
95
- * Add proto book data of the peer to the batch.
96
- *
97
- * @private
98
- * @param {PeerId} peerId
99
- * @param {Batch} batch
100
- */
101
- private _batchProtoBook;
102
- /**
103
- * Process datastore entry and add its data to the correct book.
104
- *
105
- * @private
106
- * @param {Object} params
107
- * @param {Key} params.key - datastore key
108
- * @param {Uint8Array} params.value - datastore value stored
109
- * @returns {Promise<void>}
110
- */
111
- private _processDatastoreEntry;
112
- }
113
- declare namespace PersistentPeerStore {
114
- export { Batch, Address, PersistentPeerStoreProperties, PersistentPeerStoreOptions };
115
- }
116
- import PeerStore = require("..");
117
- type PersistentPeerStoreProperties = {
118
- peerId: PeerId;
119
- datastore: import('interface-datastore').Datastore;
120
- };
121
- type PersistentPeerStoreOptions = {
122
- /**
123
- * - Number of dirty peers allowed before commit data.
124
- */
125
- threshold?: number | undefined;
126
- };
127
- type Batch = import('interface-datastore').Batch;
128
- type Address = import('../address-book.js').Address;
129
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/peer-store/persistent/index.js"],"names":[],"mappings":";AAwBA;;;GAGG;AAEH;;;;;;;GAOG;AAEH;;GAEG;AACH;IACE;;;OAGG;IACH,8CAFW,6BAA6B,GAAG,0BAA0B,EAwBpE;IAnBC;;OAEG;IACH,oDAA2B;IAE3B;;OAEG;IACH,sBAA4B;IAE5B;;;;OAIG;IACH,gBAFU,IAAI,MAAM,EAAE,IAAI,MAAM,CAAC,CAAC,CAEH;IAE/B,kBAA0B;IAsC5B;;;;;;OAMG;IACH,sBAYC;IAED;;;;;;OAMG;IACH,yBAiBC;IAED;;;;;;;OAOG;IACH,8BAiBC;IAED;;;;;OAKG;IACH,oBA+BC;IAED;;;;;;OAMG;IACH,0BA8BC;IAED;;;;;;OAMG;IACH,sBAiBC;IAED;;;;;;OAMG;IACH,2BAkBC;IAED;;;;;;OAMG;IACH,wBAmBC;IAED;;;;;;;;OAQG;IACH,+BA0DC;CACF;;;;;;YAtXa,MAAM;eACN,OAAO,qBAAqB,EAAE,SAAS;;;;;;;;aAPxC,OAAO,qBAAqB,EAAE,KAAK;eACnC,OAAO,oBAAoB,EAAE,OAAO"}