Commit Graph

170 Commits

Author SHA1 Message Date
Simon Ser
1685ba23b3
Strip network name from nickname when auto-saving network 2020-07-06 18:13:40 +02:00
Simon Ser
3397965dea
Add RemoteAddr to ircConn interface 2020-07-01 17:02:37 +02:00
Simon Ser
90250f5be5
Reply to WHO BouncerServ
Closes: https://todo.sr.ht/~emersion/soju/75
2020-06-29 18:09:48 +02:00
Hubert Hirtz
cfb1de044e
Don't save corrupted NickServ credentials
soju saved most NickServ messages[0] as credentials because of a missing
`default` clause in the check of the NickServ command.

[0] messages that had at least a command and two other parameters
2020-06-24 23:02:46 +02:00
Simon Ser
d0cf1d2882
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
2020-06-07 14:13:46 +02:00
Simon Ser
4b3469335e
Fail auth on empty password in DB 2020-06-06 12:52:22 +02:00
delthas
f7894e612b 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
2020-06-05 23:50:31 +02:00
Simon Ser
283d4bf14c
Introduce ircConn
This interface will allow a conn to be backed by a websocket.
2020-06-04 17:27:57 +02:00
fox.cpp
203dc3df6a
Implement upstream SASL EXTERNAL support
Closes: https://todo.sr.ht/~emersion/soju/47
2020-06-02 11:24:22 +02:00
Hubert Hirtz
c43ce0da29
Send the full user mask in RPL_LOGGEDIN
As per the spec [1]:

    :server 900 <nick> <nick>!<ident>@<host> <account> :Now logged in

[1]: https://ircv3.net/specs/extensions/sasl-3.1
2020-06-01 18:57:20 +02:00
delthas
f4e0c51366
Add support for TAGMSG and client message tags
Previously we dropped all TAGMSG as well as any client message tag sent
from downstream.

This adds support for properly forwarding TAGMSG and client message tags
from downstreams and upstreams.

TAGMSG messages are intentionally not logged, because they are currently
typically used for +typing, which can generate a lot of traffic and is
only useful for a few seconds after it is sent.
2020-05-27 23:48:08 +02:00
delthas
f13a9c9d86
Send a label with all messages sent from downstream
This is preparatory work for forwarding errors of downstream-initiated
messages to their sender, as well as any other unknown message.

Preivously, we only sent labels (for labeled-response) for specific
downstream messages, such as WHO, where we knew the reply should only be
sent to that specific downstream.

However, in the case of an error of a message that is not labeled, the
error reply is not be tagged with a downstream id label and we can't
forward it to a specific downstream. It is not a good solution either to
forward this error to all downstreams.

This adds labels to all downstream-initiated messages (provided the
upstream supports it).
2020-05-27 23:46:31 +02:00
delthas
791cf4b887
Add support for downstream WHOIS nick/network nick/network
Many IRC clients use the query `WHOIS nick nick` rather than
`WHOIS nick` when querying a nick. The former command means to
specifically query the WHOIS on the server to which `nick` is connected,
which is useful to get information that is sometimes not propagated
between servers, such as idle time.

In the case where a downstream sends WHOIS nick/network nick/network in
multi-server mode, we need to unmarshal both fields.

Previously, we did not unmarshal those fields, and upstreams would
receive `WHOIS nick/network nick`, which is incorrect.

This adds support for unmarshaling the target field if it is the same as
the mask field, by simply using the unmarshaled nick that is already
computed from the mask.
2020-05-27 23:44:38 +02:00
delthas
a64e1d6761
Add support for downstream LIST to a single upstream
Sometimes, doing a LIST on a single upstream can be useful: if a user is
already connected to Rizon and freenode, sending a LIST will contain
tens of thousands of LIST replies that may not be useful if the user is
interested in another upstream.

This adds support for sending `LIST */network`, which follows the ELIST
M mask extension, that will only send LIST to that specific network. No
other masks are supported by this commit.
2020-05-27 23:43:46 +02:00
delthas
2d47d7067f
Add support for downstream NICK to a single upstream
Users often have different nicks on different upstreams, and we should
support changing the user nick on a single upstream.

