@libp2p/peer-store 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +4 -0
  2. package/README.md +44 -0
  3. package/dist/src/address-book.d.ts +31 -0
  4. package/dist/src/address-book.d.ts.map +1 -0
  5. package/dist/src/address-book.js +265 -0
  6. package/dist/src/address-book.js.map +1 -0
  7. package/dist/src/errors.d.ts +5 -0
  8. package/dist/src/errors.d.ts.map +1 -0
  9. package/dist/src/errors.js +5 -0
  10. package/dist/src/errors.js.map +1 -0
  11. package/dist/src/index.d.ts +43 -0
  12. package/dist/src/index.d.ts.map +1 -0
  13. package/dist/src/index.js +88 -0
  14. package/dist/src/index.js.map +1 -0
  15. package/dist/src/key-book.d.ts +21 -0
  16. package/dist/src/key-book.d.ts.map +1 -0
  17. package/dist/src/key-book.js +98 -0
  18. package/dist/src/key-book.js.map +1 -0
  19. package/dist/src/metadata-book.d.ts +28 -0
  20. package/dist/src/metadata-book.d.ts.map +1 -0
  21. package/dist/src/metadata-book.js +168 -0
  22. package/dist/src/metadata-book.js.map +1 -0
  23. package/dist/src/pb/peer.d.ts +222 -0
  24. package/dist/src/pb/peer.js +641 -0
  25. package/dist/src/proto-book.d.ts +18 -0
  26. package/dist/src/proto-book.d.ts.map +1 -0
  27. package/dist/src/proto-book.js +170 -0
  28. package/dist/src/proto-book.js.map +1 -0
  29. package/dist/src/store.d.ts +37 -0
  30. package/dist/src/store.d.ts.map +1 -0
  31. package/dist/src/store.js +169 -0
  32. package/dist/src/store.js.map +1 -0
  33. package/package.json +162 -0
  34. package/src/README.md +145 -0
  35. package/src/address-book.ts +330 -0
  36. package/src/errors.ts +5 -0
  37. package/src/index.ts +123 -0
  38. package/src/key-book.ts +117 -0
  39. package/src/metadata-book.ts +200 -0
  40. package/src/pb/peer.d.ts +222 -0
  41. package/src/pb/peer.js +641 -0
  42. package/src/pb/peer.proto +31 -0
  43. package/src/proto-book.ts +204 -0
  44. package/src/store.ts +224 -0
