Commit Graph

318 Commits

Author SHA1 Message Date
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
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
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
5a5c93a756 Add message counter metrics 2021-11-17 15:58:19 +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
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
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
Simon Ser
e44f4b2eee Don't send user in prefix for echo messages
This is not very useful and confuses clients.
2021-11-15 23:53:25 +01:00
delthas
37c1b3e29c Return an empty CHATHISTORY TARGETS batch when in multi-upstream
When on an unbound bouncer network downstream, we should return no
targets (there are none, because there are no upstreams at all).

When on a multi-upstream downstream, we should return no targets as we
don't support multi-upstream CHATHISTORY TARGETS.

Before this patch, we returned a misleading error message:
:example.com 403 :Missing network suffix in name
2021-11-15 21:30:04 +01:00
delthas
179991036c Send the downstream host for PRIVMSG echo messages
If a downstream of prefix host `foo` sends a message, the other
downstream of prefix host `bar` should receive an echo PRIVMSG with
prefix host bar.

This fixes a regression where no prefix host was sent at all.
2021-11-15 17:45:23 +01:00
delthas
840d142f1c Add support for draft/extended-monitor
References: https://github.com/ircv3/ircv3-specifications/pull/466
2021-11-15 14:38:19 +01:00
Simon Ser
5d46dd72a4 Add support for MONITOR
Add support for MONITOR in single-upstream mode.

Each downstream has its own set of monitored targets. These sets
are merged together to compute the MONITOR commands to send to
upstream.

Each upstream has a set of monitored targets accepted by the server
alongside with their status (online/offline). This is used to
directly send replies to downstreams adding a target another
downstream has already added, and send MONITOR S[TATUS] replies.

Co-authored-by: delthas <delthas@dille.cc>
2021-11-15 14:34:04 +01:00
Simon Ser
f920f27e02 Add ELIST support in single-upstream mode
We just forward the command as-is, so we can pass down the ISUPPORT
token as well.

Closes: https://todo.sr.ht/~emersion/soju/148
2021-11-09 22:12:46 +01:00
Simon Ser
0b6ff2e61a Add a queue for WHO commands
This has the following upsides:

- We can now routes WHO replies to the correct client, without
  broadcasting them to everybody.
- We are less likely to hit server rate limits when multiple downstreams
  are issuing WHO commands at the same time.
2021-11-09 22:09:17 +01:00
Simon Ser
0c360d24c5 Remove support for mixed multi-upstream LIST
Multi-upstream connections can still send LIST commands with a
network suffix.
2021-11-09 21:32:26 +01:00
Simon Ser
802e82c272 Add context support to service
References: https://todo.sr.ht/~emersion/soju/141
2021-11-08 19:40:48 +01:00
Simon Ser
c21202160c Add context support to user and network mutations
References: https://todo.sr.ht/~emersion/soju/141
2021-11-08 19:36:10 +01:00
Simon Ser
8b3e5e7465 Plumb context in downstreamConn.handleMessageRegistered
References: https://todo.sr.ht/~emersion/soju/141
2021-11-08 18:11:24 +01:00
Simon Ser
c2047dc1a8 Add plus sign in RPL_UMODEIS reply 2021-11-03 22:02:19 +01:00
Simon Ser
26cdb0d328 Set mode +o on admins for bouncer-only connections 2021-11-03 21:42:42 +01:00
Simon Ser
abe5f362db Turn CHATHISTORY and backlog limits into constants 2021-11-03 18:29:21 +01:00
Simon Ser
ce69f00e3f msgstore: add context to messageStore methods
This allows setting a hard timeout.
2021-11-03 18:21:05 +01:00
Simon Ser
2b4f0a870f msgstore: take Network as arg instead of network
The message stores don't need to access the internal network
struct, they just need network metadata such as ID and name.

This can ease moving message stores into a separate package in the
future.
2021-11-03 16:37:01 +01:00
delthas
03f8972305 Add support for draft/event-playback 2021-11-03 15:17:16 +01:00
Simon Ser
a6aa7f0008 Make Network.Nick optional
Make Network.Nick optional, default to the user's username. This
will allow adding a global setting to set the nickname in the
future, just like we have for the real name.

References: https://todo.sr.ht/~emersion/soju/110
2021-11-02 23:33:17 +01:00
Simon Ser
07c962018d Add title config option
Closes: https://todo.sr.ht/~emersion/soju/146
2021-11-02 22:38:07 +01:00
Simon Ser
832d8b89a2 Mark bouncer users and BouncerServ as authenticated in WHOX/WHOIS 2021-11-02 18:32:39 +01:00
Simon Ser
241e27b00e Add support for WHOX
This adds support for WHOX, without bothering about flags and mask2
because Solanum and Ergo [1] don't support it either.

The motivation is to allow clients to reliably query account names.

It's not possible to use WHOX tokens to route replies to the right
client, because RPL_ENDOFWHO doesn't contain it.

[1]: https://github.com/ergochat/ergo/pull/1184

Closes: https://todo.sr.ht/~emersion/soju/135
2021-11-02 18:25:43 +01:00
Simon Ser
8c7c907d6f Fix operator flag in RPL_WHOREPLY
@ and + indicate channel privileges. * indicates that the user is
a server operator.
2021-11-01 18:36:21 +01:00
Simon Ser
62d92c660f Mark admins as server operators in self WHO/WHOIS replies 2021-11-01 18:32:01 +01:00
Simon Ser
3ab8ef17df Mark BouncerServ as server operator
That's what some widely used IRC servers do for their own services
(e.g. NickServ and ChanServ). This adds an additional level of
trust to make sure BouncerServ isn't typo'ed or impersonated.
2021-11-01 18:28:19 +01:00
Simon Ser
aa407a46e6 Get rid of io.EOF errors in logs
Closes: https://todo.sr.ht/~emersion/soju/150
2021-10-29 16:03:04 +02:00