57 Commits

Author SHA1 Message Date
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
contact
5f7e385a0e Improve registration error messages
- Don't print the raw IRC message, since we already show the original
  error message
- Avoid double-printing "registration failed"

git-svn-id: file:///srv/svn/repo/suika/trunk@399 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-19 21:35:12 +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
4ab774fcd4 Encode idents to hex instead of base64
base64 strings may contain characters rejected by ident clients such
as "+". Use hex encoding and shorten the string a little.

git-svn-id: file:///srv/svn/repo/suika/trunk@395 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-19 09:24:25 +00:00
contact
d4a0c5bd48 Add an ident server
Closes: https://todo.sr.ht/~emersion/soju/69

git-svn-id: file:///srv/svn/repo/suika/trunk@385 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 08:59:06 +00:00
contact
25dc76452b Make user.stop block
This allows callers to wait until the user has been stopped.

git-svn-id: file:///srv/svn/repo/suika/trunk@377 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-10 13:03:38 +00:00
contact
1869b37956 Add user.stop
git-svn-id: file:///srv/svn/repo/suika/trunk@376 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-10 13:03:38 +00:00
contact
b97cd39cd3 Prevent error handler from falling through in user.run
git-svn-id: file:///srv/svn/repo/suika/trunk@359 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-09 12:20:23 +00:00
contact
7c4131cbdb Introduce User.Created
For Network and Channel, the database only needed to define one Store
operation to create/update a record. However since User is missing an ID
we couldn't have a single StoreUser function like other types. We had
CreateUser and UpdatePassword. As new User fields get added (e.g. the
upcoming Admin flag) this isn't sustainable.

We could have CreateUser and UpdateUser, but this wouldn't be consistent
with other types. Instead, introduce User.Created which indicates
whether the record is already stored in the DB. This can be used in a
new StoreUser function to decide whether we need to UPDATE or INSERT
without relying on SQL constraints and INSERT OR UPDATE.

The ListUsers and GetUser functions set User.Created to true.

git-svn-id: file:///srv/svn/repo/suika/trunk@324 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-08 09:59:03 +00:00
contact
d7d1f89ecf Add network update command
The user.updateNetwork function is a bit involved because we need to
make sure that the upstream connection is closed before re-connecting
(would otherwise cause "Nick already used" errors) and that the
downstream connections' state is kept in sync.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@313 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-04 11:04:39 +00:00
contact
297ef18a09 Introduce network.isClosed
git-svn-id: file:///srv/svn/repo/suika/trunk@311 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-03 15:28:31 +00:00
contact
6d56da1757 Unexport network.Stop
An exported function makes it look like it can be called from any
goroutine.

git-svn-id: file:///srv/svn/repo/suika/trunk@309 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-03 14:18:56 +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
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
delthas
2ed4415430 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@283 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 08:49:58 +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
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
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
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
admin
017d8be225 Allow users to change password in client
Added a BouncerServ command for that.

git-svn-id: file:///srv/svn/repo/suika/trunk@252 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-10 08:16:25 +00:00
contact
ed457c1073 Remove Ring.Close
This is unused.

git-svn-id: file:///srv/svn/repo/suika/trunk@241 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 12:42:13 +00:00
contact
47d9015008 Remove network.lock
network.conn is now only accessed from the user goroutine.

git-svn-id: file:///srv/svn/repo/suika/trunk@237 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 17:11:26 +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
9b11e4dd6e Remove channel from ring buffer consumers
This is unused.

git-svn-id: file:///srv/svn/repo/suika/trunk@228 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 16:13:46 +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
9eaa5ae5c0 Use Network.GetName in network status NOTICE messages
git-svn-id: file:///srv/svn/repo/suika/trunk@223 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-05 13:15:42 +00:00
contact
d18e8f4279 Add network.{createUpdate,delete}Channel
These are about to get more complicated as we move towards per-entity
ring buffers.

git-svn-id: file:///srv/svn/repo/suika/trunk@222 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-05 13:04:52 +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
84c358d870 Introduce messageLogger
This centralizes formatting related to message logging in a single
place.

git-svn-id: file:///srv/svn/repo/suika/trunk@215 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 16:59:17 +00:00
contact
f4f532b00c Simplify ring consumer goroutine
Since network.history is now only accessed from the user goroutine, a
lock becomes unnecessary.

git-svn-id: file:///srv/svn/repo/suika/trunk@204 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 14:02:31 +00:00
contact
9ae7d253b3 Stop ring consumers when deleting network
git-svn-id: file:///srv/svn/repo/suika/trunk@203 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 13:48:56 +00:00
contact
d317a87876 Add "network delete" service command
And add all the infrastructure required to stop and delete networks.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@202 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 13:40:20 +00:00
contact
5f0e31c148 Make user.getNetwork handle Network.Name
git-svn-id: file:///srv/svn/repo/suika/trunk@201 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 13:04:32 +00:00
contact
a8b006a658 Set network.conn in user goroutine
One step closed to removing that lock.

