Commit Graph

129 Commits

Author SHA1 Message Date
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
1363a5c27e
Improve highlight matching
Detect word boundaries instead of just doing a sub-string check.
2020-05-01 19:51:22 +02:00
Simon Ser
bd8ab7230d
Send service NOTICE on highlight in detached channel 2020-05-01 19:05:20 +02:00
Simon Ser
70f26a1a5a
Unify upstream NOTICE and PRIVMSG handling 2020-05-01 18:12:47 +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
bbb5e79f59
Introduce permanentUpstreamCaps 2020-04-30 16:10:39 +02:00
Simon Ser
2a569c3b27
Add upstream cap-notify support 2020-04-30 15:27:41 +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
8445979956
Rename upstreamConn.caps to supportedCaps
For consistency with downstreamConn.
2020-04-29 19:40:31 +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
70131f5b31
Don't use forEachDownstreamByID when forwarding RPL_AWAY
We should broadcast the message, not send it to a specific downstream
connection.
2020-04-29 15:32:22 +02:00
Simon Ser
2236142681
Check upstream NOTICE prefix is non-nil 2020-04-29 15:00:17 +02:00
Simon Ser
976ae2e649
Forward RPL_AWAY messages 2020-04-29 14:53:48 +02:00
delthas
7b35757bac 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.
2020-04-28 11:41:13 +02:00
delthas
19795a2321 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.
2020-04-28 11:41:13 +02:00
Simon Ser
276ce12e7c
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.
2020-04-23 16:36:20 +02:00
delthas
7f74055380 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).
2020-04-16 17:38:47 +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
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
f2037c5d52
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.
2020-04-07 21:54:24 +02:00
Simon Ser
0a895b591e
Remove outdated comment
Locks are gone for good.
2020-04-07 19:57:36 +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
37cd9e4d89
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
2020-04-07 15:02:44 +02:00
Simon Ser
13635747c4
Fix server-time tags timezone
We need to use UTC time.
2020-04-06 22:05:49 +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
78b123be72
Log TOPIC messages
See [1].

[1]: 82c4ad8362/modules/log.cpp (L486)
2020-04-06 18:49:39 +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
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
delthas
93c96d6c21
Remove unused entityLog struct
Since the logging refactoring in 27e090, entityLog is not used anymore
and can be removed.
2020-04-04 17:34:37 +02:00
delthas
eb941d2d2b
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
2020-04-04 17:33:09 +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
Simon Ser
27e0906450
Introduce messageLogger
This centralizes formatting related to message logging in a single
place.
2020-04-03 18:59:17 +02:00
Simon Ser
e1931649e4
Use conn.ReadMessage instead of irc.Conn.ReadMessage 2020-04-03 17:01:25 +02:00
Simon Ser
2a0696b6bb
Introduce conn for common connection logic
This centralizes the common upstream & downstream bits.
2020-04-03 16:35:08 +02:00
Simon Ser
8c6328207b
Fix writer goroutine races
Any SendMessage call after Close could potentially block forever if the
outgoing channel was filled up. Now the channel is drained before the
writer goroutine exits.
2020-04-03 16:15:25 +02:00
Simon Ser
bca0b2ad76
Set connect timeout
References: https://todo.sr.ht/~emersion/soju/26
2020-04-01 16:41:17 +02:00
Simon Ser
29f2e93ab7
Set write deadlines
References: https://todo.sr.ht/~emersion/soju/26
2020-04-01 16:27:53 +02:00
Simon Ser
434e722f92
Auto away
Closes: https://todo.sr.ht/~emersion/soju/13
2020-04-01 12:16:32 +02:00
Simon Ser
190f0d3fd0
Only set network.conn when registered 2020-04-01 12:14:36 +02:00
Simon Ser
977a1b294f
Fix log dir permission
We need the permission to list files in the dir.
2020-03-31 22:21:49 +02:00
Simon Ser
2053e62162
Request server-time cap
If the server didn't populate the time tag, do it ourselves.
2020-03-31 19:45:04 +02:00
Simon Ser
29a42203b6
Avoid directly forwarding NOTICE messages
This would forward tags even if downstream doesn't support those.
2020-03-31 19:41:12 +02:00
Simon Ser
1023c2ebfc
Rename AppendLog to appendLog
This function is only safe to call from inside the user goroutine. Let's
make it private.
2020-03-31 17:30:45 +02:00
Simon Ser
aadeb327d3
Fix missing upstreamConn.closed initialization
Fixes: b33e5f29ab ("Fix race condition in upstreamConn.Close")
2020-03-28 20:00:56 +01:00