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.js | changed |
index.js | changed |
package-lock.json | changed |
package.json | changed |
scheduler.js | changed |
tests/index.js | changed |
tests/wasmContainer.js | changed |
wasmContainer.js | changed |
systemObjects.js | deleted |
egressDriver.js | ||
---|---|---|
@@ -1,5 +1,5 @@ | ||
1 | -const {ID} = require('./systemObjects') | |
1 | +const {ID} = require('primea-objects') | |
2 | 2 | const EventEmitter = require('events') |
3 | 3 | |
4 | 4 | module.exports = class Egress extends EventEmitter { |
5 | 5 | constructor () { |
index.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 | const crypto = require('crypto') |
2 | 2 | const Actor = require('./actor.js') |
3 | 3 | const Scheduler = require('./scheduler.js') |
4 | -const {ID, decoder} = require('./systemObjects.js') | |
4 | +const {ID, decoder} = require('primea-objects') | |
5 | 5 | |
6 | 6 | module.exports = class Hypervisor { |
7 | 7 | /** |
8 | 8 | * The Hypervisor manages the container instances by instantiating them and |
@@ -120,9 +120,9 @@ | ||
120 | 120 | this._containerTypes[Constructor.typeId] = Constructor |
121 | 121 | } |
122 | 122 | |
123 | 123 | registerDriver (driver) { |
124 | - this.scheduler.drivers.set(driver.id.id.toString('hex'), driver) | |
124 | + this.scheduler.drivers.set(driver.id.toString(), driver) | |
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
128 | 128 | function encodedID (id) { |
package-lock.json | ||
---|---|---|
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.json | ||
---|---|---|
@@ -33,8 +33,9 @@ | ||
33 | 33 | "binary-search-insert": "^1.0.3", |
34 | 34 | "borc": "git+https://github.com:dignifiedquire/borc.git#fix/nested-array", |
35 | 35 | "events": "^2.0.0", |
36 | 36 | "primea-annotations": "0.0.1", |
37 | + "primea-objects": "0.0.1", | |
37 | 38 | "reference-map": "^1.2.3", |
38 | 39 | "safe-buffer": "^5.1.1", |
39 | 40 | "wasm-json-toolkit": "^0.2.3", |
40 | 41 | "wasm-metering": "^0.1.1" |
scheduler.js | ||
---|---|---|
@@ -47,12 +47,12 @@ | ||
47 | 47 | this.emit('idle') |
48 | 48 | } |
49 | 49 | |
50 | 50 | async _processMessage (message) { |
51 | - const to = message.funcRef.destId.id.toString('hex') | |
51 | + const to = message.funcRef.actorID.toString() | |
52 | 52 | let actor = this.actors.get(to) || this.drivers.get(to) |
53 | 53 | if (!actor) { |
54 | - actor = await this.hypervisor.loadActor(message.funcRef.destId) | |
54 | + actor = await this.hypervisor.loadActor(message.funcRef.actorID) | |
55 | 55 | this.actors.set(to, actor) |
56 | 56 | } |
57 | 57 | return actor.runMessage(message) |
58 | 58 | } |
tests/index.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 | const tape = require('tape') |
2 | 2 | const Hypervisor = require('../') |
3 | -const {Message, FunctionRef, ModuleRef} = require('../systemObjects') | |
3 | +const {Message, FunctionRef, ModuleRef} = require('primea-objects') | |
4 | 4 | |
5 | 5 | const level = require('level-browserify') |
6 | 6 | const EgressDriver = require('../egressDriver') |
7 | 7 | const RadixTree = require('dfinity-radix-tree') |
@@ -304,9 +304,9 @@ | ||
304 | 304 | const message = new Message({ |
305 | 305 | funcRef: module.getFuncRef('main'), |
306 | 306 | funcArguments: [{ |
307 | 307 | identifier: [0, 'main'], |
308 | - destId: this.actor.id | |
308 | + actorID: this.actor.id | |
309 | 309 | }] |
310 | 310 | }) |
311 | 311 | this.actor.send(message) |
312 | 312 | } |
@@ -552,9 +552,9 @@ | ||
552 | 552 | const {module} = hypervisor.createActor(testVMContainer.typeId) |
553 | 553 | |
554 | 554 | const message = new Message({ |
555 | 555 | funcRef: module.getFuncRef('main'), |
556 | - funcArguments: [new FunctionRef({id: egress.id})] | |
556 | + funcArguments: [new FunctionRef({actorID: egress.id})] | |
557 | 557 | }) |
558 | 558 | |
559 | 559 | hypervisor.send(message) |
560 | 560 | }) |
tests/wasmContainer.js | ||
---|---|---|
@@ -1,8 +1,8 @@ | ||
1 | 1 | const tape = require('tape') |
2 | 2 | const fs = require('fs') |
3 | 3 | const path = require('path') |
4 | -const {Message} = require('../systemObjects.js') | |
4 | +const {Message} = require('primea-objects') | |
5 | 5 | const Hypervisor = require('../') |
6 | 6 | const WasmContainer = require('../wasmContainer.js') |
7 | 7 | |
8 | 8 | const level = require('level-browserify') |
wasmContainer.js | ||
---|---|---|
@@ -3,9 +3,9 @@ | ||
3 | 3 | const wasmMetering = require('wasm-metering') |
4 | 4 | const ReferanceMap = require('reference-map') |
5 | 5 | const injectGlobals = require('./injectGlobals.js') |
6 | 6 | const typeCheckWrapper = require('./typeCheckWrapper.js') |
7 | -const {Message, FunctionRef, ModuleRef, DEFAULTS} = require('./systemObjects.js') | |
7 | +const {Message, FunctionRef, ModuleRef, DEFAULTS} = require('primea-objects') | |
8 | 8 | |
9 | 9 | const nativeTypes = new Set(['i32', 'i64', 'f32', 'f64']) |
10 | 10 | const FUNC_INDEX_OFFSET = 1 |
11 | 11 | |
@@ -98,9 +98,9 @@ | ||
98 | 98 | const params = self.json.types[self.json.indexes[func.name - FUNC_INDEX_OFFSET]].params |
99 | 99 | const ref = new FunctionRef({ |
100 | 100 | identifier: [true, func.tableIndex], |
101 | 101 | params, |
102 | - id: self.actor.id | |
102 | + actorID: self.actor.id | |
103 | 103 | }) |
104 | 104 | return self.refs.add(ref, 'func') |
105 | 105 | } |
106 | 106 | }, |
systemObjects.js | ||
---|---|---|
@@ -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