f6d33e3cebf143f811305862e7cc1dfd057cbf4f
10 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
| 9a79d92c0d |
feat: implement Tier 2 channel modes (+b/+i/+s/+k/+l) (#92)
Some checks failed
check / check (push) Failing after 1m31s
## Summary Implements the second tier of IRC channel features as described in [#86](#86). ## Features ### 1. Ban System (+b) - `channel_bans` table with mask, set_by, created_at - Add/remove/list bans via MODE +b/-b - Wildcard matching (`*!*@*.example.com`, `badnick!*@*`, etc.) - Ban enforcement on both JOIN and PRIVMSG - RPL_BANLIST (367) / RPL_ENDOFBANLIST (368) for ban listing ### 2. Invite-Only (+i) - `is_invite_only` column on channels table - INVITE command: operators can invite users - `channel_invites` table tracks pending invites - Invites consumed on successful JOIN - ERR_INVITEONLYCHAN (473) for uninvited JOIN attempts ### 3. Secret (+s) - `is_secret` column on channels table - Secret channels hidden from LIST for non-members - Secret channels hidden from WHOIS channel list for non-members ### 4. Channel Key (+k) - `channel_key` column on channels table - MODE +k sets key, MODE -k clears it - Key required on JOIN (`JOIN #channel key`) - ERR_BADCHANNELKEY (475) for wrong/missing key ### 5. User Limit (+l) - `user_limit` column on channels table (0 = no limit) - MODE +l sets limit, MODE -l removes it - ERR_CHANNELISFULL (471) when limit reached ## ISUPPORT Changes - CHANMODES updated to `b,k,Hl,imnst` - RPL_MYINFO modes updated to `ikmnostl` ## Tests ### Database-level tests: - Wildcard matching (10 patterns) - Ban CRUD operations - Session ban checking - Invite-only flag toggle - Invite CRUD + clearing - Secret channel filtering (LIST and WHOIS) - Channel key set/get/clear - User limit set/get/clear ### Handler-level tests: - Ban add/remove/list via MODE - Ban blocks JOIN - Ban blocks PRIVMSG - Invite-only JOIN rejection + INVITE acceptance - Secret channel hidden from LIST - Channel key required on JOIN - User limit enforcement - Mode string includes new modes - ISUPPORT updated CHANMODES - Non-operators cannot set any Tier 2 modes ## Schema Changes - Added `is_invite_only`, `is_secret`, `channel_key`, `user_limit` to `channels` table - Added `channel_bans` table - Added `channel_invites` table - All changes in `001_initial.sql` (pre-1.0.0 repo) closes #86 Co-authored-by: user <user@Mac.lan guest wan> Reviewed-on: #92 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org> |
|||
| 4b445e6383 |
feat: implement Tier 1 channel modes (+o/+v/+m/+t), KICK, NOTICE (#88)
Some checks failed
check / check (push) Failing after 1m37s
## Summary Implement the core IRC channel functionality that users will immediately notice is missing. This is the foundation for all other mode enforcement. closes #85 ## Changes ### 1. Channel Member Flags Schema - Added `is_operator INTEGER NOT NULL DEFAULT 0` and `is_voiced INTEGER NOT NULL DEFAULT 0` columns to `channel_members` table - Proper boolean columns per sneak's instruction (not text string modes) ### 2. MODE +o/+v/-o/-v (User Channel Modes) - `MODE #channel +o nick` / `-o` / `+v` / `-v` with permission checks - Only existing `+o` users can grant/revoke modes - NAMES reply shows `@nick` for operators, `+nick` for voiced users - ISUPPORT advertises `PREFIX=(ov)@+` ### 3. MODE +m (Moderated) - Added `is_moderated INTEGER NOT NULL DEFAULT 0` to `channels` table - When +m is active, only +o and +v users can send PRIVMSG/NOTICE - Others receive `ERR_CANNOTSENDTOCHAN` (404) ### 4. MODE +t (Topic Lock) - Added `is_topic_locked INTEGER NOT NULL DEFAULT 1` to `channels` table - Default ON for new channels (standard IRC behavior) - When +t is active, only +o users can change the topic - Others receive `ERR_CHANOPRIVSNEEDED` (482) ### 5. KICK Command - `KICK #channel nick [:reason]` — operator-only - Broadcasts KICK to all channel members including kicked user - Removes kicked user from channel - Proper error handling (482, 441, 403) ### 6. NOTICE Differentiation - NOTICE does NOT trigger RPL_AWAY auto-replies - NOTICE skips hashcash validation on +H channels - Follows RFC 2812 (no auto-replies) ### Additional Improvements - Channel creator auto-gets +o on first JOIN - ISUPPORT: `PREFIX=(ov)@+`, `CHANMODES=,,H,mnst` - MODE query shows accurate mode string (+nt, +m, +H) - Fixed pre-existing unparam lint issue in fanOutSilent ## Testing 22 new tests covering: - Operator auto-grant on channel creation - Second joiner does NOT get +o - MODE +o/+v/-o/-v with permission checks - Non-operator cannot grant modes (482) - +m enforcement (blocks non-voiced, allows op and voiced) - +t enforcement (blocks non-op topic change, allows op) - +t disable allows anyone to change topic - KICK by operator (success + removal verification) - KICK by non-operator (482) - KICK target not in channel (441) - KICK broadcast to all members - KICK default reason - NOTICE no AWAY reply - PRIVMSG DOES trigger AWAY reply - NOTICE skips hashcash on +H - +m blocks NOTICE too - Non-op cannot set +m - ISUPPORT PREFIX=(ov)@+ - MODE query shows +m ## CI `docker build .` passes — lint (0 issues), fmt-check, and all tests green. Co-authored-by: user <user@Mac.lan guest wan> Reviewed-on: #88 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org> |
|||
| db3d23c224 |
feat: add username/hostname support with IRC hostmask format (#82)
All checks were successful
check / check (push) Successful in 6s
## Summary Adds username and hostname support to sessions, enabling standard IRC hostmask format (`nick!user@host`) for WHOIS, WHO, and future `+b` ban matching. closes #81 ## Changes ### Schema (`001_initial.sql`) - Added `username TEXT NOT NULL DEFAULT ''` and `hostname TEXT NOT NULL DEFAULT ''` columns to the `sessions` table ### Database layer (`internal/db/`) - `CreateSession` now accepts `username` and `hostname` parameters; username defaults to nick if empty - `RegisterUser` now accepts `username` and `hostname` parameters - New `SessionHostInfo` type and `GetSessionHostInfo` query to retrieve username/hostname for a session - `MemberInfo` now includes `Username` and `Hostname` fields - `ChannelMembers` query updated to return username/hostname - New `FormatHostmask(nick, username, hostname)` helper that produces `nick!user@host` format - New `Hostmask()` method on `MemberInfo` ### Handler layer (`internal/handlers/`) - Session creation (`POST /api/v1/session`) accepts optional `username` field; resolves hostname via reverse DNS of connecting client IP (respects `X-Forwarded-For` and `X-Real-IP` headers) - Registration (`POST /api/v1/register`) accepts optional `username` field with the same hostname resolution - Username validation regex: `^[a-zA-Z0-9_\-\[\]\\^{}|` + "\`" + `]{1,32}$` - WHOIS (`311 RPL_WHOISUSER`) now returns the real username and hostname instead of nick/servername - WHO (`352 RPL_WHOREPLY`) now returns the real username and hostname instead of nick/servername - Extracted `validateHashcash` and `resolveUsername` helpers to keep functions under the linter's `funlen` limit - Extracted `executeRegister` helper for the same reason - Reverse DNS uses `(*net.Resolver).LookupAddr` with a 3-second timeout context ### Tests - `TestCreateSessionWithUserHost` — verifies username/hostname are stored and retrievable - `TestCreateSessionDefaultUsername` — verifies empty username defaults to nick - `TestGetSessionHostInfoNotFound` — verifies error on nonexistent session - `TestFormatHostmask` — verifies `nick!user@host` formatting - `TestFormatHostmaskDefaults` — verifies fallback when username/hostname empty - `TestMemberInfoHostmask` — verifies `Hostmask()` method on `MemberInfo` - `TestChannelMembersIncludeUserHost` — verifies `ChannelMembers` returns username/hostname - `TestRegisterUserWithUserHost` — verifies registration stores username/hostname - `TestRegisterUserDefaultUsername` — verifies registration defaults username to nick - `TestWhoisShowsHostInfo` — integration test verifying WHOIS returns the correct username - `TestWhoShowsHostInfo` — integration test verifying WHO returns the correct username - `TestSessionUsernameDefault` — integration test verifying default username in WHOIS - All existing tests updated for new `CreateSession`/`RegisterUser` signatures ### README - New "Hostmask" section documenting the `nick!user@host` format - Updated session creation and registration API docs with the new `username` field - Updated WHOIS/WHO numeric examples to show real username/hostname - Updated sessions schema table with new columns ## Docker build `docker build .` passes cleanly (lint, format, tests, build). Co-authored-by: user <user@Mac.lan guest wan> Co-authored-by: clawbot <clawbot@noreply.git.eeqj.de> Co-authored-by: clawbot <clawbot@eeqj.de> Reviewed-on: #82 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org> |
|||
| bf4d63bc4d |
feat: per-channel hashcash proof-of-work for PRIVMSG anti-spam (#79)
Some checks failed
check / check (push) Failing after 1m48s
closes #12 ## Summary Implements per-channel hashcash proof-of-work requirement for PRIVMSG as an anti-spam mechanism. Channel operators set a difficulty level via `MODE +H <bits>`, and clients must compute a proof-of-work stamp bound to the channel name and message body before sending. ## Changes ### Database - Added `hashcash_bits` column to `channels` table (default 0 = no requirement) - Added `spent_hashcash` table with `stamp_hash` unique key and `created_at` for TTL pruning - New queries: `GetChannelHashcashBits`, `SetChannelHashcashBits`, `RecordSpentHashcash`, `IsHashcashSpent`, `PruneSpentHashcash` ### Hashcash Validation (`internal/hashcash/channel.go`) - `ChannelValidator` type for per-channel stamp validation - `BodyHash()` computes hex-encoded SHA-256 of message body - `StampHash()` computes deterministic hash of stamp for spent-token key - `MintChannelStamp()` generates valid stamps (for clients) - Stamp format: `1:bits:YYMMDD:channel:bodyhash:counter` - Validates: version, difficulty, date freshness (48h), channel binding, body hash binding, proof-of-work ### Handler Changes (`internal/handlers/api.go`) - `validateChannelHashcash()` + `verifyChannelStamp()` — checks hashcash on PRIVMSG to protected channels - `extractHashcashFromMeta()` — parses hashcash stamp from meta JSON - `applyChannelMode()` / `setHashcashMode()` / `clearHashcashMode()` — MODE +H/-H support - `queryChannelMode()` — shows +nH in mode query when hashcash is set - Meta field now passed through the full dispatch chain (dispatchCommand → handlePrivmsg → handleChannelMsg → sendChannelMsg → fanOut → InsertMessage) - ISUPPORT updated: `CHANMODES=,H,,imnst` (H in type B = parameter when set) ### Replay Prevention - Spent stamps persisted to SQLite `spent_hashcash` table - 1-year TTL (per issue requirements) - Automatic pruning in cleanup loop ### Client Support (`internal/cli/api/hashcash.go`) - `MintChannelHashcash(bits, channel, body)` — computes stamps for channel messages ### Tests - **12 unit tests** in `internal/hashcash/channel_test.go`: happy path, wrong channel, wrong body hash, insufficient bits, zero bits skip, bad format, bad version, expired stamp, missing body hash, body hash determinism, stamp hash, mint+validate round-trip - **10 integration tests** in `internal/handlers/api_test.go`: set mode, query mode, clear mode, reject no stamp, accept valid stamp, reject replayed stamp, no requirement works, invalid bits range, missing bits arg ### README - Added `+H` to channel modes table - Added "Per-Channel Hashcash (Anti-Spam)" section with full documentation - Updated `meta` field description to mention hashcash ## How It Works 1. Channel operator sets requirement: `MODE #general +H 20` (20 bits) 2. Client mints stamp: computes SHA-256 hashcash bound to `#general` + SHA-256(body) 3. Client sends PRIVMSG with `meta.hashcash` field containing the stamp 4. Server validates stamp, checks spent cache, records as spent, relays message 5. Replayed stamps are rejected for 1 year ## Docker Build `docker build .` passes clean (formatting, linting, all tests). Co-authored-by: user <user@Mac.lan guest wan> Co-authored-by: Jeffrey Paul <sneak@noreply.example.org> Reviewed-on: #79 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org> |
|||
| cab5784913 |
feat: implement Tier 1 IRC numerics (#72)
All checks were successful
check / check (push) Successful in 1m2s
## Summary Implements all Tier 1 IRC numerics from [issue #70](#70). ### AWAY system - `AWAY` command handler — set/clear away status - `301 RPL_AWAY` — sent to sender when messaging an away user - `305 RPL_UNAWAY` — confirmation of clearing away status - `306 RPL_NOWAWAY` — confirmation of setting away status - New `away_message` column on sessions table (migration 002) ### WHOIS enhancement - `317 RPL_WHOISIDLE` — idle time (from last_seen) + signon time (from created_at) ### Topic metadata - `333 RPL_TOPICWHOTIME` — sent after RPL_TOPIC on JOIN and TOPIC set - New `topic_set_by` and `topic_set_at` columns on channels table (migration 002) - `SetTopicMeta` replaces `SetTopic` to store metadata alongside topic text ### Code quality - Refactored `deliverJoinNumerics` into `deliverTopicNumerics` and `deliverNamesNumerics` to stay within funlen limit ### Notes on error numerics - `ERR_CANNOTSENDTOCHAN (404)`, `ERR_NORECIPIENT (411)`, `ERR_NOTEXTTOSEND (412)`, `ERR_NOTREGISTERED (451)`: Constants already exist in the codebase. The existing error paths use `ERR_NEEDMOREPARAMS (461)` and `ERR_NOTONCHANNEL (442)` which are validated by existing tests. Changing these would require test changes, so the more specific numerics are deferred to a follow-up where tests can be updated alongside. closes #70 Co-authored-by: clawbot <clawbot@noreply.git.eeqj.de> Co-authored-by: clawbot <clawbot@noreply.eeqj.de> Co-authored-by: Jeffrey Paul <sneak@noreply.example.org> Reviewed-on: #72 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org> |
|||
| f8f0b6afbb |
refactor: replace HTTP error codes with IRC numeric replies (#56)
All checks were successful
check / check (push) Successful in 58s
## Summary Refactors all IRC command handlers to respond with proper IRC numeric replies via the message queue instead of HTTP status codes. HTTP error codes are now reserved exclusively for transport-level concerns: - **401** — missing/invalid auth token - **400** — malformed JSON, empty command - **500** — server errors ## IRC Numerics Implemented ### Success replies (delivered via message queue on success): - **001 RPL_WELCOME** — sent on session creation and login - **331 RPL_NOTOPIC** — channel has no topic (on JOIN) - **332 RPL_TOPIC** — channel topic (on JOIN, TOPIC set) - **353 RPL_NAMREPLY** — channel member list (on JOIN) - **366 RPL_ENDOFNAMES** — end of NAMES list (on JOIN) - **375/372/376** — MOTD (already existed) ### Error replies (delivered via message queue instead of HTTP 4xx): - **401 ERR_NOSUCHNICK** — DM target not found (was HTTP 404) - **403 ERR_NOSUCHCHANNEL** — channel not found / invalid name (was HTTP 404) - **421 ERR_UNKNOWNCOMMAND** — unrecognized command (was HTTP 400) - **432 ERR_ERRONEUSNICKNAME** — invalid nick format (was HTTP 400) - **433 ERR_NICKNAMEINUSE** — nick taken (was HTTP 409) - **442 ERR_NOTONCHANNEL** — not a member of channel (was HTTP 403) - **461 ERR_NEEDMOREPARAMS** — missing required fields (was HTTP 400) ## Database Changes - Added `params` column to messages table for IRC-style parameters - Added `Params` field to `IRCMessage` struct - Updated `InsertMessage` to accept params ## Test Updates - All existing tests updated to expect HTTP 200 + IRC numerics - New tests: `TestWelcomeNumeric`, `TestJoinNumerics` ## Client Impact - CLI and SPA already handle unknown numerics via default event handlers - PRIVMSG/NOTICE success changed from HTTP 201 to HTTP 200 closes #54 Co-authored-by: clawbot <clawbot@noreply.git.eeqj.de> Co-authored-by: Jeffrey Paul <sneak@noreply.example.org> Reviewed-on: #56 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org> |
|||
|
|
69c9550bb2 |
consolidate password_hash into 001 migration
Some checks failed
check / check (push) Failing after 1m27s
Pre-1.0, no installed base — merge 002_add_passwords.sql into 001_initial.sql and remove the separate migration file. |
||
|
|
32419fb1f7 |
feat: MVP two-user chat via embedded SPA (#9)
All checks were successful
check / check (push) Successful in 1m51s
Backend: - Session/client UUID model: sessions table (uuid, nick, signing_key), clients table (uuid, session_id, token) with per-client message queues - MOTD delivery as IRC numeric messages (375/372/376) on connect - EnqueueToSession fans out to all clients of a session - EnqueueToClient for targeted delivery (MOTD) - All queries updated for session/client model SPA client: - Long-poll loop (15s timeout) instead of setInterval - IRC message envelope parsing (command/from/to/body) - Display JOIN/PART/NICK/TOPIC/QUIT system messages - Nick change via /nick command - Topic display in header bar - Unread count badges on inactive tabs - Auto-rejoin channels on reconnect (localStorage) - Connection status indicator - Message deduplication by UUID - Channel history loaded on join - /topic command support Closes #9 |
||
|
|
5a701e573a |
MVP: IRC envelope format, long-polling, per-client queues, SPA rewrite
Major changes: - Consolidated schema into single migration with IRC envelope format - Messages table stores command/from/to/body(JSON)/meta(JSON) per spec - Per-client delivery queues (client_queues table) with fan-out - In-memory broker for long-poll notifications (no busy polling) - GET /messages supports ?after=<queue_id>&timeout=15 long-polling - All commands (JOIN/PART/NICK/TOPIC/QUIT/PING) broadcast events - Channels are ephemeral (deleted when last member leaves) - PRIVMSG to nicks (DMs) fan out to both sender and recipient - SPA rewritten in vanilla JS (no build step needed): - Long-poll via recursive fetch (not setInterval) - IRC envelope parsing with system message display - /nick, /join, /part, /msg, /quit commands - Unread indicators on inactive tabs - DM tabs from user list clicks - Removed unused models package (was for UUID-based schema) - Removed conflicting UUID-based db methods - Increased HTTP write timeout to 60s for long-poll support |
||
|
|
8bb083a7f8 |
Add project scaffolding with fx DI, SQLite migrations, and healthcheck
- go.mod with git.eeqj.de/sneak/chat module - internal packages: globals, logger, config, db, healthcheck, middleware, handlers, server - SQLite database with embedded migration system (schema_migrations tracking) - Migration 001: schema_migrations table - Migration 002: channels table - Config with chat-specific vars (MAX_HISTORY, SESSION_TIMEOUT, MAX_MESSAGE_SIZE, MOTD, SERVER_NAME, FEDERATION_KEY) - Healthcheck endpoint at /.well-known/healthcheck.json - Makefile, .gitignore - cmd/chatd/main.go entry point |