@agoric/captp
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -11,2 +11,3 @@ // This logic was mostly lifted from @agoric/swingset-vat liveSlots.js | ||
export function makeCapTP(ourId, send, bootstrapObj = undefined) { | ||
let unplug = false; | ||
const { serialize, unserialize } = makeMarshal( | ||
@@ -24,4 +25,5 @@ // eslint-disable-next-line no-use-before-define | ||
const valToSlot = new WeakMap(); | ||
const slotToVal = new Map(); // exports, answers | ||
const slotToVal = new Map(); // exports | ||
const questions = new Map(); // chosen by us | ||
const answers = new Map(); // chosen by our peer | ||
const imports = new Map(); // chosen by our peer | ||
@@ -74,19 +76,29 @@ | ||
function makeRemote(slot) { | ||
function makeQuestion() { | ||
lastQuestionID += 1; | ||
const questionID = lastQuestionID; | ||
const pr = makeRemote(questionID); | ||
questions.set(questionID, pr); | ||
return [questionID, pr]; | ||
} | ||
function makeRemote(target) { | ||
const handler = { | ||
GET(_o, prop) { | ||
const [questionID, pr] = makeQuestion(); | ||
send({ | ||
type: 'CTP_CALL', | ||
questionID, | ||
target, | ||
method: serialize(harden([prop])), | ||
}); | ||
return harden(pr.p); | ||
}, | ||
POST(_o, prop, args) { | ||
// Support: o~.[prop](...args) remote method invocation | ||
// FIXME: Implement a HandledPromise here to support pipelining. | ||
const pr = {}; | ||
pr.p = new Promise((resolve, reject) => { | ||
pr.res = resolve; | ||
pr.rej = reject; | ||
}); | ||
lastQuestionID += 1; | ||
const questionID = lastQuestionID; | ||
questions.set(questionID, pr); | ||
const [questionID, pr] = makeQuestion(); | ||
send({ | ||
type: 'CTP_CALL', | ||
questionID, | ||
target: slot, | ||
target, | ||
method: serialize(harden([prop, args])), | ||
@@ -136,2 +148,3 @@ }); | ||
// console.log('sending bootstrap', bootstrap); | ||
answers.set(questionID, bootstrap); | ||
send({ | ||
@@ -146,11 +159,19 @@ type: 'CTP_RETURN', | ||
const [prop, args] = unserialize(obj.method); | ||
const val = unserialize({ | ||
body: JSON.stringify({ | ||
[QCLASS]: 'slot', | ||
index: 0, | ||
}), | ||
slots: [target], | ||
}); | ||
HandledPromise.applyMethod(val, prop, args) | ||
.then(res => | ||
let val; | ||
if (answers.has(target)) { | ||
val = answers.get(target); | ||
} else { | ||
val = unserialize({ | ||
body: JSON.stringify({ | ||
[QCLASS]: 'slot', | ||
index: 0, | ||
}), | ||
slots: [target], | ||
}); | ||
} | ||
const hp = args | ||
? HandledPromise.applyMethod(val, prop, args) | ||
: HandledPromise.get(val, prop); | ||
answers.set(questionID, hp); | ||
hp.then(res => | ||
send({ | ||
@@ -190,2 +211,13 @@ type: 'CTP_RETURN', | ||
}, | ||
CTP_ABORT(obj) { | ||
const {exception} = obj; | ||
unplug = true; | ||
for (const pr of questions.values()) { | ||
pr.rej(exception); | ||
} | ||
for (const pr of imports.values()) { | ||
pr.rej(exception); | ||
} | ||
send(obj); | ||
}, | ||
}; | ||
@@ -195,10 +227,3 @@ | ||
const getBootstrap = () => { | ||
const pr = {}; | ||
pr.p = new Promise((resolve, reject) => { | ||
pr.res = resolve; | ||
pr.rej = reject; | ||
}); | ||
lastQuestionID += 1; | ||
const questionID = lastQuestionID; | ||
questions.set(questionID, pr); | ||
const [questionID, pr] = makeQuestion(); | ||
send({ | ||
@@ -214,2 +239,5 @@ type: 'CTP_BOOTSTRAP', | ||
const dispatch = obj => { | ||
if (unplug) { | ||
return false; | ||
} | ||
const fn = handler[obj.type]; | ||
@@ -216,0 +244,0 @@ if (fn) { |
{ | ||
"name": "@agoric/captp", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Capability Transfer Protocol for distributed objects", | ||
@@ -49,3 +49,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@agoric/eventual-send": "^0.4.3", | ||
"@agoric/eventual-send": "^0.4.4", | ||
"@agoric/harden": "^0.0.4", | ||
@@ -52,0 +52,0 @@ "@agoric/marshal": "^0.1.1", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
286763
8145
0
Updated@agoric/eventual-send@^0.4.4