Commit 50a0ebc04208fbb22e6da71e180399a8fc00b3a3
remove web-crypto
wanderer committed on 4/26/2017, 10:20:37 AMParent: 40fce8207151c8b05af5d4bd34e82751421a7893
Files changed
index.js | changed |
kernel.js | changed |
package.json | changed |
portManager.js | changed |
tests/index.js | changed |
crypto.js | deleted |
index.js | ||
---|---|---|
@@ -1,7 +1,6 @@ | ||
1 | 1 | const Graph = require('ipld-graph-builder') |
2 | 2 | const Kernel = require('./kernel.js') |
3 | -const crypto = require('./crypto') | |
4 | 3 | |
5 | 4 | module.exports = class Hypervisor { |
6 | 5 | constructor (opts) { |
7 | 6 | this._opts = { |
@@ -9,8 +8,9 @@ | ||
9 | 8 | VMs: {} |
10 | 9 | } |
11 | 10 | |
12 | 11 | this.graph = new Graph(opts.dag) |
12 | + delete opts.dag | |
13 | 13 | this._vmInstances = new Map() |
14 | 14 | Object.assign(this._opts, opts) |
15 | 15 | } |
16 | 16 | |
@@ -57,16 +57,10 @@ | ||
57 | 57 | await this.wait(port, ticks) |
58 | 58 | return this.graph.flush(port) |
59 | 59 | } |
60 | 60 | |
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) | |
69 | 63 | } |
70 | 64 | |
71 | 65 | addVM (type, vm) { |
72 | 66 | this._opts.VMs[type] = vm |
kernel.js | ||
---|---|---|
@@ -74,9 +74,9 @@ | ||
74 | 74 | |
75 | 75 | // returns a promise that resolves once the kernel hits the threshould tick |
76 | 76 | // count |
77 | 77 | async wait (threshold) { |
78 | - if (this.vmState === 'idle' && threshold > this.ticks) { | |
78 | + if (this.vmState !== 'running' && threshold > this.ticks) { | |
79 | 79 | // the cotract is at idle so wait |
80 | 80 | return this.ports.wait(threshold) |
81 | 81 | } else { |
82 | 82 | return new Promise((resolve, reject) => { |
package.json | ||
---|---|---|
@@ -2,12 +2,12 @@ | ||
2 | 2 | "name": "primea-hypervisor", |
3 | 3 | "version": "0.0.0", |
4 | 4 | "description": "this is a JS implemention of the primea hypervisor", |
5 | 5 | "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", | |
7 | 7 | "coveralls": "npm run coverage && coveralls <coverage/lcov.info", |
8 | 8 | "lint": "standard", |
9 | - "test": "node --harmony --expose-wasm ./tests/interfaceRunner.js", | |
9 | + "test": "node ./tests/index.js", | |
10 | 10 | "build": "node ./tests/buildTests.js && ./tools/wabt/out/wast2wasm ./wasm/interface.wast -o ./wasm/interface.wasm" |
11 | 11 | }, |
12 | 12 | "repository": { |
13 | 13 | "type": "git", |
@@ -29,9 +29,8 @@ | ||
29 | 29 | "bn.js": "^4.11.6", |
30 | 30 | "deepcopy": "^0.6.3", |
31 | 31 | "fastpriorityqueue": "^0.2.4", |
32 | 32 | "ipld-graph-builder": "1.0.1", |
33 | - "node-webcrypto-ossl": "^1.0.21", | |
34 | 33 | "primea-message": "0.0.0" |
35 | 34 | }, |
36 | 35 | "devDependencies": { |
37 | 36 | "coveralls": "^2.13.0", |
portManager.js | ||
---|---|---|
@@ -25,9 +25,9 @@ | ||
25 | 25 | module.exports = class PortManager { |
26 | 26 | constructor (kernel) { |
27 | 27 | this.kernel = kernel |
28 | 28 | this.hypervisor = kernel._opts.hypervisor |
29 | - this.ports = kernel._opts.state.ports | |
29 | + this.ports = kernel._opts.state['/'].ports | |
30 | 30 | this._portMap = new Map() |
31 | 31 | } |
32 | 32 | |
33 | 33 | async start () { |
@@ -42,9 +42,10 @@ | ||
42 | 42 | // create the parent port |
43 | 43 | ports = await Promise.all(ports) |
44 | 44 | this._portMap = new Map(ports) |
45 | 45 | // 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 | |
47 | 48 | this._portMap.set(parent, new Port('parent')) |
48 | 49 | } |
49 | 50 | |
50 | 51 | queue (message) { |
@@ -95,5 +96,4 @@ | ||
95 | 96 | await this.wait(ticks) |
96 | 97 | return [...this._portMap].reduce(messageArbiter)[1].shift() |
97 | 98 | } |
98 | 99 | } |
99 | - |
tests/index.js | ||
---|---|---|
@@ -8,50 +8,68 @@ | ||
8 | 8 | console.log(err) |
9 | 9 | }) |
10 | 10 | |
11 | 11 | node.on('start', () => { |
12 | - tape.only('basic', async t => { | |
12 | + tape('basic', async t => { | |
13 | 13 | 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 { | |
15 | 34 | run (m) { |
16 | 35 | t.true(m === message, 'should recive a message') |
17 | - t.end() | |
18 | 36 | } |
19 | 37 | } |
20 | 38 | |
21 | 39 | 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 | - | |
35 | 40 | const hypervisor = new Hypervisor({ |
36 | 41 | dag: node.dag |
37 | 42 | }) |
38 | - hypervisor.addVM('test', testVM) | |
43 | + hypervisor.addVM('test', testVMContainer) | |
39 | 44 | |
40 | 45 | await hypervisor.send(state, message) |
41 | - | |
42 | 46 | await hypervisor.createStateRoot(state, Infinity) |
47 | + console.log('state root') | |
43 | 48 | t.deepEquals(state, expectedState, 'expected') |
44 | - | |
45 | - node.stop(() => { | |
46 | - process.exit() | |
47 | - }) | |
49 | + t.end() | |
48 | 50 | } catch (e) { |
49 | 51 | console.log(e) |
50 | 52 | } |
51 | 53 | }) |
52 | 54 | |
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 | + | |
54 | 72 | // const state = { |
55 | 73 | // id: {}, |
56 | 74 | // ports: { |
57 | 75 | // first: { |
Built with git-ssb-web