129 Commits

Author SHA1 Message Date
contact
d36068af4e Store last internal msg ID in DB when detaching
References: https://todo.sr.ht/~emersion/soju/98

git-svn-id: file:///srv/svn/repo/suika/trunk@497 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-04-13 16:15:30 +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
fec819c48a Panic on unknown user event type
This should never happen. Complain loudly if it does.

git-svn-id: file:///srv/svn/repo/suika/trunk@494 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-04-13 11:08:48 +00:00
contact
63c2238407 Introduce per-user logger
Adds the username to log lines.

git-svn-id: file:///srv/svn/repo/suika/trunk@493 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-04-13 11:04:23 +00:00
contact
83a6c849fd Save delivery receipts in DB
This avoids loosing history on restart for clients that don't
support chathistory.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@489 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-31 16:04:13 +00:00
contact
862be4f5b8 Rename user.clients to clientNames
This doesn't contain anything other than just the names. Make this
clearer.

git-svn-id: file:///srv/svn/repo/suika/trunk@487 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-30 10:44:56 +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
84b3a5d057 Move network.clients to user
No need to have this list per-network.

git-svn-id: file:///srv/svn/repo/suika/trunk@483 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-29 14:58:56 +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
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
35272526d6 Send NOTICE to downstream when upstream is disconnected
Closes: https://todo.sr.ht/~emersion/soju/76

git-svn-id: file:///srv/svn/repo/suika/trunk@467 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-16 08:41:07 +00:00
contact
4dfac575f6 Use sendTargetBacklog when re-attaching a channel
No need to attempt to send backlog for all targets in the network.
We're only interested in a single channel.

git-svn-id: file:///srv/svn/repo/suika/trunk@453 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-02-10 12:50:10 +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
contact
e0ef0b2c01 Add in-memory message store
Uses an in-memory ring buffer.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@442 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-01-04 16:18:30 +00:00
contact
ee6517993f Turn messageStore into an interface
This allows for other implementations that aren't based on a filesystem.

git-svn-id: file:///srv/svn/repo/suika/trunk@439 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-01-04 13:24:00 +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
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
hubert
8ca570988a Make DB.DeleteChannel take the channel ID
... to allow the caller to correctly do any necessary casemapping.

git-svn-id: file:///srv/svn/repo/suika/trunk@416 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-09-07 09:40:18 +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
contact
5f7e385a0e Improve registration error messages
- Don't print the raw IRC message, since we already show the original
  error message
- Avoid double-printing "registration failed"

git-svn-id: file:///srv/svn/repo/suika/trunk@399 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-19 21:35:12 +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
4ab774fcd4 Encode idents to hex instead of base64
base64 strings may contain characters rejected by ident clients such
as "+". Use hex encoding and shorten the string a little.

git-svn-id: file:///srv/svn/repo/suika/trunk@395 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-19 09:24:25 +00:00
contact
d4a0c5bd48 Add an ident server
Closes: https://todo.sr.ht/~emersion/soju/69

git-svn-id: file:///srv/svn/repo/suika/trunk@385 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 08:59:06 +00:00
contact
25dc76452b Make user.stop block
This allows callers to wait until the user has been stopped.

git-svn-id: file:///srv/svn/repo/suika/trunk@377 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-10 13:03:38 +00:00
contact
1869b37956 Add user.stop
git-svn-id: file:///srv/svn/repo/suika/trunk@376 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-10 13:03:38 +00:00
contact
b97cd39cd3 Prevent error handler from falling through in user.run
git-svn-id: file:///srv/svn/repo/suika/trunk@359 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-07-09 12:20:23 +00:00
contact
7c4131cbdb Introduce User.Created
For Network and Channel, the database only needed to define one Store
operation to create/update a record. However since User is missing an ID
we couldn't have a single StoreUser function like other types. We had
CreateUser and UpdatePassword. As new User fields get added (e.g. the
upcoming Admin flag) this isn't sustainable.

We could have CreateUser and UpdateUser, but this wouldn't be consistent
with other types. Instead, introduce User.Created which indicates
whether the record is already stored in the DB. This can be used in a
new StoreUser function to decide whether we need to UPDATE or INSERT
without relying on SQL constraints and INSERT OR UPDATE.

The ListUsers and GetUser functions set User.Created to true.

git-svn-id: file:///srv/svn/repo/suika/trunk@324 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-08 09:59:03 +00:00
contact
d7d1f89ecf Add network update command
The user.updateNetwork function is a bit involved because we need to
make sure that the upstream connection is closed before re-connecting
(would otherwise cause "Nick already used" errors) and that the
downstream connections' state is kept in sync.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@313 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-04 11:04:39 +00:00
contact
297ef18a09 Introduce network.isClosed
git-svn-id: file:///srv/svn/repo/suika/trunk@311 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-03 15:28:31 +00:00
contact
6d56da1757 Unexport network.Stop
An exported function makes it look like it can be called from any
goroutine.

git-svn-id: file:///srv/svn/repo/suika/trunk@309 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-03 14:18:56 +00:00
delthas
fe27882fd8 Update downstream nicks in single-server mode and after NICK
Previously, the downstream nick was never changed, even when the
downstream sent a NICK message or was in single-server mode with a
different nick.

This adds support for updating the downstream nick in the following
cases:
- when a downstream sends NICK
- additionally, in single-server mode:
  - when a downstream connects and its single network is connected
  - when an upstream connects
  - when an upstream sends NICK

git-svn-id: file:///srv/svn/repo/suika/trunk@296 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-27 21:42:38 +00:00
contact
9f84047153 Add support for detached channels
Channels can now be detached by leaving them with the reason "detach",
and re-attached by joining them again. Upon detaching the channel is
no longer forwarded to downstream connections. Upon re-attaching the
history buffer is sent.

git-svn-id: file:///srv/svn/repo/suika/trunk@284 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 13:18:14 +00:00
delthas
2ed4415430 Fix joining only one saved channel per network
This fixes a serious bug added in 276ce12e, where in newNetwork all
channels point to the same channel, which causes soju to only join a
single channel when connecting to an upstream network.

This also adds the same kind of reassignment of a for loop variable in
user.run(), even though that function currently works correctly, as a
sanity improvement in case this function is changed in the future.

git-svn-id: file:///srv/svn/repo/suika/trunk@283 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-05-01 08:49:58 +00:00
contact
e74291b093 Remove network.upstream
This is an artifact from when we used locks. No need for this anymore.

git-svn-id: file:///srv/svn/repo/suika/trunk@279 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-30 08:25:16 +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
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
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
admin
017d8be225 Allow users to change password in client
Added a BouncerServ command for that.

git-svn-id: file:///srv/svn/repo/suika/trunk@252 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-10 08:16:25 +00:00
contact
ed457c1073 Remove Ring.Close
This is unused.

git-svn-id: file:///srv/svn/repo/suika/trunk@241 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-07 12:42:13 +00:00
contact
47d9015008 Remove network.lock
network.conn is now only accessed from the user goroutine.

git-svn-id: file:///srv/svn/repo/suika/trunk@237 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-06 17:11:26 +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
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
9eaa5ae5c0 Use Network.GetName in network status NOTICE messages
git-svn-id: file:///srv/svn/repo/suika/trunk@223 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-05 13:15:42 +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