23 Commits

Author SHA1 Message Date
koizumi.aoi
cd99ccc1de Drunk as I like
Signed-off-by: Aoi K <koizumi.aoi@chaotic.ninja>

git-svn-id: file:///srv/svn/repo/suika/trunk@804 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2023-03-21 04:45:19 +00:00
contact
d5a071dd91 Add context to {conn,upstreamConn}.SendMessage
This avoids blocking on upstream message rate limiting for too
long.

git-svn-id: file:///srv/svn/repo/suika/trunk@757 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-08 17:03:40 +00:00
contact
8646b0e5db Downgrade conn log messages to debug
git-svn-id: file:///srv/svn/repo/suika/trunk@748 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-06 17:40:37 +00:00
contact
ab7067fa48 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: file:///srv/svn/repo/suika/trunk@747 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-06 17:35:49 +00:00
contact
5d8bf4f0ef Use golang.org/x/time/rate
Instead of hand-rolling our own rate-limiter based on goroutines,
use golang.org/x/time/rate.

git-svn-id: file:///srv/svn/repo/suika/trunk@741 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-12-02 22:52:29 +00:00
contact
896462a4b0 Introduce conn.NewContext
This function wraps a parent context, and returns a new context
cancelled when the connection is closed. This will make it so
operations started from downstreamConn.handleMessage will be
cancelled when the connection is closed.

git-svn-id: file:///srv/svn/repo/suika/trunk@703 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-17 12:13:55 +00:00
contact
8f1a6e4432 Allow most config options to be reloaded
Closes: https://todo.sr.ht/~emersion/soju/42

git-svn-id: file:///srv/svn/repo/suika/trunk@691 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-11-15 23:38:04 +00:00
contact
d046f6b294 Workaround lack of net.ErrClosed in WebSocket library
git-svn-id: file:///srv/svn/repo/suika/trunk@594 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-09-21 09:49:48 +00:00
contact
692d48de9e Silence net.ErrClosed errors
git-svn-id: file:///srv/svn/repo/suika/trunk@519 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-05-19 22:07:44 +00:00
contact
81f4195dd9 Correctly set WebSocket read/write deadline
The methods didn't have pointer receivers. Thus the deadline fields
were only updated for the local variable.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@465 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2021-03-16 08:19:12 +00:00
hubert
e6d1490b49 Make sure that WebSocket messages are valid UTF-8
... by replacing invalid bytes with the REPLACEMENT CHARACTER U+FFFD

This is better than:
- discarding the whole message, since the user would not see it...
- removing invalid bytes, since the user would not see their presence,
- converting the encoding (this is actually not possible).

Contrary to its documentation, strings.ToValidUTF8 doesn't copy the
string if it's valid UTF-8:
<https://golang.org/src/strings/strings.go?s=15815:15861#L623>

git-svn-id: file:///srv/svn/repo/suika/trunk@415 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-09-02 15:09:32 +00:00
contact
a3c470c0fd go fmt
git-svn-id: file:///srv/svn/repo/suika/trunk@402 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-20 07:13:56 +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
7fce9bcc76 Add conn.{Local,Remote}Addr
git-svn-id: file:///srv/svn/repo/suika/trunk@384 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 08:35:05 +00:00
contact
9880c34024 Add ircConn.LocalAddr
git-svn-id: file:///srv/svn/repo/suika/trunk@383 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-08-11 08:34:38 +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
8bf8de560b Return io.EOF on websocket connection closure
git-svn-id: file:///srv/svn/repo/suika/trunk@341 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-29 08:24:41 +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
contact
5aef4e44a8 Introduce ircConn
This interface will allow a conn to be backed by a websocket.

git-svn-id: file:///srv/svn/repo/suika/trunk@315 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-04 15:27:57 +00:00
contact
e4b8266f5c Remove setKeepAlive
Go sets a default keep-alive interval of 15 seconds on all TCP
connections, if the platform supports it. See
net.ListenConfig.KeepAlive and net.Dialer.KeepAlive.

git-svn-id: file:///srv/svn/repo/suika/trunk@314 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-04 14:58:31 +00:00
contact
bbae37410e Close net.Conn in conn.Close
Close the connection in conn.Close. This ensures the connection isn't
still alive after conn.Close, which would cause issues when
disconnecting and reconnecting quickly to an upstream server.

git-svn-id: file:///srv/svn/repo/suika/trunk@312 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-06-04 10:18:51 +00:00
contact
443eeb2b5a Use a lock to protect conn.{closed,outgoing}
Unfortunately, I don't think there's a good way to implement net.Conn
semantics on top of channels. The Close and SendMessage methods should
gracefully fail without panicking if the connection is already closed.
Using only channels leads to race conditions.

We could remove the lock if Close and SendMessage are only called from a
single goroutine. However that's not the case right now.

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

git-svn-id: file:///srv/svn/repo/suika/trunk@280 f0ae65fe-ee39-954e-97ec-027ff2717ef4
2020-04-30 08:35:02 +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