Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 565eb00

Browse files
authored
chore: update to new multiformats (#220)
Uses new CID class. Also swaps out various chai deps for version bundled with aegir, updates aegir and fixes tests that start services without tearing them down which stops the tests from finishing. BREAKING CHANGE: uses new multiformats CID class
1 parent 2137e2a commit 565eb00

39 files changed

+435
-369
lines changed

.aegir.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
2-
bundlesize: { maxSize: '190kB' }
2+
build: {
3+
bundlesizeMax: '182kB'
4+
}
35
}
4-

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ os:
2121

2222
before_install:
2323
# modules with pre-built binaries may not have deployed versions for bleeding-edge node so this lets us fall back to building from source
24-
- npm install -g node-pre-gyp
24+
- npm install -g @mapbox/node-pre-gyp
2525

2626
script: npx nyc -s npm run test:node -- --bail
2727
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

package.json

+12-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"leadMaintainer": "Vasco Santos <[email protected]>",
66
"main": "src/index.js",
77
"scripts": {
8-
"lint": "aegir lint",
8+
"lint": "aegir ts -p check && aegir lint",
99
"prepare": "npm run build",
1010
"build": "npm run build:proto && npm run build:proto-types && aegir build",
1111
"build:proto": "pbjs -t static-module -w commonjs -r libp2p-dht-message --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/dht.js ./src/message/dht.proto",
@@ -45,53 +45,46 @@
4545
"types": "dist/src/index.d.ts",
4646
"dependencies": {
4747
"abort-controller": "^3.0.0",
48-
"cids": "^1.1.5",
4948
"debug": "^4.3.1",
5049
"err-code": "^3.0.0",
5150
"hashlru": "^2.3.0",
5251
"heap": "~0.2.6",
53-
"interface-datastore": "^4.0.0",
52+
"interface-datastore": "^5.1.1",
5453
"it-first": "^1.0.4",
5554
"it-length-prefixed": "^5.0.2",
5655
"it-pipe": "^1.1.0",
5756
"k-bucket": "^5.0.0",
58-
"libp2p-crypto": "^0.19.0",
59-
"libp2p-interfaces": "^0.10.0",
60-
"libp2p-record": "^0.10.0",
61-
"multiaddr": "^9.0.0",
62-
"multihashing-async": "^2.1.0",
63-
"p-filter": "^2.1.0",
57+
"libp2p-crypto": "^0.19.5",
58+
"libp2p-interfaces": "^0.12.1",
59+
"libp2p-record": "^0.10.4",
60+
"multiaddr": "^10.0.0",
61+
"multiformats": "^9.0.0",
6462
"p-map": "^4.0.0",
6563
"p-queue": "^6.6.2",
6664
"p-timeout": "^4.1.0",
6765
"p-times": "^3.0.0",
68-
"peer-id": "^0.14.2",
69-
"promise-to-callback": "^1.0.0",
66+
"peer-id": "^0.15.0",
7067
"protobufjs": "^6.10.2",
71-
"streaming-iterables": "^5.0.4",
68+
"streaming-iterables": "^6.0.0",
7269
"uint8arrays": "^2.1.4",
7370
"varint": "^6.0.0",
7471
"xor-distance": "^2.0.0"
7572
},
7673
"devDependencies": {
7774
"@types/debug": "^4.1.5",
78-
"aegir": "^30.3.0",
75+
"aegir": "^33.1.2",
7976
"async-iterator-all": "^1.0.0",
80-
"chai": "^4.3.0",
81-
"chai-checkmark": "^1.0.1",
82-
"datastore-level": "^5.0.0",
77+
"datastore-level": "^6.0.0",
8378
"delay": "^5.0.0",
84-
"dirty-chai": "^2.0.1",
8579
"it-pair": "^1.0.0",
8680
"libp2p": "^0.31.0",
87-
"lodash": "^4.17.11",
8881
"lodash.random": "^3.2.0",
8982
"lodash.range": "^3.2.0",
9083
"p-defer": "^3.0.0",
9184
"p-each-series": "^2.1.0",
9285
"p-map-series": "^2.1.0",
9386
"p-retry": "^4.2.0",
94-
"sinon": "^10.0.0"
87+
"sinon": "^11.1.1"
9588
},
9689
"contributors": [
9790
"Vasco Santos <[email protected]>",

src/content-routing/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Query = require('../query')
1010
const utils = require('../utils')
1111

1212
/**
13-
* @typedef {import('cids')} CID
13+
* @typedef {import('multiformats/cid').CID} CID
1414
* @typedef {import('peer-id')} PeerId
1515
* @typedef {import('multiaddr').Multiaddr} Multiaddr
1616
*/

src/index.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const Record = libp2pRecord.Record
2929
* @typedef {import('interface-datastore').Datastore} Datastore
3030
* @typedef {import('libp2p/src/dialer')} Dialer
3131
* @typedef {import('libp2p/src/registrar')} Registrar
32-
* @typedef {import('cids')} CID
32+
* @typedef {import('multiformats/cid').CID} CID
3333
* @typedef {import('multiaddr').Multiaddr} Multiaddr
3434
* @typedef {object} PeerData
3535
* @property {PeerId} id
@@ -235,14 +235,16 @@ class KadDHT extends EventEmitter {
235235

236236
/**
237237
* Start listening to incoming connections.
238-
*
239-
* @returns {Promise<void>}
240238
*/
241-
async start () {
239+
start () {
240+
if (this._running) {
241+
return
242+
}
243+
242244
this._running = true
243245
this.providers.start()
244246
this._queryManager.start()
245-
await this.network.start()
247+
this.network.start()
246248

247249
// Start random walk, it will not run if it's disabled
248250
this.randomWalk.start()
@@ -251,15 +253,13 @@ class KadDHT extends EventEmitter {
251253
/**
252254
* Stop accepting incoming connections and sending outgoing
253255
* messages.
254-
*
255-
* @returns {Promise<void>}
256256
*/
257257
stop () {
258258
this._running = false
259259
this.randomWalk.stop()
260-
this.providers.stop()
260+
this.network.stop()
261261
this._queryManager.stop()
262-
return this.network.stop()
262+
this.providers.stop()
263263
}
264264

265265
/**

src/message/dht.d.ts

+44-11
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,34 @@ export class Record implements IRecord {
2828
constructor(p?: IRecord);
2929

3030
/** Record key. */
31-
public key: Uint8Array;
31+
public key?: (Uint8Array|null);
3232

3333
/** Record value. */
34-
public value: Uint8Array;
34+
public value?: (Uint8Array|null);
3535

3636
/** Record author. */
37-
public author: Uint8Array;
37+
public author?: (Uint8Array|null);
3838

3939
/** Record signature. */
40-
public signature: Uint8Array;
40+
public signature?: (Uint8Array|null);
4141

4242
/** Record timeReceived. */
43-
public timeReceived: string;
43+
public timeReceived?: (string|null);
44+
45+
/** Record _key. */
46+
public _key?: "key";
47+
48+
/** Record _value. */
49+
public _value?: "value";
50+
51+
/** Record _author. */
52+
public _author?: "author";
53+
54+
/** Record _signature. */
55+
public _signature?: "signature";
56+
57+
/** Record _timeReceived. */
58+
public _timeReceived?: "timeReceived";
4459

4560
/**
4661
* Encodes the specified Record message. Does not implicitly {@link Record.verify|verify} messages.
@@ -114,23 +129,35 @@ export class Message implements IMessage {
114129
constructor(p?: IMessage);
115130

116131
/** Message type. */
117-
public type: Message.MessageType;
132+
public type?: (Message.MessageType|null);
118133

119134
/** Message clusterLevelRaw. */
120-
public clusterLevelRaw: number;
135+
public clusterLevelRaw?: (number|null);
121136

122137
/** Message key. */
123-
public key: Uint8Array;
138+
public key?: (Uint8Array|null);
124139

125140
/** Message record. */
126-
public record: Uint8Array;
141+
public record?: (Uint8Array|null);
127142

128143
/** Message closerPeers. */
129144
public closerPeers: Message.IPeer[];
130145

131146
/** Message providerPeers. */
132147
public providerPeers: Message.IPeer[];
133148

149+
/** Message _type. */
150+
public _type?: "type";
151+
152+
/** Message _clusterLevelRaw. */
153+
public _clusterLevelRaw?: "clusterLevelRaw";
154+
155+
/** Message _key. */
156+
public _key?: "key";
157+
158+
/** Message _record. */
159+
public _record?: "record";
160+
134161
/**
135162
* Encodes the specified Message message. Does not implicitly {@link Message.verify|verify} messages.
136163
* @param m Message message or plain object to encode
@@ -214,13 +241,19 @@ export namespace Message {
214241
constructor(p?: Message.IPeer);
215242

216243
/** Peer id. */
217-
public id: Uint8Array;
244+
public id?: (Uint8Array|null);
218245

219246
/** Peer addrs. */
220247
public addrs: Uint8Array[];
221248

222249
/** Peer connection. */
223-
public connection: Message.ConnectionType;
250+
public connection?: (Message.ConnectionType|null);
251+
252+
/** Peer _id. */
253+
public _id?: "id";
254+
255+
/** Peer _connection. */
256+
public _connection?: "connection";
224257

225258
/**
226259
* Encodes the specified Peer message. Does not implicitly {@link Message.Peer.verify|verify} messages.

0 commit comments

Comments
 (0)