From c9d9a826296482b11a613fd51cb5eccf2d5c8d8e Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Tue, 4 Jun 2019 18:48:35 +0900 Subject: [PATCH] Add ChunkSize to GetBlocks --- Libplanet/Net/Messages/GetBlocks.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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)); } } }