git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit a0e8e349098f178adeedc56a664765d373d88d99

use id generation from primea-objects

Norton Wang committed on 4/20/2018, 11:17:04 PM
Parent: 560a2364b7318ac4511c7e50913ac0bcc9bbe7b6

Files changed

index.jschanged
package-lock.jsonchanged
package.jsonchanged
index.jsView
@@ -1,9 +1,8 @@
11 const Buffer = require('safe-buffer').Buffer
2-const crypto = require('crypto')
32 const Actor = require('./actor.js')
43 const Scheduler = require('./scheduler.js')
5-const {ID, decoder} = require('primea-objects')
4+const { ID, decoder, generateActorId } = require('primea-objects')
65 const cbor = require('borc')
76
87 module.exports = class Hypervisor {
98 /**
@@ -43,9 +42,9 @@
4342 * @param {ID} id
4443 * @returns {Promise<Actor>}
4544 */
4645 async loadActor (id) {
47- const state = await this.tree.get(id.id, true)
46+ const state = await this.tree.get(id.id)
4847 const [code, storage] = await Promise.all([
4948 this.tree.graph.get(state.node, '1'),
5049 this.tree.graph.get(state.node, '2')
5150 ])
@@ -76,14 +75,14 @@
7675 * @param {Object} id - the id for the actor
7776 */
7877 createActor (type, code, id = {nonce: this.nonce++, parent: null}) {
7978 const Container = this._containerTypes[type]
80- id = this.generateId(id)
81- const module = Container.onCreation(code, id)
79+ const actorId = generateActorId(id)
80+ const module = Container.onCreation(code, actorId)
8281 const metaData = [type, 0]
8382
8483 // save the container in the state
85- this.tree.set(id.id, metaData).then(node => {
84+ this.tree.set(actorId.id, metaData).then(node => {
8685 // save the code
8786 node[1] = {
8887 '/': code
8988 }
@@ -93,25 +92,13 @@
9392 }
9493 })
9594
9695 return {
97- id,
96+ id: actorId,
9897 module
9998 }
10099 }
101100
102- generateId (id) {
103- const encoded = encodedID(id)
104- const hashed = this._hash(encoded)
105- return new ID(hashed)
106- }
107-
108- _hash (buf) {
109- const hash = crypto.createHash('sha256')
110- hash.update(buf)
111- return hash.digest().slice(0, 20)
112- }
113-
114101 /**
115102 * creates a state root starting from a given container and a given number of
116103 * ticks
117104 * @param {Number} ticks the number of ticks at which to create the state root
@@ -154,12 +141,4 @@
154141 driver.startup(this)
155142 this.scheduler.drivers.set(driver.id.toString(), driver)
156143 }
157144 }
158-
159-function encodedID (id) {
160- if (id.parent) {
161- return cbor.encode([id.nonce, id.parent.id])
162- } else {
163- return cbor.encode([id.nonce, null])
164- }
165-}
package-lock.jsonView
The diff is too large to show. Use a local git client to view these changes.
Old file size: 365090 bytes
New file size: 365090 bytes
package.jsonView
@@ -31,9 +31,9 @@
3131 "dependencies": {
3232 "binary-search-insert": "^1.0.3",
3333 "borc": "git+https://github.com:dignifiedquire/borc.git#fix/nested-array",
3434 "events": "^2.0.0",
35- "primea-objects": "0.0.3",
35+ "primea-objects": "0.0.4",
3636 "safe-buffer": "^5.1.1"
3737 },
3838 "devDependencies": {
3939 "coveralls": "^3.0.0",

Built with git-ssb-web