Commit Graph

482 Commits

Author SHA1 Message Date
Simon Ser 01b28fa85d Use * instead of nick in some numeric replies
This argument is supposed to be the destination client, but is
useless. Simplify our functions by sending * instead.
2023-08-23 19:50:37 +02:00
Eric Mertens 3650446156 Pass MODE and TOPIC through for unjoined channels 2023-08-23 19:44:55 +02:00
Eric Mertens e43e472c53 Fix capability associated with account message-tag 2023-08-13 09:38:01 +02:00
Simon Ser 97cfb366b0 Replace soju.im/pre-away with draft/pre-away
The IRCv3 draft spec ended up being merged!
2023-08-03 20:14:46 +02:00
Simon Ser c36bb342fb Introduce soju.im/pre-away
The IRCv3 spec is stalled, so let's just ship a vendored extension
for now.

References: https://github.com/ircv3/ircv3-specifications/pull/514
2023-08-03 19:38:31 +02:00
Simon Ser c8d5c90d9d downstream: improve SASL error logging 2023-06-01 11:37:03 +02:00
Simon Ser fa33ce986c downstream: fix nick in auth error message
We were always printing "*" here.
2023-05-23 18:28:50 +02:00
Simon Ser 9b9fc60f62 Rename Config.Log{Driver,Path} to MsgStore 2023-05-23 11:23:38 +02:00
Simon Ser 6f01bd86c3 downstream: pass context to SendMessage
Just like upstream does.
2023-04-06 13:23:20 +02:00
Simon Ser 43e6febc15 downstream: error out if SASL PLAIN identity is specified 2023-04-05 21:18:57 +02:00
Simon Ser b3be05559b downstream: add support for ANONYMOUS SASL auth
This clears any saved SASL credentials.

Closes: https://todo.sr.ht/~emersion/soju/198
2023-04-05 21:15:18 +02:00
Simon Ser 92796248d2 downstream: rename downstreamRegistration.password to pass
This is more descriptive.
2023-04-05 20:30:34 +02:00
Simon Ser f6043e5b98 Stop setting *user in downstreamConn.register
Set it in downstreamConn.welcome instead. Makes it clearer that it
must not be accessed before welcome is called (because it can only
be accessed from the user goroutine).
2023-04-05 16:54:55 +02:00
Simon Ser c5079f7ac3 downstream: fix connection registration
Fixes: 1df1ccf91e ("downstream: take irc.Message in handleCap")
2023-04-05 16:53:18 +02:00
Simon Ser 8637550e68 downstream: inline authenticate function 2023-04-05 15:43:51 +02:00
Simon Ser 1df1ccf91e downstream: take irc.Message in handleCap 2023-04-05 14:35:51 +02:00
Simon Ser de02cb98fe downstream: return FAIL on unknown BOUNCER command before registration 2023-04-05 13:36:36 +02:00
Simon Ser f12f10a7bb downstream: return channel in cached WHO reply
References: https://github.com/ircdocs/modern-irc/pull/211
2023-04-05 10:54:43 +02:00
Simon Ser be6cc27981 downstream: set CLIENTTAGDENY=* when upstream is missing message-tags 2023-03-28 18:48:47 +02:00
Simon Ser 9579998e63 downstream: fix panic due to nil user in setUser
Fixes: 4ca8dfa37d ("downstream: fix nil pointer deref in downstreamConn.setUser")
2023-03-21 18:02:59 +01:00
Simon Ser 93af53c91d Prune old Web Push subscriptions 2023-03-17 00:00:50 +01:00
Simon Ser 4ca8dfa37d downstream: fix nil pointer deref in downstreamConn.setUser
References: https://lists.sr.ht/~emersion/soju-dev/%3CCR6PX9SU5FSO.3UR92LHKXOXML%40hades.moritz.sh%3E
2023-03-15 17:34:18 +01:00
Simon Ser 6b82ed990c downstream: fix nickCM out-of-sync with effective case-mapping
We were unconditionally using the ASCII case-mapping in updateNick(),
for instance.

Introduce downstreamConn.casemap to fix this, and use it everywhere.
2023-03-01 14:59:08 +01:00
Simon Ser aecff32103 Introduce UserUpdateFunc
References: https://todo.sr.ht/~emersion/soju/206
2023-03-01 14:16:33 +01:00
Simon Ser ebd101820b Migrate casemapMap to xirc 2023-03-01 13:52:33 +01:00
Simon Ser 2b7a83b676 Take case-mapping as param in newCasemapMap()
Avoids situations where we forget to initialize it.
2023-03-01 13:43:51 +01:00
Simon Ser de90648eaa Rename casemapMap.setCasemapping to setCaseMapping 2023-03-01 13:35:03 +01:00
Simon Ser 3eb2679612 Migrate case-mapping to xirc 2023-03-01 13:35:03 +01:00
Simon Ser 07cd1f2f5d Use generics for casemapMap 2023-03-01 13:15:38 +01:00
Simon Ser 3da6c23ad4 Pass-through ISUPPORT CASEMAPPING 2023-03-01 12:55:49 +01:00
Simon Ser 637b989a47 Add downstreamConn.updateCasemapping()
We weren't correctly updating nickCM.
2023-03-01 12:55:10 +01:00
Simon Ser ce38d16454 downstream: reset map with correct casemapping on MONITOR C 2023-02-28 19:11:39 +01:00
Simon Ser 36d6cb19a4 Move authError to auth package
This allows auth backends to customize the error message displayed
to the user.
2023-02-23 22:32:24 +01:00
Simon Ser 8f1f67f1f0 Rate limit Web Push checks
No need to re-check that a Web Push subscription is valid every
time a downstream connects. Mobile devices may reconnect pretty
frequently.

