Skip to content

Commit b1f1aaa

Browse files
authored
chore: update dht (#49)
Enables DHT by default. The tests won't pass here until libp2p is released, which needs this module to be released in order for its tests to pass. BREAKING CHANGE: The DHT is now enabled by default
1 parent cbdff6c commit b1f1aaa

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,25 @@
3838
],
3939
"license": "MIT",
4040
"devDependencies": {
41-
"aegir": "^33.1.0",
41+
"aegir": "^36.0.0",
4242
"delay": "^5.0.0",
4343
"it-pair": "^1.0.0",
4444
"mocha": "^9.0.1",
4545
"p-defer": "^3.0.0",
4646
"sinon": "^9.0.0"
4747
},
4848
"dependencies": {
49-
"cids": "^1.1.5",
5049
"debug": "^4.3.1",
5150
"it-buffer": "^0.1.3",
5251
"it-handshake": "^2.0.0",
5352
"it-length-prefixed": "^5.0.2",
5453
"it-pipe": "^1.1.0",
5554
"it-pushable": "^1.4.0",
56-
"libp2p": "^0.32.0",
55+
"libp2p": "^0.33.0",
5756
"libp2p-bootstrap": "^0.13.0",
5857
"libp2p-floodsub": "^0.27.0",
5958
"libp2p-gossipsub": "^0.11.0",
60-
"libp2p-kad-dht": "^0.23.1",
59+
"libp2p-kad-dht": "^0.26.0",
6160
"libp2p-mplex": "^0.10.0",
6261
"libp2p-noise": "^4.0.0",
6362
"libp2p-tcp": "^0.17.1",
@@ -69,7 +68,7 @@
6968
"protobufjs": "^6.10.2",
7069
"stream-to-it": "^0.2.0",
7170
"streaming-iterables": "^6.0.0",
72-
"uint8arrays": "^2.1.0",
71+
"uint8arrays": "^3.0.0",
7372
"yargs": "^15.0.2",
7473
"yargs-promise": "^1.1.0"
7574
},
@@ -79,5 +78,12 @@
7978
"Arve Knudsen <[email protected]>",
8079
"Alex Potsides <[email protected]>",
8180
"Marin Petrunić <[email protected]>"
82-
]
81+
],
82+
"eslintConfig": {
83+
"extends": "ipfs",
84+
"ignorePatterns": [
85+
"*.d.ts",
86+
"src/profocol/index.js"
87+
]
88+
}
8389
}

src/daemon.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const pipe = require('it-pipe')
1212
const pushable = require('it-pushable')
1313
const StreamHandler = require('./stream-handler')
1414
const { concat } = require('streaming-iterables')
15-
const uint8ArrayFromString = require('uint8arrays/from-string')
16-
const uint8ArrayToString = require('uint8arrays/to-string')
15+
const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string')
16+
const { toString: uint8ArrayToString } = require('uint8arrays/to-string')
1717
const { passThroughUpgrader } = require('./util')
1818
const {
1919
Request,
@@ -362,7 +362,7 @@ class Daemon {
362362
yield OkResponse({
363363
dht: {
364364
type: DHTResponse.Type.VALUE,
365-
value: value
365+
value: value.val
366366
}
367367
})
368368
} catch (err) {

src/libp2p.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const WS = require('libp2p-websockets')
66
const Bootstrap = require('libp2p-bootstrap')
77
const MPLEX = require('libp2p-mplex')
88
const { NOISE } = require('libp2p-noise')
9-
const KadDHT = require('libp2p-kad-dht')
9+
const KadDHT = require('libp2p-kad-dht/src/kad-dht')
1010
const FloodSub = require('libp2p-floodsub')
1111
const GossipSub = require('libp2p-gossipsub')
1212
const PeerID = require('peer-id')
@@ -39,7 +39,6 @@ const getPeerId = async (privateKeyPath) => {
3939
* @param {Options} opts
4040
* @param {boolean} opts.quiet
4141
* @param {boolean} opts.bootstrap
42-
* @param {boolean} opts.dht
4342
* @param {boolean} opts.connMgr
4443
* @param {number} opts.connMgrHi
4544
* @param {string} opts.id
@@ -54,7 +53,6 @@ const createLibp2p = async ({
5453
bootstrapPeers,
5554
hostAddrs,
5655
announceAddrs,
57-
dht,
5856
connMgrLo,
5957
connMgrHi,
6058
id,
@@ -90,7 +88,19 @@ const createLibp2p = async ({
9088
peerDiscovery: [
9189
Bootstrap
9290
],
93-
dht: KadDHT,
91+
dht: {
92+
// go-libp2p-daemon only has the older single-table DHT instead of the dual lan/wan version
93+
// found in recent go-ipfs versions. unfortunately it's been abandoned so here we simulate
94+
// the older config with the js implementation
95+
create: (opts) => {
96+
return new KadDHT({
97+
...opts,
98+
protocol: '/ipfs/kad/1.0.0',
99+
clientMode: false,
100+
lan: true
101+
})
102+
}
103+
},
94104
pubsub: pubsubRouter === 'floodsub' ? GossipSub : FloodSub
95105
},
96106
config: {
@@ -109,7 +119,7 @@ const createLibp2p = async ({
109119
}
110120
},
111121
dht: {
112-
enabled: dht,
122+
enabled: true,
113123
kBucketSize: 20
114124
},
115125
pubsub: {

0 commit comments

Comments
 (0)