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

[WIP] experimental routers to make ipns faster #2201

Closed
wants to merge 19 commits into from
Closed
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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ os:
- osx
- windows

script: npx nyc -s npm run test:node --timeout=10000 -- --bail
script: npx nyc -s npx aegir test -t node --timeout 10000 --bail
after_success: npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

jobs:
Expand Down Expand Up @@ -47,12 +47,12 @@ jobs:
- stage: test
name: electron-main
script:
- xvfb-run npx aegir test -t electron-main -- --bail
- xvfb-run npx aegir test -t electron-main -- --bail --timeout 10000

- stage: test
name: electron-renderer
script:
- xvfb-run npx aegir test -t electron-renderer -- --bail
- xvfb-run npx aegir test -t electron-renderer -- --bail --timeout 10000

notifications:
email: false
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<a name="0.36.4"></a>
## [0.36.4](https://github.com/ipfs/js-ipfs/compare/v0.36.3...v0.36.4) (2019-06-18)



<a name="0.36.3"></a>
## [0.36.3](https://github.com/ipfs/js-ipfs/compare/v0.36.2...v0.36.3) (2019-05-30)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ Listing of the main packages used in the IPFS ecosystem. There are also three sp
| [`ipfs-repo`](//github.com/ipfs/js-ipfs-repo) | [![npm](https://img.shields.io/npm/v/ipfs-repo.svg?maxAge=86400&style=flat)](//github.com/ipfs/js-ipfs-repo/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-repo.svg?style=flat)](https://david-dm.org/ipfs/js-ipfs-repo) | [![Travis CI](https://travis-ci.com/ipfs/js-ipfs-repo.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-repo) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-repo/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-repo) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| **Exchange** |
| [`ipfs-block-service`](//github.com/ipfs/js-ipfs-block-service) | [![npm](https://img.shields.io/npm/v/ipfs-block-service.svg?maxAge=86400&style=flat)](//github.com/ipfs/js-ipfs-block-service/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-block-service.svg?style=flat)](https://david-dm.org/ipfs/js-ipfs-block-service) | [![Travis CI](https://travis-ci.com/ipfs/js-ipfs-block-service.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-block-service) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-block-service/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-block-service) | [Volker Mische](mailto:volker.mische@gmail.com) |
| [`ipfs-bitswap`](//github.com/ipfs/js-ipfs-bitswap) | [![npm](https://img.shields.io/npm/v/ipfs-bitswap.svg?maxAge=86400&style=flat)](//github.com/ipfs/js-ipfs-bitswap/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-bitswap.svg?style=flat)](https://david-dm.org/ipfs/js-ipfs-bitswap) | [![Travis CI](https://travis-ci.com/ipfs/js-ipfs-bitswap.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-bitswap) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-bitswap/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-bitswap) | [Volker Mische](mailto:volker.mische@gmail.com) |
| [`ipfs-bitswap`](//github.com/ipfs/js-ipfs-bitswap) | [![npm](https://img.shields.io/npm/v/ipfs-bitswap.svg?maxAge=86400&style=flat)](//github.com/ipfs/js-ipfs-bitswap/releases) | [![Deps](https://david-dm.org/ipfs/js-ipfs-bitswap.svg?style=flat)](https://david-dm.org/ipfs/js-ipfs-bitswap) | [![Travis CI](https://travis-ci.com/ipfs/js-ipfs-bitswap.svg?branch=master)](https://travis-ci.com/ipfs/js-ipfs-bitswap) | [![codecov](https://codecov.io/gh/ipfs/js-ipfs-bitswap/branch/master/graph/badge.svg)](https://codecov.io/gh/ipfs/js-ipfs-bitswap) | [Dirk McCormick](mailto:dirk@protocol.ai) |
| **libp2p** |
| [`libp2p`](//github.com/libp2p/js-libp2p) | [![npm](https://img.shields.io/npm/v/libp2p.svg?maxAge=86400&style=flat)](//github.com/libp2p/js-libp2p/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p.svg?style=flat)](https://david-dm.org/libp2p/js-libp2p) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p) | [Jacob Heun](mailto:jacobheun@gmail.com) |
| [`libp2p-circuit`](//github.com/libp2p/js-libp2p-circuit) | [![npm](https://img.shields.io/npm/v/libp2p-circuit.svg?maxAge=86400&style=flat)](//github.com/libp2p/js-libp2p-circuit/releases) | [![Deps](https://david-dm.org/libp2p/js-libp2p-circuit.svg?style=flat)](https://david-dm.org/libp2p/js-libp2p-circuit) | [![Travis CI](https://travis-ci.com/libp2p/js-libp2p-circuit.svg?branch=master)](https://travis-ci.com/libp2p/js-libp2p-circuit) | [![codecov](https://codecov.io/gh/libp2p/js-libp2p-circuit/branch/master/graph/badge.svg)](https://codecov.io/gh/libp2p/js-libp2p-circuit) | [Jacob Heun](mailto:jacobheun@gmail.com) |
Expand Down
1 change: 0 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Let us know if you find any issue or if you want to contribute and add a new tut

- [Tutorial: IPFS 101, spawn a node and add a file to IPFS](./ipfs-101)
- [Tutorial: Build a tiny browser app to exchange files between nodes](./exchange-files-in-browser)
- [Tutorial: Interact with IPFS directly from your Terminal](./ipfs-cli-fun)
- [Tutorial: Resolve through IPLD graphs with the dag API](./traverse-ipld-graphs)
- [Tutorial: Use IPFS to explore the Ethereum BlockChain](./explore-ethereum-blockchain)
- [Tutorial (Video): How to build an application with IPFS PubSub Room](https://www.youtube.com/watch?v=Nv_Teb--1zg)
Expand Down
25 changes: 18 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ipfs",
"version": "0.36.3",
"version": "0.36.4",
"description": "JavaScript implementation of the IPFS specification",
"keywords": [
"IPFS"
Expand Down Expand Up @@ -76,23 +76,27 @@
"cid-tool": "~0.3.0",
"cids": "~0.7.1",
"class-is": "^1.1.0",
"clear-module": "^3.2.0",
"datastore-core": "~0.6.0",
"datastore-pubsub": "~0.1.1",
"debug": "^4.1.0",
"dlv": "^1.1.3",
"dns-packet": "^5.2.1",
"dns-socket": "^4.2.0",
"err-code": "^1.1.2",
"file-type": "^11.1.0",
"file-type": "^12.0.0",
"fnv1a": "^1.0.1",
"fsm-event": "^2.1.0",
"get-folder-size": "^2.0.0",
"glob": "^7.1.3",
"hapi-pino": "^6.0.0",
"hashlru": "^2.3.0",
"human-to-milliseconds": "^1.0.0",
"interface-datastore": "~0.6.0",
"ipfs-bitswap": "~0.24.1",
"ipfs-block": "~0.8.1",
"ipfs-block-service": "~0.15.1",
"ipfs-http-client": "^32.0.0",
"ipfs-http-client": "^32.0.1",
"ipfs-http-response": "~0.3.0",
"ipfs-mfs": "~0.11.4",
"ipfs-multipart": "~0.1.0",
Expand All @@ -110,13 +114,16 @@
"ipld-raw": "^4.0.0",
"ipld-zcash": "~0.3.0",
"ipns": "~0.5.2",
"is-domain-name": "^1.0.1",
"is-ipfs": "~0.6.1",
"is-pull-stream": "~0.0.0",
"is-stream": "^2.0.0",
"iso-url": "~0.4.6",
"just-flatten-it": "^2.1.0",
"just-safe-set": "^2.1.0",
"kind-of": "^6.0.2",
"ky": "^0.11.1",
"ky-universal": "^0.2.1",
"libp2p": "~0.25.3",
"libp2p-bootstrap": "~0.9.3",
"libp2p-crypto": "~0.16.0",
Expand All @@ -141,6 +148,8 @@
"multihashes": "~0.4.14",
"multihashing-async": "~0.6.0",
"node-fetch": "^2.3.0",
"p-any": "^2.1.0",
"p-settle": "^3.1.0",
"peer-book": "~0.9.0",
"peer-id": "~0.12.0",
"peer-info": "~0.15.0",
Expand All @@ -155,7 +164,7 @@
"pull-ndjson": "~0.1.1",
"pull-pushable": "^2.2.0",
"pull-sort": "^1.0.1",
"pull-stream": "^3.6.9",
"pull-stream": "^3.6.12",
"pull-stream-to-async-iterator": "^1.0.1",
"pull-stream-to-stream": "^1.3.4",
"pull-traverse": "^1.0.3",
Expand All @@ -176,15 +185,16 @@
"aegir": "^19.0.3",
"base64url": "^3.0.1",
"chai": "^4.2.0",
"clear-module": "^3.2.0",
"delay": "^4.1.0",
"detect-node": "^2.0.4",
"dir-compare": "^1.4.0",
"dirty-chai": "^2.0.1",
"execa": "^1.0.0",
"form-data": "^2.3.3",
"hat": "0.0.3",
"interface-ipfs-core": "~0.104.0",
"ipfsd-ctl": "~0.42.0",
"interface-ipfs-core": "~0.105.0",
"ipfsd-ctl": "~0.43.0",
"libp2p-websocket-star": "~0.10.2",
"ncp": "^2.0.0",
"qs": "^6.5.2",
Expand Down Expand Up @@ -248,8 +258,8 @@
"Henrique Dias <hacdias@gmail.com>",
"Henry Rodrick <moshisushi@gmail.com>",
"Heo Sangmin <heo@mapiacompany.com>",
"Hugo Dias <hugomrdias@gmail.com>",
"Hugo Dias <mail@hugodias.me>",
"Hugo Dias <hugomrdias@gmail.com>",
"Irakli Gozalishvili <contact@gozala.io>",
"Jacob Heun <jacobheun@gmail.com>",
"Jacob Heun <jake@andyet.net>",
Expand Down Expand Up @@ -282,6 +292,7 @@
"Paulo Rodrigues <me@paulogr.com>",
"Pedro Teixeira <i@pgte.me>",
"Portia Burton <plburton@gmail.com>",
"Prabhakar Poudel <yuvrajzohan@gmail.com>",
"Raoul Millais <raoul@raoulmillais.com>",
"RasmusErik Voel Jensen <github@solsort.com>",
"Richard Littauer <richard.littauer@gmail.com>",
Expand Down
14 changes: 14 additions & 0 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ module.exports = {
type: 'boolean',
default: false
})
.option('enable-ipns-experiment', {
type: 'boolean',
default: false,
desc: 'EXPERIMENTAL ipns routers.'
})
.option('experimental-ipns-alias', {
type: 'string',
default: '',
desc: 'EXPERIMENTAL human readable alias for ipns subdomains.'
})
.option('offline', {
type: 'boolean',
desc: 'Run offline. Do not connect to the rest of the network but provide local API.',
Expand Down Expand Up @@ -54,9 +64,13 @@ module.exports = {
preload: { enabled: argv.enablePreload },
EXPERIMENTAL: {
pubsub: argv.enablePubsubExperiment,
ipnsDNS: argv.enableIpnsExperiment,
ipnsPubsub: argv.enableNamesysPubsub,
dht: argv.enableDhtExperiment,
sharding: argv.enableShardingExperiment
},
ipns: {
alias: argv.experimentalIpnsAlias
Copy link
Member

Choose a reason for hiding this comment

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

These new constructor options need to be documented on the README.

}
})

Expand Down
22 changes: 10 additions & 12 deletions src/cli/commands/name/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

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

module.exports = {
command: 'publish <ipfsPath>',
Expand All @@ -11,36 +11,34 @@ module.exports = {
resolve: {
alias: 'r',
describe: 'Resolve given path before publishing. Default: true.',
default: true
default: true,
type: 'boolean'
},
lifetime: {
alias: 't',
describe: 'Time duration that the record will be valid for. Default: 24h.',
default: '24h'
default: '24h',
type: 'string'
},
key: {
alias: 'k',
describe: 'Name of the key to be used, as listed by "ipfs key list -l". Default: self.',
default: 'self'
default: 'self',
type: 'string'
},
ttl: {
describe: 'Time duration this record should be cached for (caution: experimental).',
default: ''
default: '',
type: 'string'
}
},

handler (argv) {
argv.resolve((async () => {
// yargs-promise adds resolve/reject properties to argv
// resolve should use the alias as resolve will always be overwritten to a function
let resolve = true

if (argv.r === false || argv.r === 'false') {
resolve = false
}

const opts = {
resolve,
resolve: argv.r,
lifetime: argv.lifetime,
key: argv.key,
ttl: argv.ttl
Expand Down
8 changes: 2 additions & 6 deletions src/cli/commands/name/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
type: 'boolean',
alias: 'r',
describe: 'Resolve until the result is not an IPNS name. Default: false.',
default: false
default: true
}
},

Expand All @@ -32,11 +32,7 @@ module.exports = {
const ipfs = await argv.getIpfs()
const result = await ipfs.name.resolve(argv.name, opts)

if (result && result.path) {
print(result.path)
} else {
print(result)
}
print(result)
})())
}
}
66 changes: 50 additions & 16 deletions src/core/components/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const parallel = require('async/parallel')
const human = require('human-to-milliseconds')
const crypto = require('libp2p-crypto')
const errcode = require('err-code')
const mergeOptions = require('merge-options')
const mh = require('multihashes')
const isDomain = require('is-domain-name')

const log = debug('ipfs:name')
log.error = debug('ipfs:name:error')
Expand Down Expand Up @@ -35,6 +38,28 @@ const keyLookup = (ipfsNode, kname, callback) => {
})
}

const appendRemainder = (cb, remainder) => {
return (err, result) => {
if (err) {
return cb(err)
}
if (remainder.length) {
return cb(null, result + '/' + remainder.join('/'))
}
return cb(null, result)
}
}

/**
* @typedef { import("../index") } IPFS
*/

/**
* IPNS - Inter-Planetary Naming System
*
* @param {IPFS} self
* @returns {Object}
*/
module.exports = function name (self) {
return {
/**
Expand Down Expand Up @@ -125,22 +150,15 @@ module.exports = function name (self) {
options = {}
}

options = options || {}
const nocache = options.nocache && options.nocache.toString() === 'true'
const recursive = options.recursive && options.recursive.toString() === 'true'
options = mergeOptions({
nocache: false,
recursive: true
}, options)

const offline = self._options.offline

if (!self.isOnline() && !offline) {
const errMsg = utils.OFFLINE_ERROR

log.error(errMsg)
return callback(errcode(errMsg, 'OFFLINE_ERROR'))
}

// TODO: params related logic should be in the core implementation

if (offline && nocache) {
if (offline && options.nocache) {
const error = 'cannot specify both offline and nocache'

log.error(error)
Expand All @@ -156,12 +174,28 @@ module.exports = function name (self) {
name = `/ipns/${name}`
}

const resolveOptions = {
nocache,
recursive
const [ namespace, hash, ...remainder ] = name.slice(1).split('/')
try {
mh.fromB58String(hash)
} catch (err) {
// lets check if we have a domain ex. /ipns/ipfs.io and resolve with dns
if (isDomain(hash)) {
return self.dns(hash, options, appendRemainder(callback, remainder))
}

log.error(err)
return callback(errcode(new Error('Invalid IPNS name.'), 'ERR_IPNS_INVALID_NAME'))
}

self._ipns.resolve(name, resolveOptions, callback)
// multihash is valid lets resolve with IPNS
// IPNS resolve needs a online daemon
if (!self.isOnline() && !offline) {
const errMsg = utils.OFFLINE_ERROR

log.error(errMsg)
return callback(errcode(errMsg, 'OFFLINE_ERROR'))
}
self._ipns.resolve(`/${namespace}/${hash}`, options, appendRemainder(callback, remainder))
}),
pubsub: namePubsub(self)
}
Expand Down
7 changes: 5 additions & 2 deletions src/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ const configSchema = s({
EXPERIMENTAL: optional(s({
pubsub: 'boolean?',
ipnsPubsub: 'boolean?',
ipnsDNS: 'boolean?',
sharding: 'boolean?',
dht: 'boolean?'
})),
}, { dht: false, pubsub: false, ipnsDNS: false, ipnsPubsub: false, sharding: false })),
connectionManager: 'object?',
config: optional(s({
API: 'object?',
Expand All @@ -69,9 +70,11 @@ const configSchema = s({
Bootstrap: optional(s(['multiaddr-ipfs']))
})),
ipld: 'object?',
ipns: 'object?',
libp2p: optional(union(['function', 'object'])) // libp2p validates this
}, {
repoOwner: true
repoOwner: true,
ipns: {}
})

const validate = (opts) => {
Expand Down
Loading