233 Commits

Author SHA1 Message Date
delthas
56f2464404 Add support for the extended-join capability
This simple implementation only advertises extended-join to downstreams
when all upstreams support it.

In the future, it could be modified so that soju buffers incoming
upstream JOINs, sends a WHO, waits for the reply, and sends an extended
join to the downstream; so that soju could advertise that capability
even when some or all upstreams do not support it. This is not the case
in this commit.

git-svn-id: file:///srv/svn/repo/suika/trunk@419 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-09-10 22:10:58 +00:00
contact
b844d9f7bd Fix panic in downstreamConn.sendNetworkHistory
This panic happens when sending history to a multi-upstream client.
sendNetworkHistory is called on each network, but dc.network is nil.

Closes: https://todo.sr.ht/~emersion/soju/93

git-svn-id: file:///srv/svn/repo/suika/trunk@413 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-26 13:28:10 +00:00
contact
f9a89d4f22 Fix downstream PING argument handling
The PONG message should have these arguments:

- Our server name
- The PING message's source name

Closes: https://todo.sr.ht/~emersion/soju/92

git-svn-id: file:///srv/svn/repo/suika/trunk@412 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-26 13:18:57 +00:00
contact
d5af5da512 Allow '/' in nickname
This allows to specify a network name in the nickname.

Closes: https://todo.sr.ht/~emersion/soju/91

git-svn-id: file:///srv/svn/repo/suika/trunk@411 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-25 09:49:22 +00:00
contact
922e9512f2 Nuke in-memory ring buffer
Instead, always read chat history from logs. Unify the implicit chat
history (pushing history to clients) and explicit chat history
(via the CHATHISTORY command).

Instead of keeping track of ring buffer cursors for each client, use
message IDs.

If necessary, the ring buffer could be re-introduced behind a
common MessageStore interface (could be useful when on-disk logs are
disabled).

References: https://todo.sr.ht/~emersion/soju/80

git-svn-id: file:///srv/svn/repo/suika/trunk@409 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-20 18:05:01 +00:00
contact
1e0a17e1e9 Replace networkHistory.offlineClients with clients
Keep the ring buffer alive even if all clients are connected. Keep the
ID of the latest delivered message even for online clients.

As-is, this is a net downgrade: memory usage increases because ring
buffers aren't free'd anymore. However upcoming commits will replace the
ring buffer with log files. This change makes reading from log files
easier.

git-svn-id: file:///srv/svn/repo/suika/trunk@406 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-20 15:38:57 +00:00
hubert
d102dd2fa0 Reject downstream NICK with illegal characters
This should avoid confusion when mixing up nickname and user name.
Also it avoid breaking downstreams (since '@' and '!' are used for host
masks).

git-svn-id: file:///srv/svn/repo/suika/trunk@404 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-20 08:00:58 +00:00
hubert
f95079a5b7 More explicit error message on INVITE with the wrong network
git-svn-id: file:///srv/svn/repo/suika/trunk@401 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-20 07:13:38 +00:00
hubert
da24989ccf More explicit error message on KICK with the wrong network
git-svn-id: file:///srv/svn/repo/suika/trunk@400 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-19 21:57:25 +00:00
contact
5ae82a781a Implement rate limiting for upstream messages
Allow up to 10 outgoing messages in a burst, then throttle to 1 message
each 2 seconds.

Closes: https://todo.sr.ht/~emersion/soju/87

git-svn-id: file:///srv/svn/repo/suika/trunk@398 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-19 17:42:33 +00:00
contact
c7e29a966a Extract history loading into functions
These will get re-used for sending history to clients that don't support
the chathistory extension.

git-svn-id: file:///srv/svn/repo/suika/trunk@387 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 13:58:50 +00:00
contact
9e9565daf0 go fmt
git-svn-id: file:///srv/svn/repo/suika/trunk@362 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-22 10:16:01 +00:00
contact
803dbabd4f Implement CHATHISTORY AFTER
References: https://todo.sr.ht/~emersion/soju/12

git-svn-id: file:///srv/svn/repo/suika/trunk@360 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-15 15:47:57 +00:00
contact
6ba63d0774 Strip network name from nickname when auto-saving network
git-svn-id: file:///srv/svn/repo/suika/trunk@354 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-06 16:13:40 +00:00
contact
51df0c157e Add RemoteAddr to ircConn interface
git-svn-id: file:///srv/svn/repo/suika/trunk@347 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-01 15:02:37 +00:00
contact
35c7c0df7f Reply to WHO BouncerServ
Closes: https://todo.sr.ht/~emersion/soju/75

git-svn-id: file:///srv/svn/repo/suika/trunk@343 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-29 16:09:48 +00:00
hubert
a23ecb0998 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

git-svn-id: file:///srv/svn/repo/suika/trunk@340 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-24 21:02:46 +00:00
contact
f38af41317 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

