Skip to content

Update: add hyperdrive client import/export tests #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a12354e
Update: add hyperdrive client import/export tests
dpaez May 12, 2020
597e286
Update: remove tape only call
dpaez May 12, 2020
259d9e4
Update: tweak export test
dpaez May 15, 2020
4dae5d1
Update: add hyperdrive client import/export tests
dpaez May 12, 2020
51a5e28
Update: remove tape only call
dpaez May 12, 2020
57332ca
Update: tweak export test
dpaez May 15, 2020
c667d7a
Merge branch 'dpaez/test-import-export' of github.com:geut/hyperdrive…
dpaez May 27, 2020
532d09a
Undo createReadStream end option fix + add test
andrewosh Jun 6, 2020
9b3b98c
1.13.18
andrewosh Jun 6, 2020
9e99256
Extend createReadStream tests + cleanup
andrewosh Jun 6, 2020
a5ff42f
Add mirroring
andrewosh May 20, 2020
1c7f118
Refactoring RPC method handling
andrewosh May 28, 2020
87350a0
Progress on API refactoring + mirroring
andrewosh Jun 5, 2020
ca83fad
Adding migrations
andrewosh Jun 6, 2020
36cbc73
More refactoring progress
andrewosh Jun 9, 2020
c1ee51f
Undo refactoring
andrewosh Jun 9, 2020
e180012
Finished undoing unnecessary refactoring
andrewosh Jun 9, 2020
011835b
Add unmirror method + mirror tests
andrewosh Jun 9, 2020
df91ee1
1.14.0
andrewosh Jun 9, 2020
b8e3d1b
Remove unused migrations file
andrewosh Jun 9, 2020
37fb59a
1.14.1
andrewosh Jun 9, 2020
d864a08
Update: add hyperdrive client import/export tests
dpaez May 12, 2020
6f89671
Update: remove tape only call
dpaez May 12, 2020
480d5ed
Update: tweak export test
dpaez May 15, 2020
b794a10
Merge branch 'dpaez/test-import-export' of github.com:geut/hyperdrive…
dpaez Jun 16, 2020
08cc347
Fix FUSE RPC methods
andrewosh Jun 16, 2020
618f120
1.14.2
andrewosh Jun 16, 2020
9c91ed9
Update: add hyperdrive client import/export tests
dpaez May 12, 2020
de1c74f
Update: remove tape only call
dpaez May 12, 2020
1a56b16
Update: tweak export test
dpaez May 15, 2020
a931de5
Merge branch 'dpaez/test-import-export' of github.com:geut/hyperdrive…
dpaez Jun 17, 2020
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
95 changes: 49 additions & 46 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const sub = require('subleveldown')
const grpc = require('@grpc/grpc-js')
const bjson = require('buffer-json-encoding')
const processTop = require('process-top')
const varint = require('varint')
const Corestore = require('corestore')
const HypercoreCache = require('hypercore-cache')
const SwarmNetworker = require('corestore-swarm-networking')
Expand All @@ -22,6 +23,7 @@ const PeersManager = require('./lib/peers')
const DebugManager = require('./lib/debug')
const FuseManager = require('./lib/fuse')
const { serverError } = require('./lib/errors')
const { getHandlers } = require('./lib/common')

const log = require('./lib/log').child({ component: 'server' })

Expand Down Expand Up @@ -139,7 +141,7 @@ class HyperdriveDaemon extends EventEmitter {
const dbs = {
fuse: sub(this.db, 'fuse', { valueEncoding: bjson }),
drives: sub(this.db, 'drives', { valueEncoding: bjson }),
profiles: sub(this.db, 'profiles', { valueEncoding: 'json' })
network: sub(this.db, 'network', { valueEncoding: 'json'})
}
this._dbs = dbs

Expand Down Expand Up @@ -261,51 +263,52 @@ class HyperdriveDaemon extends EventEmitter {
})
}

createMainHandlers () {
return {
status: async call => {
const rsp = new rpc.main.messages.StatusResponse()
rsp.setApiversion(apiVersion)
rsp.setUptime(Date.now() - this._startTime)
if (this._versions) {
rsp.setDaemonversion(this._versions.daemon)
rsp.setClientversion(this._versions.client)
rsp.setSchemaversion(this._versions.schema)
rsp.setHyperdriveversion(this._versions.hyperdrive)
rsp.setNoisekey(this.noiseKeyPair.publicKey)

const swarm = this.networking && this.networking.swarm
if (swarm) {
const remoteAddress = swarm.remoteAddress()
rsp.setHolepunchable(swarm.holepunchable())
rsp.setRemoteaddress(remoteAddress ? remoteAddress.host + ':' + remoteAddress.port : '')
}
// RPC Methods

async _rpcStatus (call) {
const rsp = new rpc.main.messages.StatusResponse()
rsp.setApiversion(apiVersion)
rsp.setUptime(Date.now() - this._startTime)
if (this._versions) {
rsp.setDaemonversion(this._versions.daemon)
rsp.setClientversion(this._versions.client)
rsp.setSchemaversion(this._versions.schema)
rsp.setHyperdriveversion(this._versions.hyperdrive)
rsp.setNoisekey(this.noiseKeyPair.publicKey)

const swarm = this.networking && this.networking.swarm
if (swarm) {
const remoteAddress = swarm.remoteAddress()
rsp.setHolepunchable(swarm.holepunchable())
rsp.setRemoteaddress(remoteAddress ? remoteAddress.host + ':' + remoteAddress.port : '')
}

if (this._versions.fuseNative) rsp.setFusenativeversion(this._versions.fuseNative)
if (this._versions.hyperdriveFuse) rsp.setHyperdrivefuseversion(this._versions.hyperdriveFuse)
if (this._versions.fuseNative) rsp.setFusenativeversion(this._versions.fuseNative)
if (this._versions.hyperdriveFuse) rsp.setHyperdrivefuseversion(this._versions.hyperdriveFuse)

if (hyperfuse) {
rsp.setFuseavailable(true)
rsp.setFuseconfigured(this.fuse.fuseConfigured)
} else {
rsp.setFuseavailable(false)
rsp.setFuseconfigured(false)
}
}
return rsp
},
refreshFuse: async call => {
await this.fuse.ready()
if (this.fuse && this.fuse.fuseConfigured) {
hyperfuse = require('hyperdrive-fuse')
this._versions.fuseNative = require('fuse-native/package.json').version
this._versions.hyperdriveFuse = require('hyperdrive-fuse/package.json').version
}
return new rpc.main.messages.FuseRefreshResponse()
if (hyperfuse) {
rsp.setFuseavailable(true)
rsp.setFuseconfigured(this.fuse.fuseConfigured)
} else {
rsp.setFuseavailable(false)
rsp.setFuseconfigured(false)
}
}
return rsp
}

async _rpcRefreshFuse (call) {
await this.fuse.ready()
if (this.fuse && this.fuse.fuseConfigured) {
hyperfuse = require('hyperdrive-fuse')
this._versions.fuseNative = require('fuse-native/package.json').version
this._versions.hyperdriveFuse = require('hyperdrive-fuse/package.json').version
}
return new rpc.main.messages.FuseRefreshResponse()
}

// Public Methods

get uptime () {
if (!this._startTime) return 0
return Date.now() - this._startTime
Expand Down Expand Up @@ -370,24 +373,24 @@ class HyperdriveDaemon extends EventEmitter {
this.server = new grpc.Server()

this.server.addService(rpc.fuse.services.FuseService, {
...wrap(this.metadata, this.fuse.getHandlers(), { authenticate: true })
...wrap(this.metadata, getHandlers(this.fuse), { authenticate: true })
})
this.server.addService(rpc.drive.services.DriveService, {
...wrap(this.metadata, this.drives.getHandlers(), { authenticate: true })
...wrap(this.metadata, getHandlers(this.drives), { authenticate: true })
})
this.server.addService(rpc.peersockets.services.PeersocketsService, {
...wrap(this.metadata, this.peersockets.getHandlers(), { authenticate: true })
...wrap(this.metadata, getHandlers(this.peersockets), { authenticate: true })
})
this.server.addService(rpc.peers.services.PeersService, {
...wrap(this.metadata, this.peers.getHandlers(), { authenticate: true })
...wrap(this.metadata, getHandlers(this.peers), { authenticate: true })
})
if (this.debug) {
this.server.addService(rpc.debug.services.DebugService, {
...wrap(this.metadata, this.debug.getHandlers(), { authenticate: true })
...wrap(this.metadata, getHandlers(this.debug), { authenticate: true })
})
}
this.server.addService(rpc.main.services.HyperdriveService, {
...wrap(this.metadata, this.createMainHandlers(), { authenticate: true })
...wrap(this.metadata, getHandlers(this), { authenticate: true })
})

await new Promise((resolve, reject) => {
Expand Down
36 changes: 36 additions & 0 deletions lib/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const collectStream = require('stream-collector')

function getHandlers (manager) {
const handlers = {}
const rpcMethods = Object.getOwnPropertyNames(manager.__proto__).filter(methodName => methodName.startsWith('_rpc'))
for (let methodName of rpcMethods) {
let rpcMethodName = methodName.slice(4)
rpcMethodName = rpcMethodName[0].toLowerCase() + rpcMethodName.slice(1)
handlers[rpcMethodName] = manager[methodName].bind(manager)
}
return handlers
}

function dbCollect (index, opts) {
return new Promise((resolve, reject) => {
collectStream(index.createReadStream(opts), (err, list) => {
if (err) return reject(err)
return resolve(list)
})
})
}

async function dbGet (db, idx) {
try {
return await db.get(idx)
} catch (err) {
if (err && !err.notFound) throw err
return null
}
}

module.exports = {
getHandlers,
dbCollect,
dbGet
}
Loading