-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vat worker SwingSet integration CHECKPOINT
this isn't close to right; I'm just using github as a backup service.
- Loading branch information
Showing
13 changed files
with
146 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,4 +62,4 @@ bundle-*.js | |
|
||
.idea/ | ||
|
||
packages/xs-vat-worker/build/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const workerBin = undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,2 @@ | ||
import fs from 'fs'; | ||
|
||
/** | ||
* return the absolute pathname of the generated xs-vat-worker | ||
* executable (or undefined if it doesn't exist yet, because yarn | ||
* build:xs-lin wasn't run) | ||
* | ||
* WARNING: uses ambient access to fs.exists, require.resolve | ||
*/ | ||
export function locateWorkerBin() { | ||
const binPath = require.resolve('../build/bin/lin/debug/xs-vat-worker'); | ||
return fs.existsSync(binPath) ? binPath : undefined; | ||
} | ||
export const workerBin = | ||
'/home/connolly/projects/agoric/agoric-sdk/packages/xs-vat-worker/node_modules/.bin/xs-vat-worker'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
function makeWorker(io) { | ||
const format = obj => JSON.stringify(obj); | ||
const send = obj => io.writeNetstring(format(obj)); | ||
|
||
const expect = async msgtype => { | ||
const txt = await io.readNetstring(); | ||
let msg; | ||
try { | ||
msg = JSON.parse(txt); | ||
} catch (badJSON) { | ||
console.error('bad JSON ', txt.length, ' chars: [', txt, ']', badJSON); | ||
throw badJSON; | ||
} | ||
if (msg.msgtype !== msgtype) { | ||
throw new Error( | ||
`expected ${msgtype}; found: ${msg.msgtype}; error: ${ | ||
msg.error | ||
} [${JSON.stringify(msg)}]`, | ||
); | ||
} | ||
return msg; | ||
}; | ||
|
||
return harden({ | ||
async loadVat(bundle) { | ||
await send({ msgtype: 'load-bundle', bundle }); | ||
return expect('load-bundle-ack'); | ||
}, | ||
async deliver(...args) { | ||
const { d, syscalls, _crankNumber } = args; | ||
await send({ msgtype: 'dispatch', type: d[0], args: d.slice(1) }); | ||
for (const syscall of syscalls) { | ||
// eslint-disable-next-line no-await-in-loop | ||
const request = await expect('syscall'); | ||
console.log('syscall request', request); | ||
// eslint-disable-next-line no-await-in-loop | ||
await send({ msgtype: 'syscall-ack', response: syscall.response }); | ||
} | ||
return expect('dispatch-ack'); | ||
}, | ||
async finish() { | ||
await send({ msgtype: 'finish' }); | ||
await expect('finish-ack'); | ||
}, | ||
}); | ||
} | ||
|
||
export function makeXsWorkerFactory({ startXsWorker }) { | ||
return harden({ | ||
async createFromBundle(vatID, bundle, _managerOptions) { | ||
const io = startXsWorker(); | ||
const worker = makeWorker(io); | ||
await worker.loadVat(bundle); | ||
return worker; | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { makePromiseKit } from '@agoric/promise-kit'; | ||
import { workerBin } from './locate'; | ||
import { readNetstring, writeNetstring } from './netstring'; | ||
|
||
// eslint-disable-next-line no-unused-vars | ||
function parentLog(first, ...args) { | ||
// console.error(`--parent: ${first}`, ...args); | ||
} | ||
|
||
// we send on fd3, and receive on fd4. We pass fd1/2 (stdout/err) through, so | ||
// console log/err from the child shows up normally. | ||
const stdio = harden(['inherit', 'inherit', 'inherit', 'pipe', 'pipe']); | ||
const INFD = 3; | ||
const OUTFD = 4; | ||
|
||
export function spawnXsWorker({ spawn }) { | ||
console.log('spawning', { workerBin }); | ||
const child = spawn(workerBin, [], { stdio }); | ||
|
||
const pk = makePromiseKit(); | ||
|
||
child.once('exit', code => { | ||
parentLog('child exit', code); | ||
pk.resolve(code); | ||
}); | ||
child.once('error', e => { | ||
parentLog('child error', e); | ||
pk.reject(e); | ||
}); | ||
parentLog(`waiting on child`); | ||
|
||
child.stdio[OUTFD].pause(); | ||
|
||
return harden({ | ||
readNetstring: () => readNetstring(child.stdio[OUTFD]), | ||
writeNetstring: s => writeNetstring(child.stdio[INFD], s), | ||
kill: () => child.kill(), | ||
done: pk.promise, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters