Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Awesome Endeavour: DHT Part II #856

Merged
merged 11 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ You can check the development status at the [Kanban Board](https://waffle.io/ipf

[![Throughput Graph](https://graphs.waffle.io/ipfs/js-ipfs/throughput.svg)](https://waffle.io/ipfs/js-ipfs/metrics/throughput)

**Please read this:** DHT (automatic content discovery) and Circuit Relay (pierce through NATs and dial between any node in the network) are two fundamental pieces that are not finalized yet. There are multiple applications that can be built without these two services but nevertheless they are fundamental to get that magic IPFS experience. If you want to track progress or contribute, please follow:

- DHT: https://github.com/ipfs/js-ipfs/pull/856
- ✅ Relay: https://github.com/ipfs/js-ipfs/pull/1063
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.




[**`Weekly Core Dev Calls`**](https://github.com/ipfs/pm/issues/650)

## Tech Lead
Expand Down Expand Up @@ -319,7 +314,6 @@ Enable and configure experimental features.
- `pubsub` (boolean): Enable libp2p pub-sub. (Default: `false`)
- `ipnsPubsub` (boolean): Enable pub-sub on IPNS. (Default: `false`)
- `sharding` (boolean): Enable directory sharding. Directories that have many child objects will be represented by multiple DAG nodes instead of just one. It can improve lookup performance when a directory has several thousand files or more. (Default: `false`)
- `dht` (boolean): Enable KadDHT. **This is currently not interoperable with `go-ipfs`.**
vasco-santos marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the DHT start automatically in the browser too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current state of this PR it is starting automatically in both browser and node. Do you think we should start by having only node.js nodes first?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend to start with node only and look at adding it to the browser as a default later, if ever. Until we get more performance benchmarking for the browser I'm hesitant to just turn it on there for everyone.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that's a good point!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so, I'm half inclined to just enable it in the browser by default, expose ourselves to the issues and get them fixed asap. That said, since this is such a big feature perhaps not having it enabled by default in the browser initially will give us some scope to test it out first and fix the bigger issues, so that we don't expose all our users to the bugs and make everyone mad.

We do need a way to enable/disable it though - if the dht config option is being removed from EXPERIMENTAL, is it being added to the top level?


##### `options.config`

Expand Down Expand Up @@ -600,7 +594,13 @@ The core API is grouped into several areas:
- [`ipfs.bootstrap.add(addr, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BOOTSTRAP.md#bootstrapadd)
- [`ipfs.bootstrap.rm(peer, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/BOOTSTRAP.md#bootstraprm)

- dht (not implemented yet)
- [dht](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/)
- [`ipfs.dht.findPeer(peerId, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DHT.md#dhtfindpeer)
- [`ipfs.dht.findProvs(multihash, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DHT.md#dhtfindprovs)
- [`ipfs.dht.get(key, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DHT.md#dhtget)
- [`ipfs.dht.provide(cid, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DHT.md#dhtprovide)
- [`ipfs.dht.put(key, value, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DHT.md#dhtput)
- [`ipfs.dht.query(peerId, [callback])`](https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/DHT.md#dhtquery)

- [pubsub](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md)
- [`ipfs.pubsub.subscribe(topic, handler, [options], [callback])`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubsubscribe)
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.96.0",
"ipfsd-ctl": "~0.40.1",
"ipfsd-ctl": "~0.41.0",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
"qs": "^6.5.2",
Expand Down Expand Up @@ -129,7 +129,7 @@
"joi": "^14.3.0",
"joi-browser": "^13.4.0",
"joi-multiaddr": "^4.0.0",
"libp2p": "~0.24.1",
"libp2p": "~0.25.0-rc.0",
"libp2p-bootstrap": "~0.9.3",
"libp2p-crypto": "~0.16.0",
"libp2p-kad-dht": "~0.14.4",
Expand All @@ -141,7 +141,7 @@
"libp2p-tcp": "~0.13.0",
"libp2p-webrtc-star": "~0.15.5",
"libp2p-websocket-star-multi": "~0.4.0",
"libp2p-websockets": "~0.12.0",
"libp2p-websockets": "~0.12.2",
"lodash": "^4.17.11",
"mafmt": "^6.0.2",
"mime-types": "^2.1.21",
Expand Down
4 changes: 0 additions & 4 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ module.exports = {
type: 'boolean',
default: false
})
.option('enable-dht-experiment', {
type: 'boolean',
default: false
})
.option('offline', {
desc: 'Run offline. Do not connect to the rest of the network but provide local API.',
default: false
Expand Down
14 changes: 14 additions & 0 deletions src/cli/commands/dht.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

module.exports = {
command: 'dht <command>',

description: 'Issue commands directly through the DHT.',

builder (yargs) {
return yargs.commandDir('dht')
},

handler (argv) {
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the DHT full implemented on http api and CLI as well? Mind updating https://github.com/ipfs/ipfs/blob/master/IMPLEMENTATION_STATUS.md#dht ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in ipfs/ipfs#388

23 changes: 23 additions & 0 deletions src/cli/commands/dht/find-peer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'findpeer <peerID>',

describe: 'Find the multiaddresses associated with a Peer ID.',

builder: {},

handler ({ getIpfs, peerID, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const peers = await ipfs.dht.findPeer(peerID)
const addresses = peers.multiaddrs.toArray().map((ma) => ma.toString())

addresses.forEach((addr) => {
print(addr)
})
})())
}
}
33 changes: 33 additions & 0 deletions src/cli/commands/dht/find-providers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'findprovs <key>',

describe: 'Find peers that can provide a specific value, given a key.',

builder: {
'num-providers': {
alias: 'n',
describe: 'The number of providers to find. Default: 20.',
default: 20
}
},

handler (argv) {
const { getIpfs, key, resolve } = argv
const opts = {
maxNumProviders: argv['num-providers']
}

resolve((async () => {
const ipfs = await getIpfs()
const provs = await ipfs.dht.findProvs(key, opts)

provs.forEach((element) => {
print(element.id.toB58String())
})
})())
}
}
20 changes: 20 additions & 0 deletions src/cli/commands/dht/get.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'get <key>',

describe: 'Given a key, query the routing system for its best value.',

builder: {},

handler ({ getIpfs, key, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const value = await ipfs.dht.get(key)

print(value)
})())
}
}
26 changes: 26 additions & 0 deletions src/cli/commands/dht/provide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

module.exports = {
command: 'provide <key>',

describe: 'Announce to the network that you are providing given values.',

builder: {
recursive: {
alias: 'r',
recursive: 'Recursively provide entire graph.',
default: false
}
},

handler ({ getIpfs, key, recursive, resolve }) {
const opts = {
recursive
}

resolve((async () => {
const ipfs = await getIpfs()
await ipfs.dht.provide(key, opts)
})())
}
}
16 changes: 16 additions & 0 deletions src/cli/commands/dht/put.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

module.exports = {
command: 'put <key> <value>',

describe: 'Write a key/value pair to the routing system.',

builder: {},

handler ({ getIpfs, key, value, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
await ipfs.dht.put(key, value)
})())
}
}
22 changes: 22 additions & 0 deletions src/cli/commands/dht/query.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const print = require('../../utils').print

module.exports = {
command: 'query <peerID>',

describe: 'Find the closest Peer IDs to a given Peer ID by querying the DHT.',

builder: {},

handler ({ getIpfs, peerID, resolve }) {
resolve((async () => {
const ipfs = await getIpfs()
const result = await ipfs.dht.query(peerID)

result.forEach((peerID) => {
print(peerID.id.toB58String())
})
})())
}
}
Loading