git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit b9ba5b15445f78c8ddf04e0c79f6e5d9caead624

use primea-objects module

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 3/27/2018, 8:11:55 PM
Parent: fad57dff2dd8eeb05b10062b336a4c44cf1bd050

Files changed

egressDriver.jschanged
index.jschanged
package-lock.jsonchanged
package.jsonchanged
scheduler.jschanged
tests/index.jschanged
tests/wasmContainer.jschanged
wasmContainer.jschanged
systemObjects.jsdeleted
egressDriver.jsView
@@ -1,5 +1,5 @@
1-const {ID} = require('./systemObjects')
1+const {ID} = require('primea-objects')
22 const EventEmitter = require('events')
33
44 module.exports = class Egress extends EventEmitter {
55 constructor () {
index.jsView
@@ -1,8 +1,8 @@
11 const crypto = require('crypto')
22 const Actor = require('./actor.js')
33 const Scheduler = require('./scheduler.js')
4-const {ID, decoder} = require('./systemObjects.js')
4+const {ID, decoder} = require('primea-objects')
55
66 module.exports = class Hypervisor {
77 /**
88 * The Hypervisor manages the container instances by instantiating them and
@@ -120,9 +120,9 @@
120120 this._containerTypes[Constructor.typeId] = Constructor
121121 }
122122
123123 registerDriver (driver) {
124- this.scheduler.drivers.set(driver.id.id.toString('hex'), driver)
124+ this.scheduler.drivers.set(driver.id.toString(), driver)
125125 }
126126 }
127127
128128 function encodedID (id) {
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 369765 bytes
New file size: 370223 bytes
package.jsonView
@@ -33,8 +33,9 @@
3333 "binary-search-insert": "^1.0.3",
3434 "borc": "git+https://github.com:dignifiedquire/borc.git#fix/nested-array",
3535 "events": "^2.0.0",
3636 "primea-annotations": "0.0.1",
37+ "primea-objects": "0.0.1",
3738 "reference-map": "^1.2.3",
3839 "safe-buffer": "^5.1.1",
3940 "wasm-json-toolkit": "^0.2.3",
4041 "wasm-metering": "^0.1.1"
scheduler.jsView
@@ -47,12 +47,12 @@
4747 this.emit('idle')
4848 }
4949
5050 async _processMessage (message) {
51- const to = message.funcRef.destId.id.toString('hex')
51+ const to = message.funcRef.actorID.toString()
5252 let actor = this.actors.get(to) || this.drivers.get(to)
5353 if (!actor) {
54- actor = await this.hypervisor.loadActor(message.funcRef.destId)
54+ actor = await this.hypervisor.loadActor(message.funcRef.actorID)
5555 this.actors.set(to, actor)
5656 }
5757 return actor.runMessage(message)
5858 }
tests/index.jsView
@@ -1,7 +1,7 @@
11 const tape = require('tape')
22 const Hypervisor = require('../')
3-const {Message, FunctionRef, ModuleRef} = require('../systemObjects')
3+const {Message, FunctionRef, ModuleRef} = require('primea-objects')
44
55 const level = require('level-browserify')
66 const EgressDriver = require('../egressDriver')
77 const RadixTree = require('dfinity-radix-tree')
@@ -304,9 +304,9 @@
304304 const message = new Message({
305305 funcRef: module.getFuncRef('main'),
306306 funcArguments: [{
307307 identifier: [0, 'main'],
308- destId: this.actor.id
308+ actorID: this.actor.id
309309 }]
310310 })
311311 this.actor.send(message)
312312 }
@@ -552,9 +552,9 @@
552552 const {module} = hypervisor.createActor(testVMContainer.typeId)
553553
554554 const message = new Message({
555555 funcRef: module.getFuncRef('main'),
556- funcArguments: [new FunctionRef({id: egress.id})]
556+ funcArguments: [new FunctionRef({actorID: egress.id})]
557557 })
558558
559559 hypervisor.send(message)
560560 })
tests/wasmContainer.jsView
@@ -1,8 +1,8 @@
11 const tape = require('tape')
22 const fs = require('fs')
33 const path = require('path')
4-const {Message} = require('../systemObjects.js')
4+const {Message} = require('primea-objects')
55 const Hypervisor = require('../')
66 const WasmContainer = require('../wasmContainer.js')
77
88 const level = require('level-browserify')
wasmContainer.jsView
@@ -3,9 +3,9 @@
33 const wasmMetering = require('wasm-metering')
44 const ReferanceMap = require('reference-map')
55 const injectGlobals = require('./injectGlobals.js')
66 const typeCheckWrapper = require('./typeCheckWrapper.js')
7-const {Message, FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js')
7+const {Message, FunctionRef, ModuleRef, DEFAULTS} = require('primea-objects')
88
99 const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64'])
1010 const FUNC_INDEX_OFFSET = 1
1111
@@ -98,9 +98,9 @@
9898 const params = self.json.types[self.json.indexes[func.name - FUNC_INDEX_OFFSET]].params
9999 const ref = new FunctionRef({
100100 identifier: [true, func.tableIndex],
101101 params,
102- id: self.actor.id
102+ actorID: self.actor.id
103103 })
104104 return self.refs.add(ref, 'func')
105105 }
106106 },
systemObjects.jsView
@@ -1,132 +1,0 @@
1-const cbor = require('borc')
2-const EventEmitter = require('events')
3-
4-const TAGS = {
5- id: 41,
6- link: 42,
7- func: 43,
8- mod: 44
9-}
10-
11-const DEFAULTS = {
12- elem: [],
13- data: Buffer.from([]),
14- id: new cbor.Tagged(TAGS.id, 0),
15- mod: new cbor.Tagged(TAGS.mod, [{}, new cbor.Tagged(TAGS.id, 0)]),
16- link: new cbor.Tagged(TAGS.link, null),
17- func: new cbor.Tagged(TAGS.func, 0)
18-}
19-
20-const decoder = new cbor.Decoder({
21- tags: {
22- [TAGS.id]: val => new ID(val),
23- [TAGS.func]: val => new FunctionRef({
24- identifier: val[0],
25- params: val[1],
26- id: val[2],
27- gas: val[3]
28- }),
29- [TAGS.mod]: val => new ModuleRef(...val),
30- [TAGS.link]: val => {
31- return {
32- '/': val
33- }
34- }
35- }
36-})
37-
38-class FunctionRef {
39- constructor (opts) {
40- this.identifier = opts.identifier
41- this.destId = opts.id
42- this.params = opts.params
43- this.gas = opts.gas || 0
44- }
45-
46- encodeCBOR (gen) {
47- return gen.write(new cbor.Tagged(TAGS.func, [
48- this.identifier,
49- this.params,
50- this.destId,
51- this.gas
52- ]))
53- }
54-}
55-
56-class ModuleRef {
57- constructor (ex, id) {
58- this.exports = ex
59- this.id = id
60- }
61-
62- getFuncRef (name) {
63- const params = this.exports[name]
64-
65- return new FunctionRef({
66- identifier: [false, name],
67- params,
68- id: this.id
69- })
70- }
71-
72- encodeCBOR (gen) {
73- return gen.write(new cbor.Tagged(TAGS.mod, [this.exports, this.id]))
74- }
75-}
76-
77-class ID {
78- constructor (id) {
79- this.id = id
80- }
81-
82- encodeCBOR (gen) {
83- return gen.write(new cbor.Tagged(TAGS.id, this.id))
84- }
85-}
86-
87-/**
88- * This implements Messages for Primea
89- * @module primea-message
90- */
91-class Message extends EventEmitter {
92- /**
93- * @param {Object} opts
94- * @param {ArrayBuffer} opts.data - the payload of the message
95- * @param {Array<Object>} opts.caps - an array of capabilities to send in the message
96- */
97- constructor (opts) {
98- super()
99- const defaults = this.constructor.defaults
100- this._opts = Object.assign(defaults, opts)
101- Object.keys(this._opts).forEach(key => {
102- Object.defineProperty(this, key, {
103- get: function () {
104- return this._opts[key]
105- },
106- set: function (y) {
107- this._opts[key] = y
108- }
109- })
110- })
111- }
112-
113- static get defaults () {
114- return {
115- ticks: 0,
116- funcRef: null,
117- funcArguments: [],
118- funcParameters: [],
119- _fromId: new ID(Buffer.alloc(20)),
120- _fromTicks: 0
121- }
122- }
123-}
124-
125-module.exports = {
126- Message,
127- ID,
128- FunctionRef,
129- ModuleRef,
130- DEFAULTS,
131- decoder
132-}

Built with git-ssb-web