85 Commits

Author SHA1 Message Date
contact
f8cbb93de1 Add panic handlers for user and downstream goroutines
This only brings down a single user or downstream on panic, instead
or bringing down the whole bouncer.

Closes: https://todo.sr.ht/~emersion/soju/139

git-svn-id: file:///srv/svn/repo/suika/trunk@689 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-15 20:40:17 +00:00
contact
86ddd39b77 Add context support to Server.createUser
git-svn-id: file:///srv/svn/repo/suika/trunk@680 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-08 19:29:14 +00:00
contact
e3bb551273 Plumb context in downstreamConn.handleMessageRegistered
References: https://todo.sr.ht/~emersion/soju/141

git-svn-id: file:///srv/svn/repo/suika/trunk@675 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-08 17:11:24 +00:00
contact
9d67b78657 Turn CHATHISTORY and backlog limits into constants
git-svn-id: file:///srv/svn/repo/suika/trunk@670 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-03 17:29:21 +00:00
contact
58db345425 msgstore: add context to messageStore methods
This allows setting a hard timeout.

git-svn-id: file:///srv/svn/repo/suika/trunk@667 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-03 17:21:05 +00:00
contact
427638fa0d Add title config option
Closes: https://todo.sr.ht/~emersion/soju/146

git-svn-id: file:///srv/svn/repo/suika/trunk@662 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-02 21:38:07 +00:00
contact
3169170b8e Fix missing imports in server.go
Oops.

git-svn-id: file:///srv/svn/repo/suika/trunk@656 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-29 14:18:34 +00:00
contact
ba0f309c71 Get rid of io.EOF errors in logs
Closes: https://todo.sr.ht/~emersion/soju/150

git-svn-id: file:///srv/svn/repo/suika/trunk@655 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-29 14:03:04 +00:00
contact
2748715183 Add context args to Database interface
This is a mecanical change, which just lifts up the context.TODO()
calls from inside the DB implementations to the callers.

Future work involves properly wiring up the contexts when it makes
sense.

git-svn-id: file:///srv/svn/repo/suika/trunk@652 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-18 17:15:15 +00:00
contact
afd52fc4c3 Add bouncer MOTD
Closes: https://todo.sr.ht/~emersion/soju/137

git-svn-id: file:///srv/svn/repo/suika/trunk@636 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-13 08:58:34 +00:00
contact
8dda53c683 Add max-user-networks config option
git-svn-id: file:///srv/svn/repo/suika/trunk@612 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-07 18:43:10 +00:00
contact
ae7aef71b3 Add "server status" command
Right now, it prints the number of active users and number of
downstream connections.

git-svn-id: file:///srv/svn/repo/suika/trunk@605 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-05 17:13:53 +00:00
contact
f5c683daec Use isErrClosed in Server.Serve
git-svn-id: file:///srv/svn/repo/suika/trunk@601 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-05 12:02:59 +00:00
contact
15036cef1e Close DB on shutdown
git-svn-id: file:///srv/svn/repo/suika/trunk@599 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-05 09:53:38 +00:00
contact
caa77db7cd Add support for IRCv3 WebSocket text subprotocol
Technically we aren't spec-compliant since we don't serve
binary.ircv3.net. Any complaints will be redirected to /dev/null.

git-svn-id: file:///srv/svn/repo/suika/trunk@597 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-09-28 19:25:06 +00:00
contact
ae0ac7c6f0 Allow admins to broadcast message to all bouncer users
Typically done via:

    /notice $<bouncer> <message>

Or, for a connection not bound to a specific network:

    /notice $* <message>

The message is broadcast as BouncerServ, because that's the only
user that can be trusted to belong to the bouncer by users. Any
other prefix would conflict with the upstream network.

git-svn-id: file:///srv/svn/repo/suika/trunk@563 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-06-23 17:23:09 +00:00
sir
2f5c2a2edd db: refactor into interface
This refactors the SQLite-specific bits into db_sqlite.go. A future
patch will add PostgreSQL support.

git-svn-id: file:///srv/svn/repo/suika/trunk@531 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-05-25 14:35:39 +00:00
contact
e2bb6fad08 Stop reading X-Forwarded-Port
X-Forwarded-Port contains the destination port, not the source port,
so it isn't useful for our purposes.

Move parsing of X-Forwarded-* header fields to parseForwarded.

git-svn-id: file:///srv/svn/repo/suika/trunk@474 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-18 12:28:46 +00:00
contact
3e20658a2c Fix Forwarded HTTP header handling
"for" contains the port, if any. "port" doesn't exist.

