@libp2p/peer-store 1.0.15 → 2.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.
- package/README.md +160 -10
- package/dist/src/address-book.d.ts +4 -4
- package/dist/src/address-book.d.ts.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/key-book.d.ts +2 -2
- package/dist/src/key-book.d.ts.map +1 -1
- package/dist/src/metadata-book.d.ts +2 -2
- package/dist/src/metadata-book.d.ts.map +1 -1
- package/dist/src/proto-book.d.ts +2 -2
- package/dist/src/proto-book.d.ts.map +1 -1
- package/dist/src/store.d.ts +3 -3
- package/dist/src/store.d.ts.map +1 -1
- package/dist/src/store.js +1 -1
- package/dist/src/store.js.map +1 -1
- package/package.json +14 -9
- package/src/address-book.ts +4 -4
- package/src/index.ts +3 -3
- package/src/key-book.ts +2 -2
- package/src/metadata-book.ts +2 -2
- package/src/proto-book.ts +2 -2
- package/src/store.ts +3 -3
- package/src/README.md +0 -145
package/README.md
CHANGED
|
@@ -1,31 +1,178 @@
|
|
|
1
|
-
# libp2p-
|
|
1
|
+
# js-libp2p-peer-store <!-- omit in toc -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/libp2p/js-libp2p-peer-store/actions/workflows/js-test-and-release.yml)
|
|
4
|
+
|
|
5
|
+
> Stores information about peers libp2p knows on the network
|
|
4
6
|
|
|
5
7
|
## Table of Contents <!-- omit in toc -->
|
|
6
8
|
|
|
7
9
|
- [Description](#description)
|
|
8
|
-
- [
|
|
10
|
+
- [Submitting records to the PeerStore](#submitting-records-to-the-peerstore)
|
|
11
|
+
- [Identify](#identify)
|
|
12
|
+
- [Peer Discovery](#peer-discovery)
|
|
13
|
+
- [Dialer](#dialer)
|
|
14
|
+
- [DHT](#dht)
|
|
15
|
+
- [Retrieving records from the PeerStore](#retrieving-records-from-the-peerstore)
|
|
16
|
+
- [Peer](#peer)
|
|
17
|
+
- [Protocols](#protocols)
|
|
18
|
+
- [Multiaddrs](#multiaddrs)
|
|
19
|
+
- [PeerStore implementation](#peerstore-implementation)
|
|
20
|
+
- [Components](#components)
|
|
21
|
+
- [Address Book](#address-book)
|
|
22
|
+
- [Key Book](#key-book)
|
|
23
|
+
- [Protocol Book](#protocol-book)
|
|
24
|
+
- [Metadata Book](#metadata-book)
|
|
25
|
+
- [API](#api)
|
|
26
|
+
- [Events](#events)
|
|
27
|
+
- [Data Persistence](#data-persistence)
|
|
28
|
+
- [Future Considerations](#future-considerations)
|
|
9
29
|
- [Installation](#installation)
|
|
10
30
|
- [License](#license)
|
|
11
31
|
- [Contribution](#contribution)
|
|
12
32
|
|
|
13
33
|
## Description
|
|
14
34
|
|
|
15
|
-
|
|
35
|
+
Libp2p's PeerStore is responsible for keeping an updated register with the relevant information of the known peers. It should be the single source of truth for all peer data, where a subsystem can learn about peers' data and where someone can listen for updates. The PeerStore comprises four main components: `addressBook`, `keyBook`, `protocolBook` and `metadataBook`.
|
|
36
|
+
|
|
37
|
+
The PeerStore manages the high level operations on its inner books. Moreover, the PeerStore should be responsible for notifying interested parties of relevant events, through its Event Emitter.
|
|
38
|
+
|
|
39
|
+
### Submitting records to the PeerStore
|
|
40
|
+
|
|
41
|
+
Several libp2p subsystems will perform operations that might gather relevant information about peers.
|
|
42
|
+
|
|
43
|
+
#### Identify
|
|
44
|
+
- The Identify protocol automatically runs on every connection when multiplexing is enabled. The protocol will put the multiaddrs and protocols provided by the peer to the PeerStore.
|
|
45
|
+
- In the background, the Identify Service is also waiting for protocol change notifications of peers via the IdentifyPush protocol. Peers may leverage the `identify-push` message to communicate protocol changes to all connected peers, so that their PeerStore can be updated with the updated protocols.
|
|
46
|
+
- While it is currently not supported in js-libp2p, future iterations may also support the [IdentifyDelta protocol](https://github.com/libp2p/specs/pull/176).
|
|
47
|
+
- Taking into account that the Identify protocol records are directly from the peer, they should be considered the source of truth and weighted accordingly.
|
|
48
|
+
|
|
49
|
+
#### Peer Discovery
|
|
50
|
+
- Libp2p discovery protocols aim to discover new peers in the network. In a typical discovery protocol, addresses of the peer are discovered along with its peer id. Once this happens, a libp2p discovery protocol should emit a `peer` event with the information of the discovered peer and this information will be added to the PeerStore by libp2p.
|
|
51
|
+
|
|
52
|
+
#### Dialer
|
|
53
|
+
- Libp2p API supports dialing a peer given a `multiaddr`, and no prior knowledge of the peer. If the node is able to establish a connection with the peer, it and its multiaddr is added to the PeerStore.
|
|
54
|
+
- When a connection is being upgraded, more precisely after its encryption, or even in a discovery protocol, a libp2p node can get to know other parties public keys. In this scenario, libp2p will add the peer's public key to its `KeyBook`.
|
|
55
|
+
|
|
56
|
+
#### DHT
|
|
57
|
+
- On some DHT operations, such as finding providers for a given CID, nodes may exchange peer data as part of the query. This passive peer discovery should result in the DHT emitting the `peer` event in the same way [Peer Discovery](#peerdiscovery) does.
|
|
58
|
+
|
|
59
|
+
### Retrieving records from the PeerStore
|
|
60
|
+
|
|
61
|
+
When data in the PeerStore is updated the PeerStore will emit events based on the changes, to allow applications and other subsystems to take action on those changes. Any subsystem interested in these notifications should subscribe the [`PeerStore events`][peer-store-events].
|
|
62
|
+
|
|
63
|
+
#### Peer
|
|
64
|
+
- Each time a new peer is discovered, the PeerStore should emit a [`peer` event][peer-store-events], so that interested parties can leverage this peer and establish a connection with it.
|
|
65
|
+
|
|
66
|
+
#### Protocols
|
|
67
|
+
- When the known protocols of a peer change, the PeerStore emits a [`change:protocols` event][peer-store-events].
|
|
68
|
+
|
|
69
|
+
#### Multiaddrs
|
|
70
|
+
- When the known listening `multiaddrs` of a peer change, the PeerStore emits a [`change:multiaddrs` event][peer-store-events].
|
|
71
|
+
|
|
72
|
+
### PeerStore implementation
|
|
16
73
|
|
|
17
|
-
|
|
74
|
+
The PeerStore wraps four main components: `addressBook`, `keyBook`, `protocolBook` and `metadataBook`. Moreover, it provides a high level API for those components, as well as data events.
|
|
18
75
|
|
|
19
|
-
|
|
76
|
+
### Components
|
|
20
77
|
|
|
21
|
-
|
|
22
|
-
import { trackedMap } from '@libp2p/tracked-map'
|
|
78
|
+
#### Address Book
|
|
23
79
|
|
|
24
|
-
|
|
80
|
+
The `addressBook` keeps the known multiaddrs of a peer. The multiaddrs of each peer may change over time and the Address Book must account for this.
|
|
25
81
|
|
|
26
|
-
|
|
82
|
+
`Map<string, Address>`
|
|
83
|
+
|
|
84
|
+
A `peerId.toString()` identifier mapping to a `Address` object, which should have the following structure:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
{
|
|
88
|
+
multiaddr: <Multiaddr>
|
|
89
|
+
}
|
|
27
90
|
```
|
|
28
91
|
|
|
92
|
+
#### Key Book
|
|
93
|
+
|
|
94
|
+
The `keyBook` tracks the public keys of the peers by keeping their [`PeerId`][peer-id].
|
|
95
|
+
|
|
96
|
+
`Map<string, PeerId`
|
|
97
|
+
|
|
98
|
+
A `peerId.toString()` identifier mapping to a `PeerId` of the peer. This instance contains the peer public key.
|
|
99
|
+
|
|
100
|
+
#### Protocol Book
|
|
101
|
+
|
|
102
|
+
The `protoBook` holds the identifiers of the protocols supported by each peer. The protocols supported by each peer are dynamic and will change over time.
|
|
103
|
+
|
|
104
|
+
`Map<string, Set<string>>`
|
|
105
|
+
|
|
106
|
+
A `peerId.toString()` identifier mapping to a `Set` of protocol identifier strings.
|
|
107
|
+
|
|
108
|
+
#### Metadata Book
|
|
109
|
+
|
|
110
|
+
The `metadataBook` keeps track of the known metadata of a peer. Its metadata is stored in a key value fashion, where a key identifier (`string`) represents a metadata value (`Uint8Array`).
|
|
111
|
+
|
|
112
|
+
`Map<string, Map<string, Uint8Array>>`
|
|
113
|
+
|
|
114
|
+
A `peerId.toString()` identifier mapping to the peer metadata Map.
|
|
115
|
+
|
|
116
|
+
### API
|
|
117
|
+
|
|
118
|
+
For the complete API documentation, you should check the [API.md](../../doc/API.md).
|
|
119
|
+
|
|
120
|
+
Access to its underlying books:
|
|
121
|
+
|
|
122
|
+
- `peerStore.addressBook.*`
|
|
123
|
+
- `peerStore.keyBook.*`
|
|
124
|
+
- `peerStore.metadataBook.*`
|
|
125
|
+
- `peerStore.protoBook.*`
|
|
126
|
+
|
|
127
|
+
### Events
|
|
128
|
+
|
|
129
|
+
- `peer` - emitted when a new peer is added.
|
|
130
|
+
- `change:multiaadrs` - emitted when a known peer has a different set of multiaddrs.
|
|
131
|
+
- `change:protocols` - emitted when a known peer supports a different set of protocols.
|
|
132
|
+
- `change:pubkey` - emitted when a peer's public key is known.
|
|
133
|
+
- `change:metadata` - emitted when known metadata of a peer changes.
|
|
134
|
+
|
|
135
|
+
## Data Persistence
|
|
136
|
+
|
|
137
|
+
The data stored in the PeerStore can be persisted if configured appropriately. Keeping a record of the peers already discovered by the peer, as well as their known data aims to improve the efficiency of peers joining the network after being offline.
|
|
138
|
+
|
|
139
|
+
The libp2p node will need to receive a [datastore](https://github.com/ipfs/interface-datastore), in order to persist this data across restarts. A [datastore](https://github.com/ipfs/interface-datastore) stores its data in a key-value fashion. As a result, we need coherent keys so that we do not overwrite data.
|
|
140
|
+
|
|
141
|
+
The PeerStore should not continuously update the datastore whenever data is changed. Instead, it should only store new data after reaching a certain threshold of "dirty" peers, as well as when the node is stopped, in order to batch writes to the datastore.
|
|
142
|
+
|
|
143
|
+
The peer id will be appended to the datastore key for each data namespace. The namespaces were defined as follows:
|
|
144
|
+
|
|
145
|
+
**AddressBook**
|
|
146
|
+
|
|
147
|
+
All the known peer addresses are stored with a key pattern as follows:
|
|
148
|
+
|
|
149
|
+
`/peers/addrs/<b32 peer id no padding>`
|
|
150
|
+
|
|
151
|
+
**ProtoBook**
|
|
152
|
+
|
|
153
|
+
All the known peer protocols are stored with a key pattern as follows:
|
|
154
|
+
|
|
155
|
+
`/peers/protos/<b32 peer id no padding>`
|
|
156
|
+
|
|
157
|
+
**KeyBook**
|
|
158
|
+
|
|
159
|
+
All public keys are stored under the following pattern:
|
|
160
|
+
|
|
161
|
+
` /peers/keys/<b32 peer id no padding>`
|
|
162
|
+
|
|
163
|
+
**MetadataBook**
|
|
164
|
+
|
|
165
|
+
Metadata is stored under the following key pattern:
|
|
166
|
+
|
|
167
|
+
`/peers/metadata/<b32 peer id no padding>/<key>`
|
|
168
|
+
|
|
169
|
+
## Future Considerations
|
|
170
|
+
|
|
171
|
+
- If multiaddr TTLs are added, the PeerStore may schedule jobs to delete all addresses that exceed the TTL to prevent AddressBook bloating
|
|
172
|
+
- Further API methods will probably need to be added in the context of multiaddr validity and confidence.
|
|
173
|
+
- When improving libp2p configuration for specific runtimes, we should take into account the PeerStore recommended datastore.
|
|
174
|
+
- When improving libp2p configuration, we should think about a possible way of allowing the configuration of Bootstrap to be influenced by the persisted peers, as a way to decrease the load on Bootstrap nodes.
|
|
175
|
+
|
|
29
176
|
## Installation
|
|
30
177
|
|
|
31
178
|
```console
|
|
@@ -42,3 +189,6 @@ Licensed under either of
|
|
|
42
189
|
### Contribution
|
|
43
190
|
|
|
44
191
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
|
192
|
+
|
|
193
|
+
[peer-id]: https://github.com/libp2p/js-peer-id
|
|
194
|
+
[peer-store-events]: [https://github.com/libp2p/js-libp2p/blob/master/doc/API.md#libp2ppeerStore]
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Multiaddr } from '@multiformats/multiaddr';
|
|
2
2
|
import { RecordEnvelope } from '@libp2p/peer-record';
|
|
3
|
-
import type { AddressFilter, PeerStore } from '@libp2p/
|
|
3
|
+
import type { AddressFilter, PeerStore } from '@libp2p/interface-peer-store';
|
|
4
4
|
import type { Store } from './store.js';
|
|
5
|
-
import type { Envelope } from '@libp2p/
|
|
6
|
-
import type { PeerId } from '@libp2p/
|
|
5
|
+
import type { Envelope } from '@libp2p/interface-record';
|
|
6
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
7
7
|
export declare class PeerStoreAddressBook {
|
|
8
8
|
private readonly dispatchEvent;
|
|
9
9
|
private readonly store;
|
|
@@ -21,7 +21,7 @@ export declare class PeerStoreAddressBook {
|
|
|
21
21
|
* Returns undefined if no record exists.
|
|
22
22
|
*/
|
|
23
23
|
getPeerRecord(peerId: PeerId): Promise<RecordEnvelope | undefined>;
|
|
24
|
-
get(peerId: PeerId): Promise<import("@libp2p/
|
|
24
|
+
get(peerId: PeerId): Promise<import("@libp2p/interface-peer-store").Address[]>;
|
|
25
25
|
set(peerId: PeerId, multiaddrs: Multiaddr[]): Promise<void>;
|
|
26
26
|
add(peerId: PeerId, multiaddrs: Multiaddr[]): Promise<void>;
|
|
27
27
|
delete(peerId: PeerId): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address-book.d.ts","sourceRoot":"","sources":["../../src/address-book.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAc,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAQhE,OAAO,KAAK,EAAE,aAAa,EAAkC,SAAS,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"address-book.d.ts","sourceRoot":"","sources":["../../src/address-book.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAEnD,OAAO,EAAc,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAQhE,OAAO,KAAK,EAAE,aAAa,EAAkC,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC5G,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAUvD,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;gBAEhC,aAAa,EAAE,SAAS,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,aAAa;IAMnG;;;;OAIG;IACG,iBAAiB,CAAE,QAAQ,EAAE,QAAQ;IAyErC,cAAc,CAAE,MAAM,EAAE,MAAM;IAmBpC;;;OAGG;IACG,aAAa,CAAE,MAAM,EAAE,MAAM;IAU7B,GAAG,CAAE,MAAM,EAAE,MAAM;IAuBnB,GAAG,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE;IAsE5C,GAAG,CAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE;IAoE5C,MAAM,CAAE,MAAM,EAAE,MAAM;CAoC7B"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from '@libp2p/interfaces/events';
|
|
2
|
-
import type { PeerStore, AddressBook, KeyBook, MetadataBook, ProtoBook, PeerStoreEvents, PeerStoreInit, Peer } from '@libp2p/
|
|
3
|
-
import type { PeerId } from '@libp2p/
|
|
4
|
-
import { Components, Initializable } from '@libp2p/
|
|
2
|
+
import type { PeerStore, AddressBook, KeyBook, MetadataBook, ProtoBook, PeerStoreEvents, PeerStoreInit, Peer } from '@libp2p/interface-peer-store';
|
|
3
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
4
|
+
import { Components, Initializable } from '@libp2p/components';
|
|
5
5
|
/**
|
|
6
6
|
* An implementation of PeerStore that stores data in a Datastore
|
|
7
7
|
*/
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAMxD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAMxD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAA;AAClJ,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAI9D;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,YAAY,CAAC,eAAe,CAAE,YAAW,SAAS,EAAE,aAAa;IACjG,WAAW,EAAE,WAAW,CAAA;IACxB,OAAO,EAAE,OAAO,CAAA;IAChB,YAAY,EAAE,YAAY,CAAA;IAC1B,SAAS,EAAE,SAAS,CAAA;IAE3B,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;gBAEhB,IAAI,GAAE,aAAkB;IAUrC,IAAI,CAAE,UAAU,EAAE,UAAU;IAKtB,OAAO,CAAE,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI;IAoBjC,GAAG,IAAK,OAAO,CAAC,IAAI,EAAE,CAAC;IAU7B;;OAEG;IACG,MAAM,CAAE,MAAM,EAAE,MAAM;IAa5B;;OAEG;IACG,GAAG,CAAE,MAAM,EAAE,MAAM;IAazB;;OAEG;IACG,GAAG,CAAE,MAAM,EAAE,MAAM;CAY1B"}
|
package/dist/src/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { PeerStoreKeyBook } from './key-book.js';
|
|
|
5
5
|
import { PeerStoreMetadataBook } from './metadata-book.js';
|
|
6
6
|
import { PeerStoreProtoBook } from './proto-book.js';
|
|
7
7
|
import { PersistentStore } from './store.js';
|
|
8
|
-
import { Components } from '@libp2p/
|
|
8
|
+
import { Components } from '@libp2p/components';
|
|
9
9
|
const log = logger('libp2p:peer-store');
|
|
10
10
|
/**
|
|
11
11
|
* An implementation of PeerStore that stores data in a Datastore
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAS,MAAM,YAAY,CAAA;AAGnD,OAAO,EAAE,UAAU,EAAiB,MAAM
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,eAAe,EAAS,MAAM,YAAY,CAAA;AAGnD,OAAO,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAA;AAE9D,MAAM,GAAG,GAA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K,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;SACrC;gBAAS;YACR,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;YAClC,OAAO,EAAE,CAAA;SACV;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAE,MAAc;QACvB,GAAG,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;QAChC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;QAChD,GAAG,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAA;QAE9B,IAAI;YACF,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;SACpC;gBAAS;YACR,GAAG,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAA;YAClC,OAAO,EAAE,CAAA;SACV;IACH,CAAC;CACF"}
|
package/dist/src/key-book.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Store } from './store.js';
|
|
2
|
-
import type { PeerStore, KeyBook } from '@libp2p/
|
|
3
|
-
import type { PeerId } from '@libp2p/
|
|
2
|
+
import type { PeerStore, KeyBook } from '@libp2p/interface-peer-store';
|
|
3
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
4
4
|
export declare class PeerStoreKeyBook implements KeyBook {
|
|
5
5
|
private readonly dispatchEvent;
|
|
6
6
|
private readonly store;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-book.d.ts","sourceRoot":"","sources":["../../src/key-book.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAiC,MAAM
|
|
1
|
+
{"version":3,"file":"key-book.d.ts","sourceRoot":"","sources":["../../src/key-book.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAiC,MAAM,8BAA8B,CAAA;AACrG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAMvD,qBAAa,gBAAiB,YAAW,OAAO;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAE7B;;OAEG;gBACU,aAAa,EAAE,SAAS,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK;IAKpE;;OAEG;IACG,GAAG,CAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU;IAgDhD;;OAEG;IACG,GAAG,CAAE,MAAM,EAAE,MAAM;IAqBnB,MAAM,CAAE,MAAM,EAAE,MAAM;CAsC7B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Store } from './store.js';
|
|
2
|
-
import type { PeerStore, MetadataBook } from '@libp2p/
|
|
3
|
-
import type { PeerId } from '@libp2p/
|
|
2
|
+
import type { PeerStore, MetadataBook } from '@libp2p/interface-peer-store';
|
|
3
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
4
4
|
export declare class PeerStoreMetadataBook implements MetadataBook {
|
|
5
5
|
private readonly dispatchEvent;
|
|
6
6
|
private readonly store;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata-book.d.ts","sourceRoot":"","sources":["../../src/metadata-book.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAgC,MAAM
|
|
1
|
+
{"version":3,"file":"metadata-book.d.ts","sourceRoot":"","sources":["../../src/metadata-book.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAgC,MAAM,8BAA8B,CAAA;AACzG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAMvD,qBAAa,qBAAsB,YAAW,YAAY;IACxD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAE7B;;;OAGG;gBACU,aAAa,EAAE,SAAS,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK;IAKpE;;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;IAwC5D;;OAEG;IACG,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;IA8CxD,MAAM,CAAE,MAAM,EAAE,MAAM;IAuCtB,WAAW,CAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;CAsC/C"}
|
package/dist/src/proto-book.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Store } from './store.js';
|
|
2
|
-
import type { PeerStore, ProtoBook } from '@libp2p/
|
|
3
|
-
import type { PeerId } from '@libp2p/
|
|
2
|
+
import type { PeerStore, ProtoBook } from '@libp2p/interface-peer-store';
|
|
3
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
4
4
|
export declare class PeerStoreProtoBook implements ProtoBook {
|
|
5
5
|
private readonly dispatchEvent;
|
|
6
6
|
private readonly store;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proto-book.d.ts","sourceRoot":"","sources":["../../src/proto-book.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAiC,SAAS,EAAE,SAAS,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"proto-book.d.ts","sourceRoot":"","sources":["../../src/proto-book.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAiC,SAAS,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACvG,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAMvD,qBAAa,kBAAmB,YAAW,SAAS;IAClD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAE7B;;;OAGG;gBACU,aAAa,EAAE,SAAS,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,KAAK;IAK9D,GAAG,CAAE,MAAM,EAAE,MAAM;IAqBnB,GAAG,CAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE;IAiDxC,GAAG,CAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE;IAkDxC,MAAM,CAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE;IAoD3C,MAAM,CAAE,MAAM,EAAE,MAAM;CAmC7B"}
|
package/dist/src/store.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Key } from 'interface-datastore/key';
|
|
2
|
-
import type { Peer } from '@libp2p/
|
|
3
|
-
import type { PeerId } from '@libp2p/
|
|
4
|
-
import { Components } from '@libp2p/
|
|
2
|
+
import type { Peer } from '@libp2p/interface-peer-store';
|
|
3
|
+
import type { PeerId } from '@libp2p/interface-peer-id';
|
|
4
|
+
import { Components } from '@libp2p/components';
|
|
5
5
|
export interface Store {
|
|
6
6
|
has: (peerId: PeerId) => Promise<boolean>;
|
|
7
7
|
save: (peer: Peer) => Promise<Peer>;
|
package/dist/src/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAM7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAM7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAM/C,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACzC,IAAI,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACvC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACzC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7D,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACrE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC7D,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,IAA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
import { Peer as PeerPB } from './pb/peer.js';
|
|
9
9
|
import mortice from 'mortice';
|
|
10
10
|
import { equals as uint8arrayEquals } from 'uint8arrays/equals';
|
|
11
|
-
import { Components } from '@libp2p/
|
|
11
|
+
import { Components } from '@libp2p/components';
|
|
12
12
|
const log = logger('libp2p:peer-store:store');
|
|
13
13
|
const NAMESPACE_COMMON = '/peers/';
|
|
14
14
|
export class PersistentStore {
|
package/dist/src/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAY,IAAI,IAAI,MAAM,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAG/D,OAAO,EAAE,UAAU,EAAE,MAAM
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAC7C,OAAO,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EAAE,IAAI,CAAC,kBAAkB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;SACpG,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,CAAE,GAAG;QACT,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,SAAS,CAAC;YAC/D,MAAM,EAAE,gBAAgB;SACzB,CAAC,EAAE;YACF,wDAAwD;YACxD,MAAM,SAAS,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YAC9C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAEpC,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAA;SACtC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/peer-store",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Stores information about peers libp2p knows on the network",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
|
-
"homepage": "https://github.com/libp2p/js-libp2p-
|
|
6
|
+
"homepage": "https://github.com/libp2p/js-libp2p-peer-store#readme",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/libp2p/js-libp2p-
|
|
9
|
+
"url": "git+https://github.com/libp2p/js-libp2p-peer-store.git"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/libp2p/js-libp2p-
|
|
12
|
+
"url": "https://github.com/libp2p/js-libp2p-peer-store/issues"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"IPFS"
|
|
@@ -138,11 +138,16 @@
|
|
|
138
138
|
"release": "aegir release"
|
|
139
139
|
},
|
|
140
140
|
"dependencies": {
|
|
141
|
-
"@libp2p/
|
|
142
|
-
"@libp2p/
|
|
141
|
+
"@libp2p/components": "^1.0.0",
|
|
142
|
+
"@libp2p/interface-peer-id": "^1.0.2",
|
|
143
|
+
"@libp2p/interface-peer-info": "^1.0.1",
|
|
144
|
+
"@libp2p/interface-peer-store": "^1.0.0",
|
|
145
|
+
"@libp2p/interface-record": "^1.0.1",
|
|
146
|
+
"@libp2p/interfaces": "^3.0.2",
|
|
147
|
+
"@libp2p/logger": "^1.1.6",
|
|
143
148
|
"@libp2p/peer-id": "^1.1.0",
|
|
144
|
-
"@libp2p/peer-record": "^
|
|
145
|
-
"@multiformats/multiaddr": "^10.
|
|
149
|
+
"@libp2p/peer-record": "^2.0.0",
|
|
150
|
+
"@multiformats/multiaddr": "^10.2.0",
|
|
146
151
|
"err-code": "^3.0.1",
|
|
147
152
|
"interface-datastore": "^6.1.0",
|
|
148
153
|
"it-all": "^1.0.6",
|
|
@@ -156,7 +161,7 @@
|
|
|
156
161
|
"uint8arrays": "^3.0.0"
|
|
157
162
|
},
|
|
158
163
|
"devDependencies": {
|
|
159
|
-
"@libp2p/interface-compliance-tests": "^
|
|
164
|
+
"@libp2p/interface-compliance-tests": "^2.0.0",
|
|
160
165
|
"@libp2p/peer-id-factory": "^1.0.0",
|
|
161
166
|
"@libp2p/utils": "^1.0.9",
|
|
162
167
|
"aegir": "^37.0.7",
|
package/src/address-book.ts
CHANGED
|
@@ -10,11 +10,11 @@ import map from 'it-map'
|
|
|
10
10
|
import each from 'it-foreach'
|
|
11
11
|
import { peerIdFromPeerId } from '@libp2p/peer-id'
|
|
12
12
|
import { CustomEvent } from '@libp2p/interfaces/events'
|
|
13
|
-
import type { AddressFilter, Peer, PeerMultiaddrsChangeData, PeerStore } from '@libp2p/
|
|
13
|
+
import type { AddressFilter, Peer, PeerMultiaddrsChangeData, PeerStore } from '@libp2p/interface-peer-store'
|
|
14
14
|
import type { Store } from './store.js'
|
|
15
|
-
import type { Envelope } from '@libp2p/
|
|
16
|
-
import type { PeerId } from '@libp2p/
|
|
17
|
-
import type { PeerInfo } from '@libp2p/
|
|
15
|
+
import type { Envelope } from '@libp2p/interface-record'
|
|
16
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
17
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
18
18
|
|
|
19
19
|
const log = logger('libp2p:peer-store:address-book')
|
|
20
20
|
const EVENT_NAME = 'change:multiaddrs'
|
package/src/index.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { PeerStoreKeyBook } from './key-book.js'
|
|
|
5
5
|
import { PeerStoreMetadataBook } from './metadata-book.js'
|
|
6
6
|
import { PeerStoreProtoBook } from './proto-book.js'
|
|
7
7
|
import { PersistentStore, Store } from './store.js'
|
|
8
|
-
import type { PeerStore, AddressBook, KeyBook, MetadataBook, ProtoBook, PeerStoreEvents, PeerStoreInit, Peer } from '@libp2p/
|
|
9
|
-
import type { PeerId } from '@libp2p/
|
|
10
|
-
import { Components, Initializable } from '@libp2p/
|
|
8
|
+
import type { PeerStore, AddressBook, KeyBook, MetadataBook, ProtoBook, PeerStoreEvents, PeerStoreInit, Peer } from '@libp2p/interface-peer-store'
|
|
9
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
10
|
+
import { Components, Initializable } from '@libp2p/components'
|
|
11
11
|
|
|
12
12
|
const log = logger('libp2p:peer-store')
|
|
13
13
|
|
package/src/key-book.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { peerIdFromPeerId } from '@libp2p/peer-id'
|
|
|
5
5
|
import { equals as uint8arrayEquals } from 'uint8arrays/equals'
|
|
6
6
|
import { CustomEvent } from '@libp2p/interfaces/events'
|
|
7
7
|
import type { Store } from './store.js'
|
|
8
|
-
import type { PeerStore, KeyBook, PeerPublicKeyChangeData, Peer } from '@libp2p/
|
|
9
|
-
import type { PeerId } from '@libp2p/
|
|
8
|
+
import type { PeerStore, KeyBook, PeerPublicKeyChangeData, Peer } from '@libp2p/interface-peer-store'
|
|
9
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
10
10
|
|
|
11
11
|
const log = logger('libp2p:peer-store:key-book')
|
|
12
12
|
|
package/src/metadata-book.ts
CHANGED
|
@@ -5,8 +5,8 @@ import { peerIdFromPeerId } from '@libp2p/peer-id'
|
|
|
5
5
|
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
|
|
6
6
|
import { CustomEvent } from '@libp2p/interfaces/events'
|
|
7
7
|
import type { Store } from './store.js'
|
|
8
|
-
import type { PeerStore, MetadataBook, PeerMetadataChangeData, Peer } from '@libp2p/
|
|
9
|
-
import type { PeerId } from '@libp2p/
|
|
8
|
+
import type { PeerStore, MetadataBook, PeerMetadataChangeData, Peer } from '@libp2p/interface-peer-store'
|
|
9
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
10
10
|
|
|
11
11
|
const log = logger('libp2p:peer-store:metadata-book')
|
|
12
12
|
|
package/src/proto-book.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { codes } from './errors.js'
|
|
|
4
4
|
import { peerIdFromPeerId } from '@libp2p/peer-id'
|
|
5
5
|
import { CustomEvent } from '@libp2p/interfaces/events'
|
|
6
6
|
import type { Store } from './store.js'
|
|
7
|
-
import type { Peer, PeerProtocolsChangeData, PeerStore, ProtoBook } from '@libp2p/
|
|
8
|
-
import type { PeerId } from '@libp2p/
|
|
7
|
+
import type { Peer, PeerProtocolsChangeData, PeerStore, ProtoBook } from '@libp2p/interface-peer-store'
|
|
8
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
9
9
|
|
|
10
10
|
const log = logger('libp2p:peer-store:proto-book')
|
|
11
11
|
|
package/src/store.ts
CHANGED
|
@@ -8,9 +8,9 @@ import { Multiaddr } from '@multiformats/multiaddr'
|
|
|
8
8
|
import { Metadata, Peer as PeerPB } from './pb/peer.js'
|
|
9
9
|
import mortice from 'mortice'
|
|
10
10
|
import { equals as uint8arrayEquals } from 'uint8arrays/equals'
|
|
11
|
-
import type { Peer } from '@libp2p/
|
|
12
|
-
import type { PeerId } from '@libp2p/
|
|
13
|
-
import { Components } from '@libp2p/
|
|
11
|
+
import type { Peer } from '@libp2p/interface-peer-store'
|
|
12
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
13
|
+
import { Components } from '@libp2p/components'
|
|
14
14
|
|
|
15
15
|
const log = logger('libp2p:peer-store:store')
|
|
16
16
|
|
package/src/README.md
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
# PeerStore
|
|
2
|
-
|
|
3
|
-
Libp2p's PeerStore is responsible for keeping an updated register with the relevant information of the known peers. It should be the single source of truth for all peer data, where a subsystem can learn about peers' data and where someone can listen for updates. The PeerStore comprises four main components: `addressBook`, `keyBook`, `protocolBook` and `metadataBook`.
|
|
4
|
-
|
|
5
|
-
The PeerStore manages the high level operations on its inner books. Moreover, the PeerStore should be responsible for notifying interested parties of relevant events, through its Event Emitter.
|
|
6
|
-
|
|
7
|
-
## Submitting records to the PeerStore
|
|
8
|
-
|
|
9
|
-
Several libp2p subsystems will perform operations that might gather relevant information about peers.
|
|
10
|
-
|
|
11
|
-
### Identify
|
|
12
|
-
- The Identify protocol automatically runs on every connection when multiplexing is enabled. The protocol will put the multiaddrs and protocols provided by the peer to the PeerStore.
|
|
13
|
-
- In the background, the Identify Service is also waiting for protocol change notifications of peers via the IdentifyPush protocol. Peers may leverage the `identify-push` message to communicate protocol changes to all connected peers, so that their PeerStore can be updated with the updated protocols.
|
|
14
|
-
- While it is currently not supported in js-libp2p, future iterations may also support the [IdentifyDelta protocol](https://github.com/libp2p/specs/pull/176).
|
|
15
|
-
- Taking into account that the Identify protocol records are directly from the peer, they should be considered the source of truth and weighted accordingly.
|
|
16
|
-
|
|
17
|
-
### Peer Discovery
|
|
18
|
-
- Libp2p discovery protocols aim to discover new peers in the network. In a typical discovery protocol, addresses of the peer are discovered along with its peer id. Once this happens, a libp2p discovery protocol should emit a `peer` event with the information of the discovered peer and this information will be added to the PeerStore by libp2p.
|
|
19
|
-
|
|
20
|
-
### Dialer
|
|
21
|
-
- Libp2p API supports dialing a peer given a `multiaddr`, and no prior knowledge of the peer. If the node is able to establish a connection with the peer, it and its multiaddr is added to the PeerStore.
|
|
22
|
-
- When a connection is being upgraded, more precisely after its encryption, or even in a discovery protocol, a libp2p node can get to know other parties public keys. In this scenario, libp2p will add the peer's public key to its `KeyBook`.
|
|
23
|
-
|
|
24
|
-
### DHT
|
|
25
|
-
- On some DHT operations, such as finding providers for a given CID, nodes may exchange peer data as part of the query. This passive peer discovery should result in the DHT emitting the `peer` event in the same way [Peer Discovery](#peerdiscovery) does.
|
|
26
|
-
|
|
27
|
-
## Retrieving records from the PeerStore
|
|
28
|
-
|
|
29
|
-
When data in the PeerStore is updated the PeerStore will emit events based on the changes, to allow applications and other subsystems to take action on those changes. Any subsystem interested in these notifications should subscribe the [`PeerStore events`][peer-store-events].
|
|
30
|
-
|
|
31
|
-
### Peer
|
|
32
|
-
- Each time a new peer is discovered, the PeerStore should emit a [`peer` event][peer-store-events], so that interested parties can leverage this peer and establish a connection with it.
|
|
33
|
-
|
|
34
|
-
### Protocols
|
|
35
|
-
- When the known protocols of a peer change, the PeerStore emits a [`change:protocols` event][peer-store-events].
|
|
36
|
-
|
|
37
|
-
### Multiaddrs
|
|
38
|
-
- When the known listening `multiaddrs` of a peer change, the PeerStore emits a [`change:multiaddrs` event][peer-store-events].
|
|
39
|
-
|
|
40
|
-
## PeerStore implementation
|
|
41
|
-
|
|
42
|
-
The PeerStore wraps four main components: `addressBook`, `keyBook`, `protocolBook` and `metadataBook`. Moreover, it provides a high level API for those components, as well as data events.
|
|
43
|
-
|
|
44
|
-
### Components
|
|
45
|
-
|
|
46
|
-
#### Address Book
|
|
47
|
-
|
|
48
|
-
The `addressBook` keeps the known multiaddrs of a peer. The multiaddrs of each peer may change over time and the Address Book must account for this.
|
|
49
|
-
|
|
50
|
-
`Map<string, Address>`
|
|
51
|
-
|
|
52
|
-
A `peerId.toString()` identifier mapping to a `Address` object, which should have the following structure:
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
{
|
|
56
|
-
multiaddr: <Multiaddr>
|
|
57
|
-
}
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
#### Key Book
|
|
61
|
-
|
|
62
|
-
The `keyBook` tracks the public keys of the peers by keeping their [`PeerId`][peer-id].
|
|
63
|
-
|
|
64
|
-
`Map<string, PeerId`
|
|
65
|
-
|
|
66
|
-
A `peerId.toString()` identifier mapping to a `PeerId` of the peer. This instance contains the peer public key.
|
|
67
|
-
|
|
68
|
-
#### Protocol Book
|
|
69
|
-
|
|
70
|
-
The `protoBook` holds the identifiers of the protocols supported by each peer. The protocols supported by each peer are dynamic and will change over time.
|
|
71
|
-
|
|
72
|
-
`Map<string, Set<string>>`
|
|
73
|
-
|
|
74
|
-
A `peerId.toString()` identifier mapping to a `Set` of protocol identifier strings.
|
|
75
|
-
|
|
76
|
-
#### Metadata Book
|
|
77
|
-
|
|
78
|
-
The `metadataBook` keeps track of the known metadata of a peer. Its metadata is stored in a key value fashion, where a key identifier (`string`) represents a metadata value (`Uint8Array`).
|
|
79
|
-
|
|
80
|
-
`Map<string, Map<string, Uint8Array>>`
|
|
81
|
-
|
|
82
|
-
A `peerId.toString()` identifier mapping to the peer metadata Map.
|
|
83
|
-
|
|
84
|
-
### API
|
|
85
|
-
|
|
86
|
-
For the complete API documentation, you should check the [API.md](../../doc/API.md).
|
|
87
|
-
|
|
88
|
-
Access to its underlying books:
|
|
89
|
-
|
|
90
|
-
- `peerStore.addressBook.*`
|
|
91
|
-
- `peerStore.keyBook.*`
|
|
92
|
-
- `peerStore.metadataBook.*`
|
|
93
|
-
- `peerStore.protoBook.*`
|
|
94
|
-
|
|
95
|
-
### Events
|
|
96
|
-
|
|
97
|
-
- `peer` - emitted when a new peer is added.
|
|
98
|
-
- `change:multiaadrs` - emitted when a known peer has a different set of multiaddrs.
|
|
99
|
-
- `change:protocols` - emitted when a known peer supports a different set of protocols.
|
|
100
|
-
- `change:pubkey` - emitted when a peer's public key is known.
|
|
101
|
-
- `change:metadata` - emitted when known metadata of a peer changes.
|
|
102
|
-
|
|
103
|
-
## Data Persistence
|
|
104
|
-
|
|
105
|
-
The data stored in the PeerStore can be persisted if configured appropriately. Keeping a record of the peers already discovered by the peer, as well as their known data aims to improve the efficiency of peers joining the network after being offline.
|
|
106
|
-
|
|
107
|
-
The libp2p node will need to receive a [datastore](https://github.com/ipfs/interface-datastore), in order to persist this data across restarts. A [datastore](https://github.com/ipfs/interface-datastore) stores its data in a key-value fashion. As a result, we need coherent keys so that we do not overwrite data.
|
|
108
|
-
|
|
109
|
-
The PeerStore should not continuously update the datastore whenever data is changed. Instead, it should only store new data after reaching a certain threshold of "dirty" peers, as well as when the node is stopped, in order to batch writes to the datastore.
|
|
110
|
-
|
|
111
|
-
The peer id will be appended to the datastore key for each data namespace. The namespaces were defined as follows:
|
|
112
|
-
|
|
113
|
-
**AddressBook**
|
|
114
|
-
|
|
115
|
-
All the known peer addresses are stored with a key pattern as follows:
|
|
116
|
-
|
|
117
|
-
`/peers/addrs/<b32 peer id no padding>`
|
|
118
|
-
|
|
119
|
-
**ProtoBook**
|
|
120
|
-
|
|
121
|
-
All the known peer protocols are stored with a key pattern as follows:
|
|
122
|
-
|
|
123
|
-
`/peers/protos/<b32 peer id no padding>`
|
|
124
|
-
|
|
125
|
-
**KeyBook**
|
|
126
|
-
|
|
127
|
-
All public keys are stored under the following pattern:
|
|
128
|
-
|
|
129
|
-
` /peers/keys/<b32 peer id no padding>`
|
|
130
|
-
|
|
131
|
-
**MetadataBook**
|
|
132
|
-
|
|
133
|
-
Metadata is stored under the following key pattern:
|
|
134
|
-
|
|
135
|
-
`/peers/metadata/<b32 peer id no padding>/<key>`
|
|
136
|
-
|
|
137
|
-
## Future Considerations
|
|
138
|
-
|
|
139
|
-
- If multiaddr TTLs are added, the PeerStore may schedule jobs to delete all addresses that exceed the TTL to prevent AddressBook bloating
|
|
140
|
-
- Further API methods will probably need to be added in the context of multiaddr validity and confidence.
|
|
141
|
-
- When improving libp2p configuration for specific runtimes, we should take into account the PeerStore recommended datastore.
|
|
142
|
-
- When improving libp2p configuration, we should think about a possible way of allowing the configuration of Bootstrap to be influenced by the persisted peers, as a way to decrease the load on Bootstrap nodes.
|
|
143
|
-
|
|
144
|
-
[peer-id]: https://github.com/libp2p/js-peer-id
|
|
145
|
-
[peer-store-events]: ../../doc/API.md#libp2ppeerstore
|