Commit Graph

15 Commits

Author SHA1 Message Date
Simon Ser
c8a54235d0 Silence net.ErrClosed errors 2021-05-20 00:07:44 +02:00
Simon Ser
67fb669434 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
2021-03-16 09:19:12 +01:00
Hubert Hirtz
42828d68e9
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>
2020-09-02 17:09:32 +02:00
Simon Ser
e523deb15c
go fmt 2020-08-20 09:13:56 +02:00
Simon Ser
bdb132ad98
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
2020-08-19 19:42:33 +02:00
Simon Ser
6faa081a7c
Add conn.{Local,Remote}Addr 2020-08-11 10:35:05 +02:00
Simon Ser
20c26d113c
Add ircConn.LocalAddr 2020-08-11 10:34:38 +02:00
Simon Ser
3397965dea
Add RemoteAddr to ircConn interface 2020-07-01 17:02:37 +02:00
Simon Ser
0fa07f5f9a
Return io.EOF on websocket connection closure 2020-06-29 10:24:41 +02:00
Simon Ser
d0cf1d2882
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
2020-06-07 14:13:46 +02:00
Simon Ser
283d4bf14c
Introduce ircConn
This interface will allow a conn to be backed by a websocket.
2020-06-04 17:27:57 +02:00
Simon Ser
77faf72fa3
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.
2020-06-04 16:58:31 +02:00
Simon Ser
bee2001e29
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.
2020-06-04 12:18:51 +02:00
Simon Ser
e9cebb6fe3
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
2020-04-30 10:35:02 +02:00
Simon Ser
2a0696b6bb
Introduce conn for common connection logic
This centralizes the common upstream & downstream bits.
2020-04-03 16:35:08 +02:00