git-svn-id: file:///srv/svn/repo/suika/trunk@323 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-07 12:13:46 +00:00
contact
b70a72598e Fail auth on empty password in DB
git-svn-id: file:///srv/svn/repo/suika/trunk@322 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-06 10:52:22 +00:00
delthas
a079662c1b 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

git-svn-id: file:///srv/svn/repo/suika/trunk@319 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-05 21:50:31 +00:00
contact
5aef4e44a8 Introduce ircConn
This interface will allow a conn to be backed by a websocket.

git-svn-id: file:///srv/svn/repo/suika/trunk@315 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-04 15:27:57 +00:00
fox.cpp
5f49770e07 Implement upstream SASL EXTERNAL support
Closes: https://todo.sr.ht/~emersion/soju/47

git-svn-id: file:///srv/svn/repo/suika/trunk@307 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-02 09:24:22 +00:00
hubert.hirtz
5de3081265 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

git-svn-id: file:///srv/svn/repo/suika/trunk@306 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-01 16:57:20 +00:00
delthas
dd583107cd 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@303 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:48:08 +00:00
delthas
fde7afdd98 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).

git-svn-id: file:///srv/svn/repo/suika/trunk@301 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:46:31 +00:00
delthas
e144b62324 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@299 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:44:38 +00:00
delthas
105e3d19b4 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@298 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:43:46 +00:00
delthas
4ca2ebb98f 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@297 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:43:04 +00:00
delthas
fe27882fd8 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

git-svn-id: file:///srv/svn/repo/suika/trunk@296 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:42:38 +00:00
delthas
db16c9dde3 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@293 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-21 20:36:54 +00:00
delthas
e26684df0e 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@292 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-11 10:25:49 +00:00
contact
b8fccc5356 Add time tag to echo messages
Closes: https://todo.sr.ht/~emersion/soju/59

git-svn-id: file:///srv/svn/repo/suika/trunk@291 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-05 14:52:50 +00:00
delthas
c376666015 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@289 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 19:56:40 +00:00
contact
2773535389 Don't clear channel key on JOIN
Closes: https://todo.sr.ht/~emersion/soju/50

git-svn-id: file:///srv/svn/repo/suika/trunk@285 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 15:39:53 +00:00
contact
9f84047153 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@284 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 13:18:14 +00:00
contact
e74291b093 Remove network.upstream
This is an artifact from when we used locks. No need for this anymore.

git-svn-id: file:///srv/svn/repo/suika/trunk@279 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-30 08:25:16 +00:00
contact
7358bf75fd Add upstreamConn.caps
Instead of adding one field per capability, let's just have a map, just
like downstreamConn.

git-svn-id: file:///srv/svn/repo/suika/trunk@278 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 17:45:37 +00:00
contact
f83ec30f22 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@276 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 17:34:44 +00:00
contact
a8f599627e Add downstream support for cap-notify
git-svn-id: file:///srv/svn/repo/suika/trunk@275 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 17:34:38 +00:00
delthas
4e989436f1 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@268 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-24 16:26:44 +00:00
contact
c65eaa7d61 Fix typo
git-svn-id: file:///srv/svn/repo/suika/trunk@262 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 15:25:39 +00:00
contact
68bf575c9e Support sending history when upstream is disconnected
Previously, we were dropping the history.

git-svn-id: file:///srv/svn/repo/suika/trunk@261 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 15:23:35 +00:00
contact
e7cc0a7f2e Make downstreamConn.marshal{Entity,UserPrefix} take a network
This will be used when sending history while upstream is disconnected.

git-svn-id: file:///srv/svn/repo/suika/trunk@260 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 15:19:00 +00:00
contact
7c7a1d3326 Kill downstreamConn.marshal{Nick,Channel}
We can just use downstreamConn.marshalEntity instead.

git-svn-id: file:///srv/svn/repo/suika/trunk@259 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 14:57:33 +00:00
contact
0266f8711f Disallow marshalling for anotehr network
git-svn-id: file:///srv/svn/repo/suika/trunk@258 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 14:54:13 +00:00
contact
3bf8f6617c Unify downstreamConn.marshal{Entity,Nick,Channel}
We don't actually need to check if the entity is a channel.

git-svn-id: file:///srv/svn/repo/suika/trunk@257 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 14:33:56 +00:00
contact
fa4001be19 Add support for downstream batch & chathistory
git-svn-id: file:///srv/svn/repo/suika/trunk@256 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-15 09:29:15 +00:00
contact
52fb2bc261 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@253 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-10 17:22:47 +00:00
contact
1f25d77be5 Document downstreamConn.{,un}marshalEntity
git-svn-id: file:///srv/svn/repo/suika/trunk@249 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 20:30:54 +00:00
contact
6743b24d74 Centralize logged messages marshaling
This allows messages added to logs to be handled just like messages
added to the ring buffer.

git-svn-id: file:///srv/svn/repo/suika/trunk@245 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 17:45:29 +00:00