Check at most once a day.
2023-02-18 13:27:13 +01:00
delthas 1ccc7ce6d2 Add a database store for messages
This adds a new config option, `logs db`, which enables storing chat
logs in the soju database.

Regular store options, CHATHISTORY options, and SEARCH operations are
supported, like the fs logs backend.

Messages are stored in a new table, Message. In order to track the list
of targets we have messages for in an optimized manner, another database
is used: MessageTarget.

All new requests are backend by indexes so should be fast even with
hundreds of thousands of messages.

A contrib script is provided for migrating existing logs fs chat logs to
the database. It can be run with eg:

  go run ./contrib/migrate-logs/ logs/ sqlite3:soju.db

Co-authored-by: Simon Ser <contact@emersion.fr>
2023-02-17 14:13:43 +01:00
Simon Ser 47f0dd5b3f downstream: send MSGREFTYPES ISUPPORT
References: https://github.com/ircv3/ircv3-specifications/pull/510
2023-02-13 19:25:42 +01:00
delthas b920facdff service: Return the error rather than printing it
This enables callers to make the difference between a successful
service call and a failed one.
2023-02-06 15:15:09 +01:00
delthas d17c7d57f2 service: Enable running service commands without users
This enables support for global service contexts, that are run
independently from a user context.

These contexts are considered to be admin. They only have access
to admin commands, because those are relevant in a global context.
2023-02-06 15:15:09 +01:00
delthas 4bd600c651 service: Store the admin capability independently the user
We can acquire admin contexts independently of the user.

This is mainly for a future commit that will introduce events
without a user.
2023-02-06 15:15:09 +01:00
Simon Ser b4731cbd71 downstream: only send CHATHISTORY ISUPPORT when supported 2023-02-02 19:36:18 +01:00
Simon Ser ca2d666056 Auto-create users after external auth when enable-user-on-auth is on 2023-01-30 11:53:01 +01:00
Simon Ser c79fc0c19e Add support for SASL OAUTHBEARER 2023-01-30 11:53:01 +01:00
Simon Ser 63ca247354 Add infrastructure for external authentication 2023-01-30 11:53:01 +01:00
delthas e7a06fe208 service: refactor downstreamConn to serviceContext
This will enable running service commands from other contexts.
2023-01-18 15:12:33 +01:00
Simon Ser 59dfa05d13 downstream: set empty CHANTYPES for bouncer connection 2023-01-16 16:46:46 +01:00
Simon Ser f44e922c42 downstream: use ERR_BADCHANMASK for invalid channel name
It's more appropriate than ERR_NOSUCHCHANNEL.
2022-12-08 15:27:02 +01:00
Simon Ser 6d64c164a7 downstream: check channel name validity on JOIN
Avoid storing garbage in the DB.
2022-12-08 15:25:39 +01:00
Simon Ser ec2c0685dd Add WHO cache
This adds a new field to upstreams, members, which is a casemapped map
of upstream users known to the soju. The upstream users known to soju
are: self, any monitored user, and any user with whom we share a
channel.

The information stored for each upstream user corresponds to the info
that can be returned by a WHO/WHOX command.

We build the upstream user information both incrementally, capturing
information contained in JOIN and AWAY messages; and with the bulk user
information contained in WHO replies we receive.

This lets us build a user cache that can then be used to return
synthetic WHO responses to later WHO requests by downstreams.

This is useful because some networks (eg Libera) heavily throttle WHO
commands, and without this cache, any downstream connecting would send 1
WHO command per channel, so possibly more than a dozen WHO commands,
which soju then forwarded to the upstream as WHO commands.

With this cache most WHO commands can be cached and avoid sending
WHO commands to the upstream.

In order to cache the "flags" field, we synthetize the field from user
info we get from incremental messages: away status (H/G) and bot status
(B). This could result in incorrect values for proprietary user fields.
Support for the server-operator status (*) is also not supported.

Of note is that it is difficult to obtain a user "connected server"
field incrementally, so clients that want to maximize their WHO cache
hit ratio can use WHOX to only request fields they need, and in
particular not include the server field flag.

Co-authored-by: delthas <delthas@dille.cc>
2022-12-01 15:50:33 +01:00
delthas ac578823dc Fix clearing webpush targets after any MARKREAD
Previously, we would clear webpush targets after any MARKREAD.

Consider the following scenario (ignore any typos, this is crafted by
hand):

    <<< @time=2020-01-01T00:00:00Z PRIVMSG #foo :hi mark!
    <<< @time=2020-01-02T00:00:00Z PRIVMSG #foo :hi again mark!
    >>> MARKREAD #foo timestamp=2020-01-01T00:00:00Z
    >>> MARKREAD #foo timestamp=2020-01-02T00:00:00Z

The push target was previously cleared on the first MARKREAD, which
means that the second MARKREAD was never broadcast to Firebase, and all
devices would keep the "hi again mark!" notification indefinitely.

This changes the webpush target map so that we store a timestamp of the
last highlight we sent. We only clear the push target when sending a
MARKREAD that is at or after the last message.
2022-11-28 17:55:19 +01:00
delthas 897c21dbb4 Truncate message times to the second when using the FS message store
The FS message store truncates message times to the second.

This means that a message sent out as 2020-01-01T00:00:00.123Z could be
sent later as part of a CHATHISTORY batch as 2020-01-01T00:00:00.000Z,
which could cause issues in clients.

One such issue is a client sending a MARKREAD for
2020-01-01T00:00:00.000Z, with another client considering the
2020-01-01T00:00:00.123Z message it has as unread.

This fixes the issue by truncating all message times to the second when
using the FS message store.
2022-11-28 17:54:13 +01:00