Skip to content

Commit

Permalink
fix(sharing-service): add Far to all pass-by-reference objects
Browse files Browse the repository at this point in the history
refs #2018
  • Loading branch information
warner committed Mar 4, 2021
1 parent d4fa4f1 commit fffd37e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
3 changes: 2 additions & 1 deletion packages/sharing-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
},
"homepage": "https://github.com/Agoric/agoric-sdk#readme",
"dependencies": {
"@agoric/assert": "^0.2.2"
"@agoric/assert": "^0.2.2",
"@agoric/marshal": "^0.3.2"
},
"devDependencies": {
"@agoric/eventual-send": "^0.13.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/sharing-service/src/sharedMap.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright (C) 2019 Agoric, under Apache License 2.0

import { assert, details as X } from '@agoric/assert';
import { Far } from '@agoric/marshal';

// Allows multiple parties to store values for retrieval by others.
function makeSharedMap(name) {
const namedEntries = new Map();
const orderedEntries = [];

return harden({
return Far('sharedMap', {
lookup(propertyName) {
if (!namedEntries.has(propertyName)) {
return undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/sharing-service/src/sharing.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (C) 2019 Agoric, under Apache License 2.0

import { assert, details as X } from '@agoric/assert';
import { Far } from '@agoric/marshal';
import { makeSharedMap } from './sharedMap';

function makeSharingService() {
Expand All @@ -9,7 +10,7 @@ function makeSharingService() {
const brand = new WeakSet();
const tombstone = [];

const sharingService = harden({
const sharingService = Far('sharingService', {
// retrieve and remove from the map.
grabSharedMap(key) {
if (!sharedMaps.has(key)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { E } from '@agoric/eventual-send';
import { assert, details as X } from '@agoric/assert';
import { Far } from '@agoric/marshal';
import { makeSharedMap } from '../../../src/sharedMap';
import { makeSharingService } from '../../../src/sharing';

Expand Down Expand Up @@ -40,7 +41,7 @@ export function buildRootObject(vatPowers, vatParameters) {
log('expected sharedMap to validate');
}

const fakeSharedMap = harden({
const fakeSharedMap = Far('fakeSharedMap', {
lookup(propertyName) {
return `${propertyName}: value`;
},
Expand Down Expand Up @@ -80,7 +81,7 @@ export function buildRootObject(vatPowers, vatParameters) {
});
}

const obj0 = {
return Far('root', {
async bootstrap(vats) {
switch (vatParameters.argv[0]) {
case 'sharedMap': {
Expand All @@ -100,6 +101,5 @@ export function buildRootObject(vatPowers, vatParameters) {
}
}
},
};
return harden(obj0);
});
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (C) 2019 Agoric, under Apache License 2.0

import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';

function makeAliceMaker() {
return harden({
return Far('aliceMaker', {
make(sharingServiceP) {
const alice = harden({
const alice = Far('alice', {
shareSomething(someKey) {
return E(sharingServiceP)
.createSharedMap(someKey)
Expand All @@ -18,9 +19,9 @@ function makeAliceMaker() {
}

export function buildRootObject(_vatPowers) {
return harden({
return Far('root', {
makeAliceMaker(_host) {
return harden(makeAliceMaker());
return makeAliceMaker();
},
});
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (C) 2019 Agoric, under Apache License 2.0

import { E } from '@agoric/eventual-send';
import { Far } from '@agoric/marshal';

function makeBobMaker() {
return harden({
return Far('bobMaker', {
make(sharingServiceP) {
const bob = harden({
const bob = Far('bob', {
findSomething(key) {
return E(sharingServiceP)
.grabSharedMap(key)
Expand All @@ -20,9 +21,9 @@ function makeBobMaker() {
}

export function buildRootObject(_vatPowers) {
return harden({
return Far('root', {
makeBobMaker(_host) {
return harden(makeBobMaker());
return makeBobMaker();
},
});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (C) 2019 Agoric, under Apache License 2.0

import { Far } from '@agoric/marshal';
import { makeSharingService } from '../../../src/sharing';

export function buildRootObject(_vatPowers) {
return harden({ makeSharingService });
return Far('root', { makeSharingService });
}

0 comments on commit fffd37e

Please sign in to comment.