61 Commits

Author SHA1 Message Date
koizumi.aoi
12cdd1e7d7 Add a 'version' subcommand to suikactl, show version on suika daemon
startup.

Signed-off-by: Aoi K <koizumi.aoi@chaotic.ninja>

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@810 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2023-03-22 12:17:57 +00:00
koizumi.aoi
d7b01232aa Use vanity module path
Signed-off-by: Aoi K <koizumi.aoi@chaotic.ninja>

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@807 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2023-03-21 23:43:07 +00:00
koizumi.aoi
90d97ebe18 Drunk as I like
Signed-off-by: Aoi K <koizumi.aoi@chaotic.ninja>

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@804 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2023-03-21 04:45:19 +00:00
koizumi.aoi
71fc998251 Rename to suika
Signed-off-by: Aoi K <koizumi.aoi@chaotic.ninja>

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@801 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2023-03-21 03:00:04 +00:00
koizumi.aoi
741ab64dc3 dev: move contrib/znc-import.go to cmd/soju-znc-import
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@800 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2023-03-21 02:29:26 +00:00
koizumi.aoi
bc26f08775 dev: move import uris to this repository
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@798 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2023-03-21 01:50:04 +00:00
contact
6da71ca598 Fix incorrect listen addr in error message
The various server goroutines would always capture the last listen
addr in the loop.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@767 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2022-01-19 21:38:13 +00:00
contact
bc24ee9e63 Add Logger.Debugf
Makes it easy to print debugging messages which aren't targeted at
the user. See [1] for motivation.

[1]: https://dave.cheney.net/2015/11/05/lets-talk-about-logging

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@747 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-06 17:35:49 +00:00
contact
22a5e0892e Add pprof HTTP server
This enables production debugging of the bouncer.

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

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@713 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 15:18:52 +00:00
contact
4cea61763e Add Prometheus instrumentation for the database
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@712 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:58:19 +00:00
contact
118d99bf47 Add basic Prometheus metrics exporter
This only exports the default metrics for now.

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

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@707 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:58:18 +00:00
contact
564e4bd53c Add per-user IP addresses
The new upstream-user-ip directive allows bouncer operators to
assign one IP address per user.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@705 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 14:07:58 +00:00
contact
f7c3673b00 sojuctl: use background context
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@695 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 10:54:28 +00:00
contact
31603868ba Add config option to globally disable multi-upstream mode
Closes: https://todo.sr.ht/~emersion/soju/122

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@694 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 10:41:11 +00:00
contact
585ad4bfef Allow most config options to be reloaded
Closes: https://todo.sr.ht/~emersion/soju/42

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@691 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-15 23:38:04 +00:00
contact
d2e8a81385 cmd/soju: bump max number of opened files
The bouncer process may be dealing with many opened FDs. The default
on Linux is 1024. To support bouncers with a lot of users, bump
RLIMIT_NOFILE to the max as advised in [1].

[1]: http://0pointer.net/blog/file-descriptor-limits.html

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@687 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-15 20:22:43 +00:00
contact
f2e55a2d73 Add title config option
Closes: https://todo.sr.ht/~emersion/soju/146

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@662 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-02 21:38:07 +00:00
contact
1f6af94dc9 Add context args to Database interface
This is a mecanical change, which just lifts up the context.TODO()
calls from inside the DB implementations to the callers.

Future work involves properly wiring up the contexts when it makes
sense.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@652 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-18 17:15:15 +00:00
contact
4259bf7d2d Don't strip spaces at start of MOTD
This breaks ASCII art. Instead, just drop the final newline if any.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@637 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-13 10:53:43 +00:00
contact
a3d6a053a1 Add bouncer MOTD
Closes: https://todo.sr.ht/~emersion/soju/137

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@636 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-13 08:58:34 +00:00
hubert
800a169ef4 PostgreSQL support
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@620 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-11 13:21:04 +00:00
contact
1865033ed1 Add max-user-networks config option
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@612 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-10-07 18:43:10 +00:00
chris
59c133b98d Set a higher timeout for proxyproto listeners
go-proxyproto added support for a read timeout in 0.6.0[1] and
defaulted it to 200ms. After this time if no data is read on
the socket, it is closed.

This is _really_ low if the underlying connection is a TLS
one as no data pops out the other end until the handshake is
done. It effectively limits you to TLS connections within
a 50ms RTT of your bouncer with clients that are fast enough
at responding.

It appears that HexChat on Arch is somehow slow enough at
TLS connections thant it consistently takes longer than
200ms even over localhost, meaning it outright can't connect
to soju any longer.

To make this a lot less painful, have soju pass in a read
timeout of 5 seconds. This feels like a reasonable tradeoff
between keeping (possibly malicious) connections open and
accepting the realities of network connections.

