From ae0e43ea09c4a87d7fe49dac6cb21920182a5669 Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Tue, 9 Apr 2024 16:10:58 -0400 Subject: [PATCH] refactor(network): rename `bind` to `bindPort` --- packages/boot/test/bootstrapTests/ibcClientMock.js | 2 +- packages/boot/test/bootstrapTests/ibcServerMock.js | 2 +- .../test/smartWallet/boot-test-utils.js | 2 +- packages/network/README.md | 8 ++++---- packages/network/src/network.js | 8 ++++---- packages/network/src/router.js | 8 ++++---- packages/network/src/shapes.js | 2 +- packages/network/src/types.js | 4 ++-- packages/network/test/test-network-misc.js | 12 +++++++----- packages/orchestration/src/orchestration.js | 2 +- .../src/proposals/orchestration-proposal.js | 4 ++-- packages/orchestration/src/types.d.ts | 2 +- packages/pegasus/src/proposals/core-proposal.js | 2 +- packages/pegasus/test/test-peg.js | 4 +++- packages/vats/src/proposals/network-proposal.js | 12 ++++++------ packages/vats/src/vat-network.js | 4 ++-- packages/vats/test/test-network.js | 2 +- packages/vats/tools/boot-test-utils.js | 2 +- 18 files changed, 43 insertions(+), 39 deletions(-) diff --git a/packages/boot/test/bootstrapTests/ibcClientMock.js b/packages/boot/test/bootstrapTests/ibcClientMock.js index 990270babce..4614e0b49c9 100644 --- a/packages/boot/test/bootstrapTests/ibcClientMock.js +++ b/packages/boot/test/bootstrapTests/ibcClientMock.js @@ -13,7 +13,7 @@ import { V as E } from '@agoric/vat-data/vow.js'; */ export const start = async (zcf, privateArgs, _baggage) => { const { address, networkVat } = privateArgs; - const myPort = await E(networkVat).bind(address); + const myPort = await E(networkVat).bindPort(address); const { log } = console; let connP; diff --git a/packages/boot/test/bootstrapTests/ibcServerMock.js b/packages/boot/test/bootstrapTests/ibcServerMock.js index 2b6120c227c..d56f316cb86 100644 --- a/packages/boot/test/bootstrapTests/ibcServerMock.js +++ b/packages/boot/test/bootstrapTests/ibcServerMock.js @@ -19,7 +19,7 @@ const { log } = console; export const start = async (zcf, privateArgs, _baggage) => { const { address, networkVat } = privateArgs; - const boundPort = await E(networkVat).bind(address); + const boundPort = await E(networkVat).bindPort(address); /** @type {Array<[label: string, resolve: (value: any) => void, reject: (reason: any) => void]>} */ const queue = []; diff --git a/packages/inter-protocol/test/smartWallet/boot-test-utils.js b/packages/inter-protocol/test/smartWallet/boot-test-utils.js index 67b36f949a2..b222b0fdab3 100644 --- a/packages/inter-protocol/test/smartWallet/boot-test-utils.js +++ b/packages/inter-protocol/test/smartWallet/boot-test-utils.js @@ -58,7 +58,7 @@ export const makeMock = log => network: Far('network', { registerProtocolHandler: noop, - bind: () => harden({ addListener: noop }), + bindPort: () => harden({ addListener: noop }), }), }, }); diff --git a/packages/network/README.md b/packages/network/README.md index ce0330e65a5..f8e9e08a925 100644 --- a/packages/network/README.md +++ b/packages/network/README.md @@ -57,15 +57,15 @@ E(home.ibcport[0]).connect(remoteEndpoint, connectionHandler) The other side of `connect()` is a "listening port". These ports are waiting for inbound connections to be established. -To get a listening port, you need a `NetworkInterface` object (such as the one on your `ag-solo` under `home.network`) and ask it to `bind()` to an endpoint. You can either provide a specific port name, or allow the API to allocate a random one for you. The endpoint specifies the type of connection that this port will be able to accept (IBC, TCP, etc), and some properties of that connection. `bind()` uses a "multiaddress" to encode this information. +To get a listening port, you need a `NetworkInterface` object (such as the one on your `ag-solo` under `home.network`) and ask it to `bindPort()` to an endpoint. You can either provide a specific port name, or allow the API to allocate a random one for you. The endpoint specifies the type of connection that this port will be able to accept (IBC, TCP, etc), and some properties of that connection. `bindPort()` uses a "multiaddress" to encode this information. ```js // ask for a random allocation - ends with a slash -E(home.network).bind('/ibc-port/') +E(home.network).bindPort('/ibc-port/') .then(port => usePort(port)); // or ask for a specific port name -E(home.network).bind('/ibc-port/my-cool-port-name') +E(home.network).bindPort('/ibc-port/my-cool-port-name') .then(port => usePort(port)); ``` @@ -147,7 +147,7 @@ Note that if you want to listen on this port again, you can just call `port.addL ### Closing the Port Entirely -Removing a listener doesn't release the port address to make it available for other `bind()` requests. You can call: +Removing a listener doesn't release the port address to make it available for other `bindPort()` requests. You can call: ```js port.revoke(); diff --git a/packages/network/src/network.js b/packages/network/src/network.js index 67255a9b6b6..2404ff54ca6 100644 --- a/packages/network/src/network.js +++ b/packages/network/src/network.js @@ -652,7 +652,7 @@ const prepareBinder = (zone, powers) => { { protocolImpl: Shape.ProtocolImplI, binder: M.interface('Binder', { - bind: M.callWhen(Shape.Endpoint).returns(Shape.Vow$(Shape.Port)), + bindPort: M.callWhen(Shape.Endpoint).returns(Shape.Vow$(Shape.Port)), }), binderInboundInstantiateWatcher: M.interface( 'BinderInboundInstantiateWatcher', @@ -840,13 +840,13 @@ const prepareBinder = (zone, powers) => { localAddr, }); }, - async bind(localAddr) { - return this.facets.binder.bind(localAddr); + async bindPort(localAddr) { + return this.facets.binder.bindPort(localAddr); }, }, binder: { /** @param {string} localAddr */ - async bind(localAddr) { + async bindPort(localAddr) { const { protocolHandler } = this.state; // Check if we are underspecified (ends in slash) diff --git a/packages/network/src/router.js b/packages/network/src/router.js index ac827f25209..919e1fe8fbf 100644 --- a/packages/network/src/router.js +++ b/packages/network/src/router.js @@ -93,7 +93,7 @@ export const prepareRouter = zone => { /** * @typedef {object} RouterProtocol - * @property {(prefix: string) => PromiseVow} bind + * @property {(prefix: string) => PromiseVow} bindPort * @property {(paths: string[], protocolHandler: ProtocolHandler) => void} registerProtocolHandler * @property {(prefix: string, protocolHandler: ProtocolHandler) => void} unregisterProtocolHandler */ @@ -119,7 +119,7 @@ export const prepareRouterProtocol = (zone, powers, E = defaultE) => { M.remotable(), ).returns(), unregisterProtocolHandler: M.call(M.string(), M.remotable()).returns(), - bind: M.callWhen(Shape.Endpoint).returns(Shape.Vow$(Shape.Port)), + bindPort: M.callWhen(Shape.Endpoint).returns(Shape.Vow$(Shape.Port)), }), () => { /** @type {Router} */ @@ -169,10 +169,10 @@ export const prepareRouterProtocol = (zone, powers, E = defaultE) => { this.state.protocolHandlers.delete(prefix); }, /** @param {Endpoint} localAddr */ - async bind(localAddr) { + async bindPort(localAddr) { const [route] = this.state.router.getRoutes(localAddr); route !== undefined || Fail`No registered router for ${localAddr}`; - return E(route[1]).bind(localAddr); + return E(route[1]).bindPort(localAddr); }, }, ); diff --git a/packages/network/src/shapes.js b/packages/network/src/shapes.js index 486675677e8..fab74462b3e 100644 --- a/packages/network/src/shapes.js +++ b/packages/network/src/shapes.js @@ -178,7 +178,7 @@ export const Shape = /** @type {const} */ harden({ }, ProtocolImplI: M.interface('ProtocolImpl', { - bind: M.callWhen(Shape2.Endpoint).returns(Shape2.Vow$(Shape2.Port)), + bindPort: M.callWhen(Shape2.Endpoint).returns(Shape2.Vow$(Shape2.Port)), inbound: M.callWhen(Shape2.Endpoint, Shape2.Endpoint).returns( Shape2.Vow$(Shape2.InboundAttempt), ), diff --git a/packages/network/src/types.js b/packages/network/src/types.js index 4486749bf07..82ce4d1672e 100644 --- a/packages/network/src/types.js +++ b/packages/network/src/types.js @@ -33,7 +33,7 @@ /** * @typedef {object} Protocol The network Protocol - * @property {(prefix: Endpoint) => PromiseVow} bind Claim a port, or if + * @property {(prefix: Endpoint) => PromiseVow} bindPort Claim a port, or if * ending in ENDPOINT_SEPARATOR, a fresh name */ @@ -182,7 +182,7 @@ * @property {() => PromiseVow} close Abort the attempt * * @typedef {object} ProtocolImpl Things the protocol can do for us - * @property {(prefix: Endpoint) => PromiseVow>} bind Claim a port, or if + * @property {(prefix: Endpoint) => PromiseVow>} bindPort Claim a port, or if * ending in ENDPOINT_SEPARATOR, a fresh name * @property {( * listenAddr: Endpoint, diff --git a/packages/network/test/test-network-misc.js b/packages/network/test/test-network-misc.js index 226f72efa46..258b601d412 100644 --- a/packages/network/test/test-network-misc.js +++ b/packages/network/test/test-network-misc.js @@ -128,7 +128,7 @@ test('handled protocol', async t => { ); const protocol = makeNetworkProtocol(makeProtocolHandler()); - const port = await when(protocol.bind('/ibc/*/ordered')); + const port = await when(protocol.bindPort('/ibc/*/ordered')); const { vow, resolver } = makeVowKit(); @@ -181,7 +181,9 @@ test('protocol connection listen', async t => { ); const protocol = makeNetworkProtocol(makeProtocolHandler()); - const port = await when(protocol.bind('/net/ordered/ordered/some-portname')); + const port = await when( + protocol.bindPort('/net/ordered/ordered/some-portname'), + ); const { vow, resolver } = makeVowKit(); const prepareConnectionHandler = () => { @@ -272,7 +274,7 @@ test('protocol connection listen', async t => { await port.addListener(listener); - const port2 = await when(protocol.bind('/net/ordered')); + const port2 = await when(protocol.bindPort('/net/ordered')); const { handler } = makeEchoConnectionHandler(); const prepareHandlerWithOpen = () => { @@ -320,7 +322,7 @@ test('loopback protocol', async t => { const protocol = makeNetworkProtocol(makeLoopbackProtocolHandler()); const { vow, resolver } = makeVowKit(); - const port = await when(protocol.bind('/loopback/foo')); + const port = await when(protocol.bindPort('/loopback/foo')); const prepareConnectionHandler = () => { const makeConnectionHandler = zone.exoClass( @@ -358,7 +360,7 @@ test('loopback protocol', async t => { const listener = makeListenHandler(); await when(port.addListener(listener)); - const port2 = await when(protocol.bind('/loopback/bar')); + const port2 = await when(protocol.bindPort('/loopback/bar')); const prepareOpener = () => { const openerHandler = zone.exoClass( 'opener', diff --git a/packages/orchestration/src/orchestration.js b/packages/orchestration/src/orchestration.js index f9f9e961d05..c7dd87f2725 100644 --- a/packages/orchestration/src/orchestration.js +++ b/packages/orchestration/src/orchestration.js @@ -209,7 +209,7 @@ const prepareOrchestration = (zone, createChainAccount) => self: { async bindPort() { const network = getPower(this.state.powers, 'network'); - const port = await E(network).bind( + const port = await E(network).bindPort( `/ibc-port/icacontroller-${this.state.icaControllerNonce}`, ); this.state.icaControllerNonce += 1; diff --git a/packages/orchestration/src/proposals/orchestration-proposal.js b/packages/orchestration/src/proposals/orchestration-proposal.js index cb81d47b95d..d9f3922692d 100644 --- a/packages/orchestration/src/proposals/orchestration-proposal.js +++ b/packages/orchestration/src/proposals/orchestration-proposal.js @@ -49,8 +49,8 @@ export const setupOrchestrationVat = async ( /** @type {AttenuatedNetwork} */ const network = Far('Attenuated Network', { /** @param {string} localAddr */ - async bind(localAddr) { - return E(networkVat).bind(localAddr); + async bindPort(localAddr) { + return E(networkVat).bindPort(localAddr); }, }); diff --git a/packages/orchestration/src/types.d.ts b/packages/orchestration/src/types.d.ts index f35ebd019d7..e787c2f5f56 100644 --- a/packages/orchestration/src/types.d.ts +++ b/packages/orchestration/src/types.d.ts @@ -1,6 +1,6 @@ import type { RouterProtocol } from '@agoric/network/src/router'; -export type AttenuatedNetwork = Pick; +export type AttenuatedNetwork = Pick; export type * from './orchestration.js'; export type * from './vat-orchestration.js'; diff --git a/packages/pegasus/src/proposals/core-proposal.js b/packages/pegasus/src/proposals/core-proposal.js index dd099e57f99..e2f906d3c7c 100644 --- a/packages/pegasus/src/proposals/core-proposal.js +++ b/packages/pegasus/src/proposals/core-proposal.js @@ -104,7 +104,7 @@ export const listenPegasus = async ({ pegasusConnectionsAdmin.resolve(nameAdmin); const pegasus = await E(zoe).getPublicFacet(pegasusInstance); - const port = await E(networkVat).bind('/ibc-port/pegasus'); + const port = await E(networkVat).bindPort('/ibc-port/pegasus'); return addPegasusTransferPort(port, pegasus, pegasusNameAdmin); }; harden(listenPegasus); diff --git a/packages/pegasus/test/test-peg.js b/packages/pegasus/test/test-peg.js index 834fa4c7b78..7e28754e5c2 100644 --- a/packages/pegasus/test/test-peg.js +++ b/packages/pegasus/test/test-peg.js @@ -95,7 +95,9 @@ async function testRemotePeg(t) { const makeNetworkProtocol = prepareNetworkProtocol(zone, powers); const network = makeNetworkProtocol(makeLoopbackHandler()); - const portP = when(E(network).bind('/ibc-channel/chanabc/ibc-port/portdef')); + const portP = when( + E(network).bindPort('/ibc-channel/chanabc/ibc-port/portdef'), + ); const portName = await E(portP).getLocalAddress(); /** diff --git a/packages/vats/src/proposals/network-proposal.js b/packages/vats/src/proposals/network-proposal.js index 18ef7265e18..d9e8523b118 100644 --- a/packages/vats/src/proposals/network-proposal.js +++ b/packages/vats/src/proposals/network-proposal.js @@ -61,8 +61,8 @@ export const registerNetworkProtocols = async (vats, dibcBridgeManager) => { * space. * * The `networkVat` is CLOSELY HELD in the core space, where later, we claim - * ports using `E(networkVat).bind(_path_)`. As discussed in `ProtocolHandler` - * docs, _path_ is: + * ports using `E(networkVat).bindPort(_path_)`. As discussed in + * `ProtocolHandler` docs, _path_ is: * * - /ibc-port/NAME for an IBC port with a known name or, * - /ibc-port/ for an IBC port with a fresh name. @@ -72,8 +72,8 @@ export const registerNetworkProtocols = async (vats, dibcBridgeManager) => { * * Testing facilities include: * - * - loopback ports: `E(networkVat).bind('/local/')` - * - an echo port: `E(vats.network).bind('/ibc-port/echo')` + * - loopback ports: `E(networkVat).bindPort('/local/')` + * - an echo port: `E(vats.network).bindPort('/ibc-port/echo')` * * @param {BootstrapPowers & { * consume: { loadCriticalVat: VatLoader }; @@ -140,7 +140,7 @@ export const setupNetworkProtocols = async ( lastICAPort += 1; bindAddr += `${INTERCHAIN_ACCOUNT_CONTROLLER_PORT_PREFIX}${lastICAPort}`; } - const port = when(E(vats.network).bind(bindAddr)); + const port = when(E(vats.network).bindPort(bindAddr)); ibcportP.push(port); } return Promise.all(ibcportP); @@ -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(vats.network).bind('/ibc-port/echo')); + const echoPort = await when(E(vats.network).bindPort('/ibc-port/echo')); const { listener } = await E(vats.network).makeEchoConnectionKit(); await when(E(echoPort).addListener(listener)); return E(client).assignBundle([_a => ({ ibcport: makePorts() })]); diff --git a/packages/vats/src/vat-network.js b/packages/vats/src/vat-network.js index f1784069f0d..8c2c25ef076 100644 --- a/packages/vats/src/vat-network.js +++ b/packages/vats/src/vat-network.js @@ -35,7 +35,7 @@ export function buildRootObject(_vatPowers, _args, baggage) { /** @param {Parameters} args */ unregisterProtocolHandler: (...args) => protocol.unregisterProtocolHandler(...args), - /** @param {Parameters} args */ - bind: (...args) => protocol.bind(...args), + /** @param {Parameters} args */ + bindPort: (...args) => protocol.bindPort(...args), }); } diff --git a/packages/vats/test/test-network.js b/packages/vats/test/test-network.js index b07f59a0d82..6bc41bffb17 100644 --- a/packages/vats/test/test-network.js +++ b/packages/vats/test/test-network.js @@ -128,7 +128,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(networkVat).bind('/ibc-port/')); + const p = await when(E(networkVat).bindPort('/ibc-port/')); const ev1 = await events.next(); t.assert(!ev1.done); t.deepEqual(ev1.value, ['bindPort', { packet: { source_port: 'port-1' } }]); diff --git a/packages/vats/tools/boot-test-utils.js b/packages/vats/tools/boot-test-utils.js index 4e938f497d5..28c7f12fc47 100644 --- a/packages/vats/tools/boot-test-utils.js +++ b/packages/vats/tools/boot-test-utils.js @@ -74,7 +74,7 @@ export const makeMock = log => network: Far('network', { registerProtocolHandler: noop, makeLoopbackProtocolHandler: noop, - bind: () => Far('network - listener', { addListener: noop }), + bindPort: () => Far('network - listener', { addListener: noop }), }), }, });