Commit Graph

740 Commits

Author SHA1 Message Date
Simon Ser
f75ee272a4 Add context to network.storeClientDeliveryReceipts 2021-12-02 23:32:12 +01:00
Simon Ser
04b0c2fd6b Add context to upstreamConn.handleMessage 2021-12-02 23:27:12 +01:00
Simon Ser
a413681253 Cancel pending commands on downstream disconnect
If a client queues a high number of commands and then disconnects,
remove all of the pending commands. This avoids unnecessarily
sending commands whose results won't be used.
2021-12-02 19:29:44 +01:00
Simon Ser
1620344f0a Mark ACCOUNT_REQUIRED error as permanent connection failure
There's no point in retrying to connect in this case.
2021-12-02 17:58:56 +01:00
Simon Ser
fd9a935f3e Don't retry connecting on permanent failure
Closes: https://todo.sr.ht/~emersion/soju/164
2021-12-02 17:33:11 +01:00
Simon Ser
578020e553 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
2021-12-02 12:14:35 +01:00
Simon Ser
8acc07d591 Add soju_upstream_connect_errors_total metric 2021-12-02 11:15:51 +01:00
Simon Ser
d11216917b Fix upstream gauge metric
It wasn't decremented on error. While at it, increment it when
connecting to the upstream network.
2021-12-02 11:03:56 +01:00
Simon Ser
73287f242e Add context to connectToUpstream 2021-12-02 10:53:43 +01:00
Simon Ser
33a639ecf0 Validate address in user.checkNetwork 2021-12-01 15:57:54 +01:00
Simon Ser
43c440e600 Add "sasl status" command 2021-12-01 11:03:27 +01:00
Simon Ser
23fd727618 Add support for draft/account-registration proxying
This adds support for the draft/account-registration extension [1].
This allows downstreams to register on upstream networks.

[1]: https://ircv3.net/specs/extensions/account-registration
2021-11-30 12:02:54 +01:00
Simon Ser
e42b507377 doc/soju.1: add network create example 2021-11-30 09:26:07 +01:00
Simon Ser
522e20cca1 downstream: improve unmarshalEntityNetwork error message
Closes: https://todo.sr.ht/~emersion/soju/162
2021-11-29 16:41:52 +01:00
Simon Ser
c36192ab02 Return more descriptive auth failure errors 2021-11-29 13:14:16 +01:00
Simon Ser
e3d7c33bcd Remove sasl cap after registration if network doesn't support it
This will stop clients from trying to issue AUTHENTICATE requests
after connection registration.
2021-11-21 16:28:38 +01:00
Simon Ser
313c6e7f97 Add support for post-connection-registration upstream SASL auth
Once the downstream connection has logged in with their bouncer
credentials, allow them to issue more SASL auths which will be
redirected to the upstream network. This allows downstream clients
to provide UIs to login to transparently login to upstream networks.
2021-11-21 16:10:54 +01:00
Simon Ser
4e84b41592 Send RPL_LOGGEDIN with bouncer account in multi-upstream mode 2021-11-21 11:00:57 +01:00
Simon Ser
c2a5461cb8 Use RPL_LOGGEDIN/OUT to mirror upstream status
This will allow clients to properly show/hide UI to login and
register.
2021-11-19 19:21:48 +01:00
Simon Ser
b5a868bbcd Abort SASL if in-progress while completing registration
Implements the following recommendation from the spec:

> If the client completes registration (with CAP END, NICK, USER and any other
> necessary messages) while the SASL authentication is still in progress, the
> server SHOULD abort it and send a 906 numeric, then register the client
> without authentication.
2021-11-19 18:55:07 +01:00
Simon Ser
c6f5508765 Add missing account-notify to permanentUpstreamCaps 2021-11-19 11:55:22 +01:00
Thomas Vigouroux
4831b61186 Add CHATHISTORY LATEST support
This patch adds a bit more compliance to the chathistory IRCv3 specification.
2021-11-18 21:06:26 +01:00
Simon Ser
cec335ee9c contrib/clients: WeeChat 3.3 enables all IRCv3 caps by default 2021-11-18 21:05:58 +01:00
Simon Ser
ac4696a507 Disallow empty string for nick 2021-11-18 09:44:33 +01:00
Hubert Hirtz
dcc1eff130 Allow AUTHENTICATE before NICK
Now that dc.nick is not blank during registration, sasl replies from the
server are correct and cap handling can be a bit simplified.
2021-11-18 09:40:23 +01:00
Simon Ser
98af48d254 doc/per-user-ip: new documentation article 2021-11-17 18:04:14 +01:00
Simon Ser
254108bd99 Upgrade dependencies 2021-11-17 16:57:41 +01:00
Simon Ser
d722f56000 Add pprof HTTP server
This enables production debugging of the bouncer.

