Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Ping nodes while show state #391

Merged
merged 4 commits into from Jun 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions neo-cli/Shell/MainService.cs
Expand Up @@ -25,6 +25,7 @@
using System.Net;
using System.Numerics;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using ECCurve = Neo.Cryptography.ECC.ECCurve;
using ECPoint = Neo.Cryptography.ECC.ECPoint;
Expand Down Expand Up @@ -938,12 +939,21 @@ private bool OnShowPoolCommand(string[] args)

private bool OnShowStateCommand(string[] args)
{
bool stop = false;
var cancel = new CancellationTokenSource();

Console.CursorVisible = false;
Console.Clear();
Task broadcast = Task.Run(async () =>
{
while (!cancel.Token.IsCancellationRequested)
{
system.LocalNode.Tell(Message.Create(MessageCommand.Ping, PingPayload.Create(Blockchain.Singleton.Height)));
await Task.Delay(Blockchain.TimePerBlock, cancel.Token);
}
});
Task task = Task.Run(async () =>
{
while (!stop)
while (!cancel.Token.IsCancellationRequested)
{
Console.SetCursorPosition(0, 0);
WriteLineWithoutFlicker($"block: {Blockchain.Singleton.Height}/{Blockchain.Singleton.HeaderHeight} connected: {LocalNode.Singleton.ConnectedCount} unconnected: {LocalNode.Singleton.UnconnectedCount}");
Expand All @@ -957,12 +967,13 @@ private bool OnShowStateCommand(string[] args)

while (++linesWritten < Console.WindowHeight)
WriteLineWithoutFlicker();
await Task.Delay(500);

await Task.Delay(500, cancel.Token);
}
});
Console.ReadLine();
stop = true;
task.Wait();
cancel.Cancel();
Task.WaitAll(task, broadcast);
Console.WriteLine();
Console.CursorVisible = true;
return true;
Expand Down