[1]: https://github.com/pires/go-proxyproto/issues/65

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@592 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-09-19 15:00:40 +00:00
rafael
3a77807ff7 Check for TLS config in wss listeners
Previously http.Server.ListenAndServeTLS would return a not very helpful
error about a failed open. This adds a check similar to the one in the
ircs case that should make it clearer to operators what the error is.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@581 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-09-09 08:06:31 +00:00
sir
ea00b9e158 db: refactor into interface
This refactors the SQLite-specific bits into db_sqlite.go. A future
patch will add PostgreSQL support.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@531 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-05-25 14:35:39 +00:00
contact
454278bcff sojuctl: don't use log.Fatalf in readPassword
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@503 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-04-19 12:11:25 +00:00
contact
2a4e5450ec cmd/soju: allow specifying -listen multiple times
Closes: https://todo.sr.ht/~emersion/soju/67

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@491 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-31 17:02:40 +00:00
delthas
98d3ad1e55 Increase downstream TCP keepalive interval to 1 hour
The rationale for increasing the TCP keepalive interval from 15 seconds
(default) to 1 hour follows.

- Why increasing TCP keepalives for downstream connections is not an
  issue wrt to detecting connection interruptions

The use case of TCP keepalives is detecting whether a TCP connection was
forcefully shut down without receiving any TCP FIN or RST frame, when no
data are sent from that endpoint to the other peer.

If any data is sent from the peer and is not ACKed because the
connection was interrupted, the socket will be closed after the TCP RTO
(usually a few seconds) anyway, without the need for TCP keepalives.

Therefore the only use of TCP keepalives is making sure that a peer that
is not writing anything to the socket, and is actively reading and
waiting for new stream data to be received, can, - instead of waiting
forever to receive packets that will never arrive because the connection
was interrupted -, detect this disconnection, close the connection
locally, then try to connect again to its peer.

This only makes sense from a client point-of-view. When an IRC client is
not write(2)ing anything to the socket but is simply waiting for new
messages to arrive, ie read(2)ing on the socket, it must ensure that the
connection is still alive so that any new messages will indeed be sent
to him. So that IRC client should probably enable TCP keepalives.

However, when an IRC server is not writing anything to its downstream
socket, it doesn't care if it misses any messages from its downstream
client: in any case, the downstream client will instantly detect when
its messages are not reaching its server, because of the TCP RTO
(keepalives are not even needed in the client in that specific case),
and will try to reconnect to the server.

Thus TCP keepalives should be enabled for upstream connections, in
order to make sure that soju does not miss any messages coming from
upstream servers, but TCP keepalives are not needed for downstream
connections.

- Why increasing TCP keepalives for downstream connections is not an
  issue wrt security, performance, and server socket resources
  exhaustion

TCP keepalives are orthogonal to security. Malicious clients can open
thousands of TCP connections and keep them open with minimal
bookkeeping, and TCP keepalives will not prevent attacks planning to
use up all available sockets to soju.

It is also unlikely that soju will keep many connections open, and in
the event that thousands of dead, disconnected connections are active in
soju, any upstream message that needs to be sent to downstreams will
disconnect all disconnected downstreams after the TCP RTO (a few
seconds). Performance could only be slightly affected in the few seconds
before a TCP RTO if many messages were sent to a very large number of
disconnected connections, which is extremely unlikely and not a large
impact to performance either.

- Why increasing TCP keepalives could be helpful to some clients running
  on mobile devices

In the current state of IRC, most clients running on mobile devices
(mostly running Android and iOS) will probably need to stay connected
at all times, even when the application is in background, in order to
receive private messages and highlight notifications, complete chat
history (and possibly reduced connection traffic due to avoiding all the
initial messages traffic, including all NAMES and WHO replies which
are quite large).

This means most IRC clients on mobile devices will keep a socket open at
all times, in background. When a mobile device runs on a cellular data
connection, it uses the phone wireless radio to transmit all TCP
packets, including TCP packets without user data, for example TCP
keepalives.

On a typical mobile device, a wireless radio consumes significant power
when full active, so it switches between several energy states in order
to conserve power when not in use. It typically has 3 energy states,
from Standby, when no messages are sent, to Low Power, to Full Power;
and switches modes on an average time scale of 15s. This means that any
time any TCP packet is sent from any socket on the device, the radio
switches to a high-power energy state, sends the packet, then stays on
that energy state for around 15s, then goes back to Standby. This
does include TCP keepalives.

If a TCP keepalive of 15s was used, this means that the IRC server would
force all clients running on mobile devices to send a TCP keepalive
packet at least once every 15s, which means that the radio would stay
in its high-power energy state at all times. This would consume a
very significant amount of power and use up battery much faster.

Even though it would seem at first that a mobile device would have many
different sockets open at any time; actually, a typical Android device
typically has at one background socket open, with Firebase Cloud
Messaging, for receiving instant push notifications (for example, for
the equivalent of IRC highlights on other messaging platforms), and
perhaps a socket open for the current foreground app. When the current
foreground app does not use the network, or when no app is currently
used and the phone is in sleep mode, and no notifications are sent, then
the device can effectively have no wireless radio usage at all. This
makes removing TCP keepalives extremely significant with regard to the
mobile device battery usage.