git-svn-id: file:///srv/svn/repo/suika/trunk@473 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-18 12:21:38 +00:00
contact
40912ed72d Add support for the Forwarded HTTP header
This is the standard replacing X-Forwarded-*.

git-svn-id: file:///srv/svn/repo/suika/trunk@472 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-18 11:08:25 +00:00
contact
0fdfbbcb9b Drop "irc" WebSocket subprotocol
The subprotocol hasn't been standardized yet. It looks like the standard
is moving in another direction.

git-svn-id: file:///srv/svn/repo/suika/trunk@471 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-18 11:02:36 +00:00
contact
5a1f5eadd1 Add support for graceful shutdown
Closes: https://todo.sr.ht/~emersion/soju/45

git-svn-id: file:///srv/svn/repo/suika/trunk@449 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-02-09 16:34:46 +00:00
contact
922e9512f2 Nuke in-memory ring buffer
Instead, always read chat history from logs. Unify the implicit chat
history (pushing history to clients) and explicit chat history
(via the CHATHISTORY command).

Instead of keeping track of ring buffer cursors for each client, use
message IDs.

If necessary, the ring buffer could be re-introduced behind a
common MessageStore interface (could be useful when on-disk logs are
disabled).

References: https://todo.sr.ht/~emersion/soju/80

git-svn-id: file:///srv/svn/repo/suika/trunk@409 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-20 18:05:01 +00:00
contact
5ae82a781a Implement rate limiting for upstream messages
Allow up to 10 outgoing messages in a burst, then throttle to 1 message
each 2 seconds.

Closes: https://todo.sr.ht/~emersion/soju/87

git-svn-id: file:///srv/svn/repo/suika/trunk@398 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-19 17:42:33 +00:00
contact
d4a0c5bd48 Add an ident server
Closes: https://todo.sr.ht/~emersion/soju/69

git-svn-id: file:///srv/svn/repo/suika/trunk@385 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 08:59:06 +00:00
contact
0dddc73278 Remove user from Server map when stopped
git-svn-id: file:///srv/svn/repo/suika/trunk@378 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-10 13:03:38 +00:00
contact
1e0e265c48 Add accept-proxy-ip config directive
This allows to set the list of IPs allowed to act as a proxy. This is
only used for WebSockets right now, but will be expanded to TCP as well
once the PROXY protocol is supported.

git-svn-id: file:///srv/svn/repo/suika/trunk@370 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-22 15:03:01 +00:00
contact
3367f4ebd8 Accept "irc" WebSocket subprotocol
git-svn-id: file:///srv/svn/repo/suika/trunk@348 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-02 09:05:49 +00:00
contact
51df0c157e Add RemoteAddr to ircConn interface
git-svn-id: file:///srv/svn/repo/suika/trunk@347 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-01 15:02:37 +00:00
contact
e9f9453cba Only read X-Forwarded-* if remote address is loopback
git-svn-id: file:///srv/svn/repo/suika/trunk@345 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-29 16:33:23 +00:00
contact
d97de5552f Extract X-Forwarded-* headers for WebSocket connections
git-svn-id: file:///srv/svn/repo/suika/trunk@344 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-29 16:27:43 +00:00
delthas
6a71f953cb Add support for the user create admin service command
This adds support for user create, a new service command only accessible
to admin users. This lets users create other users on the fly and makes
soju start the user routine immediately; unlike sojuctl which currently
requires closing soju, creating the user, and starting soju again.

git-svn-id: file:///srv/svn/repo/suika/trunk@329 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-08 20:30:09 +00:00
contact
f38af41317 Add support for WebSocket connections
WebSocket connections allow web-based clients to connect to IRC. This
commit implements the WebSocket sub-protocol as specified by the pending
IRCv3 proposal [1].

WebSocket listeners can now be set up via a "wss" protocol in the
`listen` directive. The new `http-origin` directive allows the CORS
allowed origins to be configured.

[1]: https://github.com/ircv3/ircv3-specifications/pull/342

git-svn-id: file:///srv/svn/repo/suika/trunk@323 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-07 12:13:46 +00:00
delthas
a079662c1b Add support for downstream CHATHISTORY
This adds support for the WIP (at the time of this commit)
draft/chathistory extension, based on the draft at [1] and the
additional comments at [2].

This gets the history by parsing the chat logs, and is therefore only
enabled when the logs are enabled and the log path is configured.

Getting the history only from the logs adds some restrictions:
- we cannot get history by msgid (those are not logged)
- we cannot get the users masks (maybe they could be inferred from the
  JOIN etc, but it is not worth the effort and would not work every
  time)