This adds support for a new trivial extension, `NICK nick/network`,
which will change the nick on the specified network, and do nothing for
the other networks.
2020-05-27 23:43:04 +02:00
delthas
b3742cc731
Update downstream nicks in single-server mode and after NICK
Previously, the downstream nick was never changed, even when the
downstream sent a NICK message or was in single-server mode with a
different nick.

This adds support for updating the downstream nick in the following
cases:
- when a downstream sends NICK
- additionally, in single-server mode:
  - when a downstream connects and its single network is connected
  - when an upstream connects
  - when an upstream sends NICK
2020-05-27 23:42:38 +02:00
delthas
c88700ef18
Fix parsing MODE messages by updating channel memberships
Previously, we only considered channel modes in the modes of a MODE
messages, which means channel membership changes were ignored. This
resulted in bugs where users channel memberships would not be properly
updated and cached with wrong values. Further, mode arguments
representing entities were not properly marshaled.

This adds support for correctly parsing and updating channel memberships
when processing MODE messages. Mode arguments corresponding to channel
memberships updates are now also properly marshaled.

MODE messages can't be easily sent from history because marshaling these
messages require knowing about the upstream available channel types and
channel membership types, which is currently only possible when
connected. For now this is not an issue since we do not send MODE
messages in history.
2020-05-21 22:36:54 +02:00
delthas
732b581eb2
Add support for multiple user channel memberships
User channel memberships are actually a set of memberships, not a single
value. This introduces memberships, a type representing a set of
memberships, stored as an array of memberships ordered by descending
rank.

This also adds multi-prefix to the permanent downstream and upstream
capabilities, so that we try to get all possible channel memberships.
2020-05-11 12:25:49 +02:00
Simon Ser
81e4930931
Add time tag to echo messages
Closes: https://todo.sr.ht/~emersion/soju/59
2020-05-05 16:52:50 +02:00
delthas
40ee5e8405 Fix not properly marshaling self in single-server mode
In single-server mode, we don't need to add a /network suffix when
marshaling, but we still need to replace our nick with the downstream
nick.
2020-05-01 21:56:40 +02:00
Simon Ser
aa6f3a9954
Don't clear channel key on JOIN
Closes: https://todo.sr.ht/~emersion/soju/50
2020-05-01 17:39:53 +02:00
Simon Ser
d9186e994d
Add support for detached channels
Channels can now be detached by leaving them with the reason "detach",
and re-attached by joining them again. Upon detaching the channel is
no longer forwarded to downstream connections. Upon re-attaching the
history buffer is sent.
2020-05-01 15:18:14 +02:00
Simon Ser
e7e4311160
Remove network.upstream
This is an artifact from when we used locks. No need for this anymore.
2020-04-30 10:25:16 +02:00
Simon Ser
c4655f1492
Add upstreamConn.caps
Instead of adding one field per capability, let's just have a map, just
like downstreamConn.
2020-04-29 19:45:37 +02:00
Simon Ser
0c549d68c4
Add support for away-notify
This makes use of cap-notify to dynamically advertise support for
away-notify. away-notify is advertised to downstream connections if all
upstreams support it.
2020-04-29 19:34:44 +02:00
Simon Ser
394f2853ad
Add downstream support for cap-notify 2020-04-29 19:34:38 +02:00
delthas
19854b7ec7 Unmarshal nicks in texts of PRIVMSG and NOTICE from downstreams
When writing a PRIVMSG or NOTICE on a channel, it is very common to use
autocompletion to mention other users on that channel. When using soju
in multi-network mode, all users will have their nicked suffixed by
`/network`. This suffix should be removed before sending it upstream.