Increasing the TCP keepalive from soju lets downstream clients choose
their own keepalive interval and therefore possibly save battery for
mobile devices. Most modern mobile devices have complex heuristics for
when to sleep the CPU and wireless radio, and have specific rules for
TCP keepalives depending on the current internet connection, sleep
state, etc.

By increasing the downstream TCP keepalive to such a high period, soju
lets clients choose their most optimal TCP keepalive period, which means
that in turn clients can possibly let their mobile device platform
choose best that keepalive for them, thus letting them save battery in
those cases.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@477 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-24 17:04:44 +00:00
contact
58ae3a66da Fix panic on GetCertificate
Fixes the following panic:

    panic: interface conversion: interface {} is tls.Certificate, not *tls.Certificate

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@476 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-19 08:27:19 +00:00
contact
aeb17fabe0 Reload TLS certs on SIGHUP
References: https://todo.sr.ht/~emersion/soju/42

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@475 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-18 13:07:03 +00:00
contact
955708cb27 Don't add "irc" in ALPN list for WebSocket servers
This is incorrect because HTTP listeners don't handle plain IRC
connections. This also prevents net/http from setting up an HTTP/2
server.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@470 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-18 10:33:30 +00:00
contact
c9fb9485c5 Add Unix socket listener
Closes: https://todo.sr.ht/~emersion/soju/51

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@466 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-16 08:27:40 +00:00
contact
5f0bf99508 Add irc to ALPN protocols
The new ALPN token has been approved [1]. We can start using it now.

[1]: https://mailarchive.ietf.org/arch/msg/tls-reg-review/i8YyT82XUtEgR-oXMG3sbyWYT8E/

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@455 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-02-24 18:41:12 +00:00
contact
26f056e557 Add support for graceful shutdown
Closes: https://todo.sr.ht/~emersion/soju/45

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@449 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-02-09 16:34:46 +00:00
coder.kalyan
efee4886fb sojuctl: change-password: check if user exists
When changing the password, checks if the user exists *before* prompting
for a password change, instead of after.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@432 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-11-26 18:27:08 +00:00
contact
d0fc861d00 Add support for the PROXY protocol
IPs whitelisted in accept-proxy-ip can now use the PROXY protocol to
indicate the original source/destination addresses.

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

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@418 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-09-07 19:28:24 +00:00
contact
3f55df1137 Set Server.AcceptProxyIPs
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@417 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-09-07 18:58:49 +00:00
contact
10467550f0 Add an ident server
Closes: https://todo.sr.ht/~emersion/soju/69

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@385 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 08:59:06 +00:00
contact
420fb9231f cmd/sojuctl: read user from DB before updating it
This makes sure we don't overwrite other fields, such as Admin.

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

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@380 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 08:21:49 +00:00
delthas
55d8735859 sojuctl: Add support for creating admin users
This adds a new flag, `-admin` for creating admin users, which can
access admin service commands, among which create-user to create other
users on-the-fly.

Since the person running the commands in the README will be the local
soju administrator, the user they create should be admin as well, hence
the README update.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@330 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-08 20:30:09 +00:00
delthas
e362c6ff27 Fix: Check the stdin scanner for errors when reading the password
Reading from stdin with Scanner.Scan() can either fail because of a read
error, or return no bytes because the EOF was reached.

This adds support for checking these cases before actually reading the
password.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@326 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-08 20:30:09 +00:00
contact
2a42f8a928 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: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@324 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-08 09:59:03 +00:00
contact
18b2777d5e 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: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@323 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-07 12:13:46 +00:00
contact
894d671441 Allow multiple listeners, default to ircs
Users can now specify multiple "listen" directives in their
configuration file. If -listen is specified on the CLI, it's added to
the list of listeners.

Listeners are now parsed as URLs. If the scheme is missing "ircs" is
assumed. URLs allow to enable/disable TLS on a per-listener basis and
will be used for Unix sockets too.

The default listening address is changed from irc+insecure://:6667 to
ircs://:6697. This avoids setting up an insecure listener opened to
everybody.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@317 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-04 18:16:23 +00:00
admin
1f6f244d4e Allow to read password when stdin is not a tty.
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@308 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-03 13:51:56 +00:00
admin
0cccd0807a Add ability to change password
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@251 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-10 08:09:02 +00:00
delthas
5d2fbe81f7 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: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@178 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-27 23:07:20 +00:00
contact
8a0ec2140a Rename project to soju
git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@98 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-13 17:13:03 +00:00
contact
97694757be cmd/jouncectl: new command
Allows to create users.

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@84 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-11 18:01:03 +00:00
contact
c85f485ba1 Add SQLite database
Closes: https://todo.sr.ht/~emersion/jounce/9

git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@77 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-03-04 17:22:58 +00:00