in src/ccf/ccf-provider/CcfNetworkProvider.cs [1271:1329]
private async Task<JsonObject> WaitForNodeToAppearOnNetwork(
HttpClient serviceClient,
string nodeName,
Func<Task>? onRetry = null)
{
TimeSpan readyTimeout = TimeSpan.FromSeconds(60);
var stopwatch = Stopwatch.StartNew();
while (true)
{
JsonObject? nodes = null;
using var response = await serviceClient.GetAsync("/node/network/nodes");
if (response.IsSuccessStatusCode)
{
nodes = (await response.Content.ReadFromJsonAsync<JsonObject>())!;
foreach (var node in nodes["nodes"]!.AsArray())
{
if (node?["node_data"] != null)
{
NodeData nodeData = JsonSerializer.Deserialize<NodeData>(node["node_data"])!;
var status = node["status"]!.ToString();
if (nodeData.Id == ToId(nodeName) &&
(status == "Pending" || status == "Trusted"))
{
return node.AsObject();
}
}
}
this.logger.LogInformation(
$"Waiting for " +
$"{serviceClient.BaseAddress}node/network/nodes " +
$"to list {nodeName} in its output.");
}
else
{
this.logger.LogInformation(
$"Waiting for " +
$"{serviceClient.BaseAddress}node/network/nodes " +
$"to report " +
$"success. Current statusCode: {response.StatusCode}.");
}
if (stopwatch.Elapsed > readyTimeout)
{
throw new TimeoutException(
$"Hit timeout waiting for join node '{nodeName}' to be reported in " +
$"{serviceClient.BaseAddress}node/network/nodes output." +
$"Current output: " +
$"{(nodes != null ? JsonSerializer.Serialize(nodes, Utils.Options) : "NA")}.");
}
if (onRetry != null)
{
await onRetry.Invoke();
}
await Task.Delay(TimeSpan.FromSeconds(1));
}
}