resolveLocalCeEndpoint function

Future<String?> resolveLocalCeEndpoint({
  1. Duration? timeout,
  2. Client? httpClient,
})

Resolves a loopback CE gRPC target when a local server advertises CE mode.

Returns the first probe-passing loopback target, or null when no local CE server responds. Candidate resolution order:

  1. KUMIHO_LOCAL_SERVER_ENDPOINT (loopback host required)
  2. KUMIHO_LOCAL_SERVER_PORT (host forced to 127.0.0.1)
  3. The default 127.0.0.1:9190

When timeout is omitted it is read from KUMIHO_LOCAL_DISCOVERY_TIMEOUT_SECONDS (min 50ms, default 500ms).

Throws CeDiscoveryError when an environment variable is malformed (for example a non-numeric port, or a non-loopback endpoint host).

Implementation

Future<String?> resolveLocalCeEndpoint({
  Duration? timeout,
  http.Client? httpClient,
}) async {
  final probeTimeout = timeout ?? _localCeTimeout();
  for (final target in _localCeCandidates()) {
    final ok = await _probeLocalCeCandidate(
      target,
      timeout: probeTimeout,
      httpClient: httpClient,
    );
    if (ok) {
      return target;
    }
  }
  return null;
}