accepted = (remoteGateway, cancelCurrent, currentCancelled) => {
      return {
        accept(
          _proposedRemoteGateway,
          proposedCancel,
          _proposedCancelled,
          proposedDispose,
        ) {
          // And we receive an inbound connection.
          // There are two possibilities:
          // The sender raced multiple outbound connections and this connection
          // lost the race.
          // Or, the sender restarted but left a prior connection half-open.
          // We consider the race to be the common consideration and that
          // replacing peers after establishing a connection would be far to
          // disruptive.
          // TODO: For the case where we leave a peer wedged half-open, we
          // will need health checks.
          Promise.resolve(
            proposedCancel(new Error('Already accepted a connection.')),
          ).then(proposedDispose);
          return accepted(remoteGateway, cancelCurrent, currentCancelled);
        },
        connect(
          _getProposedRemoteGateway,
          proposedCancel,
          proposedCancelled,
          proposedDispose,
        ) {
          // Use the gateway we already have.
          // Bind the fates of the current peer incarnation and the inbound
          // connection.
          Promise.all([
            currentCancelled.catch(proposedCancel),
            proposedCancelled.catch(cancelCurrent),
          ])
            .then(() => {})
            .then(proposedDispose);
          return {
            state: accepted(remoteGateway, proposedCancel, proposedCancelled),
            remoteGateway,
          };
        },
      };
    }
@type {(
  remoteGateway: Promise<EndoGateway>,
  cancel: (error: Error) => void | Promise<void>,
  cancelled: Promise<never>,
) => RemoteControlState}