243 Commits

Author SHA1 Message Date
delthas
a97dcd348b Fix sending messages from detached channels
Currently, a downstream receives MODE, RPL_CHANNELMODEIS and
RPL_CREATIONTIME messages from soju for detached channels. It should not
be sent any of these messages.

This adds a detach check to the handling of these messages to avoid
receiving these messages.

git-svn-id: file:///srv/svn/repo/suika/trunk@338 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-12 12:43:45 +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
fox.cpp
69e7615895 Fix handling of empty response to SASL challenge
git-svn-id: file:///srv/svn/repo/suika/trunk@318 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-05 09:35:43 +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
contact
cc7baf5863 Only send JOIN message if we have channels to join
Don't send a JOIN command to upstream server when no channels are configured.

git-svn-id: file:///srv/svn/repo/suika/trunk@310 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-03 15:18: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
ecs
bd6074df78 Join all channels with a single JOIN message
git-svn-id: file:///srv/svn/repo/suika/trunk@305 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-28 14:26:28 +00:00
delthas
0f15604644 Fix parsing upstream RPL_INVITING messages
Previously, we did not skip the first RPL_INVITING parameter, which is
the user nick (like in all replies), which made the parsing for that
reply incorrect.

This fixes RPL_INVITING parsing by skipping the first parameter.

git-svn-id: file:///srv/svn/repo/suika/trunk@304 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:51:44 +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
85d6b50f07 Forward all labeled errors and unknown messages to their downstream
This adds support for forwarding all errors and unknown messages labeled
with a specific downstream to that downstream.

Provided that the upstream supports labeled-response, users will now be
able to receive an error only on their client when making a command that
returns an error, as well as receiving any reply unknown to soju.

git-svn-id: file:///srv/svn/repo/suika/trunk@302 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:47:49 +00:00
delthas
d4088ba6a9 Add support for upstream ban, invite, and exception lists
This does not try to marshal nicks in masks, for simplicity and
consistency with the current behaviour of marshaling MODE messages.

git-svn-id: file:///srv/svn/repo/suika/trunk@300 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:45:13 +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
5740d21ec1 Fix sending CAP END twice when SASL is not used
When SASL is not used, we should only send CAP END after we send a CAP
REQ. Previously CAP END was sent both after a CAP REQ and a CAP ACK,
resulting in two CAP END messages.

Sending a CAP END right after the CAP REQ rather than waiting for the
CAP ACK/NAK saves 1 RTT.

git-svn-id: file:///srv/svn/repo/suika/trunk@295 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-21 20:38:07 +00:00
delthas
087d9b5493 Fix a null access due to assigning nil to the member memberships map
Even though the memberships map has type map[string]*memberships
(with memberships being defined as []membership), the default value for
that map should not be `nil` but a pointer to a nil slice.

This fixes a segfault on some servers before user channel prefixes are
sent.

git-svn-id: file:///srv/svn/repo/suika/trunk@294 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-21 20:37:37 +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
21f8ed867d Improve highlight matching
Detect word boundaries instead of just doing a sub-string check.

git-svn-id: file:///srv/svn/repo/suika/trunk@288 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 17:51:22 +00:00
contact
87317b6890 Send service NOTICE on highlight in detached channel
git-svn-id: file:///srv/svn/repo/suika/trunk@287 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 17:05:20 +00:00
contact
dd03f558ae Unify upstream NOTICE and PRIVMSG handling
git-svn-id: file:///srv/svn/repo/suika/trunk@286 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 16:12:47 +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
13cdcb19d9 Introduce permanentUpstreamCaps
git-svn-id: file:///srv/svn/repo/suika/trunk@282 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-30 14:10:39 +00:00
contact
f0544a8932 Add upstream cap-notify support
git-svn-id: file:///srv/svn/repo/suika/trunk@281 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-30 13:27:41 +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
9f64fc5a93 Rename upstreamConn.caps to supportedCaps
For consistency with downstreamConn.

git-svn-id: file:///srv/svn/repo/suika/trunk@277 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 17:40:31 +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
baccde5a95 Don't use forEachDownstreamByID when forwarding RPL_AWAY
We should broadcast the message, not send it to a specific downstream
connection.

git-svn-id: file:///srv/svn/repo/suika/trunk@274 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 13:32:22 +00:00
contact
ec0e6f5f34 Check upstream NOTICE prefix is non-nil
git-svn-id: file:///srv/svn/repo/suika/trunk@273 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 13:00:17 +00:00
contact
9c54b44ca1 Forward RPL_AWAY messages
git-svn-id: file:///srv/svn/repo/suika/trunk@272 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 12:53:48 +00:00
delthas
67237abdea Add support for the irc+insecure address scheme
Some servers do not support TLS, or have invalid, expired or self-signed
TLS certificates. While the right fix would be toi contact each server
owner to add support for valid TLS, supporting plaintext upstream
connections is sometimes necessary.

