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

refactor: migrate http api to use hapi 18 #1844

Merged
merged 49 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4c320e8
refactor: gateway for hapi 18
Jan 24, 2019
69ef7bd
refactor: /api/v0/version for hapi 18
Jan 24, 2019
641a7c4
refactor: /api/v0/shutdown for hapi 18
Jan 25, 2019
fc0f044
refactor: /ip/v0/id for hapi 18
Jan 25, 2019
665297f
refactor: /api/v0/bootstrap* for hapi 18
Jan 25, 2019
3e6f9de
refactor: error handler for hapi 18
Jan 25, 2019
f57ab08
refactor: simplify gateway and use error handler
Jan 25, 2019
ce4f1da
refactor: simplify /api/v0/bootstrap to use error handler
Jan 25, 2019
723f20b
fix: gateway tests
Jan 25, 2019
2071f50
refactor: /api/v0/block* for hapi 18
Jan 25, 2019
99de158
refactor: switch default error code to 0
Jan 26, 2019
08728a6
fix: return value for bad request to block endpoints
Jan 26, 2019
9584146
refactor: /api/v0/object* for hapi 18
Jan 26, 2019
70f0598
feat: log all errors if DEBUG env var is set
Jan 26, 2019
ebc415a
refactor: /api/v0/pin* for hapi 18
Jan 26, 2019
1709fa1
fix: pin tests
Jan 27, 2019
beed859
refactor: /api/v0/add /api/v0/cat & /api/v0/get for hapi 18
Jan 27, 2019
7d2205e
fix: pin tests
Jan 27, 2019
137fea8
chore: remove .only
Jan 27, 2019
b4c9d5d
refactor: /api/v0/repo* for hapi 18
Jan 27, 2019
49358d3
refactor: /api/v0/config* for hapi 18
Jan 27, 2019
eb212f9
refactor: better logging, less boilerplate
Jan 28, 2019
149ec34
refactor: mfs for hapi 18
Jan 28, 2019
3f4e583
chore: remove .only
Jan 28, 2019
4606f9d
refactor: use hapi logger, do not repeat logs
Jan 28, 2019
1e1777a
chore: update mfs dependency
Jan 28, 2019
a2c8fa0
refactor: /api/v0/ping for hapi 18
Jan 28, 2019
4ee90b6
refactor: /api/v0/swarm* for hapi 18
Jan 28, 2019
63c6c5f
refactor: /api/v0/bitswap* for hapi 18
Jan 28, 2019
10d6b73
refactor: use pretty print unless in production env
Jan 28, 2019
9707d94
refactor: use pretty print unless in production env
Jan 28, 2019
16ef0d8
refactor: /api/v0/file/ls for hapi 18
Jan 28, 2019
ade3f09
refactor: /api/v0/pubsub* for hapi 18
Jan 28, 2019
5beae70
refactor: /api/v0/debug/metrics/prometheus for hapi 18
Jan 28, 2019
7ec3d9e
fix: promisify tar pack entry
Jan 28, 2019
a38cca5
refactor: /webui for hapi 18
Jan 28, 2019
5993727
refactor: /api/v0/dns for hapi 18
Jan 28, 2019
395910e
refactor: /api/v0/key* for hapi 18
Jan 28, 2019
b2ee66f
refactor: /api/v0/stats* for hapi 18
Jan 28, 2019
9a5b663
refactor: /api/v0/resolve for hapi 18
Jan 29, 2019
f6a7be3
refactor: /api/v0/name* for hapi 18
Jan 29, 2019
c64bf5f
fix: communicate error message for 500+ errors
Jan 29, 2019
755baee
fix: key name query arg for key gen
Jan 29, 2019
dec15ff
fix: pin arg validation
Jan 29, 2019
db65043
fix: remove unused loggers
Jan 29, 2019
cb6c6c3
fix: subscribe disconnect/finish event
Jan 29, 2019
ff6fb0b
fix: allow pass CID path
Jan 29, 2019
e630a7e
fix: disconnect event for bandwidth stats
Jan 29, 2019
f7515d1
chore: update ipfs-mfs dependency
Jan 31, 2019
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
"fsm-event": "^2.1.0",
"get-folder-size": "^2.0.0",
"glob": "^7.1.3",
"hapi": "^16.6.2",
"hapi-set-header": "^1.0.2",
"hapi": "^18.0.0",
"hapi-pino": "^5.2.0",
"hoek": "^6.1.2",
"human-to-milliseconds": "^1.0.0",
"interface-datastore": "~0.6.0",
Expand All @@ -110,7 +110,7 @@
"ipfs-block-service": "~0.15.1",
"ipfs-http-client": "^29.0.0",
"ipfs-http-response": "~0.2.1",
"ipfs-mfs": "~0.8.0",
"ipfs-mfs": "0.9.0",
"ipfs-multipart": "~0.1.0",
"ipfs-repo": "~0.26.1",
"ipfs-unixfs": "~0.1.16",
Expand Down
29 changes: 18 additions & 11 deletions src/cli/commands/daemon.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
'use strict'

