WIP: toybox: OCapN vats on workerd, with ingress and egress as capabilities #4

Draft
dckc wants to merge 13 commits from toybox into main
pull from: toybox
4 changed files with 37 additions and 2 deletions
Showing only changes of commit f64dac4434 - Show all commits

No files matched your search

+8 -1
View File
@@ -201,7 +201,14 @@ export class VatAdmin extends DurableObject {
return harden({ id: id.toString(), root }); return harden({ id: id.toString(), root });
}, },
}); });
this.ocapn = makeClient({ debugLabel: VAT_ADMIN, swissnumTable: new Map([[VAT_ADMIN, vatAdmin]]) }); // workerd runs FinalizationRegistry callbacks outside any request, where
// sending the resulting GC message is forbidden I/O. So imports are
// never collected here; they go when their session does.
this.ocapn = makeClient({
debugLabel: VAT_ADMIN,
swissnumTable: new Map([[VAT_ADMIN, vatAdmin]]),
enableImportCollection: false,
});
const netlayer = await this.ocapn.registerNetlayer( const netlayer = await this.ocapn.registerNetlayer(
makeRpcNetLayer({ designator: VAT_ADMIN, openGateway: (designator) => this.gateway(designator) }), makeRpcNetLayer({ designator: VAT_ADMIN, openGateway: (designator) => this.gateway(designator) }),
); );
+11
View File
@@ -66,3 +66,14 @@ test("createVat passes a remote object in; the vat's root comes back", async ()
assert.equal(await E(root).hello(), "hello from the vat"); assert.equal(await E(root).hello(), "hello from the vat");
assert.equal(await E(root).greetVia("vat"), "hi vat, from carol"); assert.equal(await E(root).greetVia("vat"), "hi vat, from carol");
}); });
test("a counter vat counts; two counter vats count apart", async () => {
const src = await vatSrc("counter.js");
const { root: a } = await E(client.vatAdmin).createVat(src);
const { root: b } = await E(client.vatAdmin).createVat(src);
assert.equal(await E(a).increment(), 1);
assert.equal(await E(a).increment(), 2);
assert.equal(await E(b).increment(), 1);
assert.equal(await E(a).read(), 2);
assert.equal(await E(b).read(), 1);
});
+8 -1
View File
@@ -37,7 +37,14 @@ export class App extends DurableObject {
return root; return root;
}, },
}); });
const ocapn = makeClient({ debugLabel: vatId.slice(0, 8), swissnumTable: new Map([[VAT_SWISSNUM, bootstrap]]) }); // workerd runs FinalizationRegistry callbacks outside any request, where
// sending the resulting GC message is forbidden I/O. So imports are
// never collected here; they go when their session does.
const ocapn = makeClient({
debugLabel: vatId.slice(0, 8),
swissnumTable: new Map([[VAT_SWISSNUM, bootstrap]]),
enableImportCollection: false,
});
const netlayer = await ocapn.registerNetlayer( const netlayer = await ocapn.registerNetlayer(
makeRpcNetLayer({ designator: vatId, openGateway: (designator) => router.gateway(designator) }), makeRpcNetLayer({ designator: vatId, openGateway: (designator) => router.gateway(designator) }),
); );
+10
View File
@@ -0,0 +1,10 @@
/** A counter whose count lives in the vat's storage. */
export const buildRootObject = ({ Far, storage }) =>
Far("counterRoot", {
increment: () => {
const n = (storage.get("count") ?? 0) + 1;
storage.put("count", n);
return n;
},
read: () => storage.get("count") ?? 0,
});