libp2p 0.35.8 → 0.36.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.
- package/dist/index.min.js +55 -0
- package/dist/src/circuit/auto-relay.d.ts +8 -10
- package/dist/src/circuit/auto-relay.d.ts.map +1 -1
- package/dist/src/config.d.ts +2 -0
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -2
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/content-routing/utils.d.ts +3 -3
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/dialer/index.d.ts +12 -7
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/errors.d.ts +2 -0
- package/dist/src/fetch/constants.d.ts +2 -0
- package/dist/src/fetch/constants.d.ts.map +1 -0
- package/dist/src/fetch/index.d.ts +76 -0
- package/dist/src/fetch/index.d.ts.map +1 -0
- package/dist/src/fetch/proto.d.ts +134 -0
- package/dist/src/identify/index.d.ts +4 -4
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/index.d.ts +116 -7
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/metrics/index.d.ts +9 -4
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/dist/src/metrics/tracked-map.d.ts +6 -1
- package/dist/src/metrics/tracked-map.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-store/address-book.d.ts +30 -84
- package/dist/src/peer-store/address-book.d.ts.map +1 -1
- package/dist/src/peer-store/index.d.ts +28 -94
- package/dist/src/peer-store/index.d.ts.map +1 -1
- package/dist/src/peer-store/key-book.d.ts +31 -15
- package/dist/src/peer-store/key-book.d.ts.map +1 -1
- package/dist/src/peer-store/metadata-book.d.ts +33 -29
- package/dist/src/peer-store/metadata-book.d.ts.map +1 -1
- package/dist/src/peer-store/pb/peer.d.ts +222 -0
- package/dist/src/peer-store/proto-book.d.ts +27 -28
- package/dist/src/peer-store/proto-book.d.ts.map +1 -1
- package/dist/src/peer-store/store.d.ts +73 -0
- package/dist/src/peer-store/store.d.ts.map +1 -0
- package/dist/src/peer-store/types.d.ts +202 -0
- package/dist/src/peer-store/types.d.ts.map +1 -0
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/record/peer-record/index.d.ts +2 -2
- package/dist/src/record/peer-record/index.d.ts.map +1 -1
- package/dist/src/registrar.d.ts +5 -5
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/types.d.ts +90 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/upgrader.d.ts +8 -2
- package/dist/src/upgrader.d.ts.map +1 -1
- package/package.json +23 -26
- package/src/circuit/auto-relay.js +52 -38
- package/src/config.js +2 -0
- package/src/connection-manager/auto-dialler.js +20 -8
- package/src/connection-manager/index.js +42 -22
- package/src/content-routing/utils.js +4 -4
- package/src/dialer/dial-request.js +4 -1
- package/src/dialer/index.js +38 -8
- package/src/errors.js +2 -0
- package/src/fetch/README.md +36 -0
- package/src/fetch/constants.js +6 -0
- package/src/fetch/index.js +159 -0
- package/src/fetch/proto.d.ts +134 -0
- package/src/fetch/proto.js +333 -0
- package/src/fetch/proto.proto +15 -0
- package/src/identify/index.js +47 -38
- package/src/index.js +72 -27
- package/src/metrics/index.js +15 -8
- package/src/metrics/tracked-map.js +40 -14
- package/src/peer-routing.js +4 -1
- package/src/peer-store/address-book.js +254 -226
- package/src/peer-store/index.js +79 -110
- package/src/peer-store/key-book.js +99 -54
- package/src/peer-store/metadata-book.js +171 -101
- package/src/peer-store/pb/peer.d.ts +222 -0
- package/src/peer-store/pb/peer.js +643 -0
- package/src/peer-store/pb/peer.proto +31 -0
- package/src/peer-store/proto-book.js +171 -105
- package/src/peer-store/store.js +263 -0
- package/src/peer-store/types.ts +245 -0
- package/src/ping/index.js +6 -0
- package/src/record/peer-record/index.js +1 -1
- package/src/record/utils.js +1 -1
- package/src/registrar.js +4 -4
- package/src/types.ts +98 -0
- package/src/upgrader.js +32 -2
- package/dist/src/peer-store/book.d.ts +0 -81
- package/dist/src/peer-store/book.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/consts.d.ts +0 -6
- package/dist/src/peer-store/persistent/consts.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/index.d.ts +0 -129
- package/dist/src/peer-store/persistent/index.d.ts.map +0 -1
- package/dist/src/peer-store/persistent/pb/address-book.d.ts +0 -198
- package/dist/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
- package/src/peer-store/book.js +0 -124
- package/src/peer-store/persistent/consts.js +0 -15
- package/src/peer-store/persistent/index.js +0 -408
- package/src/peer-store/persistent/pb/address-book.d.ts +0 -198
- package/src/peer-store/persistent/pb/address-book.js +0 -522
- package/src/peer-store/persistent/pb/address-book.proto +0 -27
- package/src/peer-store/persistent/pb/proto-book.d.ts +0 -59
- package/src/peer-store/persistent/pb/proto-book.js +0 -157
- package/src/peer-store/persistent/pb/proto-book.proto +0 -5
|
@@ -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"}
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import * as $protobuf from "protobufjs";
|
|
2
|
-
/** Properties of an Addresses. */
|
|
3
|
-
export interface IAddresses {
|
|
4
|
-
|
|
5
|
-
/** Addresses addrs */
|
|
6
|
-
addrs?: (Addresses.IAddress[]|null);
|
|
7
|
-
|
|
8
|
-
/** Addresses certifiedRecord */
|
|
9
|
-
certifiedRecord?: (Addresses.ICertifiedRecord|null);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Represents an Addresses. */
|
|
13
|
-
export class Addresses implements IAddresses {
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Constructs a new Addresses.
|
|
17
|
-
* @param [p] Properties to set
|
|
18
|
-
*/
|
|
19
|
-
constructor(p?: IAddresses);
|
|
20
|
-
|
|
21
|
-
/** Addresses addrs. */
|
|
22
|
-
public addrs: Addresses.IAddress[];
|
|
23
|
-
|
|
24
|
-
/** Addresses certifiedRecord. */
|
|
25
|
-
public certifiedRecord?: (Addresses.ICertifiedRecord|null);
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Encodes the specified Addresses message. Does not implicitly {@link Addresses.verify|verify} messages.
|
|
29
|
-
* @param m Addresses message or plain object to encode
|
|
30
|
-
* @param [w] Writer to encode to
|
|
31
|
-
* @returns Writer
|
|
32
|
-
*/
|
|
33
|
-
public static encode(m: IAddresses, w?: $protobuf.Writer): $protobuf.Writer;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Decodes an Addresses message from the specified reader or buffer.
|
|
37
|
-
* @param r Reader or buffer to decode from
|
|
38
|
-
* @param [l] Message length if known beforehand
|
|
39
|
-
* @returns Addresses
|
|
40
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
41
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
42
|
-
*/
|
|
43
|
-
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Creates an Addresses message from a plain object. Also converts values to their respective internal types.
|
|
47
|
-
* @param d Plain object
|
|
48
|
-
* @returns Addresses
|
|
49
|
-
*/
|
|
50
|
-
public static fromObject(d: { [k: string]: any }): Addresses;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Creates a plain object from an Addresses message. Also converts values to other types if specified.
|
|
54
|
-
* @param m Addresses
|
|
55
|
-
* @param [o] Conversion options
|
|
56
|
-
* @returns Plain object
|
|
57
|
-
*/
|
|
58
|
-
public static toObject(m: Addresses, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Converts this Addresses to JSON.
|
|
62
|
-
* @returns JSON object
|
|
63
|
-
*/
|
|
64
|
-
public toJSON(): { [k: string]: any };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export namespace Addresses {
|
|
68
|
-
|
|
69
|
-
/** Properties of an Address. */
|
|
70
|
-
interface IAddress {
|
|
71
|
-
|
|
72
|
-
/** Address multiaddr */
|
|
73
|
-
multiaddr?: (Uint8Array|null);
|
|
74
|
-
|
|
75
|
-
/** Address isCertified */
|
|
76
|
-
isCertified?: (boolean|null);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/** Represents an Address. */
|
|
80
|
-
class Address implements IAddress {
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Constructs a new Address.
|
|
84
|
-
* @param [p] Properties to set
|
|
85
|
-
*/
|
|
86
|
-
constructor(p?: Addresses.IAddress);
|
|
87
|
-
|
|
88
|
-
/** Address multiaddr. */
|
|
89
|
-
public multiaddr: Uint8Array;
|
|
90
|
-
|
|
91
|
-
/** Address isCertified. */
|
|
92
|
-
public isCertified: boolean;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Encodes the specified Address message. Does not implicitly {@link Addresses.Address.verify|verify} messages.
|
|
96
|
-
* @param m Address message or plain object to encode
|
|
97
|
-
* @param [w] Writer to encode to
|
|
98
|
-
* @returns Writer
|
|
99
|
-
*/
|
|
100
|
-
public static encode(m: Addresses.IAddress, w?: $protobuf.Writer): $protobuf.Writer;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Decodes an Address message from the specified reader or buffer.
|
|
104
|
-
* @param r Reader or buffer to decode from
|
|
105
|
-
* @param [l] Message length if known beforehand
|
|
106
|
-
* @returns Address
|
|
107
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
108
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
109
|
-
*/
|
|
110
|
-
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses.Address;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Creates an Address message from a plain object. Also converts values to their respective internal types.
|
|
114
|
-
* @param d Plain object
|
|
115
|
-
* @returns Address
|
|
116
|
-
*/
|
|
117
|
-
public static fromObject(d: { [k: string]: any }): Addresses.Address;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Creates a plain object from an Address message. Also converts values to other types if specified.
|
|
121
|
-
* @param m Address
|
|
122
|
-
* @param [o] Conversion options
|
|
123
|
-
* @returns Plain object
|
|
124
|
-
*/
|
|
125
|
-
public static toObject(m: Addresses.Address, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Converts this Address to JSON.
|
|
129
|
-
* @returns JSON object
|
|
130
|
-
*/
|
|
131
|
-
public toJSON(): { [k: string]: any };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/** Properties of a CertifiedRecord. */
|
|
135
|
-
interface ICertifiedRecord {
|
|
136
|
-
|
|
137
|
-
/** CertifiedRecord seq */
|
|
138
|
-
seq?: (number|null);
|
|
139
|
-
|
|
140
|
-
/** CertifiedRecord raw */
|
|
141
|
-
raw?: (Uint8Array|null);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/** Represents a CertifiedRecord. */
|
|
145
|
-
class CertifiedRecord implements ICertifiedRecord {
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Constructs a new CertifiedRecord.
|
|
149
|
-
* @param [p] Properties to set
|
|
150
|
-
*/
|
|
151
|
-
constructor(p?: Addresses.ICertifiedRecord);
|
|
152
|
-
|
|
153
|
-
/** CertifiedRecord seq. */
|
|
154
|
-
public seq: number;
|
|
155
|
-
|
|
156
|
-
/** CertifiedRecord raw. */
|
|
157
|
-
public raw: Uint8Array;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Encodes the specified CertifiedRecord message. Does not implicitly {@link Addresses.CertifiedRecord.verify|verify} messages.
|
|
161
|
-
* @param m CertifiedRecord message or plain object to encode
|
|
162
|
-
* @param [w] Writer to encode to
|
|
163
|
-
* @returns Writer
|
|
164
|
-
*/
|
|
165
|
-
public static encode(m: Addresses.ICertifiedRecord, w?: $protobuf.Writer): $protobuf.Writer;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Decodes a CertifiedRecord message from the specified reader or buffer.
|
|
169
|
-
* @param r Reader or buffer to decode from
|
|
170
|
-
* @param [l] Message length if known beforehand
|
|
171
|
-
* @returns CertifiedRecord
|
|
172
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
173
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
174
|
-
*/
|
|
175
|
-
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Addresses.CertifiedRecord;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Creates a CertifiedRecord message from a plain object. Also converts values to their respective internal types.
|
|
179
|
-
* @param d Plain object
|
|
180
|
-
* @returns CertifiedRecord
|
|
181
|
-
*/
|
|
182
|
-
public static fromObject(d: { [k: string]: any }): Addresses.CertifiedRecord;
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Creates a plain object from a CertifiedRecord message. Also converts values to other types if specified.
|
|
186
|
-
* @param m CertifiedRecord
|
|
187
|
-
* @param [o] Conversion options
|
|
188
|
-
* @returns Plain object
|
|
189
|
-
*/
|
|
190
|
-
public static toObject(m: Addresses.CertifiedRecord, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Converts this CertifiedRecord to JSON.
|
|
194
|
-
* @returns JSON object
|
|
195
|
-
*/
|
|
196
|
-
public toJSON(): { [k: string]: any };
|
|
197
|
-
}
|
|
198
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import * as $protobuf from "protobufjs";
|
|
2
|
-
/** Properties of a Protocols. */
|
|
3
|
-
export interface IProtocols {
|
|
4
|
-
|
|
5
|
-
/** Protocols protocols */
|
|
6
|
-
protocols?: (string[]|null);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Represents a Protocols. */
|
|
10
|
-
export class Protocols implements IProtocols {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Constructs a new Protocols.
|
|
14
|
-
* @param [p] Properties to set
|
|
15
|
-
*/
|
|
16
|
-
constructor(p?: IProtocols);
|
|
17
|
-
|
|
18
|
-
/** Protocols protocols. */
|
|
19
|
-
public protocols: string[];
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Encodes the specified Protocols message. Does not implicitly {@link Protocols.verify|verify} messages.
|
|
23
|
-
* @param m Protocols message or plain object to encode
|
|
24
|
-
* @param [w] Writer to encode to
|
|
25
|
-
* @returns Writer
|
|
26
|
-
*/
|
|
27
|
-
public static encode(m: IProtocols, w?: $protobuf.Writer): $protobuf.Writer;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Decodes a Protocols message from the specified reader or buffer.
|
|
31
|
-
* @param r Reader or buffer to decode from
|
|
32
|
-
* @param [l] Message length if known beforehand
|
|
33
|
-
* @returns Protocols
|
|
34
|
-
* @throws {Error} If the payload is not a reader or valid buffer
|
|
35
|
-
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
36
|
-
*/
|
|
37
|
-
public static decode(r: ($protobuf.Reader|Uint8Array), l?: number): Protocols;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Creates a Protocols message from a plain object. Also converts values to their respective internal types.
|
|
41
|
-
* @param d Plain object
|
|
42
|
-
* @returns Protocols
|
|
43
|
-
*/
|
|
44
|
-
public static fromObject(d: { [k: string]: any }): Protocols;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Creates a plain object from a Protocols message. Also converts values to other types if specified.
|
|
48
|
-
* @param m Protocols
|
|
49
|
-
* @param [o] Conversion options
|
|
50
|
-
* @returns Plain object
|
|
51
|
-
*/
|
|
52
|
-
public static toObject(m: Protocols, o?: $protobuf.IConversionOptions): { [k: string]: any };
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Converts this Protocols to JSON.
|
|
56
|
-
* @returns JSON object
|
|
57
|
-
*/
|
|
58
|
-
public toJSON(): { [k: string]: any };
|
|
59
|
-
}
|
package/src/peer-store/book.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const errcode = require('err-code')
|
|
4
|
-
const PeerId = require('peer-id')
|
|
5
|
-
const { codes } = require('../errors')
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @param {any} data
|
|
9
|
-
*/
|
|
10
|
-
const passthrough = data => data
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @typedef {import('./')} PeerStore
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
class Book {
|
|
17
|
-
/**
|
|
18
|
-
* The Book is the skeleton for the PeerStore books.
|
|
19
|
-
*
|
|
20
|
-
* @class
|
|
21
|
-
* @param {Object} properties
|
|
22
|
-
* @param {PeerStore} properties.peerStore - PeerStore instance.
|
|
23
|
-
* @param {string} properties.eventName - Name of the event to emit by the PeerStore.
|
|
24
|
-
* @param {string} properties.eventProperty - Name of the property to emit by the PeerStore.
|
|
25
|
-
* @param {(data: any) => any[]} [properties.eventTransformer] - Transformer function of the provided data for being emitted.
|
|
26
|
-
*/
|
|
27
|
-
constructor ({ peerStore, eventName, eventProperty, eventTransformer = passthrough }) {
|
|
28
|
-
this._ps = peerStore
|
|
29
|
-
this.eventName = eventName
|
|
30
|
-
this.eventProperty = eventProperty
|
|
31
|
-
this.eventTransformer = eventTransformer
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Map known peers to their data.
|
|
35
|
-
*
|
|
36
|
-
* @type {Map<string, any[]|any>}
|
|
37
|
-
*/
|
|
38
|
-
this.data = new Map()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Set known data of a provided peer.
|
|
43
|
-
*
|
|
44
|
-
* @param {PeerId} peerId
|
|
45
|
-
* @param {any[]|any} data
|
|
46
|
-
*/
|
|
47
|
-
set (peerId, data) {
|
|
48
|
-
throw errcode(new Error('set must be implemented by the subclass'), codes.ERR_NOT_IMPLEMENTED)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Set data into the datastructure, persistence and emit it using the provided transformers.
|
|
53
|
-
*
|
|
54
|
-
* @protected
|
|
55
|
-
* @param {PeerId} peerId - peerId of the data to store
|
|
56
|
-
* @param {any} data - data to store.
|
|
57
|
-
* @param {Object} [options] - storing options.
|
|
58
|
-
* @param {boolean} [options.emit = true] - emit the provided data.
|
|
59
|
-
* @returns {void}
|
|
60
|
-
*/
|
|
61
|
-
_setData (peerId, data, { emit = true } = {}) {
|
|
62
|
-
const b58key = peerId.toB58String()
|
|
63
|
-
|
|
64
|
-
// Store data in memory
|
|
65
|
-
this.data.set(b58key, data)
|
|
66
|
-
|
|
67
|
-
// Emit event
|
|
68
|
-
emit && this._emit(peerId, data)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Emit data.
|
|
73
|
-
*
|
|
74
|
-
* @protected
|
|
75
|
-
* @param {PeerId} peerId
|
|
76
|
-
* @param {any} [data]
|
|
77
|
-
*/
|
|
78
|
-
_emit (peerId, data) {
|
|
79
|
-
this._ps.emit(this.eventName, {
|
|
80
|
-
peerId,
|
|
81
|
-
[this.eventProperty]: this.eventTransformer(data)
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Get the known data of a provided peer.
|
|
87
|
-
* Returns `undefined` if there is no available data for the given peer.
|
|
88
|
-
*
|
|
89
|
-
* @param {PeerId} peerId
|
|
90
|
-
* @returns {any[]|any|undefined}
|
|
91
|
-
*/
|
|
92
|
-
get (peerId) {
|
|
93
|
-
if (!PeerId.isPeerId(peerId)) {
|
|
94
|
-
throw errcode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const rec = this.data.get(peerId.toB58String())
|
|
98
|
-
|
|
99
|
-
// @ts-ignore
|
|
100
|
-
return rec ? [...rec] : undefined
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Deletes the provided peer from the book.
|
|
105
|
-
*
|
|
106
|
-
* @param {PeerId} peerId
|
|
107
|
-
* @returns {boolean}
|
|
108
|
-
*/
|
|
109
|
-
delete (peerId) {
|
|
110
|
-
if (!PeerId.isPeerId(peerId)) {
|
|
111
|
-
throw errcode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (!this.data.delete(peerId.toB58String())) {
|
|
115
|
-
return false
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
this._emit(peerId, [])
|
|
119
|
-
|
|
120
|
-
return true
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
module.exports = Book
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
module.exports.NAMESPACE_COMMON = '/peers/'
|
|
4
|
-
|
|
5
|
-
// /peers/protos/<b32 peer id no padding>
|
|
6
|
-
module.exports.NAMESPACE_ADDRESS = '/peers/addrs/'
|
|
7
|
-
|
|
8
|
-
// /peers/keys/<b32 peer id no padding>
|
|
9
|
-
module.exports.NAMESPACE_KEYS = '/peers/keys/'
|
|
10
|
-
|
|
11
|
-
// /peers/metadata/<b32 peer id no padding>/<key>
|
|
12
|
-
module.exports.NAMESPACE_METADATA = '/peers/metadata/'
|
|
13
|
-
|
|
14
|
-
// /peers/addrs/<b32 peer id no padding>
|
|
15
|
-
module.exports.NAMESPACE_PROTOCOL = '/peers/protos/'
|