[#24] Client: Implement pool part1
first iteration - base classes and methods Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
d1271df207
commit
c9a75ea025
72 changed files with 2786 additions and 468 deletions
|
@ -12,27 +12,33 @@ internal sealed class NetmapServiceProvider : ContextAccessor
|
|||
{
|
||||
private readonly NetmapService.NetmapServiceClient netmapServiceClient;
|
||||
|
||||
internal NetmapServiceProvider(NetmapService.NetmapServiceClient netmapServiceClient, ClientEnvironment context)
|
||||
internal NetmapServiceProvider(NetmapService.NetmapServiceClient netmapServiceClient, EnvironmentContext context)
|
||||
: base(context)
|
||||
{
|
||||
this.netmapServiceClient = netmapServiceClient;
|
||||
}
|
||||
|
||||
internal async Task<NetworkSettings> GetNetworkSettingsAsync(Context ctx)
|
||||
internal async Task<NetworkSettings> GetNetworkSettingsAsync(CallContext ctx)
|
||||
{
|
||||
if (Context.NetworkSettings != null)
|
||||
return Context.NetworkSettings;
|
||||
if (EnvironmentContext.NetworkSettings != null)
|
||||
return EnvironmentContext.NetworkSettings;
|
||||
|
||||
var info = await GetNetworkInfoAsync(ctx).ConfigureAwait(false);
|
||||
var response = await GetNetworkInfoAsync(ctx).ConfigureAwait(false);
|
||||
|
||||
var settings = new NetworkSettings();
|
||||
|
||||
foreach (var param in info.Body.NetworkInfo.NetworkConfig.Parameters)
|
||||
var info = response.Body.NetworkInfo;
|
||||
|
||||
settings.Epoch = info.CurrentEpoch;
|
||||
settings.MagicNumber = info.MagicNumber;
|
||||
settings.MsPerBlock = info.MsPerBlock;
|
||||
|
||||
foreach (var param in info.NetworkConfig.Parameters)
|
||||
{
|
||||
SetNetworksParam(param, settings);
|
||||
}
|
||||
|
||||
Context.NetworkSettings = settings;
|
||||
EnvironmentContext.NetworkSettings = settings;
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
@ -40,7 +46,7 @@ internal sealed class NetmapServiceProvider : ContextAccessor
|
|||
internal async Task<FrostFsNodeInfo> GetLocalNodeInfoAsync(PrmNodeInfo args)
|
||||
{
|
||||
var ctx = args.Context!;
|
||||
ctx.Key ??= Context.Key?.ECDsaKey;
|
||||
ctx.Key ??= EnvironmentContext.Key?.ECDsaKey;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
|
@ -53,6 +59,8 @@ internal sealed class NetmapServiceProvider : ContextAccessor
|
|||
request.AddMetaHeader(args.XHeaders);
|
||||
request.Sign(ctx.Key);
|
||||
|
||||
|
||||
|
||||
var response = await netmapServiceClient.LocalNodeInfoAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
||||
|
||||
Verifier.CheckResponse(response);
|
||||
|
@ -60,9 +68,9 @@ internal sealed class NetmapServiceProvider : ContextAccessor
|
|||
return response.Body.ToModel();
|
||||
}
|
||||
|
||||
internal async Task<NetworkInfoResponse> GetNetworkInfoAsync(Context ctx)
|
||||
internal async Task<NetworkInfoResponse> GetNetworkInfoAsync(CallContext ctx)
|
||||
{
|
||||
ctx.Key ??= Context.Key?.ECDsaKey;
|
||||
ctx.Key ??= EnvironmentContext.Key?.ECDsaKey;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
|
@ -83,7 +91,7 @@ internal sealed class NetmapServiceProvider : ContextAccessor
|
|||
internal async Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(PrmNetmapSnapshot args)
|
||||
{
|
||||
var ctx = args.Context!;
|
||||
ctx.Key ??= Context.Key?.ECDsaKey;
|
||||
ctx.Key ??= EnvironmentContext.Key?.ECDsaKey;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue