add network test feature (PING/PONG with latency stats)
New frame types PING (0x0B) and PONG (0x0C), each carrying an 8-byte nonce. Server echoes PING nonce verbatim in PONG. Client sends pings at random 10-100ms intervals, correlates nonces to measure RTT. Stats shown live: sent/recv counts, loss %, average latency, jitter (mean absolute delta of consecutive RTTs). Test button toggles on/off. Updated both Rust server (echo in main.rs) and C# client (PingTest.cs, SessionManager routing, MainForm Test button + stats label).
This commit is contained in:
@@ -7,16 +7,19 @@ public partial class MainForm : Form
|
||||
readonly SessionManager _sessions = new();
|
||||
readonly ComboBox _deviceBox = new();
|
||||
readonly Button _discoverBtn = new();
|
||||
readonly Button _testBtn = new();
|
||||
readonly Label _serverLabel = new();
|
||||
readonly Label _pingStatsLabel = new();
|
||||
readonly ListView _listView = new();
|
||||
readonly Label _statusLabel = new();
|
||||
TunnelLink? _link;
|
||||
PingTest? _pingTest;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
Text = "gatuna";
|
||||
Width = 520;
|
||||
Height = 380;
|
||||
Height = 420;
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Icon = SystemIcons.GetStockIcon(StockIconId.NetworkConnect, 32);
|
||||
InitializeComponents();
|
||||
@@ -54,15 +57,27 @@ public partial class MainForm : Form
|
||||
_discoverBtn.Click += OnDiscover;
|
||||
Controls.Add(_discoverBtn);
|
||||
|
||||
_testBtn.Text = "Test";
|
||||
_testBtn.Left = _discoverBtn.Right + 8; _testBtn.Top = _discoverBtn.Top;
|
||||
_testBtn.Width = 60;
|
||||
_testBtn.Click += OnTest;
|
||||
Controls.Add(_testBtn);
|
||||
|
||||
_serverLabel.Left = pad; _serverLabel.Top = _discoverBtn.Bottom + 8;
|
||||
_serverLabel.Width = ClientSize.Width - pad * 2;
|
||||
_serverLabel.AutoEllipsis = true;
|
||||
_serverLabel.Text = "Server: not connected";
|
||||
Controls.Add(_serverLabel);
|
||||
|
||||
_listView.Left = pad; _listView.Top = _serverLabel.Bottom + 8;
|
||||
_pingStatsLabel.Left = pad; _pingStatsLabel.Top = _serverLabel.Bottom + 4;
|
||||
_pingStatsLabel.Width = ClientSize.Width - pad * 2;
|
||||
_pingStatsLabel.AutoEllipsis = true;
|
||||
_pingStatsLabel.Text = "";
|
||||
Controls.Add(_pingStatsLabel);
|
||||
|
||||
_listView.Left = pad; _listView.Top = _pingStatsLabel.Bottom + 8;
|
||||
_listView.Width = ClientSize.Width - pad * 2;
|
||||
_listView.Height = 200;
|
||||
_listView.Height = 180;
|
||||
_listView.View = View.Details;
|
||||
_listView.FullRowSelect = true;
|
||||
_listView.CheckBoxes = true;
|
||||
@@ -106,6 +121,34 @@ public partial class MainForm : Form
|
||||
_statusLabel.Text = "discovering...";
|
||||
}
|
||||
|
||||
void OnTest(object? s, EventArgs e)
|
||||
{
|
||||
if (_pingTest != null && _pingTest.Running)
|
||||
{
|
||||
_sessions.StopPing();
|
||||
_pingTest = null;
|
||||
_testBtn.Text = "Test";
|
||||
return;
|
||||
}
|
||||
|
||||
_pingTest = _sessions.StartPing();
|
||||
if (_pingTest == null)
|
||||
{
|
||||
MessageBox.Show("Discover a server first.");
|
||||
return;
|
||||
}
|
||||
_pingTest.StatsUpdated += stats => this.Invoke(() =>
|
||||
{
|
||||
_pingStatsLabel.Text =
|
||||
$"sent: {stats.Sent} recv: {stats.Received} " +
|
||||
$"loss: {stats.LossPct:F1}% " +
|
||||
$"avg: {stats.AvgLatencyMs:F1}ms " +
|
||||
$"jitter: {stats.JitterMs:F1}ms";
|
||||
});
|
||||
_testBtn.Text = "Stop";
|
||||
_pingStatsLabel.Text = "pinging...";
|
||||
}
|
||||
|
||||
void PopulateList(string hostname, byte[] mac, UpstreamEntry[] entries)
|
||||
{
|
||||
var macStr = string.Join(":", mac.Select(b => b.ToString("X2")));
|
||||
|
||||
Reference in New Issue
Block a user