chore: comment cleanup pass ahead of open-sourcing
Some checks failed
Build Linux Binaries / linux/amd64 (push) Has been cancelled
Build Linux Binaries / linux/arm64 (push) Has been cancelled

Removes leftover debug scaffolding (stray Console.WriteLine/NSLog traces,
dead nick_buf_ptr, a no-op --print-config flag now implemented for real),
fixes stale/misleading comments (channel passwords are no longer a "future
M5+" feature, a wrong cross-reference, a stale TlsContext::close() mention,
an incomplete BanRecord::subject_type doc, and a smoke test pointing at a
build/m1-dev preset that no longer exists), strips internal M1-M5 milestone
jargon from comments now that the roadmap is done, trims comments that just
restated the following line, and consolidates a few "why" explanations that
were duplicated 2-3 times in the same file.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 10:20:18 +01:00
parent bda37ec27b
commit bba605401d
50 changed files with 229 additions and 331 deletions

View File

@@ -105,7 +105,6 @@ public sealed class ProcessAudioMixer : IDisposable
for (int i = 0; i < frameLen; i++)
{
int sum = mix[i] + frame[i];
// Saturating clamp
mix[i] = (short)Math.Clamp(sum, short.MinValue, short.MaxValue);
}
}

View File

@@ -92,13 +92,8 @@ public partial class ConnectDialog : Form
private void BtnConnect_Click(object? sender, EventArgs e)
{
Console.WriteLine("[ConnectDialog] BtnConnect_Click fired");
if (lstServers.SelectedItem is not SavedServer server)
{
Console.WriteLine("[ConnectDialog] no SavedServer selected — ignoring click");
return;
}
Console.WriteLine($"[ConnectDialog] selected server: Host={server.Host} Port={server.Port} AuthMode={server.AuthMode}");
try
{
StartConnect(server);
@@ -121,21 +116,15 @@ public partial class ConnectDialog : Form
: server.DisplayName;
string tofuDir = Path.GetDirectoryName(ServerListStore.TofuStorePath)!;
Console.WriteLine($"[ConnectDialog] tofu store dir: {tofuDir}");
Directory.CreateDirectory(tofuDir);
Console.WriteLine("[ConnectDialog] creating VoiceCatClient...");
_client = new VoiceCatClient("VoiceCat-Windows", VoiceCatClient.VersionString,
VcLogLevel.Info, ServerListStore.TofuStorePath);
Console.WriteLine("[ConnectDialog] VoiceCatClient created OK");
_client.EventReceived += OnEvent;
_identityDialogShown = false;
_pumpTimer.Start();
Console.WriteLine($"[ConnectDialog] pump timer started, Enabled={_pumpTimer.Enabled}, Interval={_pumpTimer.Interval}");
Console.WriteLine($"[ConnectDialog] calling Connect({server.Host}, {server.Port})...");
var connectResult = _client.Connect(server.Host, server.Port);
Console.WriteLine($"[ConnectDialog] Connect() returned {connectResult}");
if (connectResult != VcResult.Ok)
{
lblStatus.Text = $"Connect failed: {connectResult}";
@@ -146,9 +135,7 @@ public partial class ConnectDialog : Form
if (server.AuthMode == AuthMode.Guest)
{
Nickname = string.IsNullOrWhiteSpace(server.LastNickname) ? Environment.UserName : server.LastNickname;
Console.WriteLine($"[ConnectDialog] calling AuthenticateGuest({Nickname})...");
var authResult = _client.AuthenticateGuest(Nickname);
Console.WriteLine($"[ConnectDialog] AuthenticateGuest() returned {authResult}");
_client.AuthenticateGuest(Nickname);
}
else
{
@@ -169,15 +156,12 @@ public partial class ConnectDialog : Form
password = pwDlg.Password;
}
Nickname = server.SavedUsername ?? "";
Console.WriteLine($"[ConnectDialog] calling AuthenticateUser({Nickname})...");
var authResult = _client.AuthenticateUser(server.SavedUsername ?? "", password);
Console.WriteLine($"[ConnectDialog] AuthenticateUser() returned {authResult}");
_client.AuthenticateUser(server.SavedUsername ?? "", password);
}
}
private void OnEvent(VoiceCatEvent ev)
{
Console.WriteLine($"[ConnectDialog] event: {ev}");
switch (ev.Type)
{
case VcEventType.ConnectionState:
@@ -225,24 +209,18 @@ public partial class ConnectDialog : Form
private void HandleServerIdentity(VcTofuStatus status, string certFingerprintHex)
{
Console.WriteLine($"[ConnectDialog] HandleServerIdentity status={status} fp={certFingerprintHex} alreadyShown={_identityDialogShown}");
if (_identityDialogShown) return; // one decision per connect attempt
if (status == VcTofuStatus.Matched)
{
// Silent success path — no dialog. See ServerIdentityDialog's doc comment.
Console.WriteLine("[ConnectDialog] status=Matched -> auto-confirming, no dialog");
_client!.ConfirmServerIdentity(true);
return;
}
_identityDialogShown = true;
Console.WriteLine("[ConnectDialog] showing ServerIdentityDialog...");
using var dlg = new ServerIdentityDialog(status, certFingerprintHex, _client!.GetServerIdentityDisplay());
var dlgResult = dlg.ShowDialog(this);
Console.WriteLine($"[ConnectDialog] ServerIdentityDialog closed with {dlgResult}");
bool accept = dlgResult == DialogResult.OK;
var confirmResult = _client.ConfirmServerIdentity(accept);
Console.WriteLine($"[ConnectDialog] ConfirmServerIdentity({accept}) returned {confirmResult}");
bool accept = dlg.ShowDialog(this) == DialogResult.OK;
_client.ConfirmServerIdentity(accept);
if (!accept) lblStatus.Text = "Server identity rejected.";
}

View File

@@ -1114,7 +1114,7 @@ public partial class MainForm : Form
OpenPmWindow(dlg.SelectedUserId);
}
// ── M5: Moderation helpers ────────────────────────────────────────────────
// ── Moderation helpers ─────────────────────────────────────────────────────
private void UpdateSelfServerMuteState(bool muted, bool deafened)
{

View File

@@ -1,7 +1,7 @@
namespace VoiceCat.App.Forms;
/// <summary>Small modal for "type a password right now" — used when a saved server's
/// password wasn't remembered, and (Phase E) for password-protected channel joins.</summary>
/// password wasn't remembered, and for password-protected channel joins.</summary>
public partial class PasswordPromptDialog : Form
{
public string Password => txtPassword.Text;

View File

@@ -3,7 +3,7 @@ using VoiceCat.Interop;
namespace VoiceCat.App.Forms;
/// <summary>
/// TOFU server-identity confirmation (M4). Shown only for VcTofuStatus.FirstConnect/Mismatch
/// TOFU server-identity confirmation. Shown only for VcTofuStatus.FirstConnect/Mismatch
/// — never Matched (that's the silent-success "subsequent connects verify the pin" path
/// docs/security.md describes; showing a dialog on every routine reconnect would be exactly
/// the "overly chatty" experience this project avoids elsewhere too).

View File

@@ -7,17 +7,17 @@ namespace VoiceCat.App.Notifications;
/// </summary>
public enum SoundEvent
{
ChannelJoin, // another user joined my channel
ChannelLeave, // another user left my channel
ChannelJoin,
ChannelLeave,
ChannelRecv, // channel text message from someone else
ChannelSent, // channel text message I sent
PmRecv, // private message received
PmSent, // private message I sent
Login, // connected / authenticated
Logout, // clean disconnect
ConnectionLost, // unexpected disconnect
VoiceOn, // my microphone stream started
VoiceOff, // my microphone stream stopped
PmRecv,
PmSent,
Login,
Logout,
ConnectionLost,
VoiceOn,
VoiceOff,
VaStart, // my voice-activity began (off by default)
VaStop, // my voice-activity ended (off by default)
Ptt, // push-to-talk engaged (off by default)

View File

@@ -7,30 +7,21 @@ internal static class Program
[STAThread]
private static void Main()
{
// Diagnostic-logging-only for now (manual debugging session) — every exception that
// would otherwise be silently caught by WinForms' default message-loop handling (or
// crash with no visible cause) gets printed to stdout/stderr first.
// Surface exceptions that WinForms' default message-loop handling would otherwise
// swallow silently (or crash with no visible cause).
Application.ThreadException += (_, e) =>
Console.Error.WriteLine($"[UNHANDLED ThreadException] {e.Exception}");
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
Console.Error.WriteLine($"[UNHANDLED AppDomain exception] {e.ExceptionObject}");
Console.WriteLine("VoiceCat.App starting...");
ApplicationConfiguration.Initialize();
using var connectDialog = new ConnectDialog();
Console.WriteLine("Showing ConnectDialog...");
var result = connectDialog.ShowDialog();
Console.WriteLine($"ConnectDialog closed with DialogResult={result}, ConnectedClient={(connectDialog.ConnectedClient is null ? "null" : "set")}");
if (result != DialogResult.OK || connectDialog.ConnectedClient is null)
{
Console.WriteLine("Exiting (cancelled or no connected client).");
return;
}
Console.WriteLine("Launching MainForm...");
Application.Run(new MainForm(connectDialog.ConnectedClient, connectDialog.SelfUserId,
connectDialog.Nickname, connectDialog.ServerName));
Console.WriteLine("MainForm closed. Exiting.");
}
}

View File

@@ -23,10 +23,10 @@ public sealed class VoiceCatClientSmokeTests : IDisposable
_tempDir = Path.Combine(Path.GetTempPath(), "vc_csharp_smoke_" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(_tempDir);
string serverExe = Path.Combine(FindRepoRoot(), "build", "m1-dev", "bin", "voicecat-server.exe");
string serverExe = Path.Combine(FindRepoRoot(), "build", "dev", "bin", "voicecat-server.exe");
Assert.True(File.Exists(serverExe),
$"voicecat-server.exe not found at '{serverExe}' — build the m1-dev preset first " +
"(cmake --preset m1-dev && cmake --build --preset m1-dev).");
$"voicecat-server.exe not found at '{serverExe}' — build the dev preset first " +
"(cmake --preset dev && cmake --build --preset dev).");
var psi = new ProcessStartInfo(serverExe)
{
@@ -56,9 +56,9 @@ public sealed class VoiceCatClientSmokeTests : IDisposable
Assert.True(port is not null, "voicecat-server.exe did not report a bound TCP port within 10s.");
_port = port!.Value;
// M5: provision a known admin account so we can exercise moderation wrappers end-to-end.
string adminExe = Path.Combine(FindRepoRoot(), "build", "m1-dev", "bin", "voicecat-admin.exe");
Assert.True(File.Exists(adminExe), "voicecat-admin.exe not found — build the m1-dev preset.");
// Provision a known admin account so we can exercise moderation wrappers end-to-end.
string adminExe = Path.Combine(FindRepoRoot(), "build", "dev", "bin", "voicecat-admin.exe");
Assert.True(File.Exists(adminExe), "voicecat-admin.exe not found — build the dev preset.");
var adminPsi = new ProcessStartInfo(adminExe)
{
Arguments = $"--data-dir \"{_tempDir}\" account add admin2 --admin --password testpassword123",
@@ -140,14 +140,14 @@ public sealed class VoiceCatClientSmokeTests : IDisposable
var channels = client.ListChannels();
Assert.Contains(channels, c => c.Id == 1 && c.Name == "Lobby");
// M5: permissions getter round-trip.
// Permissions getter round-trip.
var perms = client.GetPermissions();
Assert.False(perms.IsAdmin);
Assert.False(perms.CanKick);
// M5: moderation request wrappers queue without error. As a guest, account listing
// Moderation request wrappers queue without error. As a guest, account listing
// is rejected by the server with a GenericResult, which proves the wrapper path works
// end-to-end and that the new event type is delivered through P/Invoke.
// end-to-end and that the event type is delivered through P/Invoke.
Assert.Equal(VcResult.Ok, client.RequestAccountList());
Assert.True(PumpUntil(client,
() => events.Any(e => e.Type == VcEventType.GenericResult), 3000),

View File

@@ -37,7 +37,7 @@ public enum VcConnectionState
TlsHandshake = 2,
Authenticating = 3,
Connected = 4,
/// <summary>M4: handshake succeeded, waiting on vc_confirm_server_identity().</summary>
/// <summary>Handshake succeeded, waiting on vc_confirm_server_identity().</summary>
VerifyingIdentity = 5,
}
@@ -84,13 +84,13 @@ public enum VcEventType
TalkState = 9,
Error = 10,
Disconnected = 11,
/// <summary>M4: reply to VoiceCatClient.JoinChannelAsync's underlying vc_join_channel.</summary>
/// <summary>Reply to VoiceCatClient.JoinChannelAsync's underlying vc_join_channel.</summary>
JoinResult = 12,
/// <summary>M4: the TOFU server-identity gate — see VcTofuStatus.</summary>
/// <summary>The TOFU server-identity gate — see VcTofuStatus.</summary>
ServerIdentity = 13,
/// <summary>M5: async result for moderation/admin/channel operations.</summary>
/// <summary>Async result for moderation/admin/channel operations.</summary>
GenericResult = 14,
/// <summary>M5: reply to VoiceCatClient.RequestAccountList — call ListAccounts() to read.</summary>
/// <summary>Reply to VoiceCatClient.RequestAccountList — call ListAccounts() to read.</summary>
AccountList = 15,
/// <summary>Voice-plane subscription state. u32a = 1 (subscribed) or 0 (unsubscribed).</summary>
VoiceState = 16,

View File

@@ -148,7 +148,7 @@ internal static partial class NativeMethods
[LibraryImport(LibName)]
internal static partial void vc_free_device_list(ref VcDeviceListNative list);
// ── M4: channel / user / stream snapshot getters ────────────────────────────────────────
// ── Channel / user / stream snapshot getters ────────────────────────────────────────────
[LibraryImport(LibName)]
internal static partial VcResult vc_list_channels(nint c, out VcChannelListNative outList);
@@ -168,7 +168,7 @@ internal static partial class NativeMethods
[LibraryImport(LibName)]
internal static partial void vc_free_stream_summary_list(ref VcStreamSummaryListNative list);
// ── M4: TOFU server-identity gate ───────────────────────────────────────────────────────
// ── TOFU server-identity gate ───────────────────────────────────────────────────────────
[LibraryImport(LibName)]
internal static partial VcResult vc_confirm_server_identity(nint c, int accept);
@@ -176,7 +176,7 @@ internal static partial class NativeMethods
internal static partial VcResult vc_get_server_identity_display(nint c, nint outBuf,
nuint bufCap, out nuint outLen);
// ── M5: Moderation & admin ─────────────────────────────────────────────────────────────
// ── Moderation & admin ───────────────────────────────────────────────────────────────────
[LibraryImport(LibName, StringMarshalling = StringMarshalling.Utf8)]
internal static partial VcResult vc_kick_user(nint c, uint userId, string? reason);

View File

@@ -95,10 +95,6 @@ public sealed class VoiceCatClient : IDisposable
internal void EnqueueEvent(VoiceCatEvent ev)
{
// Temporary diagnostic (manual debugging session) — confirms the native callback
// chain (UnmanagedCallersOnly -> GCHandle resolve -> here) actually fires, independent
// of whether the UI-thread drain (PumpEvents) ever sees it.
Console.WriteLine($"[VoiceCatClient] EnqueueEvent (native thread): {ev}");
_events.Writer.TryWrite(ev);
}
internal void EnqueueLevel(uint streamId, float rms) => _latestLevels[streamId] = rms;
@@ -116,7 +112,7 @@ public sealed class VoiceCatClient : IDisposable
public VcResult AuthenticateUser(string username, string password) =>
NativeMethods.vc_authenticate_user(_handle.DangerousGetHandle(), username, password);
// ── TOFU server-identity gate (M4) ──────────────────────────────────────────────────────
// ── TOFU server-identity gate ───────────────────────────────────────────────────────────
public VcResult ConfirmServerIdentity(bool accept) =>
NativeMethods.vc_confirm_server_identity(_handle.DangerousGetHandle(), accept ? 1 : 0);
@@ -143,9 +139,7 @@ public sealed class VoiceCatClient : IDisposable
// ── Channels ─────────────────────────────────────────────────────────────────────────
/// <summary>Result arrives as a VcEventType.JoinResult event, not via this return value
/// (which only reflects "request queued" — see voicecat.h's vc_join_channel doc comment).
/// NOTE: no in-tree channel has a server-side password to check yet (M5+ feature) — this
/// path is wired but not yet exercisable end-to-end.</summary>
/// (which only reflects "request queued" — see voicecat.h's vc_join_channel doc comment).</summary>
public VcResult JoinChannel(uint channelId, string? password = null) =>
NativeMethods.vc_join_channel(_handle.DangerousGetHandle(), channelId, password);
@@ -290,7 +284,7 @@ public sealed class VoiceCatClient : IDisposable
public VcResult SetPcmSink(nint cb, IntPtr user) =>
NativeMethods.vc_set_pcm_sink(_handle.DangerousGetHandle(), cb, user);
// ── M5: Moderation & admin ───────────────────────────────────────────────────────────
// ── Moderation & admin ───────────────────────────────────────────────────────────────
public VcResult KickUser(uint userId, string? reason = null) =>
NativeMethods.vc_kick_user(_handle.DangerousGetHandle(), userId, reason);