git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 67bff6abda5477a082d3bc7a33ada595b985e2eb

reworked ids

wanderer committed on 5/16/2017, 1:16:05 PM
Parent: e8496bb49a74c164d39ddf569e49b73296bebe78

Files changed

index.jschanged
kernel.jschanged
package.jsonchanged
index.jsView
@@ -1,6 +1,5 @@
11 const Graph = require('ipld-graph-builder')
2-const multibase = require('multibase')
32 const Kernel = require('./kernel.js')
43
54 module.exports = class Hypervisor {
65 constructor (opts) {
@@ -8,27 +7,23 @@
87 this._vmInstances = new Map()
98 this._VMs = {}
109 }
1110
12- async getInstance (port, createIfNotFound, parentPort) {
13- const id = await this.generateID(port)
14- let kernel = this._vmInstances.get(id)
15- if (!kernel && createIfNotFound) {
16- // load the the ID from the merkle store
17- await this.graph.tree(port.id, 1)
18-
11+ async getInstance (port, parentPort) {
12+ let kernel = this._vmInstances.get(port)
13+ if (!kernel) {
1914 kernel = await this.createInstance(port.type, port.link, port, parentPort)
2015 kernel.on('idle', () => {
21- this._vmInstances.delete(id)
16+ this._vmInstances.delete(port)
2217 })
2318 }
2419 return kernel
2520 }
2621
2722 // given a port, wait untill its source contract has reached the threshold
2823 // tick count
2924 async wait (port, threshold, fromPort) {
30- let kernel = await this.getInstance(port, false)
25+ let kernel = this._vmInstances.get(port)
3126 if (kernel) {
3227 return kernel.wait(threshold, fromPort)
3328 } else {
3429 return threshold
@@ -52,11 +47,10 @@
5247 state: state,
5348 VM: VM
5449 })
5550
56- const id = await this.generateID(entryPort)
5751 // save the newly created instance
58- this._vmInstances.set(id, kernel)
52+ this._vmInstances.set(entryPort, kernel)
5953 await kernel.start()
6054 return kernel
6155 }
6256
@@ -64,22 +58,8 @@
6458 await container.wait(ticks)
6559 return this.graph.flush(container.state)
6660 }
6761
68- async generateID (port) {
69- if (!port || !port.id) {
70- return null
71- }
72-
73- let id = Object.assign({}, port.id)
74- id = await this.graph.flush(id)
75- id = id['/']
76- if (Buffer.isBuffer(id)) {
77- id = multibase.encode('base58btc', id).toString()
78- }
79- return id
80- }
81-
8262 registerContainer (type, vm) {
8363 this._VMs[type] = vm
8464 }
8565 }
kernel.jsView
@@ -122,9 +122,9 @@
122122
123123 message._fromPort = this.entryPort
124124 message._fromPortTicks = this.ticks
125125
126- const vm = await this.hypervisor.getInstance(portRef, true, this.entryPort)
126+ const vm = await this.hypervisor.getInstance(portRef, this.entryPort)
127127 vm.queue(message)
128128
129129 const waiter = this._waitingMap.get(portRef)
130130 if (waiter) {
package.jsonView
@@ -27,9 +27,8 @@
2727 "dependencies": {
2828 "bn.js": "^4.11.6",
2929 "clone": "^2.1.1",
3030 "object-clear": "^0.1.0",
31- "multibase": "^0.3.4",
3231 "ipld-graph-builder": "1.1.5"
3332 },
3433 "devDependencies": {
3534 "coveralls": "^2.13.1",

Built with git-ssb-web