git ssb

0+

wanderer🌟 / js-primea-hypervisor



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.jschanged
index.jschanged
kernel.jschanged
portManager.jschanged
dfsChecker.jsView
@@ -6,9 +6,9 @@
66 * @param {object} state - the state containing all of the containers to search
77 * @param {string} root - the root id
88 * @param {Set} nodes - a set of nodes to start searching from
99 */
10-module.exports = async function DFSchecker (tree, root, nodes) {
10+module.exports = async function DFSchecker (tree, nodes, checkFn) {
1111 const checkedNodesSet = new Set()
1212 let hasRootSet = new Set()
1313 const promises = []
1414
@@ -53,9 +53,9 @@
5353 // mark the node 'checked'
5454 checkedNodes.add(id)
5555
5656 // check to see if we are at the root
57- if (id === root) {
57+ if (checkFn(id)) {
5858 hasRootSet = checkedNodes
5959 return
6060 }
6161
index.jsView
@@ -23,8 +23,10 @@
2323 this._containerTypes = {}
2424 this._nodesToCheck = new Set()
2525
2626 this.ROOT_ID = 'zdpuAm6aTdLVMUuiZypxkwtA7sKm7BWERy8MPbaCrFsmiyzxr'
27+ this.CREATION_ID = 0
28+ this.ROUTING_ID = 1
2729 this.MAX_DATA_BYTES = 65533
2830 }
2931
3032 /**
@@ -49,9 +51,18 @@
4951 }
5052 }
5153
5254 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) {
5465 const id = port.destId
5566 const instance = await this.getInstance(id)
5667 instance.queue(port.destName, message)
5768 } else {
@@ -172,8 +183,21 @@
172183 port1.destPort = port2
173184 return [port1, port2]
174185 }
175186
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 () {}
176200 /**
177201 * creates a state root starting from a given container and a given number of
178202 * ticks
179203 * @param {Number} ticks the number of ticks at which to create the state root
@@ -181,9 +205,11 @@
181205 */
182206 async createStateRoot (ticks) {
183207 await this.scheduler.wait(ticks)
184208
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+ })
186212 for (const id of unlinked) {
187213 await this.tree.delete(id)
188214 }
189215 // console.log(JSON.stringify(this.state, null, 2))
kernel.jsView
@@ -175,10 +175,18 @@
175175 message._hops++
176176 message._fromTicks = this.ticks
177177 this.ports.removeSentPorts(message)
178178
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+
179188 // if (this.currentMessage !== message && !message.responsePort) {
180189 // this.currentMessage._addSubMessage(message)
181190 // }
182- return this.hypervisor.send(port, message)
183191 }
184192 }
portManager.jsView
@@ -85,11 +85,13 @@
8585 this.hypervisor.addNodeToCheck(this.id)
8686
8787 // update the destination port
8888 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+ }
9294 return port
9395 }
9496
9597 /**
@@ -97,9 +99,11 @@
9799 * @param {string} name
98100 */
99101 async delete (name) {
100102 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+ }
102106 this._delete(name)
103107 }
104108
105109 _delete (name) {

Built with git-ssb-web