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

Commit

Permalink
Ping nodes while show state (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
shargon authored and erikzhang committed Jun 17, 2019
1 parent 2c22529 commit bd472a3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions neo-cli/Shell/MainService.cs
Original file line number Diff line number Diff line change
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

0 comments on commit bd472a3

Please sign in to comment.