const promisify = require('promisify-es6')
const utils = require('../utils')
const print = utils.print

let httpAPI
const { getRepoPath, print, ipfsPathHelp } = require('../utils')

module.exports = {
command: 'daemon',
Expand All @@ -13,7 +9,7 @@ module.exports = {

builder (yargs) {
return yargs
.epilog(utils.ipfsPathHelp)
.epilog(ipfsPathHelp)
.option('enable-sharding-experiment', {
type: 'boolean',
default: false
Expand All @@ -40,14 +36,25 @@ module.exports = {
argv.resolve((async () => {
print('Initializing IPFS daemon...')

const repoPath = utils.getRepoPath()
const repoPath = getRepoPath()

// Required inline to reduce startup time
const HttpAPI = require('../../http')
httpAPI = new HttpAPI(process.env.IPFS_PATH, null, argv)
const HttpApi = require('../../http')
const api = new HttpApi({
silent: argv.silent,
repo: process.env.IPFS_PATH,
offline: argv.offline,
pass: argv.pass,
EXPERIMENTAL: {
pubsub: argv.enablePubsubExperiment,
ipnsPubsub: argv.enableNamesysPubsub,
dht: argv.enableDhtExperiment,
sharding: argv.enableShardingExperiment
}
})

try {
await promisify(httpAPI.start)()
await api.start()
} catch (err) {
if (err.code === 'ENOENT' && err.message.match(/uninitialized/i)) {
print('Error: no initialized ipfs repo found in ' + repoPath)
Expand All @@ -61,7 +68,7 @@ module.exports = {

const cleanup = async () => {
print(`Received interrupt signal, shutting down..`)
await promisify(httpAPI.stop)()
await api.stop()
process.exit(0)
}

Expand Down
74 changes: 29 additions & 45 deletions src/http/api/resources/bitswap.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
'use strict'

const boom = require('boom')
const Joi = require('joi')
const multibase = require('multibase')
const { cidToString } = require('../../../utils/cid')
const parseKey = require('./block').parseKey

exports = module.exports
const { parseKey } = require('./block')

exports.wantlist = {
validate: {
Expand All @@ -15,19 +12,17 @@ exports.wantlist = {
}).unknown()
},

handler: (request, reply) => {
async handler (request, h) {
const { ipfs } = request.server.app
const peerId = request.query.peer
const cidBase = request.query['cid-base']

request.server.app.ipfs.bitswap.wantlist(peerId, (err, list) => {
if (err) {
return reply(boom.badRequest(err))
}
reply({
Keys: list.Keys.map(k => ({
'/': cidToString(k['/'], { base: cidBase, upgrade: false })
}))
})
const list = await ipfs.bitswap.wantlist(peerId)

return h.response({
Keys: list.Keys.map(k => ({
'/': cidToString(k['/'], { base: cidBase, upgrade: false })
}))
})
}
}
Expand All @@ -39,33 +34,26 @@ exports.stat = {
}).unknown()
},

handler: (request, reply) => {
const ipfs = request.server.app.ipfs
async handler (request, h) {
const { ipfs } = request.server.app
const cidBase = request.query['cid-base']

ipfs.bitswap.stat((err, stats) => {
if (err) {
return reply({
Message: err.toString(),
Code: 0
}).code(500)
}
const stats = await ipfs.bitswap.stat()

stats.wantlist = stats.wantlist.map(k => ({
'/': cidToString(k['/'], { base: cidBase, upgrade: false })
}))
stats.wantlist = stats.wantlist.map(k => ({
'/': cidToString(k['/'], { base: cidBase, upgrade: false })
}))

reply({
ProvideBufLen: stats.provideBufLen,
BlocksReceived: stats.blocksReceived,
Wantlist: stats.wantlist,
Peers: stats.peers,
DupBlksReceived: stats.dupBlksReceived,
DupDataReceived: stats.dupDataReceived,
DataReceived: stats.dataReceived,
BlocksSent: stats.blocksSent,
DataSent: stats.dataSent
})
return h.response({
ProvideBufLen: stats.provideBufLen,
BlocksReceived: stats.blocksReceived,
Wantlist: stats.wantlist,
Peers: stats.peers,
DupBlksReceived: stats.dupBlksReceived,
DupDataReceived: stats.dupDataReceived,
DataReceived: stats.dataReceived,
BlocksSent: stats.blocksSent,
DataSent: stats.dataSent
})
}
}
Expand All @@ -81,14 +69,10 @@ exports.unwant = {
parseArgs: parseKey,

// main route handler which is called after the above `parseArgs`, but only if the args were valid
handler: (request, reply) => {
async handler (request, h) {
const key = request.pre.args.key
const ipfs = request.server.app.ipfs
ipfs.bitswap.unwant(key, (err) => {
if (err) {
return reply(boom.badRequest(err))
}
reply({ key: cidToString(key, { base: request.query['cid-base'], upgrade: false }) })
})
const { ipfs } = request.server.app
await ipfs.bitswap.unwant(key)
return h.response({ key: cidToString(key, { base: request.query['cid-base'], upgrade: false }) })
}
}
Loading