Commit Graph

70 Commits

Author SHA1 Message Date
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
e5bce700a9 Panic if isHighlight is called with empty nick
Let's make sure callers never do this. We'd go into an infinite
loop previously.
2023-04-16 21:22:08 +02: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
568de1d5d2 Drop unused partialCasemap() helper 2023-03-01 12:54:43 +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
Simon Ser
106d40dcd4 Upgrade to gopkg.in/irc.v4 2022-11-14 12:06:58 +01:00
Simon Ser
f646dc9ff2 irc: drop needMarshaling from applyChannelModes return values
Not used anymore.
2022-09-26 16:57:05 +02:00
Simon Ser
14cbd63412 Send MARKREAD push notifications
Allows clients to dismiss notifications when another client marks
the conversation as read.
2022-07-08 16:55:29 +02:00
Simon Ser
09f2cf8489 Don't provide name in channel casemapMap Set and ForEach
The name is already provided in the struct.
2022-06-06 10:05:31 +02:00
Simon Ser
657e25b25c Make casemapMap more type-safe
In addition to a type-safe getter, also define type-safe setters
and iterators.

References: https://lists.sr.ht/~emersion/soju-dev/patches/32777
2022-06-06 09:58:39 +02:00
Simon Ser
c8f9728ff6 Drop size arg from newCasemapMap
It's unused.
2022-06-06 09:23:17 +02:00
Simon Ser
4e40b498b1 Drop casemapMap.OriginalKey
It's unused.
2022-06-06 09:20:17 +02:00
Simon Ser
289a4e118a Move batch struct to upstream.go 2022-05-30 09:45:40 +02:00
Simon Ser
da8f626e51 xirc: add GenerateSASL 2022-05-30 09:41:47 +02:00
Simon Ser
f9c4ba636f xirc: move over Membership 2022-05-30 09:12:28 +02:00
Simon Ser
f3b06f4236 xirc: move over WHOX helpers 2022-05-29 18:33:29 +02:00
Simon Ser
9b37bd2eaa xirc: move over CapRegistry 2022-05-29 18:33:22 +02:00
Simon Ser
fa6f52ed08 xirc: encode tokens in GenerateIsupport 2022-05-29 18:24:10 +02:00
Simon Ser
c10d382a7d xirfc: move over message generation functions 2022-05-29 17:57:21 +02:00
Simon Ser
997fe723f0 xirc: move ChannelStatus over 2022-05-29 17:28:25 +02:00
Simon Ser
4af7a1b8e5 Rename join to generateJoin
For consistency with other functions.
2022-05-09 17:20:17 +02:00
Simon Ser
c50fb4a26d xirc: move command constants over 2022-05-09 17:18:51 +02:00
Simon Ser
b92afa7cca Introduce an xirc package 2022-05-09 16:15:00 +02:00
Simon Ser
3a7dee8128 Introduce a database package 2022-05-09 15:08:04 +02:00
Simon Ser
747263fc2d Simplify and improve WHOIS forwarding
Group together most WHOIS replies. While at it, add a few missing
replies.
2022-04-04 09:28:04 +02:00
Simon Ser
303c663d02 Refuse to change nick on bouncer connection
Also simplify the code.

Closes: https://todo.sr.ht/~emersion/soju/192
2022-04-01 14:55:36 +02:00
Simon Ser
16e43ee3a3 upstream: don't populate time tag for numerics
Allows us to save a few bytes, e.g. in WHO replies.
2022-03-22 21:14:02 +01:00
Simon Ser
78d9a84a6f Add support for RPL_VISIBLEHOST 2022-03-21 16:09:45 +01:00
Simon Ser
744c6e3f6d Enable bot mode for BouncerServ
See [1] for details.

[1]: https://ircv3.net/specs/extensions/bot-mode
2022-03-16 18:35:48 +01:00
Simon Ser
347a4979da irc: introduce capRegistry 2022-03-14 19:25:49 +01:00
Simon Ser
379e07f7d8 irc: simplify isHighlight 2022-02-25 11:32:09 +01:00
Simon Ser
1a56b2f658 Introduce formatServerTime
It's too easy to forget to convert to UTC.
2022-02-16 14:45:09 +01:00
Simon Ser
009bc29e09 Refactor generateWHOXReply
Isolate the field letter -> value logic into a separate function.
2022-02-09 15:16:54 +01:00
Simon Ser
fe564af756 Handle upstream multi-line SASL
References: https://todo.sr.ht/~emersion/soju/173
2021-12-10 10:46:41 +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
Hubert Hirtz
7fbaaefc9c Skip list/type A mode arguments
Type-A modes always have an argument[0], but soju doesn't care about
them since it doesn't keep track of mode lists (ban/invite/.. lists).

[0] https://modern.ircdocs.horse/#mode-message
> Type A: Modes that add or remove an address to or from a list. These
> modes MUST always have a parameter when sent from the server to a
> client.
2021-11-04 12:24:15 +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
a9a066faac Add bouncer MOTD
Closes: https://todo.sr.ht/~emersion/soju/137
2021-10-13 10:58:34 +02:00
Hubert Hirtz
b078ccaf7a Implement CHATHISTORY BETWEEN 2021-05-18 10:44:10 +02:00
Simon Ser
76e332b50a Move isHighlight to irc.go 2021-04-13 18:54:58 +02:00
Hubert Hirtz
70e5ed05b6 Make casemapping work over bytes instead of runes
Fixes a panic in partialCasemap when the input string was invalid UTF-8.
2021-04-13 12:48:46 +02:00
Simon Ser
6e5a307dc7 Introduce deliveredClientMap
Adds more semantics to map[string]string. Simplifies the complicated
mapStringStringCasemapMap type.
2021-03-26 11:21:14 +01:00
Hubert Hirtz
bdd0c7bc06
Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)

== What is casemapping? ==

see <https://modern.ircdocs.horse/#casemapping-parameter>

== Casemapping and multi-upstream ==

Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],

1. soju must also update the database accordingly to upstreams'
   casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
   that is a subset of all supported casemappings (here, ascii).

[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.

Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.

downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.

Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).

== Message forwarding and casemapping ==

downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user.  This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).

marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters.  ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).

== Casemapping changes ==

Casemapping changes are not fully supported by this patch and will
result in loss of history.  This is a limitation of the protocol and
should be solved by the RENAME spec.
2021-03-24 18:15:52 +01:00