2024-04-01 20:40:03 +02:00
|
|
|
|
using ArgsUniform;
|
|
|
|
|
|
using AutoClient;
|
2024-10-30 08:56:31 +01:00
|
|
|
|
using AutoClient.Modes;
|
2025-01-16 15:13:16 +01:00
|
|
|
|
using CodexClient;
|
2025-02-22 14:41:05 +01:00
|
|
|
|
using GethPlugin;
|
2024-08-23 13:21:31 +02:00
|
|
|
|
using Utils;
|
2025-04-03 13:10:01 +02:00
|
|
|
|
using WebUtils;
|
|
|
|
|
|
using Logging;
|
2024-04-01 20:40:03 +02:00
|
|
|
|
|
2024-09-12 12:05:42 +02:00
|
|
|
|
public class Program
|
2024-04-01 20:40:03 +02:00
|
|
|
|
{
|
2024-09-12 14:38:15 +02:00
|
|
|
|
private readonly App app;
|
2024-09-12 12:05:42 +02:00
|
|
|
|
|
2024-09-12 14:38:15 +02:00
|
|
|
|
public Program(Configuration config)
|
2024-09-12 12:05:42 +02:00
|
|
|
|
{
|
2024-09-12 14:38:15 +02:00
|
|
|
|
app = new App(config);
|
2024-09-12 12:05:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-03 13:10:01 +02:00
|
|
|
|
public static void Main(string[] args)
|
2024-04-01 20:40:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
var cts = new CancellationTokenSource();
|
|
|
|
|
|
Console.CancelKeyPress += (sender, args) => cts.Cancel();
|
|
|
|
|
|
|
|
|
|
|
|
var uniformArgs = new ArgsUniform<Configuration>(PrintHelp, args);
|
|
|
|
|
|
var config = uniformArgs.Parse(true);
|
|
|
|
|
|
|
2024-06-28 08:47:09 +02:00
|
|
|
|
if (config.NumConcurrentPurchases < 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new Exception("Number of concurrent purchases must be > 0");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-12 14:38:15 +02:00
|
|
|
|
var p = new Program(config);
|
2025-04-03 13:10:01 +02:00
|
|
|
|
p.Run();
|
2024-09-12 12:05:42 +02:00
|
|
|
|
}
|
2024-04-01 20:40:03 +02:00
|
|
|
|
|
2025-04-03 13:10:01 +02:00
|
|
|
|
public void Run()
|
2024-09-12 12:05:42 +02:00
|
|
|
|
{
|
2025-04-03 13:10:01 +02:00
|
|
|
|
if (app.Config.ContractDurationMinutes - 1 < 5) throw new Exception("Contract duration config option not long enough!");
|
2025-01-16 15:13:16 +01:00
|
|
|
|
var codexNodes = CreateCodexWrappers();
|
2025-04-03 13:10:01 +02:00
|
|
|
|
var loadBalancer = new LoadBalancer(app, codexNodes);
|
2024-09-12 14:38:15 +02:00
|
|
|
|
|
2025-04-03 13:10:01 +02:00
|
|
|
|
var folderStore = new FolderStoreMode(app, loadBalancer);
|
|
|
|
|
|
folderStore.Start();
|
2024-06-27 15:38:13 +02:00
|
|
|
|
|
2024-09-12 14:38:15 +02:00
|
|
|
|
app.Cts.Token.WaitHandle.WaitOne();
|
2024-04-01 20:40:03 +02:00
|
|
|
|
|
2025-04-03 13:10:01 +02:00
|
|
|
|
folderStore.Stop();
|
2024-09-12 14:38:15 +02:00
|
|
|
|
|
|
|
|
|
|
app.Log.Log("Done");
|
2024-09-12 12:05:42 +02:00
|
|
|
|
}
|
2024-04-01 20:47:56 +02:00
|
|
|
|
|
2025-01-16 15:13:16 +01:00
|
|
|
|
private CodexWrapper[] CreateCodexWrappers()
|
2024-09-12 12:05:42 +02:00
|
|
|
|
{
|
2024-09-12 14:38:15 +02:00
|
|
|
|
var endpointStrs = app.Config.CodexEndpoints.Split(";", StringSplitOptions.RemoveEmptyEntries);
|
2025-01-16 15:13:16 +01:00
|
|
|
|
var result = new List<CodexWrapper>();
|
2024-06-28 08:47:09 +02:00
|
|
|
|
|
2025-04-03 13:10:01 +02:00
|
|
|
|
var i = 1;
|
2024-09-12 12:05:42 +02:00
|
|
|
|
foreach (var e in endpointStrs)
|
2024-06-28 08:47:09 +02:00
|
|
|
|
{
|
2025-04-03 13:10:01 +02:00
|
|
|
|
result.Add(CreateCodexWrapper(e, i));
|
|
|
|
|
|
i++;
|
2024-06-28 08:47:09 +02:00
|
|
|
|
}
|
2024-04-01 20:40:03 +02:00
|
|
|
|
|
2024-09-12 12:05:42 +02:00
|
|
|
|
return result.ToArray();
|
2024-04-01 20:40:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-03 17:12:02 +01:00
|
|
|
|
private readonly string LogLevel = "TRACE;info:discv5,providers,routingtable,manager,cache;warn:libp2p,multistream,switch,transport,tcptransport,semaphore,asyncstreamwrapper,lpstream,mplex,mplexchannel,noise,bufferstream,mplexcoder,secure,chronosstream,connection,websock,ws-session,muxedupgrade,upgrade,identify,contracts,clock,serde,json,serialization,JSONRPC-WS-CLIENT,JSONRPC-HTTP-CLIENT,repostore";
|
2025-03-03 16:44:04 +01:00
|
|
|
|
|
2025-04-03 13:10:01 +02:00
|
|
|
|
private CodexWrapper CreateCodexWrapper(string endpoint, int number)
|
2024-08-23 13:21:31 +02:00
|
|
|
|
{
|
2024-09-12 12:05:42 +02:00
|
|
|
|
var splitIndex = endpoint.LastIndexOf(':');
|
|
|
|
|
|
var host = endpoint.Substring(0, splitIndex);
|
|
|
|
|
|
var port = Convert.ToInt32(endpoint.Substring(splitIndex + 1));
|
|
|
|
|
|
|
|
|
|
|
|
var address = new Address(
|
2025-01-15 16:05:57 +01:00
|
|
|
|
logName: $"cdx@{host}:{port}",
|
2024-09-12 12:05:42 +02:00
|
|
|
|
host: host,
|
|
|
|
|
|
port: port
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-04-03 13:10:01 +02:00
|
|
|
|
var log = new LogPrefixer(app.Log, $"[{number.ToString().PadLeft(3, '0')}] ");
|
|
|
|
|
|
var httpFactory = new HttpFactory(log, new AutoClientWebTimeSet());
|
|
|
|
|
|
var codexNodeFactory = new CodexNodeFactory(log: log, httpFactory: httpFactory, dataDir: app.Config.DataPath);
|
2025-02-27 10:09:03 +01:00
|
|
|
|
var instance = CodexInstance.CreateFromApiEndpoint("[AutoClient]", address, EthAccountGenerator.GenerateNew());
|
2025-04-03 13:10:01 +02:00
|
|
|
|
var node = codexNodeFactory.CreateCodexNode(instance);
|
2025-03-03 16:44:04 +01:00
|
|
|
|
|
|
|
|
|
|
node.SetLogLevel(LogLevel);
|
2025-01-16 15:13:16 +01:00
|
|
|
|
return new CodexWrapper(app, node);
|
2024-04-01 20:47:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-01 20:40:03 +02:00
|
|
|
|
private static void PrintHelp()
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("Generates fake data and creates Codex storage contracts for it.");
|
|
|
|
|
|
}
|
2024-10-30 08:56:31 +01:00
|
|
|
|
}
|