Commit e08047273f81b45b7107bc0bc4fa2557d9f79eb0
added chunking
wanderer committed on 7/27/2017, 3:48:46 AMParent: 6723a3ab125343529593a107313cd31c8eb38d7a
Files changed
index.js | changed |
kernel.js | changed |
package.json | changed |
index.js | ||
---|---|---|
@@ -2,8 +2,10 @@ | ||
2 | 2 | const Message = require('primea-message') |
3 | 3 | const Kernel = require('./kernel.js') |
4 | 4 | const Scheduler = require('./scheduler.js') |
5 | 5 | const DFSchecker = require('./dfsChecker.js') |
6 | +const chunk = require('chunk') | |
7 | +const flatten = require('flatten') | |
6 | 8 | |
7 | 9 | const ROOT_ID = 'zdpuAm6aTdLVMUuiZypxkwtA7sKm7BWERy8MPbaCrFsmiyzxr' |
8 | 10 | |
9 | 11 | module.exports = class Hypervisor { |
@@ -18,8 +20,10 @@ | ||
18 | 20 | this.scheduler = new Scheduler() |
19 | 21 | this.state = state |
20 | 22 | this._containerTypes = {} |
21 | 23 | this._nodesToCheck = new Set() |
24 | + | |
25 | + this.MAX_DATA_BYTES = 6553 | |
22 | 26 | } |
23 | 27 | |
24 | 28 | /** |
25 | 29 | * add a potaintail node in the state graph to check for garbage collection |
@@ -57,8 +61,12 @@ | ||
57 | 61 | async _loadInstance (id) { |
58 | 62 | const state = await this.graph.get(this.state, id) |
59 | 63 | const container = this._containerTypes[state.type] |
60 | 64 | |
65 | + // if (state.code && Array.isArray(state.code[0])) { | |
66 | + // state.code = flatten(state.code) | |
67 | + // } | |
68 | + | |
61 | 69 | // create a new kernel instance |
62 | 70 | const kernel = new Kernel({ |
63 | 71 | hypervisor: this, |
64 | 72 | state: state, |
@@ -122,8 +130,18 @@ | ||
122 | 130 | resolve(instance) |
123 | 131 | // send the intialization message |
124 | 132 | await instance.initialize(message) |
125 | 133 | |
134 | + if (state.code && state.code.length > this.MAX_DATA_BYTES) { | |
135 | + state.code = chunk(state.code, this.MAX_DATA_BYTES).map(chk => { | |
136 | + return { | |
137 | + '/': chk | |
138 | + } | |
139 | + }) | |
140 | + } else { | |
141 | + console.log(state.code) | |
142 | + } | |
143 | + | |
126 | 144 | return instance |
127 | 145 | } |
128 | 146 | |
129 | 147 | /** |
@@ -137,8 +155,9 @@ | ||
137 | 155 | const unlinked = await DFSchecker(this.graph, this.state, ROOT_ID, this._nodesToCheck) |
138 | 156 | unlinked.forEach(id => { |
139 | 157 | delete this.state[id] |
140 | 158 | }) |
159 | + console.log(this.state) | |
141 | 160 | return this.graph.flush(this.state) |
142 | 161 | } |
143 | 162 | |
144 | 163 | /** |
Built with git-ssb-web