80 lines
2.2 KiB
C#
80 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
|
|
using FrostFS.SDK.Client.Models.Netmap.Placement;
|
|
using FrostFS.SDK.Cryptography;
|
|
|
|
namespace FrostFS.SDK;
|
|
|
|
public class FrostFsNodeInfo(
|
|
FrostFsVersion version,
|
|
NodeState state,
|
|
IReadOnlyCollection<string> addresses,
|
|
IReadOnlyDictionary<string, string> attributes,
|
|
ReadOnlyMemory<byte> publicKey) : IHasher
|
|
{
|
|
private ulong _hash;
|
|
|
|
// attrPrice is a key to the node attribute that indicates the
|
|
// price in GAS tokens for storing one GB of data during one Epoch.
|
|
internal const string AttrPrice = "Price";
|
|
|
|
// attrCapacity is a key to the node attribute that indicates the
|
|
// total available disk space in Gigabytes.
|
|
internal const string AttrCapacity = "Capacity";
|
|
|
|
// attrExternalAddr is a key for the attribute storing node external addresses.
|
|
internal const string AttrExternalAddr = "ExternalAddr";
|
|
|
|
// sepExternalAddr is a separator for multi-value ExternalAddr attribute.
|
|
internal const string SepExternalAddr = ",";
|
|
|
|
private ulong price = ulong.MaxValue;
|
|
|
|
public NodeState State { get; } = state;
|
|
|
|
public FrostFsVersion Version { get; } = version;
|
|
|
|
public IReadOnlyCollection<string> Addresses { get; } = addresses;
|
|
|
|
public IReadOnlyDictionary<string, string> Attributes { get; } = attributes;
|
|
|
|
public ReadOnlyMemory<byte> PublicKey { get; } = publicKey;
|
|
|
|
public ulong Hash()
|
|
{
|
|
if (_hash == 0)
|
|
{
|
|
using var murmur3 = new Murmur3(0);
|
|
murmur3.Initialize();
|
|
_hash = murmur3.GetCheckSum64(PublicKey.ToArray());
|
|
}
|
|
|
|
return _hash;
|
|
}
|
|
|
|
internal ulong GetCapacity()
|
|
{
|
|
if (!Attributes.TryGetValue(AttrCapacity, out var val))
|
|
return 0;
|
|
|
|
return ulong.Parse(val, CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
internal ulong Price
|
|
{
|
|
get
|
|
{
|
|
if (price == ulong.MaxValue)
|
|
{
|
|
if (!Attributes.TryGetValue(AttrPrice, out var val))
|
|
price = 0;
|
|
else
|
|
price = uint.Parse(val, CultureInfo.InvariantCulture);
|
|
}
|
|
|
|
return price;
|
|
}
|
|
}
|
|
}
|