git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 50a0ebc04208fbb22e6da71e180399a8fc00b3a3

remove web-crypto

wanderer committed on 4/26/2017, 10:20:37 AM
Parent: 40fce8207151c8b05af5d4bd34e82751421a7893

Files changed

index.jschanged
kernel.jschanged
package.jsonchanged
portManager.jschanged
tests/index.jschanged
crypto.jsdeleted
index.jsView
@@ -1,7 +1,6 @@
11 const Graph = require('ipld-graph-builder')
22 const Kernel = require('./kernel.js')
3-const crypto = require('./crypto')
43
54 module.exports = class Hypervisor {
65 constructor (opts) {
76 this._opts = {
@@ -9,8 +8,9 @@
98 VMs: {}
109 }
1110
1211 this.graph = new Graph(opts.dag)
12+ delete opts.dag
1313 this._vmInstances = new Map()
1414 Object.assign(this._opts, opts)
1515 }
1616
@@ -57,16 +57,10 @@
5757 await this.wait(port, ticks)
5858 return this.graph.flush(port)
5959 }
6060
61- async generateID (port) {
62- if (typeof port === 'object') {
63- let id = Buffer.concat([port.id.nonce, port.id.parent])
64- id = await crypto.subtle.digest('SHA-256', id)
65- return new Buffer(id).toString('hex')
66- } else {
67- return port
68- }
61+ generateID (port) {
62+ this.graph.flush(port.id)
6963 }
7064
7165 addVM (type, vm) {
7266 this._opts.VMs[type] = vm
kernel.jsView
@@ -74,9 +74,9 @@
7474
7575 // returns a promise that resolves once the kernel hits the threshould tick
7676 // count
7777 async wait (threshold) {
78- if (this.vmState === 'idle' && threshold > this.ticks) {
78+ if (this.vmState !== 'running' && threshold > this.ticks) {
7979 // the cotract is at idle so wait
8080 return this.ports.wait(threshold)
8181 } else {
8282 return new Promise((resolve, reject) => {
package.jsonView
@@ -2,12 +2,12 @@
22 "name": "primea-hypervisor",
33 "version": "0.0.0",
44 "description": "this is a JS implemention of the primea hypervisor",
55 "scripts": {
6- "coverage": "node --harmony ./node_modules/istanbul/lib/cli.js cover ./tests/index.js",
6+ "coverage": "node ./node_modules/istanbul/lib/cli.js cover ./tests/index.js",
77 "coveralls": "npm run coverage && coveralls <coverage/lcov.info",
88 "lint": "standard",
9- "test": "node --harmony --expose-wasm ./tests/interfaceRunner.js",
9+ "test": "node ./tests/index.js",
1010 "build": "node ./tests/buildTests.js && ./tools/wabt/out/wast2wasm ./wasm/interface.wast -o ./wasm/interface.wasm"
1111 },
1212 "repository": {
1313 "type": "git",
@@ -29,9 +29,8 @@
2929 "bn.js": "^4.11.6",
3030 "deepcopy": "^0.6.3",
3131 "fastpriorityqueue": "^0.2.4",
3232 "ipld-graph-builder": "1.0.1",
33- "node-webcrypto-ossl": "^1.0.21",
3433 "primea-message": "0.0.0"
3534 },
3635 "devDependencies": {
3736 "coveralls": "^2.13.0",
portManager.jsView
@@ -25,9 +25,9 @@
2525 module.exports = class PortManager {
2626 constructor (kernel) {
2727 this.kernel = kernel
2828 this.hypervisor = kernel._opts.hypervisor
29- this.ports = kernel._opts.state.ports
29+ this.ports = kernel._opts.state['/'].ports
3030 this._portMap = new Map()
3131 }
3232
3333 async start () {
@@ -42,9 +42,10 @@
4242 // create the parent port
4343 ports = await Promise.all(ports)
4444 this._portMap = new Map(ports)
4545 // add the parent port
46- const parent = this.kernel._opts.id.parent.length === 0 ? 'root' : this.kernel._opts.id.parent
46+ let parent = await this.hypervisor.graph.get(this.kernel._opts.id, 'parent')
47+ parent = parent === null ? 'root' : parent
4748 this._portMap.set(parent, new Port('parent'))
4849 }
4950
5051 queue (message) {
@@ -95,5 +96,4 @@
9596 await this.wait(ticks)
9697 return [...this._portMap].reduce(messageArbiter)[1].shift()
9798 }
9899 }
99-
tests/index.jsView
@@ -8,50 +8,68 @@
88 console.log(err)
99 })
1010
1111 node.on('start', () => {
12- tape.only('basic', async t => {
12+ tape('basic', async t => {
1313 const message = new Message()
14- class testVM {
14+ const state = {
15+ messages: [],
16+ id: {
17+ '/': {
18+ nonce: new Buffer([0]),
19+ parent: {
20+ '/': null
21+ }
22+ }
23+ },
24+ type: 'test',
25+ vm: {
26+ '/': {
27+ ports: {}
28+ }
29+ }
30+ }
31+ const expectedState = { '/': 'zdpuAnCsh9tVFa3asqkC7iNkwK6dYyZqJDxQrB7PMt8foLRKJ' }
32+
33+ class testVMContainer {
1534 run (m) {
1635 t.true(m === message, 'should recive a message')
17- t.end()
1836 }
1937 }
2038
2139 try {
22- const state = {
23- id: {
24- nonce: new Buffer([0]),
25- parent: new Buffer([])
26- },
27- type: 'test',
28- vm: {
29- ports: {}
30- }
31- }
32-
33- const expectedState = { '/': 'zdpuApqUjZFhw8LTkw8gXAbVcqc5Y7TsbTVadU879TgucoqSF' }
34-
3540 const hypervisor = new Hypervisor({
3641 dag: node.dag
3742 })
38- hypervisor.addVM('test', testVM)
43+ hypervisor.addVM('test', testVMContainer)
3944
4045 await hypervisor.send(state, message)
41-
4246 await hypervisor.createStateRoot(state, Infinity)
47+ console.log('state root')
4348 t.deepEquals(state, expectedState, 'expected')
44-
45- node.stop(() => {
46- process.exit()
47- })
49+ t.end()
4850 } catch (e) {
4951 console.log(e)
5052 }
5153 })
5254
53- tape('messaging', t => {
55+ tape('one child contract', t => {
56+ t.end()
57+ node.stop(() => {
58+ process.exit()
59+ })
60+
61+ const message = new Message()
62+ class testVMContainer {
63+ constuctor (kernel) {
64+ this.kernel = kernel
65+ }
66+
67+ run (m) {
68+
69+ }
70+ }
71+
5472 // const state = {
5573 // id: {},
5674 // ports: {
5775 // first: {
crypto.jsView
@@ -1,4 +1,0 @@
1-const WebCrypto = require('node-webcrypto-ossl')
2-module.exports = new WebCrypto({
3- directory: `${__dirname}/.webcrypto`
4-})

Built with git-ssb-web