Commit Graph

79 Commits

Author SHA1 Message Date
Simon Ser
53d4f9f71b
s/List/LIST/ when referring to the command 2020-03-28 01:03:00 +01:00
Simon Ser
2ae43be525
Document functions safe to call from any goroutine 2020-03-28 00:54:42 +01:00
Simon Ser
1c3da31f2e
Introduce eventUpstreamDisconnected
This allows us to perform cleanup actions in the user goroutine. This
removes the need for pendingLISTsLock.
2020-03-28 00:51:58 +01:00
delthas
0607b940e2 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.
2020-03-28 00:07:20 +01:00
delthas
10ea698022 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
2020-03-28 00:07:20 +01:00
delthas
72a285aaeb 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.
2020-03-28 00:07:20 +01:00
Simon Ser
b33e5f29ab
Fix race condition in upstreamConn.Close
upstreamConn.closed was a bool accessed from different goroutines. Use
the same pattern as downstreamConn instead.
2020-03-27 23:08:35 +01:00
delthas
f08063c943
Fix parsing wrong empty element in RPL_WHOISCHANNELS channel list
Some servers add a trailing space to the channel list in
RPL_WHOISCHANNELS. This commit works around this issue by removing any
empty trailing element after splitting.

Since RPL_WHOISCHANNELS could send an empty channel parameter, we can't
just use strings.TrimRight(s, " "), because splitting on an empty string
would still return an empty element.

Closes: https://todo.sr.ht/~emersion/soju/25
2020-03-27 22:53:21 +01:00
delthas
8c56e610ff
Marshal NOTICE user prefixes and channels
NOTICE messages can be both special messages from the server (with no
prefix nick), or regular PRIVMSG-like messages from users. This commit
adds support for marshaling channel and user prefixes in the latter
case.
2020-03-27 21:12:16 +01:00
Simon Ser
474f2889d9
Introduce a user.events channel
This allows to easily add new events, and also guarantees ordering
between different event types.
2020-03-27 16:33:19 +01:00
delthas
9530df5db0
Add downstream INVITE support 2020-03-26 22:43:48 +01:00
delthas
3b6e175365
Add upstream RPL_CREATIONTIME support 2020-03-26 22:33:44 +01:00
delthas
2cb0cf3665
Fix capitalization of 'id'
Following the Go project source code guidelines, id is an abbreviation
and must typically be written as id or ID, not Id.
2020-03-26 22:28:13 +01:00
delthas
bab26c7a6f
Add KICK support
Downstream and upstream message handling are slightly different because
downstreams can send KICK messages with multiple channels or users,
while upstreams can only send KICK messages with one channel and one
user (according to the RFC).
2020-03-26 00:15:26 +01:00
delthas
d00698e15c
Fix wrong handling of members parameter of RPL_NAMREPLY
Some servers (namely UnrealIRCd) wrongly add a trailing space to the
members parameters of the RPL_NAMREPLY command, which was not handled
correctly.

Adding a trailing space is not legal wrt the IRC specs, but since
UnrealIRCd does it and is in wide use today, we have to work around it.
2020-03-25 23:21:26 +01:00
delthas
6e72071716
Route NAMES, WHO, WHOIS replies to the requesting downstream
Using labeled-response, the replies to several commands such as NAMES,
WHO, WHOIS can be routed back to a specific downstream, rather than
being broadcast to all downstreams.

