222 Commits

Author SHA1 Message Date
contact
f0544a8932 Add upstream cap-notify support
git-svn-id: file:///srv/svn/repo/suika/trunk@281 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-30 13:27:41 +00:00
contact
7358bf75fd Add upstreamConn.caps
Instead of adding one field per capability, let's just have a map, just
like downstreamConn.

git-svn-id: file:///srv/svn/repo/suika/trunk@278 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 17:45:37 +00:00
contact
9f64fc5a93 Rename upstreamConn.caps to supportedCaps
For consistency with downstreamConn.

git-svn-id: file:///srv/svn/repo/suika/trunk@277 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 17:40:31 +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
baccde5a95 Don't use forEachDownstreamByID when forwarding RPL_AWAY
We should broadcast the message, not send it to a specific downstream
connection.

git-svn-id: file:///srv/svn/repo/suika/trunk@274 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 13:32:22 +00:00
contact
ec0e6f5f34 Check upstream NOTICE prefix is non-nil
git-svn-id: file:///srv/svn/repo/suika/trunk@273 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 13:00:17 +00:00
contact
9c54b44ca1 Forward RPL_AWAY messages
git-svn-id: file:///srv/svn/repo/suika/trunk@272 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-29 12:53:48 +00:00
delthas
67237abdea 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@270 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-28 09:41:13 +00:00
delthas
d94fe63d8a 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@269 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-28 09:41:13 +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
delthas
218af4327e 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).

git-svn-id: file:///srv/svn/repo/suika/trunk@263 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 15:38:47 +00:00
contact
68bf575c9e Support sending history when upstream is disconnected
Previously, we were dropping the history.

git-svn-id: file:///srv/svn/repo/suika/trunk@261 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 15:23:35 +00:00
contact
e7cc0a7f2e Make downstreamConn.marshal{Entity,UserPrefix} take a network
This will be used when sending history while upstream is disconnected.

git-svn-id: file:///srv/svn/repo/suika/trunk@260 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 15:19:00 +00:00
contact
7c7a1d3326 Kill downstreamConn.marshal{Nick,Channel}
We can just use downstreamConn.marshalEntity instead.

git-svn-id: file:///srv/svn/repo/suika/trunk@259 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-16 14:57:33 +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
cec36bb0e1 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.

git-svn-id: file:///srv/svn/repo/suika/trunk@248 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 19:54:24 +00:00
contact
019e760145 Remove outdated comment
Locks are gone for good.

git-svn-id: file:///srv/svn/repo/suika/trunk@246 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 17:57:36 +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
3857f41e57 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

git-svn-id: file:///srv/svn/repo/suika/trunk@244 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 13:02:44 +00:00
contact
d334df9ade Fix server-time tags timezone
We need to use UTC time.

git-svn-id: file:///srv/svn/repo/suika/trunk@240 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 20:05:49 +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
acc3c1c6f1 Log TOPIC messages
See [1].

[1]: 82c4ad8362/modules/log.cpp (L486)

git-svn-id: file:///srv/svn/repo/suika/trunk@235 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 16:49:39 +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
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
delthas
31ed348a11 Remove unused entityLog struct
Since the logging refactoring in 27e090, entityLog is not used anymore
and can be removed.

git-svn-id: file:///srv/svn/repo/suika/trunk@221 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-04 15:34:37 +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
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
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
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
0e879e79d8 Set connect timeout
References: https://todo.sr.ht/~emersion/soju/26

git-svn-id: file:///srv/svn/repo/suika/trunk@206 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-01 14:41:17 +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
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
db2e08e72e Fix log dir permission
We need the permission to list files in the dir.

git-svn-id: file:///srv/svn/repo/suika/trunk@195 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-31 20:21:49 +00:00
contact
c2083296b3 Request server-time cap
If the server didn't populate the time tag, do it ourselves.

git-svn-id: file:///srv/svn/repo/suika/trunk@193 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-31 17:45:04 +00:00
contact
106949d6e0 Avoid directly forwarding NOTICE messages
This would forward tags even if downstream doesn't support those.

git-svn-id: file:///srv/svn/repo/suika/trunk@192 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-31 17:41:12 +00:00
contact
547e49964d Rename AppendLog to appendLog
This function is only safe to call from inside the user goroutine. Let's
make it private.

git-svn-id: file:///srv/svn/repo/suika/trunk@187 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-31 15:30:45 +00:00
contact
5f94f2b629 Fix missing upstreamConn.closed initialization
Fixes: b33e5f29abbe ("Fix race condition in upstreamConn.Close")

git-svn-id: file:///srv/svn/repo/suika/trunk@186 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-28 19:00:56 +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
3ac0e6bd4d Add support for bouncer logs
Add bouncer logs, in a network/channel/date.log format, in a similar
manner to ZNC log module. PRIVMSG, JOIN, PART, QUIT, MODE are logged.

Add a config directive for the logs file, including a way to disable
them entirely.

git-svn-id: file:///srv/svn/repo/suika/trunk@178 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 23:07:20 +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
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