Skip to content

Commit

Permalink
refactor: add custom to name
Browse files Browse the repository at this point in the history
  • Loading branch information
iomekam committed Apr 30, 2024
1 parent a7993a8 commit 4a64a8a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/boot/test/bootstrapTests/ibcClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { V as E } from '@agoric/vat-data/vow.js';
export const start = async (zcf, privateArgs, _baggage) => {
const { portAllocator } = privateArgs;

const myPort = await E(portAllocator).allocateIBCPort();
const myPort = await E(portAllocator).allocateCustomIBCPort();

const { log } = console;
let connP;
Expand Down
2 changes: 1 addition & 1 deletion packages/boot/test/bootstrapTests/ibcServerMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const { log } = console;
export const start = async (zcf, privateArgs, _baggage) => {
const { portAllocator } = privateArgs;

const boundPort = await E(portAllocator).allocateIBCPort();
const boundPort = await E(portAllocator).allocateCustomIBCPort();

/** @type {Array<[label: string, resolve: (value: any) => void, reject: (reason: any) => void]>} */
const queue = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/network/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ To get a listening port, you need a `NetworkInterface` object (such as the one o
```js
// ask for a random allocation - ends with a slash
E(home.network).getPortAllocator()
.then(portAllocator => E(portAllocator).allocateIBCPort())
.then(portAllocator => E(portAllocator).allocateCustomIBCPort())
.then(port => usePort(port));
```

Expand Down
8 changes: 4 additions & 4 deletions packages/network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -1450,17 +1450,17 @@ export const preparePortAllocator = (zone, { watch }) =>
zone.exoClass(
'PortAllocator',
M.interface('PortAllocator', {
allocateIBCPort: M.callWhen()
allocateCustomIBCPort: M.callWhen()
.optional(M.string())
.returns(Shape.Vow$(Shape.Port)),
allocateICAControllerPort: M.callWhen().returns(Shape.Vow$(Shape.Port)),
allocateLocalPort: M.callWhen()
allocateCustomLocalPort: M.callWhen()
.optional(M.string())
.returns(Shape.Vow$(Shape.Port)),
}),
({ protocol }) => ({ protocol, lastICAPortNum: 0n }),
{
allocateIBCPort(specifiedName = '') {
allocateCustomIBCPort(specifiedName = '') {
const { state } = this;
let localAddr = `/ibc-port/`;

Expand All @@ -1482,7 +1482,7 @@ export const preparePortAllocator = (zone, { watch }) =>
),
);
},
allocateLocalPort(specifiedName = '') {
allocateCustomLocalPort(specifiedName = '') {
const { state } = this;

let localAddr = `/local/`;
Expand Down
14 changes: 9 additions & 5 deletions packages/network/test/test-network-misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ test('verify port allocation', async t => {
const makePortAllocator = preparePortAllocator(zone, powers);
const portAllocator = makePortAllocator({ protocol });

const ibcPort = await when(portAllocator.allocateIBCPort());
const ibcPort = await when(portAllocator.allocateCustomIBCPort());
t.is(ibcPort.getLocalAddress(), '/ibc-port/port-1');

const namedIbcPort = await when(portAllocator.allocateIBCPort('test-1'));
const namedIbcPort = await when(
portAllocator.allocateCustomIBCPort('test-1'),
);
t.is(namedIbcPort.getLocalAddress(), '/ibc-port/custom-test-1');

const icaControllerPort1 = await when(
Expand All @@ -202,13 +204,15 @@ test('verify port allocation', async t => {
);
t.is(icaControllerPort2.getLocalAddress(), '/ibc-port/icacontroller-2');

const localPort = await when(portAllocator.allocateLocalPort());
const localPort = await when(portAllocator.allocateCustomLocalPort());
t.is(localPort.getLocalAddress(), '/local/port-5');

const namedLocalPort = await when(portAllocator.allocateLocalPort('local-1'));
const namedLocalPort = await when(
portAllocator.allocateCustomLocalPort('local-1'),
);
t.is(namedLocalPort.getLocalAddress(), '/local/custom-local-1');

await t.throwsAsync(when(portAllocator.allocateIBCPort('/test-1')), {
await t.throwsAsync(when(portAllocator.allocateCustomIBCPort('/test-1')), {
message: 'Invalid IBC port name: /test-1',
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/pegasus/src/proposals/core-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const listenPegasus = async ({
pegasusConnectionsAdmin.resolve(nameAdmin);

const pegasus = await E(zoe).getPublicFacet(pegasusInstance);
const port = await E(portAllocator).allocateIBCPort('pegasus');
const port = await E(portAllocator).allocateCustomIBCPort('pegasus');
return addPegasusTransferPort(port, pegasus, pegasusNameAdmin);
};
harden(listenPegasus);
12 changes: 6 additions & 6 deletions packages/vats/src/proposals/network-proposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ export const registerNetworkProtocols = async (vats, dibcBridgeManager) => {
* bootstrap space.
*
* The `portAllocator` is CLOSELY HELD in the core space, where later, we claim
* ports using `E(portAllocator).allocateIBCPort`, for example.
* ports using `E(portAllocator).allocateCustomIBCPort`, for example.
*
* Contracts are expected to use the services of the network and IBC vats by way
* of such ports.
*
* Testing facilities include:
*
* - loopback ports: `E(portAllocator).allocateLocalPort()`
* - an echo port: `E(portAllocator).allocateIBCPort("echo")d
* /ibc-port/custom-echo
* - loopback ports: `E(portAllocator).allocateCustomLocalPort()`
* - an echo port: `E(portAllocator).allocateCustomIBCPort("echo")`
* - echo port addrees: /ibc-port/custom-echo
*
* @param {BootstrapPowers & {
* consume: { loadCriticalVat: VatLoader<any> };
Expand Down Expand Up @@ -139,7 +139,7 @@ export const setupNetworkProtocols = async (
const portP = when(E(allocator).allocateICAControllerPort());
ibcportP.push(portP);
} else {
const portP = when(E(allocator).allocateIBCPort());
const portP = when(E(allocator).allocateCustomIBCPort());
ibcportP.push(portP);
}
}
Expand All @@ -152,7 +152,7 @@ export const setupNetworkProtocols = async (
await registerNetworkProtocols(vats, dibcBridgeManager);

// Add an echo listener on our ibc-port network (whether real or virtual).
const echoPort = await when(E(allocator).allocateIBCPort('echo'));
const echoPort = await when(E(allocator).allocateCustomIBCPort('echo'));
const { listener } = await E(vats.network).makeEchoConnectionKit();
await when(E(echoPort).addListener(listener));
return E(client).assignBundle([_a => ({ ibcport: makePorts() })]);
Expand Down
2 changes: 1 addition & 1 deletion packages/vats/test/test-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ test('network - ibc', async t => {
// Actually test the ibc port binding.
// TODO: Do more tests on the returned Port object.
t.log('Opening a Listening Port');
const p = await when(E(portAllocator).allocateIBCPort());
const p = await when(E(portAllocator).allocateCustomIBCPort());
const ev1 = await events.next();
t.assert(!ev1.done);
t.deepEqual(ev1.value, ['bindPort', { packet: { source_port: 'port-1' } }]);
Expand Down

0 comments on commit 4a64a8a

Please sign in to comment.