-
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.
fix: add missing files and dependencies
- Loading branch information
1 parent
35e8729
commit 2dc3e07
Showing
2 changed files
with
50 additions
and
0 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 |
---|---|---|
@@ -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; | ||
}, | ||
}); | ||
}; |
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