Skip to content

Commit eb04539

Browse files
committed
Use promise API for client. Change storage defaults
1 parent 35540ee commit eb04539

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

bin/start.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
const p = require('path')
2+
const os = require('os')
3+
24
const chalk = require('chalk')
35
const forever = require('forever')
46

57
const { createMetadata } = require('../lib/metadata')
68
const { HyperdriveClient } = require('hyperdrive-daemon-client')
79

10+
const HYPERDRIVE_DIR = p.join(os.homedir(), '.hyperdrive')
11+
812
exports.command = 'start'
913
exports.desc = 'Start the Hyperdrive daemon.'
1014
exports.builder = {
@@ -16,7 +20,7 @@ exports.builder = {
1620
storage: {
1721
description: 'The storage directory for hyperdrives and associated metadata.',
1822
type: 'string',
19-
default: './storage'
23+
default: p.join(HYPERDRIVE_DIR, 'storage')
2024
},
2125
'log-level': {
2226
description: 'The log level',

index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ function extractArguments () {
163163
.argv
164164
}
165165

166-
function wrap (metadata, methods) {
167-
const promisified = promisify(methods)
168-
let authenticated = authenticate(metadata, methods)
169-
}
170-
171166
function wrap (metadata, methods, opts) {
172167
const wrapped = {}
173168
const authenticate = opts && opts.authenticate

lib/metadata.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ const os = require('os')
33
const fs = require('fs-extra')
44

55
const sodium = require('sodium-universal')
6+
const mkdirp = require('mkdirp')
67

7-
const METADATA_FILE_PATH = p.join(os.homedir(), '.hyperdrive')
8+
const HYPERDRIVE_DIR = p.join(os.homedir(), '.hyperdrive')
9+
const METADATA_FILE_PATH = p.join(HYPERDRIVE_DIR, 'config.json')
810

911
async function createMetadata (endpoint) {
1012
var token = process.env['HYPERDRIVE_TOKEN']
@@ -13,6 +15,12 @@ async function createMetadata (endpoint) {
1315
sodium.randombytes_buf(rnd)
1416
token = rnd.toString('hex')
1517
}
18+
await new Promise((resolve, reject) => {
19+
mkdirp(HYPERDRIVE_DIR, err => {
20+
if (err) return reject(err)
21+
return resolve()
22+
})
23+
})
1624
return fs.writeFile(METADATA_FILE_PATH, JSON.stringify({
1725
token,
1826
endpoint

test/replication.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('can replicate many mounted drives between daemons', async t => {
3333
const firstClient = clients[0]
3434
const secondClient = clients[1]
3535

36-
const NUM_MOUNTS = 20
36+
const NUM_MOUNTS = 15
3737

3838
try {
3939
const mounts = await createFirst()

test/util/create.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const dht = require('@hyperswarm/dht')
55
const loadClient = require('hyperdrive-daemon-client/lib/loader')
66
const start = require('../..')
77

8-
const BASE_PORT = 3101
8+
const BASE_PORT = 4101
99
const BOOTSTRAP_PORT = 3100
1010
const BOOTSTRAP_URL = `localhost:${BOOTSTRAP_PORT}`
1111

@@ -65,10 +65,7 @@ async function createInstance (id, port, bootstrap) {
6565
return loadClient(endpoint, token, (err, client) => {
6666
if (err) return reject(err)
6767
return resolve({
68-
client: {
69-
drive: promisifyClass(client.drive),
70-
fuse: promisifyClass(client.fuse)
71-
},
68+
client,
7269
cleanup
7370
})
7471
})
@@ -80,14 +77,6 @@ async function createInstance (id, port, bootstrap) {
8077
}
8178
}
8279

83-
function promisifyClass (clazz) {
84-
const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(clazz)).filter(name => name !== 'constructor')
85-
methods.forEach(name => {
86-
clazz[name] = pify(clazz[name])
87-
})
88-
return clazz
89-
}
90-
9180
module.exports = {
9281
create,
9382
createOne

0 commit comments

Comments
 (0)