Commit a0e8e349098f178adeedc56a664765d373d88d99
use id generation from primea-objects
Norton Wang committed on 4/20/2018, 11:17:04 PMParent: 560a2364b7318ac4511c7e50913ac0bcc9bbe7b6
Files changed
index.js | changed |
package-lock.json | changed |
package.json | changed |
index.js | ||
---|---|---|
@@ -1,9 +1,8 @@ | ||
1 | 1 | const Buffer = require('safe-buffer').Buffer |
2 | -const crypto = require('crypto') | |
3 | 2 | const Actor = require('./actor.js') |
4 | 3 | const Scheduler = require('./scheduler.js') |
5 | -const {ID, decoder} = require('primea-objects') | |
4 | +const { ID, decoder, generateActorId } = require('primea-objects') | |
6 | 5 | const cbor = require('borc') |
7 | 6 | |
8 | 7 | module.exports = class Hypervisor { |
9 | 8 | /** |
@@ -43,9 +42,9 @@ | ||
43 | 42 | * @param {ID} id |
44 | 43 | * @returns {Promise<Actor>} |
45 | 44 | */ |
46 | 45 | async loadActor (id) { |
47 | - const state = await this.tree.get(id.id, true) | |
46 | + const state = await this.tree.get(id.id) | |
48 | 47 | const [code, storage] = await Promise.all([ |
49 | 48 | this.tree.graph.get(state.node, '1'), |
50 | 49 | this.tree.graph.get(state.node, '2') |
51 | 50 | ]) |
@@ -76,14 +75,14 @@ | ||
76 | 75 | * @param {Object} id - the id for the actor |
77 | 76 | */ |
78 | 77 | createActor (type, code, id = {nonce: this.nonce++, parent: null}) { |
79 | 78 | 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) | |
82 | 81 | const metaData = [type, 0] |
83 | 82 | |
84 | 83 | // save the container in the state |
85 | - this.tree.set(id.id, metaData).then(node => { | |
84 | + this.tree.set(actorId.id, metaData).then(node => { | |
86 | 85 | // save the code |
87 | 86 | node[1] = { |
88 | 87 | '/': code |
89 | 88 | } |
@@ -93,25 +92,13 @@ | ||
93 | 92 | } |
94 | 93 | }) |
95 | 94 | |
96 | 95 | return { |
97 | - id, | |
96 | + id: actorId, | |
98 | 97 | module |
99 | 98 | } |
100 | 99 | } |
101 | 100 | |
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 | - | |
114 | 101 | /** |
115 | 102 | * creates a state root starting from a given container and a given number of |
116 | 103 | * ticks |
117 | 104 | * @param {Number} ticks the number of ticks at which to create the state root |
@@ -154,12 +141,4 @@ | ||
154 | 141 | driver.startup(this) |
155 | 142 | this.scheduler.drivers.set(driver.id.toString(), driver) |
156 | 143 | } |
157 | 144 | } |
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.json | ||
---|---|---|
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.json | ||
---|---|---|
@@ -31,9 +31,9 @@ | ||
31 | 31 | "dependencies": { |
32 | 32 | "binary-search-insert": "^1.0.3", |
33 | 33 | "borc": "git+https://github.com:dignifiedquire/borc.git#fix/nested-array", |
34 | 34 | "events": "^2.0.0", |
35 | - "primea-objects": "0.0.3", | |
35 | + "primea-objects": "0.0.4", | |
36 | 36 | "safe-buffer": "^5.1.1" |
37 | 37 | }, |
38 | 38 | "devDependencies": { |
39 | 39 | "coveralls": "^3.0.0", |
Built with git-ssb-web