-
Notifications
You must be signed in to change notification settings - Fork 139
/
BlockDownloadState.cs
70 lines (58 loc) · 2.2 KB
/
BlockDownloadState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using Libplanet.Blocks;
namespace Libplanet.Net
{
/// <summary>
/// Indicates a progress of downloading blocks.
/// </summary>
public class BlockDownloadState : PreloadState, IEquatable<BlockDownloadState>
{
/// <summary>
/// Total number of blocks to receive in the current batch.
/// </summary>
public long TotalBlockCount { get; internal set; }
/// <summary>
/// The number of currently received blocks.
/// </summary>
public long ReceivedBlockCount { get; internal set; }
/// <summary>
/// The hash digest of the block just received.
/// </summary>
public BlockHash ReceivedBlockHash { get; internal set; }
/// <inheritdoc />
public override int CurrentPhase => 2;
/// <summary>
/// The peer which sent the block.
/// </summary>
public BoundPeer? SourcePeer { get; internal set; }
public static bool operator ==(BlockDownloadState left, BlockDownloadState right) =>
left.Equals(right);
public static bool operator !=(BlockDownloadState left, BlockDownloadState right) =>
!left.Equals(right);
public bool Equals(BlockDownloadState? other)
{
if (other is null)
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return base.Equals(other) &&
TotalBlockCount == other.TotalBlockCount &&
ReceivedBlockCount == other.ReceivedBlockCount &&
ReceivedBlockHash.Equals(other.ReceivedBlockHash) &&
((SourcePeer is null && other.SourcePeer is null) ||
(SourcePeer is { } p1 && other.SourcePeer is { } p2 && p1.Equals(p2)));
}
public override bool Equals(object? obj) =>
obj is BlockDownloadState other && Equals(other);
public override int GetHashCode() => HashCode.Combine(
base.GetHashCode(),
TotalBlockCount,
ReceivedBlockCount,
ReceivedBlockHash,
SourcePeer);
}
}