2023-04-12 11:53:55 +00:00
|
|
|
|
using KubernetesWorkflow;
|
2023-06-29 14:07:49 +00:00
|
|
|
|
using Logging;
|
|
|
|
|
using Utils;
|
2023-04-12 11:53:55 +00:00
|
|
|
|
|
|
|
|
|
namespace DistTestCore.Codex
|
|
|
|
|
{
|
|
|
|
|
public class CodexAccess
|
|
|
|
|
{
|
2023-06-29 14:07:49 +00:00
|
|
|
|
private readonly BaseLog log;
|
|
|
|
|
private readonly ITimeSet timeSet;
|
2023-04-30 08:08:32 +00:00
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public CodexAccess(BaseLog log, RunningContainer container, ITimeSet timeSet, Address address)
|
2023-04-12 11:53:55 +00:00
|
|
|
|
{
|
2023-06-29 14:07:49 +00:00
|
|
|
|
this.log = log;
|
|
|
|
|
Container = container;
|
|
|
|
|
this.timeSet = timeSet;
|
|
|
|
|
Address = address;
|
2023-04-18 13:33:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-21 06:28:40 +00:00
|
|
|
|
public RunningContainer Container { get; }
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public Address Address { get; }
|
2023-05-11 10:44:53 +00:00
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public CodexDebugResponse GetDebugInfo()
|
2023-05-04 09:34:43 +00:00
|
|
|
|
{
|
2023-06-29 14:07:49 +00:00
|
|
|
|
return Http(TimeSpan.FromSeconds(2)).HttpGetJson<CodexDebugResponse>("debug/info");
|
|
|
|
|
}
|
2023-05-04 09:34:43 +00:00
|
|
|
|
|
2023-06-29 14:07:49 +00:00
|
|
|
|
public CodexDebugPeerResponse GetDebugPeer(string peerId)
|
|
|
|
|
{
|
|
|
|
|
return GetDebugPeer(peerId, TimeSpan.FromSeconds(2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CodexDebugPeerResponse GetDebugPeer(string peerId, TimeSpan timeout)
|
|
|
|
|
{
|
|
|
|
|
var http = Http(timeout);
|
|
|
|
|
var str = http.HttpGetString($"debug/peer/{peerId}");
|
|
|
|
|
|
|
|
|
|
if (str.ToLowerInvariant() == "unable to find peer!")
|
2023-05-04 09:34:43 +00:00
|
|
|
|
{
|
2023-06-29 14:07:49 +00:00
|
|
|
|
return new CodexDebugPeerResponse
|
|
|
|
|
{
|
|
|
|
|
IsPeerFound = false
|
|
|
|
|
};
|
2023-05-04 09:34:43 +00:00
|
|
|
|
}
|
2023-06-29 14:07:49 +00:00
|
|
|
|
|
|
|
|
|
var result = http.TryJsonDeserialize<CodexDebugPeerResponse>(str);
|
|
|
|
|
result.IsPeerFound = true;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CodexStoragePurchase GetPurchaseStatus(string purchaseId)
|
|
|
|
|
{
|
|
|
|
|
return Http().HttpGetJson<CodexStoragePurchase>($"storage/purchases/{purchaseId}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ConnectToPeer(string peerId, string peerMultiAddress)
|
|
|
|
|
{
|
|
|
|
|
return Http().HttpGetString($"connect/{peerId}?addrs={peerMultiAddress}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Http Http(TimeSpan? timeoutOverride = null)
|
|
|
|
|
{
|
|
|
|
|
return new Http(log, timeSet, Address, baseUrl: "/api/codex/v1", timeoutOverride);
|
2023-05-04 09:34:43 +00:00
|
|
|
|
}
|
2023-04-18 13:33:12 +00:00
|
|
|
|
}
|
2023-04-12 11:53:55 +00:00
|
|
|
|
}
|