Closes: https://todo.sr.ht/~emersion/soju/155
2021-11-17 16:18:52 +01:00
Simon Ser
ea98ac042e Add Prometheus instrumentation for the database 2021-11-17 15:58:19 +01:00
Simon Ser
5a5c93a756 Add message counter metrics 2021-11-17 15:58:19 +01:00
Simon Ser
efc4c62725 Add number of upstream connections to metrics 2021-11-17 15:58:19 +01:00
Simon Ser
7fa8c78122 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.
2021-11-17 15:58:19 +01:00
Simon Ser
df6b161f55 Add basic active users and downstreams metrics 2021-11-17 15:58:19 +01:00
Simon Ser
8f8d7aab0e Add basic Prometheus metrics exporter
This only exports the default metrics for now.

References: https://todo.sr.ht/~emersion/soju/142
2021-11-17 15:58:18 +01:00
Simon Ser
4d3b640989 Update downstream caps/nick/realname before sending MOTD
The MOTD indicates the end of the registration's message burst, and
the server can send arbitrary messages before it.

Update the supported capabilities, the nick and the realname before
MOTD to make it so client logic that runs on MOTD can work with
up-to-date info.
2021-11-17 15:27:34 +01:00
Simon Ser
55840312b4 Add per-user IP addresses
The new upstream-user-ip directive allows bouncer operators to
assign one IP address per user.
2021-11-17 15:07:58 +01:00
Simon Ser
97152191ad Add timeout for downstream connection registration 2021-11-17 14:54:03 +01:00
Simon Ser
6143e6f12d Introduce conn.NewContext
This function wraps a parent context, and returns a new context
cancelled when the connection is closed. This will make it so
operations started from downstreamConn.handleMessage will be
cancelled when the connection is closed.
2021-11-17 13:13:55 +01:00
Simon Ser
eb47f0dcd7 Lift up context to downstreamConn.handleMessage 2021-11-17 12:38:08 +01:00
Simon Ser
e28332a5aa Add context arg to downstreamConn.welcome() 2021-11-17 12:33:30 +01:00
Simon Ser
e459dcdb76 Add context to downstreamConn.handleMessageUnregistered 2021-11-17 12:29:23 +01:00
Simon Ser
06ce0b8da9 Lower sanityCheckServer timeout to 15s
Should still be more than enough to connect even if the network is
somewhat flaky.
2021-11-17 12:12:40 +01:00
Simon Ser
47c8ec5238 Add context arg to sanityCheckServer
As a bonus, the timeout now applies to the whole TLS dial
operation. Before the timeout only applied to the net dial
operation, making it possible for a bad server to stall the request
by making the TLS handshake extremely slow.
2021-11-17 12:10:56 +01:00
Simon Ser
2381e14d6a Use background context in tests 2021-11-17 12:04:24 +01:00
Simon Ser
7160713ea9 contrib/znc-import: use background context 2021-11-17 11:56:16 +01:00
Simon Ser
0c5aa8cbff sojuctl: use background context 2021-11-17 11:54:28 +01:00
Simon Ser
3941f67380 Add config option to globally disable multi-upstream mode
Closes: https://todo.sr.ht/~emersion/soju/122
2021-11-17 11:41:11 +01:00
Simon Ser
61e6b2efa4 Set isMultiUpstream flag in downstreamConn.welcome()
This will make it easier to globally disable multi-upstream mode.
2021-11-17 11:22:26 +01:00
Simon Ser
ff44ea314e Add downstreamConn.isMultiUpstream 2021-11-17 11:17:09 +01:00
Simon Ser
73295e4fa7 Allow most config options to be reloaded
Closes: https://todo.sr.ht/~emersion/soju/42
2021-11-16 00:38:04 +01:00