diff --git a/Libplanet/Net/Messages/GetBlocks.cs b/Libplanet/Net/Messages/GetBlocks.cs index 29299db4d21..07668115611 100644 --- a/Libplanet/Net/Messages/GetBlocks.cs +++ b/Libplanet/Net/Messages/GetBlocks.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; @@ -7,9 +8,19 @@ namespace Libplanet.Net.Messages { internal class GetBlocks : Message { - public GetBlocks(IEnumerable> hashes) + public GetBlocks( + IEnumerable> hashes, + int chunkSize = 500) { + if (chunkSize <= 0) + { + throw new ArgumentOutOfRangeException( + nameof(chunkSize), + "Chunk size must be greater than 0."); + } + BlockHashes = hashes; + ChunkSize = chunkSize; } public GetBlocks(NetMQFrame[] frames) @@ -19,10 +30,13 @@ public GetBlocks(NetMQFrame[] frames) .Skip(1).Take(hashCount) .Select(f => f.ConvertToHashDigest()) .ToList(); + ChunkSize = frames[1 + hashCount].ConvertToInt32(); } public IEnumerable> BlockHashes { get; } + public int ChunkSize { get; } + protected override MessageType Type => MessageType.GetBlocks; protected override IEnumerable DataFrames @@ -36,6 +50,9 @@ protected override IEnumerable DataFrames { yield return new NetMQFrame(hash.ToByteArray()); } + + yield return new NetMQFrame( + NetworkOrderBitsConverter.GetBytes(ChunkSize)); } } }