makePeer = async (networksDirectoryId, nodeId, addresses, context) => {
    const remoteControl = provideRemoteControl(nodeId);
    return remoteControl.connect(
      async () => {
        // TODO race networks that support protocol for connection
        // TODO retry, exponential back-off, with full jitter
        // TODO (in connect implementations) allow for the possibility of
        // connection loss and invalidate the connection formula and its transitive
        // dependees when this occurs.
        const networks = await getAllNetworks(networksDirectoryId);
        // Connect on first support address.
        for (const address of addresses) {
          const { protocol } = new URL(address);
          for (const network of networks) {
            // eslint-disable-next-line no-await-in-loop
            if (await E(network).supports(protocol)) {
              return E(network).connect(address, makeFarContext(context));
            }
          }
        }
        throw new Error('Cannot connect to peer: no supported addresses');
      },
      context.cancel,
      context.cancelled,
    );
  }
@param {string} networksDirectoryId
@param {string} nodeId
@param {string[]} addresses
@param {Context} context