Skip to content

Commit

Permalink
Set LINELEN to 8k for clients that support long messages
Browse files Browse the repository at this point in the history
This matches the value already negotiated for cap multiline. I think we
could go up to 16k without difficulty, but 8k is probably sufficient.

This also tells gen_tcp to use an 8k buffer; the default buffer size is
about 1.5k (one TCP packet, maybe?) and cuts off longer commands, with
tragic results.
  • Loading branch information
ToxicFrog committed Feb 12, 2024
1 parent 80dc1da commit 7ece9ae
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/irc/handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,8 @@ defmodule M51.IrcConn.Handler do
"CHANMODES=b,,,i",
"CHANTYPES=#!",
"CHATHISTORY=100",
# Matrix limit is 64k for the whole event, so this is fairly conservative.
"LINELEN=8192",
"MAXTARGETS=1",
# https://github.com/ircv3/ircv3-specifications/pull/510
"MSGREFTYPES=msgid",
Expand Down
2 changes: 1 addition & 1 deletion lib/irc_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule M51.IrcServer do
end

defp accept(port, retries_left \\ 10) do
case :gen_tcp.listen(port, [:binary, :inet6, packet: :line, active: false, reuseaddr: true]) do
case :gen_tcp.listen(port, [:binary, :inet6, packet: :line, active: false, reuseaddr: true, buffer: 8192]) do
{:ok, server_sock} ->
Logger.info("Listening on port #{port}")
loop_accept(server_sock)
Expand Down
2 changes: 1 addition & 1 deletion test/irc/handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule M51.IrcConn.HandlerTest do

@cap_ls_302 ":server. CAP * LS :account-tag batch draft/account-registration=before-connect draft/channel-rename draft/chathistory draft/message-redaction draft/multiline=max-bytes=8192 draft/no-implicit-names draft/sasl-ir echo-message extended-join labeled-response message-tags sasl=PLAIN server-time soju.im/account-required standard-replies userhost-in-names\r\n"
@cap_ls ":server. CAP * LS :account-tag batch draft/account-registration draft/channel-rename draft/chathistory draft/message-redaction draft/multiline draft/no-implicit-names draft/sasl-ir echo-message extended-join labeled-response message-tags sasl server-time soju.im/account-required standard-replies userhost-in-names\r\n"
@isupport "CASEMAPPING=rfc3454 CLIENTTAGDENY=*,-draft/react,-draft/reply CHANLIMIT= CHANMODES=b,,,i CHANTYPES=#! CHATHISTORY=100 MAXTARGETS=1 MSGREFTYPES=msgid PREFIX= TARGMAX=JOIN:1,PART:1 UTF8ONLY :are supported by this server\r\n"
@isupport "CASEMAPPING=rfc3454 CLIENTTAGDENY=*,-draft/react,-draft/reply CHANLIMIT= CHANMODES=b,,,i CHANTYPES=#! CHATHISTORY=100 LINELEN=8192 MAXTARGETS=1 MSGREFTYPES=msgid PREFIX= TARGMAX=JOIN:1,PART:1 UTF8ONLY :are supported by this server\r\n"

setup do
start_supervised!({MockMatrixClient, {self()}})
Expand Down

0 comments on commit 7ece9ae

Please sign in to comment.