100 Commits

Author SHA1 Message Date
contact
f7264b0bef Retry on temporary net.Listener failure
Instead of stopping to listen, retry on temporary failure. This
can happen when running out of FDs.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@766 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2022-01-19 21:35:46 +00:00
contact
bafd6c3e41 server: cleanup user in defer
If a user goroutine panics, this correctly removes it from the
global map instead of leaving a dangling entry behind.

git-svn-id: file:///srv/svn/repo/suika/trunk@756 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-08 14:00:02 +00:00
contact
ab7067fa48 Add Logger.Debugf
Makes it easy to print debugging messages which aren't targeted at
the user. See [1] for motivation.

[1]: https://dave.cheney.net/2015/11/05/lets-talk-about-logging

git-svn-id: file:///srv/svn/repo/suika/trunk@747 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-06 17:35:49 +00:00
contact
608d415c30 Remove Logger.Print
Callers can just use Logger.Printf instead.

git-svn-id: file:///srv/svn/repo/suika/trunk@746 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-06 17:27:36 +00:00
contact
993177a2c0 Add exponential backoff when re-connecting to upstream
The first reconnection attempt waits for 1min, the second the 2min,
and so on up to 10min. There's a 1min jitter so that multiple failed
connections don't try to reconnect at the exact same time.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@735 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-02 11:14:35 +00:00
contact
1eaf9afc48 Add soju_upstream_connect_errors_total metric
git-svn-id: file:///srv/svn/repo/suika/trunk@734 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-02 10:15:51 +00:00
contact
ca58716f6c Add message counter metrics
git-svn-id: file:///srv/svn/repo/suika/trunk@711 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:58:19 +00:00
contact
867d701eed Add number of upstream connections to metrics
git-svn-id: file:///srv/svn/repo/suika/trunk@710 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:58:19 +00:00
contact
edb293a257 Add int64 gauge abstraction
We want to serve metrics via both BouncerServ and Prometheus. Add
a tiny abstraction to avoid updating multiple metrics at once.

git-svn-id: file:///srv/svn/repo/suika/trunk@709 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:58:19 +00:00
contact
f3ca203794 Add basic active users and downstreams metrics
git-svn-id: file:///srv/svn/repo/suika/trunk@708 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:58:19 +00:00
contact
7eaaf2b78f Add basic Prometheus metrics exporter
This only exports the default metrics for now.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@707 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:58:18 +00:00
contact
5161f92e29 Add per-user IP addresses
The new upstream-user-ip directive allows bouncer operators to
assign one IP address per user.

git-svn-id: file:///srv/svn/repo/suika/trunk@705 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:07:58 +00:00
contact
56e1247cf4 Add timeout for downstream connection registration
git-svn-id: file:///srv/svn/repo/suika/trunk@704 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 13:54:03 +00:00
contact
d473fb1a5d Add config option to globally disable multi-upstream mode
Closes: https://todo.sr.ht/~emersion/soju/122

git-svn-id: file:///srv/svn/repo/suika/trunk@694 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 10:41:11 +00:00
contact
8f1a6e4432 Allow most config options to be reloaded
Closes: https://todo.sr.ht/~emersion/soju/42

git-svn-id: file:///srv/svn/repo/suika/trunk@691 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-15 23:38:04 +00:00
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