@@ -0,0 +1,28 @@
1
+ import { PeerId } from '@libp2p/peer-id';
2
+ import type { Store } from './store.js';
3
+ import type { PeerStore, MetadataBook } from '@libp2p/interfaces/src/peer-store';
4
+ export declare class PeerStoreMetadataBook implements MetadataBook {
5
+ private emit;
6
+ private store;
7
+ /**
8
+ * The MetadataBook is responsible for keeping metadata
9
+ * about known peers
10
+ */
11
+ constructor(emit: PeerStore["emit"], store: Store);
12
+ /**
13
+ * Get the known data of a provided peer
14
+ */
15
+ get(peerId: PeerId): Promise<Map<any, any>>;
16
+ /**
17
+ * Get specific metadata value, if it exists
18
+ */
19
+ getValue(peerId: PeerId, key: string): Promise<Uint8Array | undefined>;
20
+ set(peerId: PeerId, metadata: Map<string, Uint8Array>): Promise<void>;
21
+ /**
22
+ * Set metadata key and value of a provided peer
23
+ */
24
+ setValue(peerId: PeerId, key: string, value: Uint8Array): Promise<void>;
25
+ delete(peerId: PeerId): Promise<void>;
26
+ deleteValue(peerId: PeerId, key: string): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=metadata-book.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata-book.d.ts","sourceRoot":"","sources":["../../src/metadata-book.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAMhF,qBAAa,qBAAsB,YAAW,YAAY;IACxD,OAAO,CAAC,IAAI,CAAmB;IAC/B,OAAO,CAAC,KAAK,CAAO;IAEpB;;;OAGG;gBACU,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK;IAKlD;;OAEG;IACG,GAAG,CAAE,MAAM,EAAE,MAAM;IAuBzB;;OAEG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAqBrC,GAAG,CAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC;IAwB5D;;OAEG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;IAuCxD,MAAM,CAAE,MAAM,EAAE,MAAM;IA2BtB,WAAW,CAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;CA+B/C"}
@@ -0,0 +1,168 @@
1
+ import { logger } from '@libp2p/logger';
2
+ import errcode from 'err-code';
3
+ import { codes } from './errors.js';
4
+ import { PeerId } from '@libp2p/peer-id';
5
+ import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
6
+ const log = logger('libp2p:peer-store:metadata-book');
7
+ const EVENT_NAME = 'change:metadata';
8
+ export class PeerStoreMetadataBook {
9
+ /**
10
+ * The MetadataBook is responsible for keeping metadata
11
+ * about known peers
12
+ */
13
+ constructor(emit, store) {
14
+ this.emit = emit;
15
+ this.store = store;
16
+ }
17
+ /**
18
+ * Get the known data of a provided peer
19
+ */
20
+ async get(peerId) {
21
+ peerId = PeerId.fromPeerId(peerId);
22
+ log('get await read lock');
23
+ const release = await this.store.lock.readLock();
24
+ log('get got read lock');
25
+ try {
26
+ const peer = await this.store.load(peerId);
27
+ return peer.metadata;
28
+ }
29
+ catch (err) {
30
+ if (err.code !== codes.ERR_NOT_FOUND) {
31
+ throw err;
32
+ }
33
+ }
34
+ finally {
35
+ log('get release read lock');
36
+ release();
37
+ }
38
+ return new Map();
39
+ }
40
+ /**
41
+ * Get specific metadata value, if it exists
42
+ */
43
+ async getValue(peerId, key) {
44
+ peerId = PeerId.fromPeerId(peerId);
45
+ log('getValue await read lock');
46
+ const release = await this.store.lock.readLock();
47
+ log('getValue got read lock');
48
+ try {
49
+ const peer = await this.store.load(peerId);
50
+ return peer.metadata.get(key);
51
+ }
52
+ catch (err) {
53
+ if (err.code !== codes.ERR_NOT_FOUND) {
54
+ throw err;
55
+ }
56
+ }
57
+ finally {
58
+ log('getValue release write lock');
59
+ release();
60
+ }
61
+ }
62
+ async set(peerId, metadata) {
63
+ peerId = PeerId.fromPeerId(peerId);
64
+ if (!metadata || !(metadata instanceof Map)) {
65
+ log.error('valid metadata must be provided to store data');
66
+ throw errcode(new Error('valid metadata must be provided'), codes.ERR_INVALID_PARAMETERS);
67
+ }
68
+ log('set await write lock');
69
+ const release = await this.store.lock.writeLock();
70
+ log('set got write lock');
71
+ try {
72
+ await this.store.mergeOrCreate(peerId, {
73
+ metadata
74
+ });
75
+ }
76
+ finally {
77
+ log('set release write lock');
78
+ release();
79
+ }
80
+ this.emit(EVENT_NAME, { peerId, metadata });
81
+ }
82
+ /**
83
+ * Set metadata key and value of a provided peer
84
+ */
85
+ async setValue(peerId, key, value) {
86
+ peerId = PeerId.fromPeerId(peerId);
87
+ if (typeof key !== 'string' || !(value instanceof Uint8Array)) {
88
+ log.error('valid key and value must be provided to store data');
89
+ throw errcode(new Error('valid key and value must be provided'), codes.ERR_INVALID_PARAMETERS);
90
+ }
91
+ log('setValue await write lock');
92
+ const release = await this.store.lock.writeLock();
93
+ log('setValue got write lock');
94
+ let updatedPeer;
95
+ try {
96
+ try {
97
+ const existingPeer = await this.store.load(peerId);
98
+ const existingValue = existingPeer.metadata.get(key);
99
+ if (existingValue != null && uint8ArrayEquals(value, existingValue)) {
100
+ return;
101
+ }
102
+ }
103
+ catch (err) {
104
+ if (err.code !== codes.ERR_NOT_FOUND) {
105
+ throw err;
106
+ }
107
+ }
108
+ updatedPeer = await this.store.mergeOrCreate(peerId, {
109
+ metadata: new Map([[key, value]])
110
+ });
111
+ }
112
+ finally {
113
+ log('setValue release write lock');
114
+ release();
115
+ }
116
+ this.emit(EVENT_NAME, { peerId, metadata: updatedPeer.metadata });
117
+ }
118
+ async delete(peerId) {
119
+ peerId = PeerId.fromPeerId(peerId);
120
+ log('delete await write lock');
121
+ const release = await this.store.lock.writeLock();
122
+ log('delete got write lock');
123
+ let has;
124
+ try {
125
+ has = await this.store.has(peerId);
126
+ if (has) {
127
+ await this.store.patch(peerId, {
128
+ metadata: new Map()
129
+ });
130
+ }
131
+ }
132
+ finally {
133
+ log('delete release write lock');
134
+ release();
135
+ }
136
+ if (has) {
137
+ this.emit(EVENT_NAME, { peerId, metadata: new Map() });
138
+ }
139
+ }
140
+ async deleteValue(peerId, key) {
141
+ peerId = PeerId.fromPeerId(peerId);
142
+ log('deleteValue await write lock');
143
+ const release = await this.store.lock.writeLock();
144
+ log('deleteValue got write lock');
145
+ let metadata;
146
+ try {
147
+ const peer = await this.store.load(peerId);
148
+ metadata = peer.metadata;
149
+ metadata.delete(key);
150
+ await this.store.patch(peerId, {
151
+ metadata
152
+ });
153
+ }
154
+ catch (err) {
155
+ if (err.code !== codes.ERR_NOT_FOUND) {
156
+ throw err;
157
+ }
158
+ }
159
+ finally {
160
+ log('deleteValue release write lock');
161
+ release();
162
+ }
163
+ if (metadata) {
164
+ this.emit(EVENT_NAME, { peerId, metadata });
165
+ }
166
+ }
167
+ }
168
+ //# sourceMappingURL=metadata-book.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata-book.js","sourceRoot":"","sources":["../../src/metadata-book.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAI/D,MAAM,GAAG,GAAG,MAAM,CAAC,iCAAiC,CAAC,CAAA;AAErD,MAAM,UAAU,GAAG,iBAAiB,CAAA;AAEpC,MAAM,OAAO,qBAAqB;IAIhC;;;OAGG;IACH,YAAa,IAAuB,EAAE,KA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,IAAI,KAAK,KAAK,CAAC,aAAa,EAAE;gBACpC,MAAM,GAAG,CAAA;aACV;SACF;gBAAS;YACR,GAAG,CAAC,gCAAgC,CAAC,CAAA;YACrC,OAAO,EAAE,CAAA;SACV;QAED,IAAI,QAAQ,EAAE;YACZ,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;SAC5C;IACH,CAAC;CACF"}
@@ -0,0 +1,222 @@
1
+ import * as $protobuf from "protobufjs";
2
+ /** Properties of a Peer. */
3
+ export interface IPeer {
4
+
5
+ /** Peer addresses */
6
+ addresses?: (IAddress[]|null);
7
+
8
+ /** Peer protocols */
9
+ protocols?: (string[]|null);
10
+
11
+ /** Peer metadata */
12
+ metadata?: (IMetadata[]|null);
13
+
14
+ /** Peer pubKey */
15
+ pubKey?: (Uint8Array|null);
16
+
17
+ /** Peer peerRecordEnvelope */
18
+ peerRecordEnvelope?: (Uint8Array|null);
19
+ }
20
+
21
+ /** Represents a Peer. */
22
+ export class Peer implements IPeer {
23
+
24
+ /**
25
+ * Constructs a new Peer.
26
+ * @param [p] Properties to set
27
+ */
28
+ constructor(p?: IPeer);
29
+
30
+ /** Peer addresses. */
31
+ public addresses: IAddress[];
32
+
33
+ /** Peer protocols. */
34
+ public protocols: string[];
35
+
36
+ /** Peer metadata. */
37
+ public metadata: IMetadata[];
38
+
39
+ /** Peer pubKey. */
40
+ public pubKey?: (Uint8Array|null);
41
+
42
+ /** Peer peerRecordEnvelope. */
43
+ public peerRecordEnvelope?: (Uint8Array|null);
44
+
45
+ /** Peer _pubKey. */
46
+ public _pubKey?: "pubKey";
47
+
48
+ /** Peer _peerRecordEnvelope. */
49
+ public _peerRecordEnvelope?: "peerRecordEnvelope";
50
+
51
+ /**
52
+ * Encodes the specified Peer message. Does not implicitly {@link Peer.verify|verify} messages.
53
+ * @param m Peer message or plain object to encode
54
+ * @param [w] Writer to encode to
55
+ * @returns Writer
56
+ */
57
+ public static encode(m: IPeer, w?: $protobuf.Writer): $protobuf.Writer;
58
+
59
+ /**
60
+ * Decodes a Peer message from the specified reader or buffer.
61
+ * @param r Reader or buffer to decode from
62
+ * @param [l] Message length if known beforehand
63
+ * @returns Peer
64
+ * @throws {Error} If the payload is not a reader or valid buffer
65
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
66
+ */
67
+ public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Peer;
68
+
69
+ /**
70
+ * Creates a Peer message from a plain object. Also converts values to their respective internal types.
71
+ * @param d Plain object
72
+ * @returns Peer
73
+ */
74
+ public static fromObject(d: { [k: string]: any }): Peer;
75
+
76
+ /**
77
+ * Creates a plain object from a Peer message. Also converts values to other types if specified.
78
+ * @param m Peer
79
+ * @param [o] Conversion options
80
+ * @returns Plain object
81
+ */
82
+ public static toObject(m: Peer, o?: $protobuf.IConversionOptions): { [k: string]: any };
83
+
84
+ /**
85
+ * Converts this Peer to JSON.
86
+ * @returns JSON object
87
+ */
88
+ public toJSON(): { [k: string]: any };
89
+ }
90
+
91
+ /** Properties of an Address. */
92
+ export interface IAddress {
93
+
94
+ /** Address multiaddr */
95
+ multiaddr?: (Uint8Array|null);
96
+
97
+ /** Address isCertified */
98
+ isCertified?: (boolean|null);
99
+ }
100
+
101
+ /** Represents an Address. */
102
+ export class Address implements IAddress {
103
+
104
+ /**
105
+ * Constructs a new Address.
106
+ * @param [p] Properties to set
107
+ */
108
+ constructor(p?: IAddress);
109
+
110
+ /** Address multiaddr. */
111
+ public multiaddr: Uint8Array;
112
+
113
+ /** Address isCertified. */
114
+ public isCertified?: (boolean|null);
115
+
116
+ /** Address _isCertified. */
117
+ public _isCertified?: "isCertified";
118
+
119
+ /**
120
+ * Encodes the specified Address message. Does not implicitly {@link Address.verify|verify} messages.
121
+ * @param m Address message or plain object to encode
122
+ * @param [w] Writer to encode to
123
+ * @returns Writer
124
+ */
125
+ public static encode(m: IAddress, w?: $protobuf.Writer): $protobuf.Writer;
126
+
127
+ /**
128
+ * Decodes an Address message from the specified reader or buffer.
129
+ * @param r Reader or buffer to decode from
130
+ * @param [l] Message length if known beforehand
131
+ * @returns Address
132
+ * @throws {Error} If the payload is not a reader or valid buffer
133
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
134
+ */
135
+ public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Address;
136
+
137
+ /**
138
+ * Creates an Address message from a plain object. Also converts values to their respective internal types.
139
+ * @param d Plain object
140
+ * @returns Address
141
+ */
142
+ public static fromObject(d: { [k: string]: any }): Address;
143
+
144
+ /**
145
+ * Creates a plain object from an Address message. Also converts values to other types if specified.
146
+ * @param m Address
147
+ * @param [o] Conversion options
148
+ * @returns Plain object
149
+ */
150
+ public static toObject(m: Address, o?: $protobuf.IConversionOptions): { [k: string]: any };
151
+
152
+ /**
153
+ * Converts this Address to JSON.
154
+ * @returns JSON object
155
+ */
156
+ public toJSON(): { [k: string]: any };
157
+ }
158
+
159
+ /** Properties of a Metadata. */
160
+ export interface IMetadata {
161
+
162
+ /** Metadata key */
163
+ key?: (string|null);
164
+
165
+ /** Metadata value */
166
+ value?: (Uint8Array|null);
167
+ }
168
+
169
+ /** Represents a Metadata. */
170
+ export class Metadata implements IMetadata {
171
+
172
+ /**
173
+ * Constructs a new Metadata.
174
+ * @param [p] Properties to set
175
+ */
176
+ constructor(p?: IMetadata);
177
+
178
+ /** Metadata key. */
179
+ public key: string;
180
+
181
+ /** Metadata value. */
182
+ public value: Uint8Array;
183
+
184
+ /**
185
+ * Encodes the specified Metadata message. Does not implicitly {@link Metadata.verify|verify} messages.
186
+ * @param m Metadata message or plain object to encode
187
+ * @param [w] Writer to encode to
188
+ * @returns Writer
189
+ */
190
+ public static encode(m: IMetadata, w?: $protobuf.Writer): $protobuf.Writer;
191
+
192
+ /**
193
+ * Decodes a Metadata message from the specified reader or buffer.
194
+ * @param r Reader or buffer to decode from
195
+ * @param [l] Message length if known beforehand
196
+ * @returns Metadata
197
+ * @throws {Error} If the payload is not a reader or valid buffer
198
+ * @throws {$protobuf.util.ProtocolError} If required fields are missing
199
+ */
200
+ public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Metadata;
201
+
202
+ /**
203
+ * Creates a Metadata message from a plain object. Also converts values to their respective internal types.
204
+ * @param d Plain object
205
+ * @returns Metadata
206
+ */
207
+ public static fromObject(d: { [k: string]: any }): Metadata;
208
+
209
+ /**
210
+ * Creates a plain object from a Metadata message. Also converts values to other types if specified.
211
+ * @param m Metadata
212
+ * @param [o] Conversion options
213
+ * @returns Plain object
214
+ */
215
+ public static toObject(m: Metadata, o?: $protobuf.IConversionOptions): { [k: string]: any };
216
+
217
+ /**
218
+ * Converts this Metadata to JSON.
219
+ * @returns JSON object
220
+ */
221
+ public toJSON(): { [k: string]: any };
222
+ }