215 Commits

Author SHA1 Message Date
contact
562beca198 Skip backlog logic in downstreamConn.welcome on chathistory
git-svn-id: file:///srv/svn/repo/suika/trunk@496 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-04-13 15:50:03 +00:00
contact
e32cf2acd9 Take msg ID in sendTargetBacklog
git-svn-id: file:///srv/svn/repo/suika/trunk@495 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-04-13 15:49:37 +00:00
contact
00fbbb9d0d Use BARE for internal message IDs
This allows to have shorter and more future-proof IDs. This also
guarantees the IDs will only use reasonable ASCII characters (no
spaces), removing the need to encode them for PING/PONG tokens.

git-svn-id: file:///srv/svn/repo/suika/trunk@488 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-31 15:57:24 +00:00
contact
180e314a01 Make NickServ detection casemapping-aware
git-svn-id: file:///srv/svn/repo/suika/trunk@486 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-30 10:28:45 +00:00
contact
e94da85df6 Introduce deliveredStore
This hides the double-map complexity behind a dedicated type.

git-svn-id: file:///srv/svn/repo/suika/trunk@485 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-29 15:49:50 +00:00
contact
10a2f92f68 Ensure targets are case-mapped before being passed to messageStore
messageStore isn't aware of the network's case-mapping. We need
to canonicalize the names before passing them to messageStore.

git-svn-id: file:///srv/svn/repo/suika/trunk@484 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-29 15:07:39 +00:00
contact
a313a3aead Simplify network.offlineClients
Replace it with a list of all clients (online or offline).

git-svn-id: file:///srv/svn/repo/suika/trunk@482 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-29 14:55:57 +00:00
contact
2cba08b50e Introduce deliveredClientMap
Adds more semantics to map[string]string. Simplifies the complicated
mapStringStringCasemapMap type.