This adds support for removing all `/network` suffixes in messages sent
to a channel of that network.
2020-04-24 18:26:44 +02:00
Simon Ser
9c463b61ec
Fix typo 2020-04-16 17:25:39 +02:00
Simon Ser
3e80573765
Support sending history when upstream is disconnected
Previously, we were dropping the history.
2020-04-16 17:23:35 +02:00
Simon Ser
45e897c1c1
Make downstreamConn.marshal{Entity,UserPrefix} take a network
This will be used when sending history while upstream is disconnected.
2020-04-16 17:19:00 +02:00
Simon Ser
5cf876cb89
Kill downstreamConn.marshal{Nick,Channel}
We can just use downstreamConn.marshalEntity instead.
2020-04-16 16:57:33 +02:00
Simon Ser
96be0b5945
Disallow marshalling for anotehr network 2020-04-16 16:54:13 +02:00
Simon Ser
e508f2ca81
Unify downstreamConn.marshal{Entity,Nick,Channel}
We don't actually need to check if the entity is a channel.
2020-04-16 16:33:56 +02:00
Simon Ser
8e852cc7e4
Add support for downstream batch & chathistory 2020-04-15 11:29:15 +02:00
Simon Ser
db198335aa
Per-entity ring buffers
Instead of having one ring buffer per network, each network has one ring
buffer per entity (channel or nick). This allows history to be more
fair: if there's a lot of activity in a channel, it won't prune activity
in other channels.

We now track history sequence numbers per client and per network in
networkHistory. The overall list of offline clients is still tracked in
network.offlineClients.

When all clients have received history, the ring buffer can be released.

In the future, we should get rid of too-old offline clients to avoid
having to maintain history for them forever. We should also add a
per-user limit on the number of ring buffers.
2020-04-10 19:22:47 +02:00
Simon Ser
9f6e59195c
Document downstreamConn.{,un}marshalEntity 2020-04-07 22:30:54 +02:00
Simon Ser
3195809c30
Centralize logged messages marshaling
This allows messages added to logs to be handled just like messages
added to the ring buffer.
2020-04-07 19:45:29 +02:00
Simon Ser
dd08acc3ea
Make Ring.NewConsumer seq argument mandatory
There's no point in supporting a nil argument anymore.
2020-04-07 14:45:08 +02:00
Simon Ser
9692114f37
Make upstreamConn.produce log messages 2020-04-06 21:42:55 +02:00
Simon Ser
baadb964bc
Add origin argument to upstreamConn.produce 2020-04-06 21:34:45 +02:00
Simon Ser
1c17d25731
Remove downstreamConn.ourMessages
We can just do the filtering when dispatching the message.
2020-04-06 19:08:43 +02:00
Simon Ser
e1ea0d4fb5
Simplify ring consumer loop
No need to use Peek here.
2020-04-06 18:34:33 +02:00
Simon Ser
f0bc919885
Remove downstreamConn.ringConsumers
We no longer need long-lived ring buffer consumers now that
upstreamConn.produce dispatches messages to downstream connections.
2020-04-06 18:31:48 +02:00
Simon Ser
40ff14ec6c
Remove downstreamConn.lock
Everything is now accessed from the user goroutine now that the
per-network ring buffer goroutine is gone.
2020-04-06 18:23:39 +02:00
Simon Ser
d541587701
Remove channel from ring buffer consumers
This is unused.
2020-04-06 18:13:46 +02:00
Simon Ser
ad2c142c36
Remove per-network ring buffer goroutines
Just dispatch from the user goroutine. This allows removes a lot of complexity.
2020-04-06 18:05:36 +02:00
Simon Ser
0c06142ae9
Introduce upstreamConn.produce
The logic in this function is about to get more complicated. It'll soon
also dispatch messages in connected downstreams.
2020-04-06 17:28:49 +02:00
Simon Ser
e70bf9c42a
Add network.{createUpdate,delete}Channel
These are about to get more complicated as we move towards per-entity
ring buffers.
2020-04-05 15:04:52 +02:00
Simon Ser
ee8aae7a96
Add NOTICE messages to ring buffer
References: https://todo.sr.ht/~emersion/soju/33
2020-04-03 21:00:19 +02:00
Simon Ser
3d142cae9f
Add time tag to all messages 2020-04-03 20:48:23 +02:00