129 Commits

Author SHA1 Message Date
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
contact
9779857f91 Drop messages on closed connections
This prevents this panic:

    panic: send on closed channel
    goroutine 9 [running]:
    git.sr.ht/~emersion/soju.(*upstreamConn).SendMessage(...)
            /home/simon/src/soju/upstream.go:866
    git.sr.ht/~emersion/soju.(*upstreamConn).handleMessage(0xc000084b40, 0xc000144680, 0x2, 0x0)
            /home/simon/src/soju/upstream.go:152 +0x62b
    git.sr.ht/~emersion/soju.(*user).run(0xc0000b8070)
            /home/simon/src/soju/user.go:144 +0x53d
    created by git.sr.ht/~emersion/soju.(*Server).Run
            /home/simon/src/soju/server.go:88 +0x286

git-svn-id: file:///srv/svn/repo/suika/trunk@133 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-21 07:29:44 +00:00
contact
1577d3620c Move upstreamConn.history to network
git-svn-id: file:///srv/svn/repo/suika/trunk@131 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-20 21:48:17 +00:00
delthas
c4fc09cea0 Add create-network bouncer service command
git-svn-id: file:///srv/svn/repo/suika/trunk@120 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-19 00:14:44 +00:00
delthas
cbb0e4e8fa Add suffixing for multi-upstream connections
git-svn-id: file:///srv/svn/repo/suika/trunk@119 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-18 23:06:48 +00:00
delthas
0b5e3e828a schema: add Network.name
git-svn-id: file:///srv/svn/repo/suika/trunk@118 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-18 23:06:48 +00:00
contact
55f987eb29 Per-user dispatcher goroutine
This allows message handlers to read upstream/downstream connection
information without causing any race condition.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@103 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-16 11:44:59 +00:00
contact
f169a0a35a Split user logic into its own file
git-svn-id: file:///srv/svn/repo/suika/trunk@101 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-16 10:18:41 +00:00