From 2fe2edf4ffd79fc722dc313c0ba13b078e2c75fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 26 May 2025 14:48:13 +0200 Subject: [PATCH] Fix signal int sizes --- src/cowboy_http3.erl | 16 ++-------------- test/draft_h3_webtransport_SUITE.erl | 14 ++++++-------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/cowboy_http3.erl b/src/cowboy_http3.erl index bc87ceb6..8a01c795 100644 --- a/src/cowboy_http3.erl +++ b/src/cowboy_http3.erl @@ -556,8 +556,8 @@ early_error(State0=#state{ref=Ref, opts=Opts, peer=Peer}, %% Datagrams. parse_datagram(State, Data) -> - case parse_var_int(Data) of - {ok, QuarterID, Rest} -> + case cow_http3:parse_int(Data) of + {QuarterID, Rest} -> SessionID = QuarterID * 4, case stream_get(State, SessionID) of #stream{status=webtransport_session} -> @@ -571,18 +571,6 @@ parse_datagram(State, Data) -> loop(State) end. -%% @todo Move to Cowlib and use in cow_http3. -parse_var_int(<<0:2, Int:6, Rest/bits>>) -> - {ok, Int, Rest}; -parse_var_int(<<1:2, Int:14, Rest/bits>>) -> - {ok, Int, Rest}; -parse_var_int(<<2:2, Int:30, Rest/bits>>) -> - {ok, Int, Rest}; -parse_var_int(<<3:2, Int:62, Rest/bits>>) -> - {ok, Int, Rest}; -parse_var_int(_) -> - more. - %% Erlang messages. down(State0=#state{opts=Opts, children=Children0}, Pid, Msg) -> diff --git a/test/draft_h3_webtransport_SUITE.erl b/test/draft_h3_webtransport_SUITE.erl index 2832774a..4cde6170 100644 --- a/test/draft_h3_webtransport_SUITE.erl +++ b/test/draft_h3_webtransport_SUITE.erl @@ -115,7 +115,7 @@ accept_session_when_enabled(Config) -> } = do_webtransport_connect(Config), %% Create a bidi stream, send Hello, get Hello back. {ok, BidiStreamRef} = quicer:start_stream(Conn, #{}), - {ok, _} = quicer:send(BidiStreamRef, <<16#41, 0:2, SessionID:6, "Hello">>), + {ok, _} = quicer:send(BidiStreamRef, <<1:2, 16#41:14, 0:2, SessionID:6, "Hello">>), {ok, <<"Hello">>} = rfc9114_SUITE:do_receive_data(BidiStreamRef), ok. @@ -125,8 +125,6 @@ accept_session_when_enabled(Config) -> %% 3.4. Application Protocol Negotiation -%% The user agent MAY include a WT-Available-Protocols header field in the CONNECT request. The WT-Available-Protocols enumerates the possible protocols in preference order. If the server receives such a header, it MAY include a WT-Protocol field in a successful (2xx) response. If it does, the server SHALL include a single choice from the client's list in that field. Servers MAY reject the request if the client did not include a suitable protocol. (3.4) - application_protocol_negotiation(Config) -> doc("Applications can negotiate a protocol to use via WebTransport. " "(draft_webtrans_http3 3.4)"), @@ -162,11 +160,11 @@ unidirectional_streams(Config) -> {ok, LocalStreamRef} = quicer:start_stream(Conn, #{open_flag => ?QUIC_STREAM_OPEN_FLAG_UNIDIRECTIONAL}), {ok, _} = quicer:send(LocalStreamRef, - <<16#54, 0:2, SessionID:6, "Hello">>, + <<1:2, 16#54:14, 0:2, SessionID:6, "Hello">>, ?QUIC_SEND_FLAG_FIN), %% Accept an identical unidi stream. {unidi, RemoteStreamRef} = do_receive_new_stream(), - {nofin, <<16#54, 0:2, SessionID:6>>} = do_receive_data(RemoteStreamRef), + {nofin, <<1:2, 16#54:14, 0:2, SessionID:6>>} = do_receive_data(RemoteStreamRef), {fin, <<"Hello">>} = do_receive_data(RemoteStreamRef), ok. @@ -182,7 +180,7 @@ bidirectional_streams_client(Config) -> } = do_webtransport_connect(Config), %% Create a bidi stream, send Hello, get Hello back. {ok, LocalStreamRef} = quicer:start_stream(Conn, #{}), - {ok, _} = quicer:send(LocalStreamRef, <<16#41, 0:2, SessionID:6, "Hello">>), + {ok, _} = quicer:send(LocalStreamRef, <<1:2, 16#41:14, 0:2, SessionID:6, "Hello">>), %% @todo Use the local do_receive_data instead to have the fin flag. {ok, <<"Hello">>} = rfc9114_SUITE:do_receive_data(LocalStreamRef), ok. @@ -197,10 +195,10 @@ bidirectional_streams_server(Config) -> } = do_webtransport_connect(Config), %% Create a bidi stream, send a special instruction to make it create a bidi stream. {ok, LocalStreamRef} = quicer:start_stream(Conn, #{}), - {ok, _} = quicer:send(LocalStreamRef, <<16#41, 0:2, SessionID:6, "TEST:open_bidi">>), + {ok, _} = quicer:send(LocalStreamRef, <<1:2, 16#41:14, 0:2, SessionID:6, "TEST:open_bidi">>), %% Accept the bidi stream and receive the data. {bidi, RemoteStreamRef} = do_receive_new_stream(), - {nofin, <<16#41, 0:2, SessionID:6>>} = do_receive_data(RemoteStreamRef), + {nofin, <<1:2, 16#41:14, 0:2, SessionID:6>>} = do_receive_data(RemoteStreamRef), {ok, _} = quicer:send(RemoteStreamRef, <<"Hello">>, ?QUIC_SEND_FLAG_FIN), {fin, <<"Hello">>} = do_receive_data(RemoteStreamRef),