339 Commits

Author SHA1 Message Date
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
contact
688a078a27 Make Ring.NewConsumer seq argument mandatory
There's no point in supporting a nil argument anymore.

git-svn-id: file:///srv/svn/repo/suika/trunk@242 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 12:45:08 +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
c9b976b306 Remove downstreamConn.ourMessages
We can just do the filtering when dispatching the message.

git-svn-id: file:///srv/svn/repo/suika/trunk@236 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 17:08:43 +00:00
contact
058e67bf45 Simplify ring consumer loop
No need to use Peek here.

git-svn-id: file:///srv/svn/repo/suika/trunk@233 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 16:34:33 +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
24ee9e80fd Remove downstreamConn.lock
Everything is now accessed from the user goroutine now that the
per-network ring buffer goroutine is gone.

git-svn-id: file:///srv/svn/repo/suika/trunk@230 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 16:23:39 +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
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
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
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
contact
f4c48f9b05 Add time tag to all messages
git-svn-id: file:///srv/svn/repo/suika/trunk@216 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 18:48:23 +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
58be470d17 Log self-messages too
Closes: https://todo.sr.ht/~emersion/soju/44

git-svn-id: file:///srv/svn/repo/suika/trunk@213 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 15:15:12 +00:00
contact
143c84e287 Use conn.ReadMessage instead of irc.Conn.ReadMessage
git-svn-id: file:///srv/svn/repo/suika/trunk@212 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 15:01:25 +00:00
contact
0b30f8fccd Add support for downstream echo-message extension
git-svn-id: file:///srv/svn/repo/suika/trunk@211 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 14:55:49 +00:00
contact
7e2bd554a4 Introduce conn for common connection logic
This centralizes the common upstream & downstream bits.

git-svn-id: file:///srv/svn/repo/suika/trunk@210 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 14:35:08 +00:00
contact
204f1ede17 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@209 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-03 14:15:25 +00:00
contact
9fe572eb4f Fix SQL error logged on JOIN
Closes: https://todo.sr.ht/~emersion/soju/40

git-svn-id: file:///srv/svn/repo/suika/trunk@207 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 15:34:22 +00:00
contact
db1e84ce20 Set write deadlines
References: https://todo.sr.ht/~emersion/soju/26

git-svn-id: file:///srv/svn/repo/suika/trunk@205 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 14:27:53 +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
dcb04da885 Add downstream support for server-time
git-svn-id: file:///srv/svn/repo/suika/trunk@194 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-31 17:50:31 +00:00
contact
ee53042d08 Expose message-tags capability downstream
Strip tags if the client doesn't support them.

git-svn-id: file:///srv/svn/repo/suika/trunk@191 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-31 17:39:06 +00:00
contact
fc6c4cf40b Make "@" and "/" indicate client name and network, respectively
This allows both kinds "<username>@<client>/<network>" and
"<username>/<network>@<client>".

git-svn-id: file:///srv/svn/repo/suika/trunk@190 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-31 17:02:02 +00:00
contact
e972f4b7de Consume ring messages outside of writer goroutine
This fixes out-of-order JOIN and PRIVMSG messages.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@188 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-31 16:16:54 +00:00
contact
b487a7dff2 Use clientName to decide whether or not history should be sent
Closes: https://todo.sr.ht/~emersion/soju/31

git-svn-id: file:///srv/svn/repo/suika/trunk@185 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-28 16:36:09 +00:00
contact
40efde6626 Remove downstreamConn.username
Replace it with downstreamConn.user.Username

git-svn-id: file:///srv/svn/repo/suika/trunk@184 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-28 16:28:28 +00:00
contact
0e1223c13d Add downstreamConn.clientName
git-svn-id: file:///srv/svn/repo/suika/trunk@183 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-28 16:25:48 +00:00
contact
ac7553c1fb Update password on NickServ SET PASSWORD message
git-svn-id: file:///srv/svn/repo/suika/trunk@182 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-28 09:40:33 +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
5396567c1b Document functions safe to call from any goroutine
git-svn-id: file:///srv/svn/repo/suika/trunk@180 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 23:54:42 +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
delthas
f8dc7b05a1 Make upstream.SendMessageLabeled use an uint64 id
This commit is preparatory work for code that will call
SendMessageLabeled with a direct downstream id rather than a
downstreamConnection pointer.

git-svn-id: file:///srv/svn/repo/suika/trunk@176 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 23:07:20 +00:00
contact
a17e0acde2 Stop accessing user data in downstreamConn.authenticate
This becomes racy once user.Password is updated on-the-fly.

git-svn-id: file:///srv/svn/repo/suika/trunk@173 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 21:38:38 +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
delthas
43fd40bf31 Add downstream NOTICE support
git-svn-id: file:///srv/svn/repo/suika/trunk@164 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 08:40:51 +00:00
delthas
fc905bc9ed Add downstream INVITE support
git-svn-id: file:///srv/svn/repo/suika/trunk@163 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-26 21:43:48 +00:00
delthas
290366abfb Add upstream RPL_CREATIONTIME support
git-svn-id: file:///srv/svn/repo/suika/trunk@162 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-26 21:33:44 +00:00