Commit d577a28a042f4ebf1025240c70acdecfbf7bac56
update DFS checker
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 8/21/2017, 10:31:24 PM
Parent: 68cc73836e15ec6228578626640d3d6da846d0ca
Files changed
dfsChecker.js | changed |
index.js | changed |
kernel.js | changed |
portManager.js | changed |
dfsChecker.js | ||
---|---|---|
@@ -6,9 +6,9 @@ | ||
6 | 6 | * @param {object} state - the state containing all of the containers to search |
7 | 7 | * @param {string} root - the root id |
8 | 8 | * @param {Set} nodes - a set of nodes to start searching from |
9 | 9 | */ |
10 | -module.exports = async function DFSchecker (tree, root, nodes) { | |
10 | +module.exports = async function DFSchecker (tree, nodes, checkFn) { | |
11 | 11 | const checkedNodesSet = new Set() |
12 | 12 | let hasRootSet = new Set() |
13 | 13 | const promises = [] |
14 | 14 | |
@@ -53,9 +53,9 @@ | ||
53 | 53 | // mark the node 'checked' |
54 | 54 | checkedNodes.add(id) |
55 | 55 | |
56 | 56 | // check to see if we are at the root |
57 | - if (id === root) { | |
57 | + if (checkFn(id)) { | |
58 | 58 | hasRootSet = checkedNodes |
59 | 59 | return |
60 | 60 | } |
61 | 61 |
index.js | ||
---|---|---|
@@ -23,8 +23,10 @@ | ||
23 | 23 | this._containerTypes = {} |
24 | 24 | this._nodesToCheck = new Set() |
25 | 25 | |
26 | 26 | this.ROOT_ID = 'zdpuAm6aTdLVMUuiZypxkwtA7sKm7BWERy8MPbaCrFsmiyzxr' |
27 | + this.CREATION_ID = 0 | |
28 | + this.ROUTING_ID = 1 | |
27 | 29 | this.MAX_DATA_BYTES = 65533 |
28 | 30 | } |
29 | 31 | |
30 | 32 | /** |
@@ -49,9 +51,18 @@ | ||
49 | 51 | } |
50 | 52 | } |
51 | 53 | |
52 | 54 | async send (port, message) { |
53 | - if (port.destId) { | |
55 | + if (port.destID === this.ROUTING_ID) { | |
56 | + port.destID = message.data.id | |
57 | + const destPort = this.getDestPort(port.destName) | |
58 | + if (destPort.destID === this.ROUTING_ID) { | |
59 | + message._data = message.data.payload | |
60 | + this.send(port, message) | |
61 | + } else { | |
62 | + throw new Error('invalid routing port') | |
63 | + } | |
64 | + } else if (port.destId) { | |
54 | 65 | const id = port.destId |
55 | 66 | const instance = await this.getInstance(id) |
56 | 67 | instance.queue(port.destName, message) |
57 | 68 | } else { |
@@ -172,8 +183,21 @@ | ||
172 | 183 | port1.destPort = port2 |
173 | 184 | return [port1, port2] |
174 | 185 | } |
175 | 186 | |
187 | + getCreationPort () { | |
188 | + return { | |
189 | + destID: this.CREATION_ID | |
190 | + } | |
191 | + } | |
192 | + | |
193 | + getRoutingPort () { | |
194 | + return { | |
195 | + destID: this.ROUTING_ID | |
196 | + } | |
197 | + } | |
198 | + | |
199 | + copyNativePort () {} | |
176 | 200 | /** |
177 | 201 | * creates a state root starting from a given container and a given number of |
178 | 202 | * ticks |
179 | 203 | * @param {Number} ticks the number of ticks at which to create the state root |
@@ -181,9 +205,11 @@ | ||
181 | 205 | */ |
182 | 206 | async createStateRoot (ticks) { |
183 | 207 | await this.scheduler.wait(ticks) |
184 | 208 | |
185 | - const unlinked = await DFSchecker(this.tree, this.ROOT_ID, this._nodesToCheck) | |
209 | + const unlinked = await DFSchecker(this.tree, this._nodesToCheck, (id) => { | |
210 | + return this.ROOT_ID === id | |
211 | + }) | |
186 | 212 | for (const id of unlinked) { |
187 | 213 | await this.tree.delete(id) |
188 | 214 | } |
189 | 215 | // console.log(JSON.stringify(this.state, null, 2)) |
kernel.js | ||
---|---|---|
@@ -175,10 +175,18 @@ | ||
175 | 175 | message._hops++ |
176 | 176 | message._fromTicks = this.ticks |
177 | 177 | this.ports.removeSentPorts(message) |
178 | 178 | |
179 | + const copyPort = this.hypervisor.copyNativePort(port, message) | |
180 | + if (copyPort) { | |
181 | + this.queue(port.destName, new Message({ports: [copyPort]})) | |
182 | + } else if (port.destId === this.hypervisor.CREATION_ID) { | |
183 | + return this.createInstance(message) | |
184 | + } else { | |
185 | + return this.hypervisor.send(port, message) | |
186 | + } | |
187 | + | |
179 | 188 | // if (this.currentMessage !== message && !message.responsePort) { |
180 | 189 | // this.currentMessage._addSubMessage(message) |
181 | 190 | // } |
182 | - return this.hypervisor.send(port, message) | |
183 | 191 | } |
184 | 192 | } |
portManager.js | ||
---|---|---|
@@ -85,11 +85,13 @@ | ||
85 | 85 | this.hypervisor.addNodeToCheck(this.id) |
86 | 86 | |
87 | 87 | // update the destination port |
88 | 88 | const destPort = await this.hypervisor.getDestPort(port) |
89 | - delete destPort.destName | |
90 | - delete destPort.destId | |
91 | - destPort.destPort = port | |
89 | + if (destPort) { | |
90 | + delete destPort.destName | |
91 | + delete destPort.destId | |
92 | + destPort.destPort = port | |
93 | + } | |
92 | 94 | return port |
93 | 95 | } |
94 | 96 | |
95 | 97 | /** |
@@ -97,9 +99,11 @@ | ||
97 | 99 | * @param {string} name |
98 | 100 | */ |
99 | 101 | async delete (name) { |
100 | 102 | const port = this.ports[name] |
101 | - await this.kernel.send(port, new DeleteMessage()) | |
103 | + if (port.destID !== this.hypervisor.CREATION_ID) { | |
104 | + await this.kernel.send(port, new DeleteMessage()) | |
105 | + } | |
102 | 106 | this._delete(name) |
103 | 107 | } |
104 | 108 | |
105 | 109 | _delete (name) { |
Built with git-ssb-web