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
package/src/peer-store/index.js
CHANGED
|
@@ -1,152 +1,121 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const debug = require('debug')
|
|
5
4
|
const { EventEmitter } = require('events')
|
|
6
|
-
const PeerId = require('peer-id')
|
|
7
|
-
|
|
8
5
|
const AddressBook = require('./address-book')
|
|
9
6
|
const KeyBook = require('./key-book')
|
|
10
7
|
const MetadataBook = require('./metadata-book')
|
|
11
8
|
const ProtoBook = require('./proto-book')
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
codes: { ERR_INVALID_PARAMETERS }
|
|
15
|
-
} = require('../errors')
|
|
9
|
+
const Store = require('./store')
|
|
16
10
|
|
|
17
11
|
/**
|
|
18
|
-
* @typedef {import('./
|
|
12
|
+
* @typedef {import('./types').PeerStore} PeerStore
|
|
13
|
+
* @typedef {import('./types').Peer} Peer
|
|
14
|
+
* @typedef {import('peer-id')} PeerId
|
|
15
|
+
* @typedef {import('multiaddr').Multiaddr} Multiaddr
|
|
19
16
|
*/
|
|
20
17
|
|
|
18
|
+
const log = Object.assign(debug('libp2p:peer-store'), {
|
|
19
|
+
error: debug('libp2p:peer-store:err')
|
|
20
|
+
})
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
|
-
*
|
|
23
|
+
* An implementation of PeerStore that stores data in a Datastore
|
|
23
24
|
*
|
|
24
|
-
* @
|
|
25
|
-
* @fires PeerStore#change:protocols Emitted when a known peer supports a different set of protocols.
|
|
26
|
-
* @fires PeerStore#change:multiaddrs Emitted when a known peer has a different set of multiaddrs.
|
|
27
|
-
* @fires PeerStore#change:pubkey Emitted emitted when a peer's public key is known.
|
|
28
|
-
* @fires PeerStore#change:metadata Emitted when the known metadata of a peer change.
|
|
25
|
+
* @implements {PeerStore}
|
|
29
26
|
*/
|
|
30
|
-
class
|
|
27
|
+
class DefaultPeerStore extends EventEmitter {
|
|
31
28
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* @
|
|
35
|
-
* @
|
|
36
|
-
* @property {Address[]} addresses peer's addresses containing its multiaddrs and metadata.
|
|
37
|
-
* @property {string[]} protocols peer's supported protocols.
|
|
38
|
-
* @property {Map<string, Uint8Array>|undefined} metadata peer's metadata map.
|
|
29
|
+
* @param {object} properties
|
|
30
|
+
* @param {PeerId} properties.peerId
|
|
31
|
+
* @param {import('interface-datastore').Datastore} properties.datastore
|
|
32
|
+
* @param {(peerId: PeerId, multiaddr: Multiaddr) => Promise<boolean>} properties.addressFilter
|
|
39
33
|
*/
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Responsible for managing known peers, as well as their addresses, protocols and metadata.
|
|
43
|
-
*
|
|
44
|
-
* @param {object} options
|
|
45
|
-
* @param {PeerId} options.peerId
|
|
46
|
-
* @class
|
|
47
|
-
*/
|
|
48
|
-
constructor ({ peerId }) {
|
|
34
|
+
constructor ({ peerId, datastore, addressFilter }) {
|
|
49
35
|
super()
|
|
50
36
|
|
|
51
37
|
this._peerId = peerId
|
|
38
|
+
this._store = new Store(datastore)
|
|
52
39
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
this.
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* KeyBook containing a map of peerIdStr to their PeerId with public keys.
|
|
60
|
-
*/
|
|
61
|
-
this.keyBook = new KeyBook(this)
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* MetadataBook containing a map of peerIdStr to their metadata Map.
|
|
65
|
-
*/
|
|
66
|
-
this.metadataBook = new MetadataBook(this)
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* ProtoBook containing a map of peerIdStr to supported protocols.
|
|
70
|
-
*/
|
|
71
|
-
this.protoBook = new ProtoBook(this)
|
|
40
|
+
this.addressBook = new AddressBook(this.emit.bind(this), this._store, addressFilter)
|
|
41
|
+
this.keyBook = new KeyBook(this.emit.bind(this), this._store)
|
|
42
|
+
this.metadataBook = new MetadataBook(this.emit.bind(this), this._store)
|
|
43
|
+
this.protoBook = new ProtoBook(this.emit.bind(this), this._store)
|
|
72
44
|
}
|
|
73
45
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
46
|
+
async * getPeers () {
|
|
47
|
+
log('getPeers await read lock')
|
|
48
|
+
const release = await this._store.lock.readLock()
|
|
49
|
+
log('getPeers got read lock')
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
for await (const peer of this._store.all()) {
|
|
53
|
+
if (peer.id.toB58String() === this._peerId.toB58String()) {
|
|
54
|
+
// Remove self peer if present
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
yield peer
|
|
59
|
+
}
|
|
60
|
+
} finally {
|
|
61
|
+
log('getPeers release read lock')
|
|
62
|
+
release()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
83
65
|
|
|
84
66
|
/**
|
|
85
|
-
*
|
|
67
|
+
* Delete the information of the given peer in every book
|
|
86
68
|
*
|
|
87
|
-
* @
|
|
69
|
+
* @param {PeerId} peerId
|
|
88
70
|
*/
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const peersData = new Map()
|
|
101
|
-
storedPeers.forEach((idStr) => {
|
|
102
|
-
peersData.set(idStr, this.get(PeerId.createFromB58String(idStr)))
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
return peersData
|
|
71
|
+
async delete (peerId) {
|
|
72
|
+
log('delete await write lock')
|
|
73
|
+
const release = await this._store.lock.writeLock()
|
|
74
|
+
log('delete got write lock')
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await this._store.delete(peerId)
|
|
78
|
+
} finally {
|
|
79
|
+
log('delete release write lock')
|
|
80
|
+
release()
|
|
81
|
+
}
|
|
106
82
|
}
|
|
107
83
|
|
|
108
84
|
/**
|
|
109
|
-
*
|
|
85
|
+
* Get the stored information of a given peer
|
|
110
86
|
*
|
|
111
87
|
* @param {PeerId} peerId
|
|
112
|
-
* @returns {boolean} true if found and removed
|
|
113
88
|
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
89
|
+
async get (peerId) {
|
|
90
|
+
log('get await read lock')
|
|
91
|
+
const release = await this._store.lock.readLock()
|
|
92
|
+
log('get got read lock')
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
return this._store.load(peerId)
|
|
96
|
+
} finally {
|
|
97
|
+
log('get release read lock')
|
|
98
|
+
release()
|
|
99
|
+
}
|
|
121
100
|
}
|
|
122
101
|
|
|
123
102
|
/**
|
|
124
|
-
*
|
|
103
|
+
* Returns true if we have a record of the peer
|
|
125
104
|
*
|
|
126
105
|
* @param {PeerId} peerId
|
|
127
|
-
* @returns {Peer|undefined}
|
|
128
106
|
*/
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (!id && !addresses && !metadata && !protocols) {
|
|
140
|
-
return undefined
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
id: id || peerId,
|
|
145
|
-
addresses: addresses || [],
|
|
146
|
-
protocols: protocols || [],
|
|
147
|
-
metadata: metadata
|
|
107
|
+
async has (peerId) {
|
|
108
|
+
log('has await read lock')
|
|
109
|
+
const release = await this._store.lock.readLock()
|
|
110
|
+
log('has got read lock')
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
return this._store.has(peerId)
|
|
114
|
+
} finally {
|
|
115
|
+
log('has release read lock')
|
|
116
|
+
release()
|
|
148
117
|
}
|
|
149
118
|
}
|
|
150
119
|
}
|
|
151
120
|
|
|
152
|
-
module.exports =
|
|
121
|
+
module.exports = DefaultPeerStore
|
|
@@ -1,96 +1,141 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const debug = require('debug')
|
|
4
|
-
const log = Object.assign(debug('libp2p:peer-store:key-book'), {
|
|
5
|
-
error: debug('libp2p:peer-store:key-book:err')
|
|
6
|
-
})
|
|
7
4
|
const errcode = require('err-code')
|
|
8
|
-
|
|
5
|
+
const { codes } = require('../errors')
|
|
9
6
|
const PeerId = require('peer-id')
|
|
10
|
-
|
|
11
|
-
const Book = require('./book')
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
codes: { ERR_INVALID_PARAMETERS }
|
|
15
|
-
} = require('../errors')
|
|
7
|
+
const { equals: uint8arrayEquals } = require('uint8arrays/equals')
|
|
16
8
|
|
|
17
9
|
/**
|
|
18
|
-
* @typedef {import('./')} PeerStore
|
|
19
|
-
* @typedef {import('
|
|
10
|
+
* @typedef {import('./types').PeerStore} PeerStore
|
|
11
|
+
* @typedef {import('./types').KeyBook} KeyBook
|
|
12
|
+
* @typedef {import('libp2p-interfaces/src/keys/types').PublicKey} PublicKey
|
|
20
13
|
*/
|
|
21
14
|
|
|
15
|
+
const log = Object.assign(debug('libp2p:peer-store:key-book'), {
|
|
16
|
+
error: debug('libp2p:peer-store:key-book:err')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const EVENT_NAME = 'change:pubkey'
|
|
20
|
+
|
|
22
21
|
/**
|
|
23
|
-
* @
|
|
22
|
+
* @implements {KeyBook}
|
|
24
23
|
*/
|
|
25
|
-
class
|
|
24
|
+
class PeerStoreKeyBook {
|
|
26
25
|
/**
|
|
27
26
|
* The KeyBook is responsible for keeping the known public keys of a peer.
|
|
28
27
|
*
|
|
29
|
-
* @
|
|
30
|
-
* @param {
|
|
28
|
+
* @param {PeerStore["emit"]} emit
|
|
29
|
+
* @param {import('./types').Store} store
|
|
31
30
|
*/
|
|
32
|
-
constructor (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
eventName: 'change:pubkey',
|
|
36
|
-
eventProperty: 'pubkey',
|
|
37
|
-
eventTransformer: (data) => data.pubKey
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Map known peers to their known Public Key.
|
|
42
|
-
*
|
|
43
|
-
* @type {Map<string, PeerId>}
|
|
44
|
-
*/
|
|
45
|
-
this.data = new Map()
|
|
31
|
+
constructor (emit, store) {
|
|
32
|
+
this._emit = emit
|
|
33
|
+
this._store = store
|
|
46
34
|
}
|
|
47
35
|
|
|
48
36
|
/**
|
|
49
|
-
* Set the Peer public key
|
|
37
|
+
* Set the Peer public key
|
|
50
38
|
*
|
|
51
|
-
* @override
|
|
52
39
|
* @param {PeerId} peerId
|
|
53
40
|
* @param {PublicKey} publicKey
|
|
54
|
-
* @returns {KeyBook}
|
|
55
41
|
*/
|
|
56
|
-
set (peerId, publicKey) {
|
|
42
|
+
async set (peerId, publicKey) {
|
|
57
43
|
if (!PeerId.isPeerId(peerId)) {
|
|
58
44
|
log.error('peerId must be an instance of peer-id to store data')
|
|
59
|
-
throw errcode(new Error('peerId must be an instance of peer-id'), ERR_INVALID_PARAMETERS)
|
|
45
|
+
throw errcode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS)
|
|
60
46
|
}
|
|
61
47
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (!recPeerId && publicKey) {
|
|
67
|
-
// This might be unecessary, but we want to store the PeerId
|
|
68
|
-
// to avoid an async operation when reconstructing the PeerId
|
|
69
|
-
peerId.pubKey = publicKey
|
|
48
|
+
if (!publicKey) {
|
|
49
|
+
log.error('publicKey must be an instance of PublicKey to store data')
|
|
50
|
+
throw errcode(new Error('publicKey must be an instance of PublicKey'), codes.ERR_INVALID_PARAMETERS)
|
|
51
|
+
}
|
|
70
52
|
|
|
71
|
-
|
|
72
|
-
|
|
53
|
+
log('set await write lock')
|
|
54
|
+
const release = await this._store.lock.writeLock()
|
|
55
|
+
log('set got write lock')
|
|
56
|
+
|
|
57
|
+
let updatedKey = false
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
try {
|
|
61
|
+
const existing = await this._store.load(peerId)
|
|
62
|
+
|
|
63
|
+
if (existing.pubKey && uint8arrayEquals(existing.pubKey.bytes, publicKey.bytes)) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
} catch (/** @type {any} */ err) {
|
|
67
|
+
if (err.code !== codes.ERR_NOT_FOUND) {
|
|
68
|
+
throw err
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await this._store.patchOrCreate(peerId, {
|
|
73
|
+
pubKey: publicKey
|
|
74
|
+
})
|
|
75
|
+
updatedKey = true
|
|
76
|
+
} finally {
|
|
77
|
+
log('set release write lock')
|
|
78
|
+
release()
|
|
73
79
|
}
|
|
74
80
|
|
|
75
|
-
|
|
81
|
+
if (updatedKey) {
|
|
82
|
+
this._emit(EVENT_NAME, { peerId, pubKey: publicKey })
|
|
83
|
+
}
|
|
76
84
|
}
|
|
77
85
|
|
|
78
86
|
/**
|
|
79
|
-
* Get Public key of the given PeerId, if stored
|
|
87
|
+
* Get Public key of the given PeerId, if stored
|
|
80
88
|
*
|
|
81
|
-
* @override
|
|
82
89
|
* @param {PeerId} peerId
|
|
83
|
-
* @returns {PublicKey | undefined}
|
|
84
90
|
*/
|
|
85
|
-
get (peerId) {
|
|
91
|
+
async get (peerId) {
|
|
86
92
|
if (!PeerId.isPeerId(peerId)) {
|
|
87
|
-
|
|
93
|
+
log.error('peerId must be an instance of peer-id to store data')
|
|
94
|
+
throw errcode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS)
|
|
88
95
|
}
|
|
89
96
|
|
|
90
|
-
|
|
97
|
+
log('get await write lock')
|
|
98
|
+
const release = await this._store.lock.readLock()
|
|
99
|
+
log('get got write lock')
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const peer = await this._store.load(peerId)
|
|
103
|
+
|
|
104
|
+
return peer.pubKey
|
|
105
|
+
} catch (/** @type {any} */ err) {
|
|
106
|
+
if (err.code !== codes.ERR_NOT_FOUND) {
|
|
107
|
+
throw err
|
|
108
|
+
}
|
|
109
|
+
} finally {
|
|
110
|
+
log('get release write lock')
|
|
111
|
+
release()
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @param {PeerId} peerId
|
|
117
|
+
*/
|
|
118
|
+
async delete (peerId) {
|
|
119
|
+
if (!PeerId.isPeerId(peerId)) {
|
|
120
|
+
log.error('peerId must be an instance of peer-id to store data')
|
|
121
|
+
throw errcode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
log('delete await write lock')
|
|
125
|
+
const release = await this._store.lock.writeLock()
|
|
126
|
+
log('delete got write lock')
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
await this._store.patchOrCreate(peerId, {
|
|
130
|
+
pubKey: undefined
|
|
131
|
+
})
|
|
132
|
+
} finally {
|
|
133
|
+
log('delete release write lock')
|
|
134
|
+
release()
|
|
135
|
+
}
|
|
91
136
|
|
|
92
|
-
|
|
137
|
+
this._emit(EVENT_NAME, { peerId, pubKey: undefined })
|
|
93
138
|
}
|
|
94
139
|
}
|
|
95
140
|
|
|
96
|
-
module.exports =
|
|
141
|
+
module.exports = PeerStoreKeyBook
|