diff --git a/Tools/AutoClient/AutoClient.csproj b/Tools/AutoClient/AutoClient.csproj
index 07a0250..9340dc9 100644
--- a/Tools/AutoClient/AutoClient.csproj
+++ b/Tools/AutoClient/AutoClient.csproj
@@ -7,22 +7,6 @@
enable
-
-
-
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
- all
- runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
-
diff --git a/Tools/AutoClient/CodexUser.cs b/Tools/AutoClient/CodexUser.cs
new file mode 100644
index 0000000..bf71026
--- /dev/null
+++ b/Tools/AutoClient/CodexUser.cs
@@ -0,0 +1,45 @@
+using CodexOpenApi;
+using Logging;
+using static Org.BouncyCastle.Math.EC.ECCurve;
+using Utils;
+
+namespace AutoClient
+{
+ public class CodexUser
+ {
+ private readonly ILog log;
+ private readonly CodexApi codex;
+ private readonly HttpClient client;
+ private readonly Address address;
+ private readonly IFileGenerator generator;
+ private readonly Configuration config;
+ private readonly CancellationToken cancellationToken;
+
+ public CodexUser(ILog log, CodexApi codex, HttpClient client, Address address, IFileGenerator generator, Configuration config, CancellationToken cancellationToken)
+ {
+ this.log = log;
+ this.codex = codex;
+ this.client = client;
+ this.address = address;
+ this.generator = generator;
+ this.config = config;
+ this.cancellationToken = cancellationToken;
+ }
+
+ public async Task Run()
+ {
+ var purchasers = new List();
+ for (var i = 0; i < config.NumConcurrentPurchases; i++)
+ {
+ purchasers.Add(new Purchaser(new LogPrefixer(log, $"({i}) "), client, address, codex, config, generator, cancellationToken));
+ }
+
+ var delayPerPurchaser = TimeSpan.FromMinutes(config.ContractDurationMinutes) / config.NumConcurrentPurchases;
+ foreach (var purchaser in purchasers)
+ {
+ purchaser.Start();
+ await Task.Delay(delayPerPurchaser);
+ }
+ }
+ }
+}
diff --git a/Tools/AutoClient/Configuration.cs b/Tools/AutoClient/Configuration.cs
index d21deb5..86a5494 100644
--- a/Tools/AutoClient/Configuration.cs
+++ b/Tools/AutoClient/Configuration.cs
@@ -4,11 +4,8 @@ namespace AutoClient
{
public class Configuration
{
- [Uniform("codex-host", "ch", "CODEXHOST", false, "Codex Host address. (default 'http://localhost')")]
- public string CodexHost { get; set; } = "http://localhost";
-
- [Uniform("codex-port", "cp", "CODEXPORT", false, "port number of Codex API. (8080 by default)")]
- public int CodexPort { get; set; } = 8080;
+ [Uniform("codex-endpoints", "ce", "CODEXENDPOINTS", false, "Codex endpoints. Semi-colon separated. (default 'http://localhost:8080')")]
+ public string CodexEndpoints { get; set; } = "http://localhost";
[Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")]
public string DataPath { get; set; } = "datapath";
diff --git a/Tools/AutoClient/Program.cs b/Tools/AutoClient/Program.cs
index fc4e340..07c7500 100644
--- a/Tools/AutoClient/Program.cs
+++ b/Tools/AutoClient/Program.cs
@@ -3,14 +3,27 @@ using AutoClient;
using CodexOpenApi;
using Core;
using Logging;
+using Nethereum.Model;
using Utils;
-public static class Program
+public class Program
{
+ private readonly CancellationTokenSource cts;
+ private readonly Configuration config;
+ private readonly LogSplitter log;
+ private readonly IFileGenerator generator;
+
+ public Program(CancellationTokenSource cts, Configuration config, LogSplitter log, IFileGenerator generator)
+ {
+ this.cts = cts;
+ this.config = config;
+ this.log = log;
+ this.generator = generator;
+ }
+
public static async Task Main(string[] args)
{
var cts = new CancellationTokenSource();
- var cancellationToken = cts.Token;
Console.CancelKeyPress += (sender, args) => cts.Cancel();
var uniformArgs = new ArgsUniform(PrintHelp, args);
@@ -21,66 +34,64 @@ public static class Program
throw new Exception("Number of concurrent purchases must be > 0");
}
- var c = new AutoClientCenterAPI.swaggerClient("", new HttpClient());
- var tasks = await c.TasksAsync();
- foreach (var task in tasks.Tasks)
- {
- foreach (var step in task.Steps)
- {
-
- }
- }
-
var log = new LogSplitter(
new FileLog(Path.Combine(config.LogPath, "autoclient")),
new ConsoleLog()
);
+ var generator = CreateGenerator(config, log);
+
+ var p = new Program(cts, config, log, generator);
+ await p.Run(args);
+ cts.Token.WaitHandle.WaitOne();
+ log.Log("Done.");
+ }
+
+ public async Task Run(string[] args)
+ {
+ var codexUsers = CreateUsers();
+
+
+
+ }
+
+ private async Task CreateUsers()
+ {
+ var endpointStrs = config.CodexEndpoints.Split(";", StringSplitOptions.RemoveEmptyEntries);
+ var result = new List();
+
+ foreach (var e in endpointStrs)
+ {
+ result.Add(await CreateUser(e));
+ }
+
+ return result.ToArray();
+ }
+
+ private async Task CreateUser(string endpoint)
+ {
+ var splitIndex = endpoint.LastIndexOf(':');
+ var host = endpoint.Substring(0, splitIndex);
+ var port = Convert.ToInt32(endpoint.Substring(splitIndex + 1));
+
var address = new Address(
- host: config.CodexHost,
- port: config.CodexPort
+ host: host,
+ port: port
);
log.Log($"Start. Address: {address}");
- var generator = CreateGenerator(config, log);
var client = new HttpClient();
var codex = new CodexApi(client);
codex.BaseUrl = $"{address.Host}:{address.Port}/api/codex/v1";
- await CheckCodex(codex, log);
+ await CheckCodex(codex);
- var purchasers = new List();
- for (var i = 0; i < config.NumConcurrentPurchases; i++)
- {
- purchasers.Add(
- new Purchaser(new LogPrefixer(log, $"({i}) "), client, address, codex, config, generator, cancellationToken)
- );
- }
-
- var delayPerPurchaser = TimeSpan.FromMinutes(config.ContractDurationMinutes) / config.NumConcurrentPurchases;
- foreach (var purchaser in purchasers)
- {
- purchaser.Start();
- await Task.Delay(delayPerPurchaser);
- }
-
- cancellationToken.WaitHandle.WaitOne();
-
- log.Log("Done.");
+ return new CodexUser();
}
- private static IFileGenerator CreateGenerator(Configuration config, LogSplitter log)
- {
- if (config.FileSizeMb > 0)
- {
- return new RandomFileGenerator(config, log);
- }
- return new ImageGenerator(log);
- }
-
- private static async Task CheckCodex(CodexApi codex, ILog log)
+ private async Task CheckCodex(CodexApi codex)
{
log.Log("Checking Codex...");
try
@@ -95,6 +106,15 @@ public static class Program
}
}
+ private static IFileGenerator CreateGenerator(Configuration config, LogSplitter log)
+ {
+ if (config.FileSizeMb > 0)
+ {
+ return new RandomFileGenerator(config, log);
+ }
+ return new ImageGenerator(log);
+ }
+
private static void PrintHelp()
{
Console.WriteLine("Generates fake data and creates Codex storage contracts for it.");
diff --git a/Tools/AutoClientCenter/AutoClientCenter.csproj b/Tools/AutoClientCenter/AutoClientCenter.csproj
index d5e2255..59bce48 100644
--- a/Tools/AutoClientCenter/AutoClientCenter.csproj
+++ b/Tools/AutoClientCenter/AutoClientCenter.csproj
@@ -13,4 +13,9 @@
+
+
+
+
+