Skip to content

Commit cba3803

Browse files
committed
Moving to grpc APIs
1 parent 0915881 commit cba3803

15 files changed

+935
-399
lines changed

bin/list.js

-38
This file was deleted.

bin/mount.js

-48
This file was deleted.

bin/start.js

+32-28
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
11
const p = require('path')
2-
const { URL } = require('url')
3-
const request = require('request-promise-native')
42
const chalk = require('chalk')
53
const forever = require('forever')
64

7-
const { loadMetadata, createMetadata } = require('../lib/metadata')
5+
const { createMetadata } = require('../lib/metadata')
6+
const { HyperdriveClient } = require('hyperdrive-daemon-client')
87

98
exports.command = 'start'
10-
exports.desc = 'Start the Hypermount daemon.'
9+
exports.desc = 'Start the Hyperdrive daemon.'
1110
exports.builder = {
1211
port: {
13-
description: 'The HTTP port that the daemon will bind to.',
12+
description: 'The gRPC port that the daemon will bind to.',
1413
type: 'number',
1514
default: 3101
1615
},
17-
replicationPort: {
18-
description: 'The port that the hypercore replicator will bind to.',
19-
type: 'number',
20-
default: 3102
16+
storage: {
17+
description: 'The storage directory for hyperdrives and associated metadata.',
18+
type: 'string',
19+
default: './storage'
2120
}
2221
}
2322
exports.handler = async function (argv) {
24-
let metadata = await loadMetadata()
25-
if (metadata) {
26-
try {
27-
await request.get(new URL('/status', metadata.endpoint).toString(), {
28-
auth: {
29-
bearer: metadata.token
30-
}
31-
})
32-
} catch (err) {
33-
await start(argv)
34-
}
35-
} else {
36-
await start(argv)
23+
const client = new HyperdriveClient(`localhost:${argv.port}`)
24+
console.log(0)
25+
client.ready(err => {
26+
console.log('err:', err)
27+
if (err) return onerror(err)
28+
console.log(chalk.green('The Hyperdrive daemon is already running.'))
29+
})
30+
31+
function onerror (err) {
32+
if (!err.disconnected) return showError(err)
33+
console.log('starting here')
34+
start(argv).catch(showError)
35+
}
36+
37+
function showError (err) {
38+
console.error(chalk.red('Could not start the Hyperdrive daemon:'))
39+
console.error(chalk.red(` ${err}`))
3740
}
3841
}
3942

4043
async function start (argv) {
41-
let endpoint = `http://localhost:${argv.port}`
44+
console.log('in start')
45+
let endpoint = `localhost:${argv.port}`
4246
await createMetadata(endpoint)
4347
forever.startDaemon(p.join(__dirname, '..', 'index.js'), {
44-
uid: 'hypermount',
48+
uid: 'hyperdrive',
4549
max: 1,
46-
logFile: './hypermount.log',
47-
outFile: './hypermount.log',
48-
errFile: './hypermount.log',
49-
args: ['--replicationPort', argv.replicationPort, '--port', argv.port]
50+
logFile: './hyperdrive.log',
51+
outFile: './hyperdrive.log',
52+
errFile: './hyperdrive.log',
53+
args: ['--port', argv.port, '--storage', argv.storage]
5054
})
5155
console.log(chalk.green(`Daemon started at ${endpoint}`))
5256
}

bin/status.js

-25
This file was deleted.

bin/stop.js

-23
This file was deleted.

bin/unmount.js

-32
This file was deleted.

cli.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/usr/bin/env node
2-
const yargs = require('yargs')
2+
const client = require('hyperdrive-daemon-client/cli')
33

4-
yargs.commandDir('bin')
4+
client.commandDir('bin')
55
.demandCommand()
66
.help()
77
.argv
8+
9+
10+

0 commit comments

Comments
 (0)