diff --git a/packages/cosmic-swingset/lib/ag-solo/vats/captp.js b/packages/cosmic-swingset/lib/ag-solo/vats/captp.js new file mode 100644 index 00000000000..ad8fa1eccf2 --- /dev/null +++ b/packages/cosmic-swingset/lib/ag-solo/vats/captp.js @@ -0,0 +1,49 @@ +// Avoid importing the full captp bundle, which would carry +// in its own makeHardener, etc. +import { makeCapTP } from '@agoric/captp/lib/captp'; +import harden from '@agoric/harden'; + +export const getCapTPHandler = (E, sendMulticast, getBootstrapObject) => { + const conns = new Map(); + const handler = harden({ + onConnect(_obj, meta) { + const { connectionHandle, origin = 'unknown' } = meta || {}; + console.info(`Starting CapTP`, meta); + const sendObj = o => { + sendMulticast(o, [connectionHandle]); + }; + const { dispatch, abort } = makeCapTP( + origin, + sendObj, + getBootstrapObject, + ); + conns.set(connectionHandle, [dispatch, abort]); + }, + onDisconnect(_obj, meta) { + console.log(`Finishing CapTP`, meta); + const dispatchAbort = conns.get(meta.connectionHandle); + if (dispatchAbort) { + (1, dispatchAbort[1])(); + } + conns.delete(meta.connectionHandle); + }, + onError(obj, meta) { + console.log(`Error in CapTP`, meta, obj.error); + }, + onMessage(obj, meta) { + console.error('processing inbound', obj); + const dispatchAbort = conns.get(meta.connectionHandle); + if (!dispatchAbort || !(1, dispatchAbort[0])(obj)) { + console.error(`Could not find CapTP handler ${obj.type}`, meta); + return false; + } + return true; + }, + }); + + return harden({ + getCommandHandler() { + return handler; + }, + }); +}; diff --git a/packages/cosmic-swingset/package.json b/packages/cosmic-swingset/package.json index fb35ae41ac3..a1ea14928f4 100644 --- a/packages/cosmic-swingset/package.json +++ b/packages/cosmic-swingset/package.json @@ -30,6 +30,7 @@ "@agoric/registrar": "^0.0.1", "@agoric/same-structure": "^0.0.1", "@agoric/sharing-service": "^0.0.1", + "@agoric/spawner": "^0.0.3", "@agoric/store": "^0.0.1", "@agoric/swing-store-simple": "^0.1.0", "@agoric/swingset-vat": "^0.3.0",