2023-04-12 11:53:55 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-04-30 08:08:32 +00:00
|
|
|
|
using Logging;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
namespace DistTestCore.Codex
|
|
|
|
|
{
|
|
|
|
|
public class CodexAccess
|
|
|
|
|
{
|
2023-04-30 08:08:32 +00:00
|
|
|
|
private readonly BaseLog log;
|
2023-05-04 06:55:20 +00:00
|
|
|
|
private readonly ITimeSet timeSet;
|
2023-04-30 08:08:32 +00:00
|
|
|
|
|
2023-05-04 06:55:20 +00:00
|
|
|
|
public CodexAccess(BaseLog log, ITimeSet timeSet, RunningContainer runningContainer)
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-04-30 08:08:32 +00:00
|
|
|
|
this.log = log;
|
2023-05-04 06:55:20 +00:00
|
|
|
|
this.timeSet = timeSet;
|
2023-04-13 07:33:10 +00:00
|
|
|
|
Container = runningContainer;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public RunningContainer Container { get; }
|
|
|
|
|
|
2023-04-12 11:53:55 +00:00
|
|
|
|
public CodexDebugResponse GetDebugInfo()
|
|
|
|
|
{
|
2023-04-17 07:10:39 +00:00
|
|
|
|
return Http().HttpGetJson<CodexDebugResponse>("debug/info");
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-13 07:33:10 +00:00
|
|
|
|
public string UploadFile(FileStream fileStream)
|
|
|
|
|
{
|
|
|
|
|
return Http().HttpPostStream("upload", fileStream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Stream DownloadFile(string contentId)
|
|
|
|
|
{
|
|
|
|
|
return Http().HttpGetStream("download/" + contentId);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-18 13:33:12 +00:00
|
|
|
|
public CodexSalesAvailabilityResponse SalesAvailability(CodexSalesAvailabilityRequest request)
|
|
|
|
|
{
|
|
|
|
|
return Http().HttpPostJson<CodexSalesAvailabilityRequest, CodexSalesAvailabilityResponse>("sales/availability", request);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-24 14:07:32 +00:00
|
|
|
|
public string RequestStorage(CodexSalesRequestStorageRequest request, string contentId)
|
2023-04-18 13:33:12 +00:00
|
|
|
|
{
|
2023-04-24 14:07:32 +00:00
|
|
|
|
return Http().HttpPostJson($"storage/request/{contentId}", request);
|
2023-04-18 13:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-04 09:34:43 +00:00
|
|
|
|
public void EnsureOnline()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var debugInfo = GetDebugInfo();
|
|
|
|
|
if (debugInfo == null || string.IsNullOrEmpty(debugInfo.id)) throw new InvalidOperationException("Unable to get debug-info from codex node at startup.");
|
|
|
|
|
|
|
|
|
|
var nodePeerId = debugInfo.id;
|
|
|
|
|
var nodeName = Container.Name;
|
|
|
|
|
log.AddStringReplace(nodePeerId, $"___{nodeName}___");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
log.Error($"Failed to start codex node: {e}. Test infra failure.");
|
|
|
|
|
throw new InvalidOperationException($"Failed to start codex node. Test infra failure.", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 11:53:55 +00:00
|
|
|
|
private Http Http()
|
|
|
|
|
{
|
2023-04-13 08:11:33 +00:00
|
|
|
|
var ip = Container.Pod.Cluster.IP;
|
2023-04-13 07:33:10 +00:00
|
|
|
|
var port = Container.ServicePorts[0].Number;
|
2023-05-04 06:55:20 +00:00
|
|
|
|
return new Http(log, timeSet, ip, port, baseUrl: "/api/codex/v1");
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
2023-04-13 07:33:10 +00:00
|
|
|
|
|
|
|
|
|
public string ConnectToPeer(string peerId, string peerMultiAddress)
|
|
|
|
|
{
|
|
|
|
|
return Http().HttpGetString($"connect/{peerId}?addrs={peerMultiAddress}");
|
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CodexDebugResponse
|
|
|
|
|
{
|
|
|
|
|
public string id { get; set; } = string.Empty;
|
|
|
|
|
public string[] addrs { get; set; } = new string[0];
|
|
|
|
|
public string repo { get; set; } = string.Empty;
|
|
|
|
|
public string spr { get; set; } = string.Empty;
|
2023-04-26 12:40:54 +00:00
|
|
|
|
public EnginePeerResponse[] enginePeers { get; set; } = Array.Empty<EnginePeerResponse>();
|
|
|
|
|
public SwitchPeerResponse[] switchPeers { get; set; } = Array.Empty<SwitchPeerResponse>();
|
2023-04-12 11:53:55 +00:00
|
|
|
|
public CodexDebugVersionResponse codex { get; set; } = new();
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-26 12:40:54 +00:00
|
|
|
|
public class EnginePeerResponse
|
|
|
|
|
{
|
|
|
|
|
public string peerId { get; set; } = string.Empty;
|
|
|
|
|
public EnginePeerContextResponse context { get; set; } = new();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class EnginePeerContextResponse
|
|
|
|
|
{
|
|
|
|
|
public int blocks { get; set; } = 0;
|
|
|
|
|
public int peerWants { get; set; } = 0;
|
|
|
|
|
public int exchanged { get; set; } = 0;
|
|
|
|
|
public string lastExchange { get; set; } = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SwitchPeerResponse
|
|
|
|
|
{
|
|
|
|
|
public string peerId { get; set; } = string.Empty;
|
|
|
|
|
public string key { get; set; } = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-12 11:53:55 +00:00
|
|
|
|
public class CodexDebugVersionResponse
|
|
|
|
|
{
|
|
|
|
|
public string version { get; set; } = string.Empty;
|
|
|
|
|
public string revision { get; set; } = string.Empty;
|
|
|
|
|
}
|
2023-04-18 13:33:12 +00:00
|
|
|
|
|
|
|
|
|
public class CodexSalesAvailabilityRequest
|
|
|
|
|
{
|
|
|
|
|
public string size { get; set; } = string.Empty;
|
|
|
|
|
public string duration { get; set; } = string.Empty;
|
|
|
|
|
public string minPrice { get; set; } = string.Empty;
|
|
|
|
|
public string maxCollateral { get; set; } = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CodexSalesAvailabilityResponse
|
|
|
|
|
{
|
|
|
|
|
public string id { get; set; } = string.Empty;
|
|
|
|
|
public string size { get; set; } = string.Empty;
|
|
|
|
|
public string duration { get; set; } = string.Empty;
|
|
|
|
|
public string minPrice { get; set; } = string.Empty;
|
|
|
|
|
public string maxCollateral { get; set; } = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CodexSalesRequestStorageRequest
|
|
|
|
|
{
|
|
|
|
|
public string duration { get; set; } = string.Empty;
|
|
|
|
|
public string proofProbability { get; set; } = string.Empty;
|
|
|
|
|
public string reward { get; set; } = string.Empty;
|
|
|
|
|
public string collateral { get; set; } = string.Empty;
|
|
|
|
|
public string? expiry { get; set; }
|
|
|
|
|
public uint? nodes { get; set; }
|
|
|
|
|
public uint? tolerance { get; set;}
|
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|