The regular soju network history is not sent to clients that support
draft/chathistory, so that they can fetch what they need by manually
calling CHATHISTORY.

The only supported command is BEFORE for now, because that is the only
required command for an app that offers an "infinite history scrollback"
feature.

Regarding implementation, rather than reading the file from the end in
reverse, we simply start from the beginning of each log file, store each
PRIVMSG into a ring, then add the last lines of that ring into the
history we'll return later. The message parsing implementation must be
kept somewhat fast because an app could potentially request thousands of
messages in several files. Here we are using simple sscanf and indexOf
rather than regexps.

In case some log files do not contain any message (for example because
the user had not joined a channel at that time), we try up to a 100 days
of empty log files before giving up.

[1]: https://github.com/prawnsalad/ircv3-specifications/pull/3/files
[2]: https://github.com/ircv3/ircv3-specifications/pull/393/files#r350210018

git-svn-id: file:///srv/svn/repo/suika/trunk@319 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-05 21:50:31 +00:00
contact
17b8361e8b Remove keepAlivePeriod
This is a remnant of setKeepAlive.

Fixes: 77faf72fa33a ("Remove setKeepAlive")

git-svn-id: file:///srv/svn/repo/suika/trunk@316 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-04 16:38:04 +00:00
contact
7e2bd554a4 Introduce conn for common connection logic
This centralizes the common upstream & downstream bits.

git-svn-id: file:///srv/svn/repo/suika/trunk@210 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 14:35:08 +00:00
contact
0e879e79d8 Set connect timeout
References: https://todo.sr.ht/~emersion/soju/26

git-svn-id: file:///srv/svn/repo/suika/trunk@206 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 14:41:17 +00:00
contact
db1e84ce20 Set write deadlines
References: https://todo.sr.ht/~emersion/soju/26

git-svn-id: file:///srv/svn/repo/suika/trunk@205 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 14:27:53 +00:00
delthas
3ac0e6bd4d Add support for bouncer logs
Add bouncer logs, in a network/channel/date.log format, in a similar
manner to ZNC log module. PRIVMSG, JOIN, PART, QUIT, MODE are logged.

Add a config directive for the logs file, including a way to disable
them entirely.

git-svn-id: file:///srv/svn/repo/suika/trunk@178 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 23:07:20 +00:00
contact
ff41376348 Get rid of Server.downstreamConns
This is unused right now. Let's remove it, we'll add it back if we
really need it.

git-svn-id: file:///srv/svn/repo/suika/trunk@172 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 21:24:12 +00:00
contact
520585d901 Add eventDownstreamDisconnected
This should remove the need for protecting user.downstreamConns with a
mutex.

git-svn-id: file:///srv/svn/repo/suika/trunk@167 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 16:55:03 +00:00
contact
0def23b671 Add eventDownstreamConnected
In a later commit, we'll be able to move part of downstreamConn.register
into the user goroutine to prevent races.

References: https://todo.sr.ht/~emersion/soju/22

git-svn-id: file:///srv/svn/repo/suika/trunk@166 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 16:21:05 +00:00
contact
f4631f5dd6 Introduce a user.events channel
This allows to easily add new events, and also guarantees ordering
between different event types.

git-svn-id: file:///srv/svn/repo/suika/trunk@165 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 15:33:19 +00:00
delthas
472306d40a Add a server-unique id to each downstream
Adding a simple uint64 id to each downstream is preparatory work
for labeled-responses tags targeting a specific downstream.

git-svn-id: file:///srv/svn/repo/suika/trunk@154 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-25 22:17:46 +00:00
contact
55f987eb29 Per-user dispatcher goroutine
This allows message handlers to read upstream/downstream connection
information without causing any race condition.

References: https://todo.sr.ht/~emersion/soju/1

git-svn-id: file:///srv/svn/repo/suika/trunk@103 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-16 11:44:59 +00:00
contact
f169a0a35a Split user logic into its own file
git-svn-id: file:///srv/svn/repo/suika/trunk@101 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-16 10:18:41 +00:00
contact
1a9d6a58a0 Rename project to soju
git-svn-id: file:///srv/svn/repo/suika/trunk@98 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-13 17:13:03 +00:00
contact
ad42226219 Auto-save IRC networks
git-svn-id: file:///srv/svn/repo/suika/trunk@91 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-12 20:28:09 +00:00
contact
9eb7349674 Store NICK changes in the DB
git-svn-id: file:///srv/svn/repo/suika/trunk@90 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-12 18:17:06 +00:00
contact
c75d825938 go fmt
git-svn-id: file:///srv/svn/repo/suika/trunk@79 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-04 18:23:24 +00:00