git-svn-id: file:///srv/svn/repo/suika/trunk@480 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-26 10:21:14 +00:00
hubert
3cad542811 Fix CHATHISTORY target not being casemapped
git-svn-id: file:///srv/svn/repo/suika/trunk@479 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-26 09:39:52 +00:00
hubert
1b73446cbb Implement casemapping
TL;DR: supports for casemapping, now logs are saved in
casemapped/canonical/tolower form
(eg. in the #channel directory instead of #Channel... or something)

== What is casemapping? ==

see <https://modern.ircdocs.horse/#casemapping-parameter>

== Casemapping and multi-upstream ==

Since each upstream does not necessarily use the same casemapping, and
since casemappings cannot coexist [0],

1. soju must also update the database accordingly to upstreams'
   casemapping, otherwise it will end up inconsistent,
2. soju must "normalize" entity names and expose only one casemapping
   that is a subset of all supported casemappings (here, ascii).

[0] On some upstreams, "emersion[m]" and "emersion{m}" refer to the same
user (upstreams that advertise rfc1459 for example), while on others
(upstreams that advertise ascii) they don't.

Once upstream's casemapping is known (default to rfc1459), entity names
in map keys are made into casemapped form, for upstreamConn,
upstreamChannel and network.

downstreamConn advertises "CASEMAPPING=ascii", and always casemap map
keys with ascii.

Some functions require the caller to casemap their argument (to avoid
needless calls to casemapping functions).

== Message forwarding and casemapping ==

downstream message handling (joins and parts basically):
When relaying entity names from downstreams to upstreams, soju uses the
upstream casemapping, in order to not get in the way of the user.  This
does not brings any issue, as long as soju replies with the ascii
casemapping in mind (solves point 1.).

marshalEntity/marshalUserPrefix:
When relaying entity names from upstreams with non-ascii casemappings,
soju *partially* casemap them: it only change the case of characters
which are not ascii letters.  ASCII case is thus kept intact, while
special symbols like []{} are the same every time soju sends them to
downstreams (solves point 2.).

== Casemapping changes ==

Casemapping changes are not fully supported by this patch and will
result in loss of history.  This is a limitation of the protocol and
should be solved by the RENAME spec.

git-svn-id: file:///srv/svn/repo/suika/trunk@478 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-24 17:15:52 +00:00
contact
1f128ff7fc Improve ERR_NOSUCHCHANNEL error messages
References: https://todo.sr.ht/~emersion/soju/63

git-svn-id: file:///srv/svn/repo/suika/trunk@464 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-16 08:13:46 +00:00
contact
aba32b60ab Passthrough some ISUPPORT tokens
git-svn-id: file:///srv/svn/repo/suika/trunk@463 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-15 22:41:37 +00:00
contact
b8b77b8f0b Use upstream ISUPPORT map for NETWORK
git-svn-id: file:///srv/svn/repo/suika/trunk@461 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-15 22:08:19 +00:00
hubert
75dee80758 Send correct CHATHISTORY error messages
git-svn-id: file:///srv/svn/repo/suika/trunk@456 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-05 08:53:59 +00:00
contact
6ee586ea01 Introduce downstreamConn.sendTargetBacklog
git-svn-id: file:///srv/svn/repo/suika/trunk@452 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-02-10 12:48:41 +00:00
contact
77f0241cf5 Rename network.history to network.delivered
"History" is over-loaded with e.g. CHATHISTORY support.

git-svn-id: file:///srv/svn/repo/suika/trunk@451 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-02-10 10:31:34 +00:00
contact
5c1bf5b701 Rename sendNetworkHistory to sendNetworkBacklog
"History" is a little bit over-loaded with CHATHISTORY support.

git-svn-id: file:///srv/svn/repo/suika/trunk@450 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-02-10 09:23:51 +00:00
hubert
f5d025bd79 Request invite-notify to upstreams
... and do not forward INVITEs to downstreams that do not support the
capability.

The downstream capability can be permanent because there is no way for a
client to get the list of people invited to a channel, thus no state can
be corrupted.

git-svn-id: file:///srv/svn/repo/suika/trunk@448 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-01-31 21:18:51 +00:00
contact
24d2196f8d Forward ISUPPORT NETWORK token
git-svn-id: file:///srv/svn/repo/suika/trunk@447 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-01-22 11:00:38 +00:00
contact
004e7a4a18 Send RPL_ISUPPORT CHATHISTORY token
git-svn-id: file:///srv/svn/repo/suika/trunk@446 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-01-22 10:55:06 +00:00
contact
c94290b989 Make chat history operations optional in messageStore
Some stores may want not to implement chat history operations.

git-svn-id: file:///srv/svn/repo/suika/trunk@441 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-01-04 16:17:35 +00:00
contact
c1308993f8 Add store-agnostic message ID format
Allow to query the network ID and entity from the message ID regardless
of the underlying store used.

git-svn-id: file:///srv/svn/repo/suika/trunk@440 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-01-04 15:26:30 +00:00
hubert
b1d4fde2f5 Improve dc.authenticate()'s error messages
git-svn-id: file:///srv/svn/repo/suika/trunk@438 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-12-25 12:37:15 +00:00
hubert
ee16ab9833 Advertise all caps, CAP DEL them on registration
... so that the JOIN/history batch takes into account all capabilities.
Without this commit for example, enabling multi-prefix after the batch
makes the client send NAMES requests for all channels, which generate
needless traffic.

git-svn-id: file:///srv/svn/repo/suika/trunk@437 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-12-25 12:35:20 +00:00
delthas
638a2229cb Add customizable auto-detaching, auto-reattaching, relaying.
This uses the fields added previously to the Channel struct to implement
the actual detaching/reattaching/relaying logic.

The `FilterDefault` values of the messages filters are currently
hardcoded.

The values of the message filters are not currently user-settable.

This introduces a new user event, eventChannelDetach, which stores an
upstreamConn (which might become invalid at the time of processing), and
a channel name, used for auto-detaching. Every time the channel detach
timer is refreshed (by receveing a message, etc.), a new timer is
created on the upstreamChannel, which will dispatch this event after the
duration (and discards the previous timer, if any).

git-svn-id: file:///srv/svn/repo/suika/trunk@435 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-12-14 19:54:02 +00:00
hubert
2f7629e4f7 Uphold echo-message even with BouncerServ
Fixes <https://todo.sr.ht/~emersion/soju/74>

git-svn-id: file:///srv/svn/repo/suika/trunk@431 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-11-24 13:25:19 +00:00
contact
92f6ab3b7e Fix nickname in ERR_ERRONEOUSNICKNAME
git-svn-id: file:///srv/svn/repo/suika/trunk@430 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-11-24 13:22:39 +00:00
hubert
1f2dc3a9a1 Prevent downstreams from changing their nick to service's
This commit prevents downstream from sending those commands:
- NICK BouncerServ
- NICK BouncerServ/<network>

The later is necessary because soju would otherwise save the nick change
and, in the event that the downstream connects in single-upstream mode
to <network>, it will end up with the nickname "BouncerServ".

git-svn-id: file:///srv/svn/repo/suika/trunk@429 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-11-24 13:22:18 +00:00
contact
1735c59993 Implement delivery receipts via PING messages
This patch implements basic message delivery receipts via PING and PONG.

When a PRIVMSG or NOTICE message is sent, a PING message with a token is
also sent. The history cursor isn't immediately advanced, instead the
bouncer will wait for a PONG message before doing so.

Self-messages trigger a PING for simplicity's sake. We can't immediately
advance the history cursor in this case, because a prior message might
still have an outstanding PING.

Future work may include optimizations such as removing the need to send
a PING after a self-message, or groupping multiple PING messages
together.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@428 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-11-24 13:13:24 +00:00
hubert
3cabab7275 Don't send TAGMSG to upstreams that don't support it
TAGMSG are (in current specs and drafts from IRCv3) only used for
client tags. These are optional information by design (since they are
not distributed to all users), therefore it is preferable to discard
them accordingly to upstream, instead of waiting for all upstreams to
support the capability to advertise it.

git-svn-id: file:///srv/svn/repo/suika/trunk@427 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-11-20 10:37:43 +00:00
contact
2010feb337 Add message store abstraction
Introduce a messageStore type, which will allow for multiple
implementations (e.g. in the DB or in-memory instead of on-disk).

The message store is per-user so that we don't need to deal with locking
and it's easier to implement per-user limits.

git-svn-id: file:///srv/svn/repo/suika/trunk@423 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-10-25 16:47:38 +00:00
contact
28c243adec Switch DB API to user IDs
This commit changes the Network schema to use user IDs instead of
usernames. While at it, a new UNIQUE(user, name) constraint ensures
there is no conflict with custom network names.

Closes: https://todo.sr.ht/~emersion/soju/86
References: https://todo.sr.ht/~emersion/soju/29

git-svn-id: file:///srv/svn/repo/suika/trunk@421 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-10-24 13:14:23 +00:00
delthas
56f2464404 Add support for the extended-join capability
This simple implementation only advertises extended-join to downstreams
when all upstreams support it.

In the future, it could be modified so that soju buffers incoming
upstream JOINs, sends a WHO, waits for the reply, and sends an extended
join to the downstream; so that soju could advertise that capability
even when some or all upstreams do not support it. This is not the case
in this commit.

git-svn-id: file:///srv/svn/repo/suika/trunk@419 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-09-10 22:10:58 +00:00
contact
b844d9f7bd Fix panic in downstreamConn.sendNetworkHistory
This panic happens when sending history to a multi-upstream client.
sendNetworkHistory is called on each network, but dc.network is nil.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@413 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-26 13:28:10 +00:00
contact
f9a89d4f22 Fix downstream PING argument handling
The PONG message should have these arguments:

- Our server name
- The PING message's source name

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

git-svn-id: file:///srv/svn/repo/suika/trunk@412 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-26 13:18:57 +00:00
contact
d5af5da512 Allow '/' in nickname
This allows to specify a network name in the nickname.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@411 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-25 09:49:22 +00:00
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
hubert
d102dd2fa0 Reject downstream NICK with illegal characters
This should avoid confusion when mixing up nickname and user name.
Also it avoid breaking downstreams (since '@' and '!' are used for host
masks).

git-svn-id: file:///srv/svn/repo/suika/trunk@404 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-20 08:00:58 +00:00
hubert
f95079a5b7 More explicit error message on INVITE with the wrong network
git-svn-id: file:///srv/svn/repo/suika/trunk@401 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-20 07:13:38 +00:00
hubert
da24989ccf More explicit error message on KICK with the wrong network
git-svn-id: file:///srv/svn/repo/suika/trunk@400 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-19 21:57:25 +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
c7e29a966a Extract history loading into functions
These will get re-used for sending history to clients that don't support
the chathistory extension.

git-svn-id: file:///srv/svn/repo/suika/trunk@387 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 13:58:50 +00:00
contact
9e9565daf0 go fmt
git-svn-id: file:///srv/svn/repo/suika/trunk@362 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-22 10:16:01 +00:00
contact
803dbabd4f Implement CHATHISTORY AFTER
References: https://todo.sr.ht/~emersion/soju/12

git-svn-id: file:///srv/svn/repo/suika/trunk@360 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-15 15:47:57 +00:00
contact
6ba63d0774 Strip network name from nickname when auto-saving network
git-svn-id: file:///srv/svn/repo/suika/trunk@354 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-06 16:13:40 +00:00
contact
51df0c157e Add RemoteAddr to ircConn interface
git-svn-id: file:///srv/svn/repo/suika/trunk@347 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-01 15:02:37 +00:00
contact
35c7c0df7f Reply to WHO BouncerServ
Closes: https://todo.sr.ht/~emersion/soju/75

git-svn-id: file:///srv/svn/repo/suika/trunk@343 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-29 16:09:48 +00:00
hubert
a23ecb0998 Don't save corrupted NickServ credentials
soju saved most NickServ messages[0] as credentials because of a missing
`default` clause in the check of the NickServ command.

[0] messages that had at least a command and two other parameters

git-svn-id: file:///srv/svn/repo/suika/trunk@340 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-24 21:02:46 +00:00
contact
f38af41317 Add support for WebSocket connections
WebSocket connections allow web-based clients to connect to IRC. This
commit implements the WebSocket sub-protocol as specified by the pending
IRCv3 proposal [1].

WebSocket listeners can now be set up via a "wss" protocol in the
`listen` directive. The new `http-origin` directive allows the CORS
allowed origins to be configured.

[1]: https://github.com/ircv3/ircv3-specifications/pull/342

git-svn-id: file:///srv/svn/repo/suika/trunk@323 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-07 12:13:46 +00:00