Commit graph

296 commits

Author SHA1 Message Date
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 566986fdd5
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.
2020-05-21 22:38:07 +02:00
delthas de7b4c8588
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.
2020-05-21 22:37:37 +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
Simon Ser f79cf305ab
readme: add CI badge 2020-05-01 21:58:29 +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 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 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
delthas a99d6dd019 Fix joining only one saved channel per network
This fixes a serious bug added in 276ce12e, where in newNetwork all
channels point to the same channel, which causes soju to only join a
single channel when connecting to an upstream network.

This also adds the same kind of reassignment of a for loop variable in
user.run(), even though that function currently works correctly, as a
sanity improvement in case this function is changed in the future.
2020-05-01 10:49:58 +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 e9cebb6fe3
Use a lock to protect conn.{closed,outgoing}
Unfortunately, I don't think there's a good way to implement net.Conn
semantics on top of channels. The Close and SendMessage methods should
gracefully fail without panicking if the connection is already closed.
Using only channels leads to race conditions.

We could remove the lock if Close and SendMessage are only called from a
single goroutine. However that's not the case right now.

Closes: https://todo.sr.ht/~emersion/soju/55
2020-04-30 10:35:02 +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 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 394f2853ad
Add downstream support for cap-notify 2020-04-29 19:34:38 +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
Simon Ser 6899e748c6
Abbreviate net status service reply
Don't print the nickname if it's the same as the downstream
connection's.
2020-04-28 16:27:53 +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
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 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
Simon Ser dbd6cd689e
doc/architecture: ring buffers are now per-channel 2020-04-17 18:29:49 +02:00
Simon Ser d74fa2d222
readme: fix ref to manpage 2020-04-16 18:55:21 +02:00
Simon Ser 9436b89723
doc: describe more default settings 2020-04-16 18:54:47 +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 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 2194259124
Set up DB migration infrastructure
The database is now initialized automatically on first run. The schema
version is stored in SQLite's user_version special field. Migrations are
stored in an array and applied based on the schema version.
2020-04-10 22:45:02 +02:00
Simon Ser da4b91793e
doc: fix SQL driver name in manpage 2020-04-10 22:37:14 +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
Thorben Günther 20a58b1fa3
Allow users to change password in client
Added a BouncerServ command for that.
2020-04-10 10:16:25 +02:00
Thorben Günther 148bbc8102
Add ability to change password 2020-04-10 10:09:02 +02:00
Simon Ser 155f35bd84
Parse timestamp from message tags in messageLogger.Append 2020-04-08 10:19:33 +02:00
Simon Ser 9f6e59195c
Document downstreamConn.{,un}marshalEntity 2020-04-07 22:30:54 +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 64b537d799
Extract logic to build log filepath into a function
This will get re-used when parsing logs.
2020-04-07 21:50:12 +02:00