git-svn-id: file:///srv/svn/repo/suika/trunk@199 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 10:21:31 +00:00
contact
b476131682 Auto away
Closes: https://todo.sr.ht/~emersion/soju/13

git-svn-id: file:///srv/svn/repo/suika/trunk@198 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 10:16:32 +00:00
contact
fc82577f45 Only set network.conn when registered
git-svn-id: file:///srv/svn/repo/suika/trunk@197 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 10:14:36 +00:00
contact
baadefdaef Add eventUpstreamConnected
This is used in the next commit.

git-svn-id: file:///srv/svn/repo/suika/trunk@196 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 10:05:25 +00:00
contact
ec1777f84e s/List/LIST/ when referring to the command
git-svn-id: file:///srv/svn/repo/suika/trunk@181 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-28 00:03:00 +00:00
contact
003b8f8ec6 Introduce eventUpstreamDisconnected
This allows us to perform cleanup actions in the user goroutine. This
removes the need for pendingLISTsLock.

git-svn-id: file:///srv/svn/repo/suika/trunk@179 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 23:51:58 +00:00
delthas
9aeb067b1b Add LIST support
This commit adds support for downstream LIST messages from multiple
concurrent downstreams to multiple concurrent upstreams, including
support for multiple pending LIST requests from the same downstream.

Because a unique RPL_LISTEND message must be sent to the requesting
downstream, and that there might be multiple upstreams, each sending
their own RPL_LISTEND, a cache of RPL_LISTEND replies of some sort is
required to match RPL_LISTEND together in order to only send one back
downstream.

This commit adds a list of "pending LIST" structs, which each contain a
map of all upstreams that yet need to send a RPL_LISTEND, and the
corresponding LIST request associated with that response. This list of
pending LISTs is sorted according to the order that the requesting
downstreams sent the LIST messages in. Each pending set also stores the
id of the requesting downstream, in order to only forward the replies to
it and no other downstream. (This is important because LIST replies can
typically amount to several thousands messages on large servers.)

When a single downstream makes multiple LIST requests, only the first
one will be immediately sent to the upstream servers. The next ones will
be buffered until the first one is completed. Distinct downstreams can
make concurrent LIST requests without any request buffering.

Each RPL_LIST message is forwarded to the downstream of the first
matching pending LIST struct.

When an upstream sends an RPL_LISTEND message, the upstream is removed
from the first matching pending LIST struct, but that message is not
immediately forwarded downstream. If there are no remaining pending LIST
requests in that struct is then empty, that means all upstreams have
sent back all their RPL_LISTEND replies (which means they also sent all
their RPL_LIST replies); so a unique RPL_LISTEND is sent to downstream
and that pending LIST set is removed from the cache.

Upstreams are removed from the pending LIST structs in two other cases:
- when they are closed (to avoid stalling because of a disconnected
upstream that will never reply to the LIST message): they are removed
from all pending LIST structs
- when they reply with an ERR_UNKNOWNCOMMAND or RPL_TRYAGAIN LIST reply,
which is typically used when a user is not allowed to LIST because they
just joined the server: they are removed from the first pending LIST
struct, as if an RPL_LISTEND message was received

git-svn-id: file:///srv/svn/repo/suika/trunk@177 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 23:07:20 +00:00
contact
21656bbbc9 Fix race condition in upstreamConn.Close
upstreamConn.closed was a bool accessed from different goroutines. Use
the same pattern as downstreamConn instead.

git-svn-id: file:///srv/svn/repo/suika/trunk@175 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 22:08:35 +00:00
contact
d288ab6aad Nuke user.lock
Split user.register into two functions, one to make sure the user is
authenticated, the other to send our current state. This allows to get
rid of data races by doing the second part in the user goroutine.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@168 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 18:17:58 +00:00
contact
520585d901 Add eventDownstreamDisconnected
This should remove the need for protecting user.downstreamConns with a
mutex.

git-svn-id: file:///srv/svn/repo/suika/trunk@167 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 16:55:03 +00:00
contact
0def23b671 Add eventDownstreamConnected
In a later commit, we'll be able to move part of downstreamConn.register
into the user goroutine to prevent races.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@166 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 16:21:05 +00:00
contact
f4631f5dd6 Introduce a user.events channel
This allows to easily add new events, and also guarantees ordering
between different event types.

git-svn-id: file:///srv/svn/repo/suika/trunk@165 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 15:33:19 +00:00
contact
1f17d1a841 Consume ring buffer for networks added on-the-fly
git-svn-id: file:///srv/svn/repo/suika/trunk@144 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-25 10:28:25 +00:00
contact
d7d76f9c25 Move upstreamConn.ring to network
This handles upstream disconnection and re-connection better.

git-svn-id: file:///srv/svn/repo/suika/trunk@143 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-25 09:53:08 +00:00
contact
913e583b44 Add user.{add,remove}Downstream
git-svn-id: file:///srv/svn/repo/suika/trunk@137 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-23 15:05:00 +00:00
contact
b360940009 Add network.upstream helper
git-svn-id: file:///srv/svn/repo/suika/trunk@136 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-21 09:24:38 +00:00