This adds support for the irc+insecure address scheme, which connects to
a network in plain-text over TCP.

git-svn-id: file:///srv/svn/repo/suika/trunk@270 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-28 09:41:13 +00:00
delthas
d94fe63d8a Add support for IRC address schemes
This is preparatory work for adding other connection types to upstream
servers. The service command `network create` now accepts a scheme in
the address flag, which specifies how to connect to the upstream server.

The only supported scheme for now is ircs, which is also the default if
no scheme is specified. ircs connects to a network over a TLS TCP
connection.

git-svn-id: file:///srv/svn/repo/suika/trunk@269 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-28 09:41:13 +00:00
contact
a448e04600 Add network.channels, remove DB.GetChannel
Store the list of configured channels in the network data structure.
This removes the need for a database lookup and will be useful for
detached channels.

git-svn-id: file:///srv/svn/repo/suika/trunk@267 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-23 14:36:20 +00:00
delthas
218af4327e Add support for custom network on-connect commands
Some servers use custom IRC bots with custom commands for registering to
specific services after connection.

This adds support for setting custom raw IRC messages, that will be
sent after registering to a network.

It also adds support for a custom flag.Value type for string
slice flags (flags taking several string values).

git-svn-id: file:///srv/svn/repo/suika/trunk@263 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 15:38:47 +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
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
cec36bb0e1 Make newMessageLogger take a *network instead of an *upstreamConn
There's no reason why messgeLogger needs access to the whole connection,
the network is enough.

git-svn-id: file:///srv/svn/repo/suika/trunk@248 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 19:54:24 +00:00
contact
019e760145 Remove outdated comment
Locks are gone for good.

git-svn-id: file:///srv/svn/repo/suika/trunk@246 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 17:57:36 +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
contact
3857f41e57 Fix upstream NICK handling
- uc.nicl was compared to msg.Prefix.Name after being updated to the new
  nick
- The new nick wasn't marshaled

git-svn-id: file:///srv/svn/repo/suika/trunk@244 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 13:02:44 +00:00
contact
d334df9ade Fix server-time tags timezone
We need to use UTC time.

git-svn-id: file:///srv/svn/repo/suika/trunk@240 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 20:05:49 +00:00
contact
8723fe0c4a Make upstreamConn.produce log messages
git-svn-id: file:///srv/svn/repo/suika/trunk@239 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 19:42:55 +00:00
contact
661f555ae0 Add origin argument to upstreamConn.produce
git-svn-id: file:///srv/svn/repo/suika/trunk@238 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 19:34:45 +00:00
contact
acc3c1c6f1 Log TOPIC messages
See [1].

[1]: 82c4ad8362/modules/log.cpp (L486)

git-svn-id: file:///srv/svn/repo/suika/trunk@235 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 16:49:39 +00:00
contact
9c84a1279e Remove downstreamConn.ringConsumers
We no longer need long-lived ring buffer consumers now that
upstreamConn.produce dispatches messages to downstream connections.

git-svn-id: file:///srv/svn/repo/suika/trunk@231 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 16:31:48 +00:00
contact
35c751da2b Remove per-network ring buffer goroutines
Just dispatch from the user goroutine. This allows removes a lot of complexity.

git-svn-id: file:///srv/svn/repo/suika/trunk@227 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 16:05:36 +00:00
contact
7e96015851 Introduce upstreamConn.produce
The logic in this function is about to get more complicated. It'll soon
also dispatch messages in connected downstreams.

git-svn-id: file:///srv/svn/repo/suika/trunk@226 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 15:28:49 +00:00
delthas
31ed348a11 Remove unused entityLog struct
Since the logging refactoring in 27e090, entityLog is not used anymore
and can be removed.

git-svn-id: file:///srv/svn/repo/suika/trunk@221 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-04 15:34:37 +00:00
delthas
c03e14ee9e Send one NOTICE on new upstream disconnect/connect errors
In order to notify the user when we are disconnected from a network
(either due to an error, or due a QUIT), and when we fail reconnecting,
this commit adds support for sending a short NOTICE message from the
service user to all relevant downstreams.

The last error is stored, and cleared on successful connection, to
ensure that the user is *not* flooded with identical connection error
messages, which can often happen when a server is down.

No lock is needed on lastError because it is only read and modified from
the user goroutine.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@218 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-04 15:33:09 +00:00
contact
7e7beef866 Add NOTICE messages to ring buffer
References: https://todo.sr.ht/~emersion/soju/33

git-svn-id: file:///srv/svn/repo/suika/trunk@217 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 19:00:19 +00:00