121 lines
4.0 KiB
C#
121 lines
4.0 KiB
C#
using KubernetesWorkflow;
|
|
using Logging;
|
|
|
|
namespace DistTestCore.Codex
|
|
{
|
|
public class CodexAccess
|
|
{
|
|
private readonly BaseLog log;
|
|
|
|
public CodexAccess(BaseLog log, RunningContainer runningContainer)
|
|
{
|
|
this.log = log;
|
|
Container = runningContainer;
|
|
}
|
|
|
|
public RunningContainer Container { get; }
|
|
|
|
public CodexDebugResponse GetDebugInfo()
|
|
{
|
|
return Http().HttpGetJson<CodexDebugResponse>("debug/info");
|
|
}
|
|
|
|
public string UploadFile(FileStream fileStream)
|
|
{
|
|
return Http().HttpPostStream("upload", fileStream);
|
|
}
|
|
|
|
public Stream DownloadFile(string contentId)
|
|
{
|
|
return Http().HttpGetStream("download/" + contentId);
|
|
}
|
|
|
|
public CodexSalesAvailabilityResponse SalesAvailability(CodexSalesAvailabilityRequest request)
|
|
{
|
|
return Http().HttpPostJson<CodexSalesAvailabilityRequest, CodexSalesAvailabilityResponse>("sales/availability", request);
|
|
}
|
|
|
|
public string RequestStorage(CodexSalesRequestStorageRequest request, string contentId)
|
|
{
|
|
return Http().HttpPostJson($"storage/request/{contentId}", request);
|
|
}
|
|
|
|
private Http Http()
|
|
{
|
|
var ip = Container.Pod.Cluster.IP;
|
|
var port = Container.ServicePorts[0].Number;
|
|
return new Http(log, ip, port, baseUrl: "/api/codex/v1");
|
|
}
|
|
|
|
public string ConnectToPeer(string peerId, string peerMultiAddress)
|
|
{
|
|
return Http().HttpGetString($"connect/{peerId}?addrs={peerMultiAddress}");
|
|
}
|
|
}
|
|
|
|
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;
|
|
public EnginePeerResponse[] enginePeers { get; set; } = Array.Empty<EnginePeerResponse>();
|
|
public SwitchPeerResponse[] switchPeers { get; set; } = Array.Empty<SwitchPeerResponse>();
|
|
public CodexDebugVersionResponse codex { get; set; } = new();
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public class CodexDebugVersionResponse
|
|
{
|
|
public string version { get; set; } = string.Empty;
|
|
public string revision { get; set; } = string.Empty;
|
|
}
|
|
|
|
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;}
|
|
}
|
|
}
|