For example, after this commit, if the server supports labeled-response,
if a downstream requests the NAMES or WHO or WHOIS of a channel, the
replies of the upstream will only be sent back to that downstream, and
the other downstreams won't receive these messages.
2020-03-25 23:21:14 +01:00
delthas
e19f8aaba4
Add upstream labeled-response capability support 2020-03-25 23:20:56 +01:00
delthas
df8bfb75f2
Add upstream batch capability support 2020-03-25 23:16:53 +01:00
delthas
27dae3e8ad
Add upstream message-tags capability support 2020-03-25 23:15:48 +01:00
Simon Ser
33dacc4fb0
Add support for channel keys 2020-03-25 11:54:08 +01:00
Simon Ser
293a0e8e20
Move upstreamConn.ring to network
This handles upstream disconnection and re-connection better.
2020-03-25 10:53:08 +01:00
delthas
9486d657c5
Add downstream self WHO and WHOIS support 2020-03-25 09:51:22 +01:00
delthas
9ff8429a53
Add downstream NAMES support
NAMES reply for channels currently joined will be returned from cache;
requests for channels not joined will be forwarded from upstream.
2020-03-25 09:47:26 +01:00
delthas
98a95e9955
Add MODE arguments support
- Add RPL_ISUPPORT support with CHANMODES, CHANTYPES, PREFIX parsing
- Add support for channel mode state with mode arguments
- Add upstream support for RPL_UMODEIS, RPL_CHANNELMODEIS
- Request channel MODE on upstream channel JOIN
- Use sane default channel mode and channel mode types
2020-03-25 09:40:08 +01:00
Simon Ser
45d118dd12
Move upstreamConn.history to network 2020-03-20 22:48:17 +01:00
delthas
aedf66c73d Fix MODE downstream support
- Fix replies without client as first argument
- Replace wrong prefix check with a proper entity type check
2020-03-20 10:11:27 +01:00
delthas
b3ad960529 Add WHOIS support 2020-03-20 10:11:27 +01:00
delthas
54275c25ac Add WHO support 2020-03-20 00:29:03 +01:00
Simon Ser
166d8b0626
Remove some IRCv3 constants
go-irc v3.1.2 adds some missing IRCv3 constants.
2020-03-19 14:51:45 +01:00
Simon Ser
e3d97bb164
Add basic infrastructure for bouncer service 2020-03-18 12:23:08 +01:00
delthas
c82438625e Add upstream INVITE support 2020-03-18 10:26:25 +01:00
Simon Ser
1241bf82aa
Protect upstreamConn.history with a lock 2020-03-16 15:08:56 +01:00
Simon Ser
3919ee2036
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
2020-03-16 12:44:59 +01:00
Simon Ser
cdab0dc825
Rename messages channels to outgoing 2020-03-16 11:26:54 +01:00
Simon Ser
f3940117d1
Rename project to soju 2020-03-13 18:13:03 +01:00
Simon Ser
2239b94399
Forward NOTICE messages coming from upstream connections 2020-03-13 16:39:49 +01:00
Simon Ser
85ffadea33
Update dependencies
go-irc v3.1.1 contains a breaking change.

References: https://github.com/go-irc/irc/issues/76
2020-03-13 16:18:53 +01:00
Simon Ser
03d5600da6
Add support for SASL authentication
We now store SASL credentials in the database and automatically populate
them on NickServ REGISTER/IDENTIFY.

References: https://todo.sr.ht/~emersion/jounce/10
2020-03-13 15:12:44 +01:00
Simon Ser
fee8fc79c6
Add support for upstream PASS command 2020-03-13 12:06:02 +01:00
Simon Ser
e39948cdbd
Add upstream CAP LS support 2020-03-13 11:26:43 +01:00
Simon Ser
2a1db4cb8d
Pass-through QUIT messages 2020-03-06 18:51:11 +01:00
Simon Ser
7883e8fa23
Pass-through NICK messages for other users 2020-03-06 18:43:56 +01:00
Simon Ser
9db953c7e5
go fmt 2020-03-04 19:23:24 +01:00
Simon Ser
84fe3ae255
Add SQLite database
Closes: https://todo.sr.ht/~emersion/jounce/9
2020-03-04 18:22:58 +01:00
Simon Ser
88cc4c41f1
Fix TOPIC parsing, broadcast to downstream clients 2020-03-04 15:45:14 +01:00
Simon Ser
c22ce793a1
Allow clients to specify an upstream name in their username 2020-03-04 15:44:13 +01:00
Simon Ser
d1550a3cdb
Remove upstream prefix for outgoing MODE and PRIVMSG
We shouldn't set the prefix when sending these commands.
2020-03-03 15:33:21 +01:00
Simon Ser
70fcef297b
Add functions to translate between upstream and downstream names 2020-02-19 18:25:19 +01:00
Simon Ser
ef2d145d1f
Fix PING handlers, again 2020-02-18 20:40:32 +01:00
Simon Ser
1141698a92
Enable TCP keep-alive on all connections 2020-02-18 17:26:17 +01:00